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-02-26 20:52:22 -08:00
|
|
|
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor {} {
|
2022-02-08 10:03:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t MCP9808Sensor::runOnce() {
|
|
|
|
|
unsigned mcp9808Status;
|
|
|
|
|
// Default i2c address for MCP9808
|
|
|
|
|
mcp9808Status = mcp9808.begin(0x18);
|
|
|
|
|
if (!mcp9808Status) {
|
|
|
|
|
DEBUG_MSG("Could not find a valid MCP9808 sensor, check wiring, address, sensor ID!");
|
|
|
|
|
} else {
|
2022-02-26 20:52:22 -08:00
|
|
|
DEBUG_MSG("TelemetrySensor: Opened MCP9808 on default i2c bus");
|
2022-02-08 10:03:34 -07:00
|
|
|
// Reduce resolution from 0.0625 degrees (precision) to 0.125 degrees (high).
|
|
|
|
|
mcp9808.setResolution(2);
|
|
|
|
|
}
|
|
|
|
|
return (MCP_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
bool MCP9808Sensor::getMeasurement(Telemetry *measurement) {
|
2022-02-08 10:03:34 -07:00
|
|
|
measurement->temperature = mcp9808.readTempC();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|