-
Notifications
You must be signed in to change notification settings - Fork 12
/
MHZ19PWM.h
46 lines (41 loc) · 911 Bytes
/
MHZ19PWM.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <Arduino.h>
#if defined(ARDUINO_ARCH_ESP8266)
#define ISR_ATTR ICACHE_RAM_ATTR
#elif defined(ARDUINO_ARCH_ESP32)
#define ISR_ATTR IRAM_ATTR
#else
#define ISR_ATTR
#endif
enum MHZ_MODE {
MHZ_CONTINUOUS_MODE,
MHZ_DELAYED_MODE,
MHZ_ASYNC_MODE
};
class MHZ19PWM
{
public:
static MHZ19PWM * instance;
static void ISR_ATTR isr();
MHZ19PWM(byte pin, MHZ_MODE mode = MHZ_DELAYED_MODE);
~MHZ19PWM();
void useLimit(unsigned int value);
float getCO2();
void requestData();
bool isDataReady();
private:
MHZ_MODE _mode;
byte _pin;
unsigned int _limit = 5000;
bool _attached = false;
volatile bool _skipLow = false;
volatile float _currentValue = 0;
unsigned long _startHigh = 0;
unsigned long _startLow = 0;
float _timeHigh = 0;
float _timeLow = 0;
void start();
void stop();
void waitForData();
void ISR_ATTR isrInternal();
};