2024-03-14 21:17:43 +07:00
|
|
|
#ifndef _PMS5003_BASE_H_
|
|
|
|
#define _PMS5003_BASE_H_
|
2024-02-17 17:28:51 +07:00
|
|
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
2024-08-25 20:21:26 +07:00
|
|
|
#define PMS_FAIL_COUNT_SET_INVALID 3
|
|
|
|
|
2024-03-14 21:17:43 +07:00
|
|
|
class PMSBase {
|
2024-02-17 17:28:51 +07:00
|
|
|
public:
|
|
|
|
bool begin(Stream *stream);
|
2024-03-14 21:17:43 +07:00
|
|
|
void handle();
|
|
|
|
bool isFailed(void);
|
2024-08-25 20:21:26 +07:00
|
|
|
void updateFailCount(void);
|
|
|
|
void resetFailCount(void);
|
|
|
|
int getFailCount(void);
|
|
|
|
int getFailCountMax(void);
|
2024-03-14 21:17:43 +07:00
|
|
|
uint16_t getRaw0_1(void);
|
|
|
|
uint16_t getRaw2_5(void);
|
|
|
|
uint16_t getRaw10(void);
|
|
|
|
uint16_t getPM0_1(void);
|
|
|
|
uint16_t getPM2_5(void);
|
|
|
|
uint16_t getPM10(void);
|
|
|
|
uint16_t getCount0_3(void);
|
|
|
|
uint16_t getCount0_5(void);
|
|
|
|
uint16_t getCount1_0(void);
|
|
|
|
uint16_t getCount2_5(void);
|
|
|
|
|
|
|
|
/** For PMS5003 */
|
|
|
|
uint16_t getCount5_0(void);
|
|
|
|
uint16_t getCount10(void);
|
|
|
|
|
|
|
|
/** For PMS5003T*/
|
2024-08-15 09:10:48 +07:00
|
|
|
int16_t getTemp(void);
|
2024-03-14 21:17:43 +07:00
|
|
|
uint16_t getHum(void);
|
2024-07-20 08:53:19 +07:00
|
|
|
uint8_t getFirmwareVersion(void);
|
2024-08-07 08:50:43 +07:00
|
|
|
uint8_t getErrorCode(void);
|
2024-03-14 21:17:43 +07:00
|
|
|
|
|
|
|
int pm25ToAQI(int pm02);
|
2024-08-26 11:56:01 +07:00
|
|
|
int compensate(int pm25, float humidity);
|
2024-02-17 17:28:51 +07:00
|
|
|
|
|
|
|
private:
|
2024-03-14 21:17:43 +07:00
|
|
|
Stream *stream;
|
|
|
|
char package[32];
|
|
|
|
int packageIndex;
|
|
|
|
bool failed = false;
|
|
|
|
uint32_t lastRead;
|
2024-08-25 20:21:26 +07:00
|
|
|
const int failCountMax = 10;
|
|
|
|
int failCount = 0;
|
2024-03-14 21:17:43 +07:00
|
|
|
|
2024-08-15 09:10:48 +07:00
|
|
|
int16_t toI16(char *buf);
|
|
|
|
uint16_t toU16(char* buf);
|
2024-03-14 21:17:43 +07:00
|
|
|
bool validate(char *buf);
|
2024-02-17 17:28:51 +07:00
|
|
|
};
|
|
|
|
|
2024-03-14 21:17:43 +07:00
|
|
|
#endif /** _PMS5003_BASE_H_ */
|