2021-01-17 20:59:48 +00:00
|
|
|
#pragma once
|
|
|
|
#include "ProtobufPlugin.h"
|
|
|
|
#include "../mesh/generated/environmental_measurement.pb.h"
|
2021-02-21 21:46:46 +00:00
|
|
|
#include <OLEDDisplay.h>
|
|
|
|
#include <OLEDDisplayUi.h>
|
2021-03-03 02:12:22 +00:00
|
|
|
#include <DHT.h>
|
2021-01-17 20:59:48 +00:00
|
|
|
|
2021-03-03 02:12:22 +00:00
|
|
|
class EnvironmentalMeasurementPlugin : private concurrency::OSThread, public ProtobufPlugin<EnvironmentalMeasurement>
|
2021-01-17 20:59:48 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-03-03 02:12:22 +00:00
|
|
|
EnvironmentalMeasurementPlugin(): concurrency::OSThread("EnvironmentalMeasurementPlugin"), ProtobufPlugin("EnvironmentalMeasurement", PortNum_ENVIRONMENTAL_MEASUREMENT_APP, &EnvironmentalMeasurement_msg) {
|
2021-02-28 04:23:50 +00:00
|
|
|
lastMeasurementPacket = nullptr;
|
2021-02-23 02:00:41 +00:00
|
|
|
}
|
2021-03-03 02:12:22 +00:00
|
|
|
virtual bool wantUIFrame();
|
2021-02-21 21:46:46 +00:00
|
|
|
virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
|
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
|
|
|
|
*/
|
2021-08-01 18:20:38 +00:00
|
|
|
virtual bool handleReceivedProtobuf(const MeshPacket &mp, EnvironmentalMeasurement *p);
|
2021-03-03 02:12:22 +00:00
|
|
|
virtual int32_t runOnce();
|
|
|
|
/**
|
|
|
|
* Send our EnvironmentalMeasurement into the mesh
|
|
|
|
*/
|
|
|
|
bool sendOurEnvironmentalMeasurement(NodeNum dest = NODENUM_BROADCAST, bool wantReplies = false);
|
|
|
|
|
2021-02-21 21:46:46 +00:00
|
|
|
private:
|
2021-03-03 02:12:22 +00:00
|
|
|
float CelsiusToFarenheit(float c);
|
|
|
|
bool firstTime = 1;
|
|
|
|
DHT* dht;
|
2021-02-28 04:23:50 +00:00
|
|
|
const MeshPacket *lastMeasurementPacket;
|
2021-03-03 02:12:22 +00:00
|
|
|
uint32_t sensor_read_error_count = 0;
|
|
|
|
};
|