mirror of
https://github.com/airgradienthq/arduino.git
synced 2025-07-17 18:52:07 +02:00
Restart device after PMS sensor read failed 10 times
This commit is contained in:
@ -12,6 +12,7 @@ bool PMSBase::begin(Stream *stream) {
|
||||
this->stream = stream;
|
||||
|
||||
failed = true;
|
||||
failCount = 0;
|
||||
lastRead = 0; // To read buffer on handle without wait after 1.5sec
|
||||
|
||||
this->stream->flush();
|
||||
@ -147,6 +148,36 @@ void PMSBase::handle() {
|
||||
*/
|
||||
bool PMSBase::isFailed(void) { return failed; }
|
||||
|
||||
/**
|
||||
* @brief Increate number of fail
|
||||
*
|
||||
*/
|
||||
void PMSBase::updateFailCount(void) {
|
||||
if (failCount < failCountMax) {
|
||||
failCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset number of fail
|
||||
*
|
||||
*/
|
||||
void PMSBase::resetFailCount(void) {failCount = 0;}
|
||||
|
||||
/**
|
||||
* @brief Get number of fail
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMSBase::getFailCount(void) { return failCount; }
|
||||
|
||||
/**
|
||||
* @brief Get maximum of fail count max
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMSBase::getFailCountMax(void) { return failCountMax; }
|
||||
|
||||
/**
|
||||
* @brief Read PMS 0.1 ug/m3 with CF = 1 PM estimates
|
||||
*
|
||||
|
@ -3,11 +3,17 @@
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
#define PMS_FAIL_COUNT_SET_INVALID 3
|
||||
|
||||
class PMSBase {
|
||||
public:
|
||||
bool begin(Stream *stream);
|
||||
void handle();
|
||||
bool isFailed(void);
|
||||
void updateFailCount(void);
|
||||
void resetFailCount(void);
|
||||
int getFailCount(void);
|
||||
int getFailCountMax(void);
|
||||
uint16_t getRaw0_1(void);
|
||||
uint16_t getRaw2_5(void);
|
||||
uint16_t getRaw10(void);
|
||||
@ -36,6 +42,8 @@ private:
|
||||
int packageIndex;
|
||||
bool failed = false;
|
||||
uint32_t lastRead;
|
||||
const int failCountMax = 10;
|
||||
int failCount = 0;
|
||||
|
||||
int16_t toI16(char *buf);
|
||||
uint16_t toU16(char* buf);
|
||||
|
@ -175,3 +175,33 @@ void PMS5003::handle(void) { pms.handle(); }
|
||||
* @return false Communication timeout or sensor has removed
|
||||
*/
|
||||
bool PMS5003::isFailed(void) { return pms.isFailed(); }
|
||||
|
||||
/**
|
||||
* @brief Increate number of fail
|
||||
*
|
||||
*/
|
||||
void PMS5003::updateFailCount(void) {
|
||||
pms.updateFailCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset fail count
|
||||
*
|
||||
*/
|
||||
void PMS5003::resetFailCount(void) {
|
||||
pms.resetFailCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get number of fail count
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003::getFailCount(void) { return pms.getFailCount(); }
|
||||
|
||||
/**
|
||||
* @brief Get number of fail count max
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||
|
@ -19,6 +19,10 @@ public:
|
||||
void end(void);
|
||||
void handle(void);
|
||||
bool isFailed(void);
|
||||
void updateFailCount(void);
|
||||
void resetFailCount(void);
|
||||
int getFailCount(void);
|
||||
int getFailCountMax(void);
|
||||
int getPm01Ae(void);
|
||||
int getPm25Ae(void);
|
||||
int getPm10Ae(void);
|
||||
|
@ -216,3 +216,32 @@ void PMS5003T::handle(void) { pms.handle(); }
|
||||
*/
|
||||
bool PMS5003T::isFailed(void) { return pms.isFailed(); }
|
||||
|
||||
/**
|
||||
* @brief Increate number of fail
|
||||
*
|
||||
*/
|
||||
void PMS5003T::updateFailCount(void) {
|
||||
pms.updateFailCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reset fail count
|
||||
*
|
||||
*/
|
||||
void PMS5003T::resetFailCount(void) {
|
||||
pms.resetFailCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Get fail count
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003T::getFailCount(void) { return pms.getFailCount(); }
|
||||
|
||||
/**
|
||||
* @brief Get fail count max
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
int PMS5003T::getFailCountMax(void) { return pms.getFailCountMax(); }
|
||||
|
@ -22,6 +22,10 @@ public:
|
||||
|
||||
void handle(void);
|
||||
bool isFailed(void);
|
||||
void updateFailCount(void);
|
||||
void resetFailCount(void);
|
||||
int getFailCount(void);
|
||||
int getFailCountMax(void);
|
||||
int getPm01Ae(void);
|
||||
int getPm25Ae(void);
|
||||
int getPm10Ae(void);
|
||||
|
Reference in New Issue
Block a user