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-10 12:04:04 -05:00
|
|
|
MCP9808Sensor::MCP9808Sensor() :
|
|
|
|
|
TelemetrySensor(TelemetrySensorType_MCP9808, "MCP9808")
|
2022-06-05 09:50:06 -05:00
|
|
|
{
|
2022-02-08 10:03:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MCP9808Sensor::runOnce() {
|
2022-06-11 16:44:56 -05:00
|
|
|
DEBUG_MSG("Init sensor: %s\n", sensorName);
|
2022-06-10 12:04:04 -05:00
|
|
|
if (!hasSensor()) {
|
2022-06-05 09:50:06 -05:00
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
2022-11-13 14:56:52 +01:00
|
|
|
status = mcp9808.begin(nodeTelemetrySensorsMap[sensorType]);
|
2022-06-10 12:04:04 -05:00
|
|
|
return initI2CSensor();
|
|
|
|
|
}
|
2022-06-05 09:50:06 -05:00
|
|
|
|
2022-06-10 12:04:04 -05:00
|
|
|
void MCP9808Sensor::setup() {
|
|
|
|
|
mcp9808.setResolution(2);
|
2022-02-08 10:03:34 -07:00
|
|
|
}
|
|
|
|
|
|
2022-06-10 12:04:04 -05:00
|
|
|
bool MCP9808Sensor::getMetrics(Telemetry *measurement) {
|
|
|
|
|
DEBUG_MSG("MCP9808Sensor::getMetrics\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;
|
|
|
|
|
}
|