-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpm1006.h
52 lines (40 loc) · 1.06 KB
/
pm1006.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
47
48
49
50
51
#include <Arduino.h>
#include <stdbool.h>
#include <stdint.h>
typedef enum {
PM1006_HEADER,
PM1006_LENGTH,
PM1006_DATA,
PM1006_CHECK
} pm1006_state_t;
class PM1006 {
private:
Stream *_serial;
bool _debug;
pm1006_state_t _state;
size_t _rxlen;
size_t _index;
uint8_t _txbuf[16];
uint8_t _rxbuf[20];
uint8_t _checksum;
int build_tx(size_t cmd_len, const uint8_t *cmd_data);
bool process_rx(uint8_t c);
public:
static const int BIT_RATE = 9600;
/**
* Constructor.
*
* @param serial the serial port, NOTE: the serial port has to be configured for a bit rate of PM1006::BIT_RATE !
*/
explicit PM1006(Stream *serial, bool debug = false);
/**
* Reads the PM2.5 value (plus some other yet unknown parameters)
*
* @param pm the PM2.5 value
* @return true if the value was read successfully
*/
bool read_pm25(uint16_t *pm);
// experimentation
bool send_command(size_t cmd_len, const uint8_t *cmd_data);
size_t get_response(uint8_t *rsp_data);
};