mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-20 17:52:35 +00:00
Scan for i2c sensors in environmental telemetry if enabled (#1492)
* Scan for i2c sensors in environmental telemetry if enabled * Update TelemetrySensor.h * Added surpression. * Remove suppression and fix real bug * Interrogate BME sensor id registers
This commit is contained in:
@@ -4,23 +4,28 @@
|
||||
#include "BME280Sensor.h"
|
||||
#include <Adafruit_BME280.h>
|
||||
|
||||
BME280Sensor::BME280Sensor() : TelemetrySensor {} {
|
||||
BME280Sensor::BME280Sensor() : TelemetrySensor {}
|
||||
{
|
||||
}
|
||||
|
||||
int32_t BME280Sensor::runOnce() {
|
||||
unsigned bme280Status;
|
||||
// Default i2c address for BME280
|
||||
bme280Status = bme280.begin(0x76);
|
||||
if (!bme280Status) {
|
||||
DEBUG_MSG("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
|
||||
// TODO more verbose diagnostics
|
||||
} else {
|
||||
DEBUG_MSG("Telemetry: Opened BME280 on default i2c bus");
|
||||
DEBUG_MSG("Init sensor: TelemetrySensorType_BME280\n");
|
||||
if (!hasSensor(TelemetrySensorType_BME280)) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
return BME_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
bme280Status = bme280.begin(nodeTelemetrySensorsMap[TelemetrySensorType_BME280]);
|
||||
if (!bme280Status) {
|
||||
DEBUG_MSG("Could not connect to any detected BME-280 sensor.\nRemoving from nodeTelemetrySensorsMap.\n");
|
||||
nodeTelemetrySensorsMap[TelemetrySensorType_BME280] = 0;
|
||||
} else {
|
||||
DEBUG_MSG("Opened BME280 on default i2c bus\n");
|
||||
}
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
||||
bool BME280Sensor::getMeasurement(Telemetry *measurement) {
|
||||
DEBUG_MSG("BME280Sensor::getMeasurement\n");
|
||||
measurement->variant.environment_metrics.temperature = bme280.readTemperature();
|
||||
measurement->variant.environment_metrics.relative_humidity = bme280.readHumidity();
|
||||
measurement->variant.environment_metrics.barometric_pressure = bme280.readPressure() / 100.0F;
|
||||
|
||||
Reference in New Issue
Block a user