Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improv pms5003t #211

Merged
merged 9 commits into from
Sep 20, 2024
45 changes: 43 additions & 2 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,27 @@ bool Sensors::pm1006Read() {
return false;
}

/**
* @brief PMS5003T particulate meter, T&H, sensors read.
* @return true if header and sensor data is right.
*/

bool Sensors::pm5003TRead() {
if (!isSensorRegistered(SENSORS::P5003T)) return false;
pm5003t->handle();
pm1 = pm5003t->getPm01Ae();
pm25 = pm5003t->getPm25Ae();
pm10 = pm5003t->getPm10Ae();
temp = pm5003t->getTemperature();
humi = pm5003t->getRelativeHumidity();
unitRegister(UNIT::PM1);
unitRegister(UNIT::PM25);
unitRegister(UNIT::PM10);
unitRegister(UNIT::HUM);
unitRegister(UNIT::TEMP);
return true;
}

/**
* @brief PMSensor Serial read to basic string
* @param SENSOR_RETRY attempts before failure
Expand Down Expand Up @@ -915,6 +936,10 @@ bool Sensors::pmSensorRead() {
return senseAirS8Read();
break;

case P5003T:
return pm5003TRead();
break;

default:
return false;
break;
Expand Down Expand Up @@ -1252,6 +1277,9 @@ bool Sensors::sensorSerialInit(u_int pms_type, int pms_rx, int pms_tx) {
} else if (pms_type == SENSORS::IKEAVK) {
DEBUG("-->[SLIB] UART detecting type\t: SENSEAIRS8");
if (!serialInit(pms_type, PM1006::BIT_RATE, pms_rx, pms_tx)) return false;
} else if (pms_type == SENSORS::P5003T) {
DEBUG("-->[SLIB] UART detecting type\t: PMS5003T");
if (!serialInit(pms_type, 9600, pms_rx, pms_tx)) return false;
}

// starting auto detection loop
Expand Down Expand Up @@ -1298,6 +1326,13 @@ bool Sensors::pmSensorAutoDetect(u_int pms_type) {
}
}

if (pms_type == SENSORS::P5003T) {
if (PM5003TInit()) {
dev_uart_type = SENSORS::P5003T;
return true;
}
}

if (pms_type == SENSORS::SMHZ19) {
if (CO2Mhz19Init()) {
dev_uart_type = SENSORS::SMHZ19;
Expand Down Expand Up @@ -1350,6 +1385,13 @@ bool Sensors::PM1006Init() {
return pm1006Read();
}

bool Sensors::PM5003TInit() {
pm5003t = new PMS5003T(*_serial);
if (!pm5003t->begin()) return false;
sensorRegister(SENSORS::P5003T);
return true;
}

bool Sensors::CO2CM1106Init() {
DEBUG("-->[SLIB] try to enable sensor\t: CM1106..");
cm1106 = new CM1106_UART(*_serial);
Expand Down Expand Up @@ -1753,9 +1795,8 @@ void Sensors::setSCD4xTempOffset(float offset) {
/// get SCD4x temperature compensation
float Sensors::getSCD4xTempOffset() {
float offset = 0.0;
uint16_t error;
if (isSensorRegistered(SENSORS::SSCD4X)) {
scd4x.stopPeriodicMeasurement();
uint16_t error = scd4x.stopPeriodicMeasurement();
if (error) {
DEBUG("[SLIB] SCD4x stopPeriodicMeasurement()\t: error:", String(error).c_str());
return 0.0;
Expand Down
6 changes: 6 additions & 0 deletions src/Sensors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <SensirionI2CSgp41.h>
#include <SparkFun_Particle_Sensor_SN-GCJA5_Arduino_Library.h>
#include <cm1106_uart.h>
#include <drivers/PMS5003T.h>
#include <drivers/geiger.h>
#include <drivers/pm1006.h>
#include <s8_uart.h>
Expand Down Expand Up @@ -143,6 +144,7 @@ typedef enum UNIT : size_t { SENSOR_UNITS } UNIT;
X(SCM1106, "CM1106", 2) \
X(SAIRS8, "SAIRS8", 2) \
X(IKEAVK, "IKEAVK", 1) \
X(P5003T, "PM5003T", 1) \
X(SSCD30, "SCD30", 2) \
X(SSCD4X, "SCD4X", 2) \
X(SSEN5X, "SEN5X", 1) \
Expand Down Expand Up @@ -266,6 +268,8 @@ class Sensors {
DFRobot_GAS_I2C dfrNO2;
/// Geiger CAJOE object sensor
GEIGER *rad;
/// PMS5003T Plantower with T&H of Airgradient
PMS5003T *pm5003t;

void init(u_int pms_type = 0, int pms_rx = PMS_RX, int pms_tx = PMS_TX);

Expand Down Expand Up @@ -493,13 +497,15 @@ class Sensors {
bool pmGCJA5Read();
bool pmSDS011Read();
bool pm1006Read();
bool pm5003TRead();
bool CO2Mhz19Read();
bool CO2CM1106Read();
bool CO2Mhz19Init();
bool CO2CM1106Init();
bool senseAirS8Init();
bool senseAirS8Read();
bool PM1006Init();
bool PM5003TInit();

bool sps30I2CInit();
bool sps30UARTInit();
Expand Down
Loading
Loading