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:
Ben Meadors
2022-06-05 09:50:06 -05:00
committed by GitHub
parent 4ab831c103
commit eafbef0c2f
17 changed files with 133 additions and 98 deletions

View File

@@ -4,25 +4,31 @@
#include "MCP9808Sensor.h"
#include <Adafruit_MCP9808.h>
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor {} {
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor {}
{
}
int32_t MCP9808Sensor::runOnce() {
unsigned mcp9808Status;
// Default i2c address for MCP9808
mcp9808Status = mcp9808.begin(0x18);
DEBUG_MSG("Init sensor: TelemetrySensorType_MCP9808\n");
if (!hasSensor(TelemetrySensorType_MCP9808)) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}
mcp9808Status = mcp9808.begin(nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808]);
if (!mcp9808Status) {
DEBUG_MSG("Could not find a valid MCP9808 sensor, check wiring, address, sensor ID!");
DEBUG_MSG("Could not connect to detected MCP9808 sensor.\n Removing from nodeTelemetrySensorsMap.\n");
nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = 0;
} else {
DEBUG_MSG("TelemetrySensor: Opened MCP9808 on default i2c bus");
DEBUG_MSG("TelemetrySensor: Opened MCP9808 on default i2c bus\n");
// Reduce resolution from 0.0625 degrees (precision) to 0.125 degrees (high).
mcp9808.setResolution(2);
}
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
}
bool MCP9808Sensor::getMeasurement(Telemetry *measurement) {
DEBUG_MSG("MCP9808Sensor::getMeasurement\n");
measurement->variant.environment_metrics.temperature = mcp9808.readTempC();
return true;
}