2021-01-17 20:59:48 +00:00
|
|
|
#pragma once
|
|
|
|
#include "../mesh/generated/environmental_measurement.pb.h"
|
2021-10-23 19:10:25 +00:00
|
|
|
#include "ProtobufPlugin.h"
|
|
|
|
#include <DHT.h>
|
|
|
|
#include <DS18B20.h>
|
2021-02-21 21:46:46 +00:00
|
|
|
#include <OLEDDisplay.h>
|
|
|
|
#include <OLEDDisplayUi.h>
|
2021-10-23 19:10:25 +00:00
|
|
|
#include <OneWire.h>
|
2022-01-22 21:09:17 +00:00
|
|
|
#include <Adafruit_Sensor.h>
|
|
|
|
#include <Adafruit_BME280.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-10-23 19:10:25 +00:00
|
|
|
EnvironmentalMeasurementPlugin()
|
|
|
|
: concurrency::OSThread("EnvironmentalMeasurementPlugin"),
|
|
|
|
ProtobufPlugin("EnvironmentalMeasurement", PortNum_ENVIRONMENTAL_MEASUREMENT_APP, &EnvironmentalMeasurement_msg)
|
|
|
|
{
|
|
|
|
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-10-23 19:10:25 +00:00
|
|
|
|
2021-02-21 21:46:46 +00:00
|
|
|
private:
|
2021-03-03 02:12:22 +00:00
|
|
|
float CelsiusToFarenheit(float c);
|
|
|
|
bool firstTime = 1;
|
2021-10-23 19:10:25 +00:00
|
|
|
DHT *dht;
|
|
|
|
OneWire *oneWire;
|
|
|
|
DS18B20 *ds18b20;
|
2022-01-22 21:09:17 +00:00
|
|
|
Adafruit_BME280 bme;
|
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;
|
|
|
|
};
|