mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-22 10:42:49 +00:00
Refactoring some of the i2c boilerplate (#1498)
* Refactoring some of the i2c boilerplate * Default value * Debug statement
This commit is contained in:
@@ -4,31 +4,26 @@
|
||||
#include "MCP9808Sensor.h"
|
||||
#include <Adafruit_MCP9808.h>
|
||||
|
||||
MCP9808Sensor::MCP9808Sensor() : TelemetrySensor {}
|
||||
MCP9808Sensor::MCP9808Sensor() :
|
||||
TelemetrySensor(TelemetrySensorType_MCP9808, "MCP9808")
|
||||
{
|
||||
}
|
||||
|
||||
int32_t MCP9808Sensor::runOnce() {
|
||||
unsigned mcp9808Status;
|
||||
DEBUG_MSG("Init sensor: TelemetrySensorType_MCP9808\n");
|
||||
if (!hasSensor(TelemetrySensorType_MCP9808)) {
|
||||
if (!hasSensor()) {
|
||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
||||
mcp9808Status = mcp9808.begin(nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808]);
|
||||
if (!mcp9808Status) {
|
||||
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\n");
|
||||
// Reduce resolution from 0.0625 degrees (precision) to 0.125 degrees (high).
|
||||
mcp9808.setResolution(2);
|
||||
}
|
||||
return (DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS);
|
||||
status = mcp9808.begin(nodeTelemetrySensorsMap[TelemetrySensorType_MCP9808]);
|
||||
return initI2CSensor();
|
||||
}
|
||||
|
||||
bool MCP9808Sensor::getMeasurement(Telemetry *measurement) {
|
||||
DEBUG_MSG("MCP9808Sensor::getMeasurement\n");
|
||||
void MCP9808Sensor::setup() {
|
||||
mcp9808.setResolution(2);
|
||||
}
|
||||
|
||||
bool MCP9808Sensor::getMetrics(Telemetry *measurement) {
|
||||
DEBUG_MSG("MCP9808Sensor::getMetrics\n");
|
||||
measurement->variant.environment_metrics.temperature = mcp9808.readTempC();
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user