2021-01-17 20:59:48 +00:00
|
|
|
#pragma once
|
2023-01-18 14:56:47 +00:00
|
|
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
2022-05-01 19:26:05 +00:00
|
|
|
#include "NodeDB.h"
|
2022-05-07 10:31:21 +00:00
|
|
|
#include "ProtobufModule.h"
|
2021-02-21 21:46:46 +00:00
|
|
|
#include <OLEDDisplay.h>
|
|
|
|
#include <OLEDDisplayUi.h>
|
2021-01-17 20:59:48 +00:00
|
|
|
|
2023-01-21 17:22:19 +00:00
|
|
|
class EnvironmentTelemetryModule : private concurrency::OSThread, public ProtobufModule<meshtastic_Telemetry>
|
2021-01-17 20:59:48 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-03-27 14:55:35 +00:00
|
|
|
EnvironmentTelemetryModule()
|
|
|
|
: concurrency::OSThread("EnvironmentTelemetryModule"),
|
2023-01-21 17:22:19 +00:00
|
|
|
ProtobufModule("EnvironmentTelemetry", meshtastic_PortNum_TELEMETRY_APP, &meshtastic_Telemetry_msg)
|
2021-10-23 19:10:25 +00:00
|
|
|
{
|
2023-01-18 20:51:48 +00:00
|
|
|
lastMeasurementPacket = nullptr;
|
|
|
|
setIntervalFromNow(10 * 1000);
|
2021-02-23 02:00:41 +00:00
|
|
|
}
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual bool wantUIFrame() override;
|
2022-07-31 12:11:47 +00:00
|
|
|
#if !HAS_SCREEN
|
2022-05-06 13:41:37 +00:00
|
|
|
void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
|
|
|
#else
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) override;
|
2022-05-06 13:41:37 +00:00
|
|
|
#endif
|
2021-01-17 20:59:48 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/** Called to handle a particular incoming message
|
|
|
|
@return true if you've guaranteed you've handled this message and no other handlers should be considered for it
|
|
|
|
*/
|
2023-01-21 17:22:19 +00:00
|
|
|
virtual bool handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshtastic_Telemetry *p) override;
|
2022-01-24 17:24:40 +00:00
|
|
|
virtual int32_t runOnce() override;
|
2021-03-03 02:12:22 +00:00
|
|
|
/**
|
2022-02-27 04:52:22 +00:00
|
|
|
* Send our Telemetry into the mesh
|
2021-03-03 02:12:22 +00:00
|
|
|
*/
|
2022-10-16 16:36:38 +00:00
|
|
|
bool sendTelemetry(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
2021-10-23 19:10:25 +00:00
|
|
|
|
2021-02-21 21:46:46 +00:00
|
|
|
private:
|
2022-03-20 03:15:32 +00:00
|
|
|
float CelsiusToFahrenheit(float c);
|
2021-03-03 02:12:22 +00:00
|
|
|
bool firstTime = 1;
|
2023-02-02 14:26:31 +00:00
|
|
|
meshtastic_MeshPacket *lastMeasurementPacket;
|
2022-10-16 16:36:38 +00:00
|
|
|
uint32_t sendToPhoneIntervalMs = SECONDS_IN_MINUTE * 1000; // Send to phone every minute
|
|
|
|
uint32_t lastSentToMesh = 0;
|
2021-03-03 02:12:22 +00:00
|
|
|
uint32_t sensor_read_error_count = 0;
|
2022-01-24 07:00:14 +00:00
|
|
|
};
|