mirror of
https://github.com/meshtastic/firmware.git
synced 2025-07-31 19:05:44 +00:00
Enable PM sensor before sending telemetry.
This enables the PM sensor for a predefined period to allow for warmup. Once telemetry is sent, the sensor shuts down again.
This commit is contained in:
parent
e985e97f76
commit
cfc2f59caa
@ -93,8 +93,14 @@ int32_t AirQualityTelemetryModule::runOnce()
|
|||||||
return pmsa003iSensor.wakeUp();
|
return pmsa003iSensor.wakeUp();
|
||||||
#endif /* PMSA003I_ENABLE_PIN */
|
#endif /* PMSA003I_ENABLE_PIN */
|
||||||
|
|
||||||
if (sen5xSensor.hasSensor() && !sen5xSensor.isActive())
|
// Wake up the sensors that need it, before we need to take telemetry data
|
||||||
return sen5xSensor.wakeUp();
|
if ((lastSentToMesh == 0) ||
|
||||||
|
!Throttle::isWithinTimespanMs(lastSentToMesh - SEN5X_WARMUP_MS_1, Default::getConfiguredOrDefaultMsScaled(
|
||||||
|
moduleConfig.telemetry.air_quality_interval,
|
||||||
|
default_telemetry_broadcast_interval_secs, numOnlineNodes))) {
|
||||||
|
if (sen5xSensor.hasSensor() && !sen5xSensor.isActive())
|
||||||
|
return sen5xSensor.wakeUp();
|
||||||
|
}
|
||||||
|
|
||||||
if (((lastSentToMesh == 0) ||
|
if (((lastSentToMesh == 0) ||
|
||||||
!Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled(
|
!Throttle::isWithinTimespanMs(lastSentToMesh, Default::getConfiguredOrDefaultMsScaled(
|
||||||
@ -112,14 +118,14 @@ int32_t AirQualityTelemetryModule::runOnce()
|
|||||||
lastSentToPhone = millis();
|
lastSentToPhone = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - When running this continuously, we are turning on and off the sensors but not sending data to mesh or phone, which turns on the device unnecessarily for a while
|
|
||||||
|
// TODO - Add logic here to send the sensor to idle ONLY if there is enough time to wake it up before the next reading cycle
|
||||||
#ifdef PMSA003I_ENABLE_PIN
|
#ifdef PMSA003I_ENABLE_PIN
|
||||||
pmsa003iSensor.sleep();
|
pmsa003iSensor.sleep();
|
||||||
#endif /* PMSA003I_ENABLE_PIN */
|
#endif /* PMSA003I_ENABLE_PIN */
|
||||||
|
|
||||||
// TODO - Add logic here to send the sensor to idle ONLY if there is enough time to wake it up before the next reading cycle
|
if (sen5xSensor.hasSensor() && sen5xSensor.isActive())
|
||||||
sen5xSensor.idle();
|
sen5xSensor.idle();
|
||||||
|
|
||||||
}
|
}
|
||||||
return min(sendToPhoneIntervalMs, result);
|
return min(sendToPhoneIntervalMs, result);
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,7 @@ bool SEN5XSensor::sendCommand(uint16_t command, uint8_t* buffer, uint8_t byteNum
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Transmit the data
|
// Transmit the data
|
||||||
LOG_INFO("Beginning connection to SEN5X: 0x%x", address);
|
// LOG_INFO("Beginning connection to SEN5X: 0x%x", address);
|
||||||
bus->beginTransmission(address);
|
bus->beginTransmission(address);
|
||||||
size_t writtenBytes = bus->write(toSend, bufferSize);
|
size_t writtenBytes = bus->write(toSend, bufferSize);
|
||||||
uint8_t i2c_error = bus->endTransmission();
|
uint8_t i2c_error = bus->endTransmission();
|
||||||
@ -276,14 +276,14 @@ bool SEN5XSensor::isActive(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint32_t SEN5XSensor::wakeUp(){
|
uint32_t SEN5XSensor::wakeUp(){
|
||||||
LOG_INFO("SEN5X: Attempting to wakeUp sensor");
|
// LOG_INFO("SEN5X: Attempting to wakeUp sensor");
|
||||||
if (!sendCommand(SEN5X_START_MEASUREMENT)) {
|
if (!sendCommand(SEN5X_START_MEASUREMENT)) {
|
||||||
LOG_INFO("SEN5X: Error starting measurement");
|
LOG_INFO("SEN5X: Error starting measurement");
|
||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
}
|
}
|
||||||
delay(50); // From Sensirion Arduino library
|
delay(50); // From Sensirion Arduino library
|
||||||
|
|
||||||
LOG_INFO("SEN5X: Setting measurement mode");
|
// LOG_INFO("SEN5X: Setting measurement mode");
|
||||||
uint32_t now;
|
uint32_t now;
|
||||||
now = getTime();
|
now = getTime();
|
||||||
measureStarted = now;
|
measureStarted = now;
|
||||||
|
Loading…
Reference in New Issue
Block a user