From fd1f35f6d8af2ec74756d16411fc6beeb62de1dc Mon Sep 17 00:00:00 2001 From: samuelbles07 Date: Tue, 22 Oct 2024 15:28:58 +0700 Subject: [PATCH] Getter to get other PMS sensor data --- src/PMS/PMS.cpp | 14 +++++++++---- src/PMS/PMS5003.cpp | 50 ++++++++++++++++++++++++++++++++++++++++---- src/PMS/PMS5003.h | 10 +++++++++ src/PMS/PMS5003T.cpp | 45 ++++++++++++++++++++++++++++++++++----- src/PMS/PMS5003T.h | 9 ++++++++ 5 files changed, 115 insertions(+), 13 deletions(-) diff --git a/src/PMS/PMS.cpp b/src/PMS/PMS.cpp index 45c16c0..68df585 100644 --- a/src/PMS/PMS.cpp +++ b/src/PMS/PMS.cpp @@ -399,20 +399,26 @@ bool PMSBase::validate(const uint8_t *buf) { } void PMSBase::parse(const uint8_t *buf) { + // Standard particle pms_raw0_1 = toU16(&buf[4]); pms_raw2_5 = toU16(&buf[6]); pms_raw10 = toU16(&buf[8]); + // atmospheric pms_pm0_1 = toU16(&buf[10]); pms_pm2_5 = toU16(&buf[12]); pms_pm10 = toU16(&buf[14]); + + // particle count pms_count0_3 = toU16(&buf[16]); pms_count0_5 = toU16(&buf[18]); pms_count1_0 = toU16(&buf[20]); pms_count2_5 = toU16(&buf[22]); - pms_count5_0 = toU16(&buf[24]); - pms_count10 = toU16(&buf[26]); - pms_temp = toU16(&buf[24]); - pms_hum = toU16(&buf[26]); + pms_count5_0 = toU16(&buf[24]); // PMS5003 only + pms_count10 = toU16(&buf[26]); // PMS5003 only + + // Others + pms_temp = toU16(&buf[24]); // PMS5003T only + pms_hum = toU16(&buf[26]); // PMS5003T only pms_firmwareVersion = buf[28]; pms_errorCode = buf[29]; } diff --git a/src/PMS/PMS5003.cpp b/src/PMS/PMS5003.cpp index 7b021bf..1605375 100644 --- a/src/PMS/PMS5003.cpp +++ b/src/PMS/PMS5003.cpp @@ -81,26 +81,47 @@ bool PMS5003::begin(void) { /** * @brief Read PM1.0 must call this function after @ref readData success * - * @return int PM1.0 index + * @return int PM1.0 index (atmospheric environment) */ int PMS5003::getPm01Ae(void) { return pms.getPM0_1(); } /** * @brief Read PM2.5 must call this function after @ref readData success * - * @return int PM2.5 index + * @return int PM2.5 index (atmospheric environment) */ int PMS5003::getPm25Ae(void) { return pms.getPM2_5(); } /** * @brief Read PM10.0 must call this function after @ref readData success * - * @return int PM10.0 index + * @return int PM10.0 index (atmospheric environment) */ int PMS5003::getPm10Ae(void) { return pms.getPM10(); } /** - * @brief Read PM0.3 must call this function after @ref readData success + * @brief Read PM1.0 must call this function after @ref readData success + * + * @return int PM1.0 index (standard particle) + */ +int PMS5003::getPm01Sp(void) { return pms.getRaw0_1(); } + +/** + * @brief Read PM2.5 must call this function after @ref readData success + * + * @return int PM2.5 index (standard particle) + */ +int PMS5003::getPm25Sp(void) { return pms.getRaw2_5(); } + +/** + * @brief Read PM10 must call this function after @ref readData success + * + * @return int PM10 index (standard particle) + */ +int PMS5003::getPm10Sp(void) { return pms.getRaw10(); } + +/** + * @brief Read particle 0.3 count must call this function after @ref readData success * * @return int PM0.3 index */ @@ -108,6 +129,27 @@ int PMS5003::getPm03ParticleCount(void) { return pms.getCount0_3(); } +/** + * @brief Read particle 1.0 count must call this function after @ref readData success + * + * @return int particle 1.0 count index + */ +int PMS5003::getPm01ParticleCount(void) { return pms.getCount1_0(); } + +/** + * @brief Read particle 2.5 count must call this function after @ref readData success + * + * @return int particle 2.5 count index + */ +int PMS5003::getPm25ParticleCount(void) { return pms.getCount2_5(); } + +/** + * @brief Read particle 10 count must call this function after @ref readData success + * + * @return int particle 10 count index + */ +int PMS5003::getPm10ParticleCount(void) { return pms.getCount10(); } + /** * @brief Convert PM2.5 to US AQI * diff --git a/src/PMS/PMS5003.h b/src/PMS/PMS5003.h index d8fc862..0e3ca13 100644 --- a/src/PMS/PMS5003.h +++ b/src/PMS/PMS5003.h @@ -25,10 +25,20 @@ public: void resetFailCount(void); int getFailCount(void); int getFailCountMax(void); + // Atmospheric environment int getPm01Ae(void); int getPm25Ae(void); int getPm10Ae(void); + // Standard particle + int getPm01Sp(void); + int getPm25Sp(void); + int getPm10Sp(void); + // Particle count int getPm03ParticleCount(void); + int getPm01ParticleCount(void); + int getPm25ParticleCount(void); + int getPm10ParticleCount(void); + int convertPm25ToUsAqi(int pm25); float compensate(float pm25, float humidity); int getFirmwareVersion(void); diff --git a/src/PMS/PMS5003T.cpp b/src/PMS/PMS5003T.cpp index 38ce259..494bf2f 100644 --- a/src/PMS/PMS5003T.cpp +++ b/src/PMS/PMS5003T.cpp @@ -110,33 +110,68 @@ bool PMS5003T::begin(void) { /** * @brief Read PM1.0 must call this function after @ref readData success * - * @return int PM1.0 index + * @return int PM1.0 index (atmospheric environment) */ int PMS5003T::getPm01Ae(void) { return pms.getPM0_1(); } /** * @brief Read PM2.5 must call this function after @ref readData success * - * @return int PM2.5 index + * @return int PM2.5 index (atmospheric environment) */ int PMS5003T::getPm25Ae(void) { return pms.getPM2_5(); } /** * @brief Read PM10.0 must call this function after @ref readData success * - * @return int PM10.0 index + * @return int PM10.0 index (atmospheric environment) */ int PMS5003T::getPm10Ae(void) { return pms.getPM10(); } /** - * @brief Read PM 0.3 Count must call this function after @ref readData success + * @brief Read PM1.0 must call this function after @ref readData success * - * @return int PM 0.3 Count index + * @return int PM1.0 index (standard particle) + */ +int PMS5003T::getPm01Sp(void) { return pms.getRaw0_1(); } + +/** + * @brief Read PM2.5 must call this function after @ref readData success + * + * @return int PM2.5 index (standard particle) + */ +int PMS5003T::getPm25Sp(void) { return pms.getRaw2_5(); } + +/** + * @brief Read PM10 must call this function after @ref readData success + * + * @return int PM10 index (standard particle) + */ +int PMS5003T::getPm10Sp(void) { return pms.getRaw10(); } + +/** + * @brief Read particle 0.3 count must call this function after @ref readData success + * + * @return int particle 0.3 count index */ int PMS5003T::getPm03ParticleCount(void) { return pms.getCount0_3(); } +/** + * @brief Read particle 1.0 count must call this function after @ref readData success + * + * @return int particle 1.0 count index + */ +int PMS5003T::getPm01ParticleCount(void) { return pms.getCount1_0(); } + +/** + * @brief Read particle 2.5 count must call this function after @ref readData success + * + * @return int particle 2.5 count index + */ +int PMS5003T::getPm25ParticleCount(void) { return pms.getCount2_5(); } + /** * @brief Convert PM2.5 to US AQI * diff --git a/src/PMS/PMS5003T.h b/src/PMS/PMS5003T.h index eac4a8d..695439b 100644 --- a/src/PMS/PMS5003T.h +++ b/src/PMS/PMS5003T.h @@ -28,10 +28,19 @@ public: void resetFailCount(void); int getFailCount(void); int getFailCountMax(void); + // Atmospheric environment int getPm01Ae(void); int getPm25Ae(void); int getPm10Ae(void); + // Standard particle + int getPm01Sp(void); + int getPm25Sp(void); + int getPm10Sp(void); + // Particle count int getPm03ParticleCount(void); + int getPm01ParticleCount(void); + int getPm25ParticleCount(void); + int convertPm25ToUsAqi(int pm25); float getTemperature(void); float getRelativeHumidity(void);