Optimize PMS sensor read data on active mode send each second

This commit is contained in:
Phat Nguyen committed 2024-09-14 14:05:35 +07:00
1 parent 9ec74450a5
commit 21232ec49d
7 files changed
+171 -164

No files matched your search

+30 -11
View File
@@ -7,9 +7,8 @@
class PMSBase {
public:
bool begin(Stream *stream);
void handle();
bool isFailed(void);
bool begin(HardwareSerial& serial);
void readPackage(HardwareSerial& serial);
void updateFailCount(void);
void resetFailCount(void);
int getFailCount(void);
@@ -24,6 +23,7 @@ public:
uint16_t getCount0_5(void);
uint16_t getCount1_0(void);
uint16_t getCount2_5(void);
bool connected(void);
/** For PMS5003 */
uint16_t getCount5_0(void);
@@ -39,17 +39,36 @@ public:
int compensate(int pm25, float humidity);
private:
Stream *stream;
char package[32];
int packageIndex;
bool failed = false;
uint32_t lastRead;
static const uint8_t package_size = 32;
const int failCountMax = 10;
int failCount = 0;
int16_t toI16(char *buf);
uint16_t toU16(char* buf);
bool validate(char *buf);
uint8_t readBuffer[package_size];
uint8_t readBufferIndex = 0;
unsigned long lastPackage = 0;
bool _connected;
uint16_t pms_raw0_1;
uint16_t pms_raw2_5;
uint16_t pms_raw10;
uint16_t pms_pm0_1;
uint16_t pms_pm2_5;
uint16_t pms_pm10;
uint16_t pms_count0_3;
uint16_t pms_count0_5;
uint16_t pms_count1_0;
uint16_t pms_count2_5;
uint16_t pms_count5_0;
uint16_t pms_count10;
int16_t pms_temp;
uint16_t pms_hum;
uint8_t pms_errorCode;
uint8_t pms_firmwareVersion;
int16_t toI16(const uint8_t *buf);
uint16_t toU16(const uint8_t *buf);
bool validate(const uint8_t *buf);
void parse(const uint8_t* buf);
};
#endif /** _PMS5003_BASE_H_ */