2022-02-26 20:52:22 -08:00
|
|
|
#include "../mesh/generated/telemetry.pb.h"
|
2022-02-08 10:03:34 -07:00
|
|
|
#include "configuration.h"
|
2022-02-26 20:52:22 -08:00
|
|
|
#include "TelemetrySensor.h"
|
2022-02-08 10:03:34 -07:00
|
|
|
#include "MCP9808Sensor.h"
|
|
|
|
|
#include <Adafruit_MCP9808.h>
|
|
|
|
|
|
2022-06-05 09:50:06 -05:00
|
|
|
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor {}
|
|
|
|
|
{
|
2022-02-08 10:03:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MCP9808Sensor::runOnce() {
|
|
|
|
|
unsigned mcp9808Status;
|
2022-06-05 09:50:06 -05:00
|
|
|
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]);
|
2022-02-08 10:03:34 -07:00
|
|
|
if (!mcp9808Status) {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("Could not connect to detected MCP9808 sensor.\n Removing from nodeTelemetrySensorsMap.\n");
|
|
|
|
|
nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808] = 0;
|
2022-02-08 10:03:34 -07:00
|
|
|
} else {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("TelemetrySensor: Opened MCP9808 on default i2c bus\n");
|
2022-02-08 10:03:34 -07:00
|
|
|
// Reduce resolution from 0.0625 degrees (precision) to 0.125 degrees (high).
|
|
|
|
|
mcp9808.setResolution(2);
|
|
|
|
|
}
|
2022-06-05 09:50:06 -05:00
|
|
|
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
2022-02-08 10:03:34 -07:00
|
|
|
}
|
|
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
bool MCP9808Sensor::getMeasurement(Telemetry *measurement) {
|
2022-06-05 09:50:06 -05:00
|
|
|
DEBUG_MSG("MCP9808Sensor::getMeasurement\n");
|
2022-03-27 14:55:35 +00:00
|
|
|
measurement->variant.environment_metrics.temperature = mcp9808.readTempC();
|
2022-02-08 10:03:34 -07:00
|
|
|
return true;
|
|
|
|
|
}
|