2022-02-26 20:52:22 -08:00
|
|
|
#pragma once
|
2023-01-18 08:56:47 -06:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2022-05-01 14:26:05 -05:00
|
|
|
#include "NodeDB.h"
|
2022-06-05 09:50:06 -05:00
|
|
|
#include "main.h"
|
|
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
|
|
|
|
|
2022-05-07 20:31:21 +10:00
|
|
|
class TelemetrySensor
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2022-06-10 12:04:04 -05:00
|
|
|
TelemetrySensor(TelemetrySensorType sensorType, const char *sensorName)
|
|
|
|
|
{
|
|
|
|
|
this->sensorName = sensorName;
|
|
|
|
|
this->sensorType = sensorType;
|
|
|
|
|
this->status = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *sensorName;
|
|
|
|
|
TelemetrySensorType sensorType;
|
|
|
|
|
unsigned status;
|
|
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
int32_t initI2CSensor()
|
|
|
|
|
{
|
2022-06-10 12:04:04 -05:00
|
|
|
if (!status) {
|
2022-12-30 10:27:07 -06:00
|
|
|
LOG_WARN("Could not connect to detected %s sensor.\n Removing from nodeTelemetrySensorsMap.\n", sensorName);
|
2022-06-10 12:04:04 -05:00
|
|
|
nodeTelemetrySensorsMap[sensorType] = 0;
|
|
|
|
|
} else {
|
2022-12-30 10:27:07 -06:00
|
|
|
LOG_INFO("Opened %s sensor on default i2c bus\n", sensorName);
|
2022-06-10 12:04:04 -05:00
|
|
|
setup();
|
|
|
|
|
}
|
|
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
|
|
|
|
virtual void setup();
|
2022-05-07 20:31:21 +10:00
|
|
|
|
|
|
|
|
public:
|
2023-01-18 14:51:48 -06:00
|
|
|
bool hasSensor() { return sensorType < sizeof(nodeTelemetrySensorsMap) && nodeTelemetrySensorsMap[sensorType] > 0; }
|
2022-06-10 12:04:04 -05:00
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
virtual int32_t runOnce() = 0;
|
2022-06-10 12:04:04 -05:00
|
|
|
virtual bool getMetrics(Telemetry *measurement) = 0;
|
2022-02-26 20:52:22 -08:00
|
|
|
};
|