2024-04-29 22:10:49 +12:00
|
|
|
#include "configuration.h"
|
|
|
|
|
|
2024-04-27 18:05:39 +12:00
|
|
|
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
|
|
|
|
|
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"
|
2024-06-16 02:59:22 +02:00
|
|
|
#include "MeshModule.h"
|
2022-05-01 14:26:05 -05:00
|
|
|
#include "NodeDB.h"
|
2023-10-15 02:33:45 +02:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
|
|
class TwoWire;
|
2022-06-05 09:50:06 -05:00
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
#define DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000
|
2023-10-15 02:33:45 +02:00
|
|
|
extern std::pair<uint8_t, TwoWire *> nodeTelemetrySensorsMap[_meshtastic_TelemetrySensorType_MAX + 1];
|
2022-02-26 20:52:22 -08:00
|
|
|
|
2022-05-07 20:31:21 +10:00
|
|
|
class TelemetrySensor
|
|
|
|
|
{
|
|
|
|
|
protected:
|
2023-01-21 18:22:19 +01:00
|
|
|
TelemetrySensor(meshtastic_TelemetrySensorType sensorType, const char *sensorName)
|
2022-06-10 12:04:04 -05:00
|
|
|
{
|
|
|
|
|
this->sensorName = sensorName;
|
|
|
|
|
this->sensorType = sensorType;
|
|
|
|
|
this->status = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char *sensorName;
|
2023-10-15 02:33:45 +02:00
|
|
|
meshtastic_TelemetrySensorType sensorType = meshtastic_TelemetrySensorType_SENSOR_UNSET;
|
2022-06-10 12:04:04 -05:00
|
|
|
unsigned status;
|
2023-06-02 06:32:34 -05:00
|
|
|
bool initialized = false;
|
2022-06-10 12:04:04 -05:00
|
|
|
|
2023-01-18 14:51:48 -06:00
|
|
|
int32_t initI2CSensor()
|
|
|
|
|
{
|
2022-06-10 12:04:04 -05:00
|
|
|
if (!status) {
|
2024-11-06 07:03:25 -06:00
|
|
|
LOG_WARN("Can't connect to detected %s sensor. Remove from nodeTelemetrySensorsMap", sensorName);
|
2023-10-15 02:33:45 +02:00
|
|
|
nodeTelemetrySensorsMap[sensorType].first = 0;
|
2022-06-10 12:04:04 -05:00
|
|
|
} else {
|
2024-10-14 06:11:43 +02:00
|
|
|
LOG_INFO("Opened %s sensor on i2c bus", sensorName);
|
2022-06-10 12:04:04 -05:00
|
|
|
setup();
|
|
|
|
|
}
|
2023-06-02 06:32:34 -05:00
|
|
|
initialized = true;
|
2022-06-10 12:04:04 -05:00
|
|
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
|
|
|
|
}
|
|
|
|
|
virtual void setup();
|
2022-05-07 20:31:21 +10:00
|
|
|
|
|
|
|
|
public:
|
2024-06-16 02:59:22 +02:00
|
|
|
virtual AdminMessageHandleResult handleAdminMessage(const meshtastic_MeshPacket &mp, meshtastic_AdminMessage *request,
|
|
|
|
|
meshtastic_AdminMessage *response)
|
|
|
|
|
{
|
|
|
|
|
return AdminMessageHandleResult::NOT_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-15 02:33:45 +02:00
|
|
|
bool hasSensor() { return nodeTelemetrySensorsMap[sensorType].first > 0; }
|
2022-06-10 12:04:04 -05:00
|
|
|
|
2022-02-26 20:52:22 -08:00
|
|
|
virtual int32_t runOnce() = 0;
|
2023-06-02 06:32:34 -05:00
|
|
|
virtual bool isInitialized() { return initialized; }
|
|
|
|
|
virtual bool isRunning() { return status > 0; }
|
|
|
|
|
|
2023-01-21 18:22:19 +01:00
|
|
|
virtual bool getMetrics(meshtastic_Telemetry *measurement) = 0;
|
2024-04-27 18:05:39 +12:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|