-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPMSX003.h
42 lines (34 loc) · 1.39 KB
/
PMSX003.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
#ifndef __WICKED_DEVICE_PMSX003__
#define __WICKED_DEVICE_PMSX003__
#include <Arduino.h>
#include <SoftwareSerial.h>
#include <HardwareSerial.h>
#include <stdint.h>
class PMSX003 {
public:
PMSX003(HardwareSerial * serial);
PMSX003(SoftwareSerial * swserial);
void setSerial(HardwareSerial *serial);
void setSerial(SoftwareSerial *serial);
boolean begin(void); // puts sensor into passive mode
boolean getSample(float * pm1p0, float * pm2p5, float * pm10); // returns only data fields 4, 5, and 6
boolean getFields(uint16_t * buf); // returns 13 data field values into buf
boolean getRaw(uint8_t * buf); // returns 32 bytes into buf
private:
uint8_t response[32]; // temporary storage for response
HardwareSerial * hwserial;
SoftwareSerial * swserial;
void resetSerial();
void endSerial();
uint8_t read();
void write(uint8_t * value, int size);
void write(uint8_t value);
boolean pmsx003ValidResponse(uint8_t * response);
boolean pmsx003ValidResponse(uint8_t * response, uint8_t length);
uint16_t pmsx003GetValue(uint8_t * response, uint8_t field_index);
boolean pmsx003ConsumeResponse(uint8_t * response);
boolean pmsx003ConsumeResponse(uint8_t * response, uint8_t length);
boolean pmsx003SendRequest(uint8_t * request);
void clearPMSX003SerialInput(void);
};
#endif