mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-23 19:20:41 +00:00
use BSEC2 for ESP32-C3
This commit is contained in:
@@ -13,8 +13,12 @@ int32_t BME680Sensor::runOnce()
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
bme680.begin(nodeTelemetrySensorsMap[sensorType], Wire);
|
||||
#ifdef USE_BSEC2
|
||||
if (bme680.status == BSEC_OK) {
|
||||
#else
|
||||
if (bme680.bsecStatus == BSEC_OK) {
|
||||
bme680.setConfig(bsec_config_iaq);
|
||||
#endif
|
||||
bme680.setConfig(Default_H2S_NonH2S_config);
|
||||
loadState();
|
||||
bme680.updateSubscription(sensorList, 13, BSEC_SAMPLE_RATE_LP);
|
||||
status = 1;
|
||||
@@ -22,6 +26,7 @@ int32_t BME680Sensor::runOnce()
|
||||
status = 0;
|
||||
}
|
||||
|
||||
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
@@ -30,10 +35,17 @@ void BME680Sensor::setup() {}
|
||||
bool BME680Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
bme680.run();
|
||||
#ifdef USE_BSEC2
|
||||
measurement->variant.environment_metrics.temperature = bme680.getData(BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_TEMPERATURE).signal;
|
||||
measurement->variant.environment_metrics.relative_humidity = bme680.getData(BSEC_OUTPUT_SENSOR_HEAT_COMPENSATED_HUMIDITY).signal;
|
||||
measurement->variant.environment_metrics.barometric_pressure = bme680.getData(BSEC_OUTPUT_RAW_PRESSURE).signal / 100.0F;
|
||||
measurement->variant.environment_metrics.gas_resistance = bme680.getData(BSEC_OUTPUT_RAW_GAS).signal / 1000.0;
|
||||
#else
|
||||
measurement->variant.environment_metrics.temperature = bme680.temperature;
|
||||
measurement->variant.environment_metrics.relative_humidity = bme680.humidity;
|
||||
measurement->variant.environment_metrics.barometric_pressure = bme680.pressure / 100.0F;
|
||||
measurement->variant.environment_metrics.gas_resistance = bme680.gasResistance / 1000.0;
|
||||
#endif
|
||||
// Check if we need to save state to filesystem (every STATE_SAVE_PERIOD ms)
|
||||
updateState();
|
||||
return true;
|
||||
@@ -62,12 +74,17 @@ void BME680Sensor::updateState()
|
||||
bool update = false;
|
||||
if (stateUpdateCounter == 0) {
|
||||
/* First state update when IAQ accuracy is >= 3 */
|
||||
if (bme680.iaqAccuracy >= 3) {
|
||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
#ifdef USE_BSEC2
|
||||
accuracy = bme680.getData(BSEC_OUTPUT_IAQ).accuracy;
|
||||
#else
|
||||
accuracy = bme680.iaqAccuracy;
|
||||
#endif
|
||||
if (accuracy >= 3) {
|
||||
LOG_DEBUG("%s state update IAQ accuracy %u >= 3\n", sensorName, accuracy);
|
||||
update = true;
|
||||
stateUpdateCounter++;
|
||||
} else {
|
||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, bme680.iaqAccuracy);
|
||||
LOG_DEBUG("%s not updated, IAQ accuracy is %u >= 3\n", sensorName, accuracy);
|
||||
}
|
||||
} else {
|
||||
/* Update every STATE_SAVE_PERIOD minutes */
|
||||
|
||||
@@ -1,22 +1,35 @@
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#ifdef USE_BSEC2
|
||||
#include <bsec2.h>
|
||||
#else
|
||||
#include <bsec.h>
|
||||
#endif // USE_BSEC2
|
||||
|
||||
#define STATE_SAVE_PERIOD UINT32_C(360 * 60 * 1000) // That's 6 hours worth of millis()
|
||||
|
||||
const uint8_t bsec_config_iaq[] = {
|
||||
#ifdef USE_BSEC2
|
||||
#include "config/Default_H2S_NonH2S/Default_H2S_NonH2S.h"
|
||||
#else
|
||||
const uint8_t Default_H2S_NonH2S_config[] = {
|
||||
#include <config/generic_33v_3s_4d/bsec_iaq.txt>
|
||||
};
|
||||
#endif // USE_BSEC2
|
||||
|
||||
class BME680Sensor : virtual public TelemetrySensor
|
||||
{
|
||||
private:
|
||||
#ifdef USE_BSEC2
|
||||
Bsec2 bme680;
|
||||
#else
|
||||
Bsec bme680;
|
||||
#endif // USE_BSEC2
|
||||
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
const char *bsecConfigFileName = "/prefs/bsec.dat";
|
||||
uint8_t bsecState[BSEC_MAX_STATE_BLOB_SIZE] = {0};
|
||||
uint8_t accuracy = 0;
|
||||
uint16_t stateUpdateCounter = 0;
|
||||
bsec_virtual_sensor_t sensorList[13] = {BSEC_OUTPUT_IAQ,
|
||||
BSEC_OUTPUT_STATIC_IAQ,
|
||||
|
||||
Reference in New Issue
Block a user