Fixes on PMS class

This commit is contained in:
oscgonfer 2025-07-02 13:12:07 +02:00
parent a1c6fdb5a0
commit a10e316893
3 changed files with 12 additions and 5 deletions

View File

@ -74,7 +74,7 @@ int32_t AirQualityTelemetryModule::runOnce()
// Wake up the sensors that need it
#ifdef PMSA003I_ENABLE_PIN
if (pmsa003iSensor.hasSensor() && pmsa003iSensor.state == pmsa003iSensor::State::IDLE)
if (pmsa003iSensor.hasSensor() && !pmsa003iSensor.isActive())
return pmsa003iSensor.wakeUp();
#endif /* PMSA003I_ENABLE_PIN */

View File

@ -48,24 +48,31 @@ int32_t PMSA003ISensor::runOnce()
void PMSA003ISensor::setup()
{
#ifdef PMSA003I_ENABLE_PIN
pinMode(PMSA003I_ENABLE_PIN, OUTPUT);
#endif /* PMSA003I_ENABLE_PIN */
}
#ifdef PMSA003I_ENABLE_PIN
void sleep() {
void PMSA003ISensor::sleep() {
digitalWrite(PMSA003I_ENABLE_PIN, LOW);
state = State::IDLE;
}
uint32_t wakeUp() {
uint32_t PMSA003ISensor::wakeUp() {
digitalWrite(PMSA003I_ENABLE_PIN, HIGH);
state = State::ACTIVE;
}
#endif /* PMSA003I_ENABLE_PIN */
bool PMSA003ISensor::isActive() {
return state == State::ACTIVE;
}
bool PMSA003ISensor::getMetrics(meshtastic_Telemetry *measurement)
{
if (!pmsa003i.read(&pmsa003iData)) {
LOG_WARN("Skip send measurements. Could not read AQIn");
LOG_WARN("Skip send measurements. Could not read AQI");
return false;
}

View File

@ -38,13 +38,13 @@ class PMSA003ISensor : public TelemetrySensor
// the PMSA003I sensor uses about 300mW on its own; support powering it off when it's not actively taking
// a reading
// put the sensor to sleep on startup
pinMode(PMSA003I_ENABLE_PIN, OUTPUT);
State state = State::IDLE;
#else
State state = State::ACTIVE;
#endif
PMSA003ISensor();
bool isActive();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
};