From 0b20c46b790872e3fbaaa372397d10b9cb08d888 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 11:39:20 -0500 Subject: [PATCH 01/14] standardize log line beginnings --- src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 76eda3d2d..0497a2b67 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -28,7 +28,7 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { #ifndef NO_ESP32 if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup - DEBUG_MSG("Initializing Environmental Measurement Plugin -- Sender\n"); + DEBUG_MSG("EnvironmentalMeasurement: Initializing as sender\n"); environmentalMeasurementPluginRadio = new EnvironmentalMeasurementPluginRadio(); firstTime = 0; // begin reading measurements from the sensor @@ -45,11 +45,11 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { // so just do what we intend to do on the interval if(sensor_read_error_count > SENSOR_READ_ERROR_COUNT_THRESHOLD) { - DEBUG_MSG("Environmental Measurement Plugin: DISABLED; The SENSOR_READ_ERROR_COUNT_THRESHOLD has been exceed: %d\n",SENSOR_READ_ERROR_COUNT_THRESHOLD); - return(DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); + DEBUG_MSG("EEnvironmentalMeasurement: DISABLED; The SENSOR_READ_ERROR_COUNT_THRESHOLD has been exceed: %d\n",SENSOR_READ_ERROR_COUNT_THRESHOLD); + return(FAILED_STATE_SENSOR_READ_MULTIPLIER * DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); } else if (sensor_read_error_count > 0){ - DEBUG_MSG("Environmental Measurement Plugin: There have been %d sensor read failures.\n",sensor_read_error_count); + DEBUG_MSG("EnvironmentalMeasurement: There have been %d sensor read failures.\n",sensor_read_error_count); } if (! environmentalMeasurementPluginRadio->sendOurEnvironmentalMeasurement() ){ // if we failed to read the sensor, then try again @@ -80,13 +80,13 @@ bool EnvironmentalMeasurementPluginRadio::sendOurEnvironmentalMeasurement(NodeNu DEBUG_MSG("-----------------------------------------\n"); - DEBUG_MSG("Environmental Measurement Plugin: Read data\n"); + DEBUG_MSG("EnvironmentalMeasurement: Read data\n"); DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", m.relative_humidity); DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", m.temperature); if (isnan(m.relative_humidity) || isnan(m.temperature) ){ sensor_read_error_count++; - DEBUG_MSG("Environmental Measurement Plugin: FAILED TO READ DATA\n"); + DEBUG_MSG("EnvironmentalMeasurement: FAILED TO READ DATA\n"); return false; } From 765a6fcc627c6a53d3b770201ade1a6abc06f5ee Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 11:39:45 -0500 Subject: [PATCH 02/14] Display received measurements in logs and on screen --- .../esp32/EnvironmentalMeasurementPlugin.cpp | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 0497a2b67..d141bf8d8 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -20,7 +20,8 @@ uint32_t sensor_read_error_count = 0; #define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 #define SENSOR_READ_ERROR_COUNT_THRESHOLD 5 #define SENSOR_READ_MULTIPLIER 3 - +#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 +#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true DHT dht(DHT_11_GPIO_PIN,DHT11); @@ -66,7 +67,27 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacket &mp, const EnvironmentalMeasurement &p) { - // This plugin doesn't really do anything with the messages it receives. + bool wasBroadcast = mp.to == NODENUM_BROADCAST; + String sender; + + if (nodeDB.getNode(mp.from)){ + sender = nodeDB.getNode(mp.from)->user.short_name; + } + else { + sender = "UNK"; + } + // Show new nodes on LCD screen + if (DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN && wasBroadcast) { + String lcd = String("Env Measured: ") + sender + "\n" + + "T: " + p.temperature + "\n" + + "H: " + p.relative_humidity + "\n"; + screen->print(lcd.c_str()); + } + DEBUG_MSG("-----------------------------------------\n"); + + DEBUG_MSG("EnvironmentalMeasurement: Received data from %s\n",sender); + DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", p.relative_humidity); + DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", p.temperature); return false; // Let others look at this message also if they want } From 5817afd4ac2a632f62eb1ab4abbdcdcc7a021869 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 11:42:03 -0500 Subject: [PATCH 03/14] fix port number for ENVIRONMENTAL_MEASUREMENT_APP --- proto | 2 +- src/mesh/generated/portnums.pb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proto b/proto index 564292ee8..c92fafdf6 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 564292ee83bbd085d0c51a7f882d3a2aa305d6d6 +Subproject commit c92fafdf61b923618a5f671ff2fa5a4a9f8bd65c diff --git a/src/mesh/generated/portnums.pb.h b/src/mesh/generated/portnums.pb.h index 8d262c471..8f261c947 100644 --- a/src/mesh/generated/portnums.pb.h +++ b/src/mesh/generated/portnums.pb.h @@ -18,7 +18,7 @@ typedef enum _PortNum { PortNum_NODEINFO_APP = 4, PortNum_REPLY_APP = 32, PortNum_IP_TUNNEL_APP = 33, - PortNum_ENVIRONMENTAL_MEASUREMENT_APP = 34, + PortNum_ENVIRONMENTAL_MEASUREMENT_APP = 67, PortNum_SERIAL_APP = 64, PortNum_STORE_FORWARD_APP = 65, PortNum_RANGE_TEST_APP = 66, From fc72d16bcb121a6acb81abe6e6a3c65ca50b6cb0 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 11:48:32 -0500 Subject: [PATCH 04/14] Disable the plugin by default --- src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index d141bf8d8..1e6aed778 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -17,6 +17,7 @@ uint32_t sensor_read_error_count = 0; #define DHT_11_GPIO_PIN 13 //TODO: Make a related radioconfig preference to allow less-frequent reads +#define ENVIRONMENTAL_MEASUREMENT_APP_ENABLED false // DISABLED by default; set this to true if you want to use the plugin #define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 #define SENSOR_READ_ERROR_COUNT_THRESHOLD 5 #define SENSOR_READ_MULTIPLIER 3 @@ -27,6 +28,10 @@ DHT dht(DHT_11_GPIO_PIN,DHT11); int32_t EnvironmentalMeasurementPlugin::runOnce() { #ifndef NO_ESP32 + if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ + // If this plugin is not enabled, don't waste any OSThread time on it + return (INT32_MAX); + } if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup DEBUG_MSG("EnvironmentalMeasurement: Initializing as sender\n"); @@ -67,6 +72,10 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacket &mp, const EnvironmentalMeasurement &p) { + if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ + // If this plugin is not enabled, don't handle the packet, and allow other plugins to consume + return false; + } bool wasBroadcast = mp.to == NODENUM_BROADCAST; String sender; From 087945d7cb61b1726e87c188b9eb77bda5700468 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 12:05:23 -0500 Subject: [PATCH 05/14] udpate protobufs --- proto | 2 +- src/mesh/generated/portnums.pb.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/proto b/proto index c92fafdf6..930646441 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit c92fafdf61b923618a5f671ff2fa5a4a9f8bd65c +Subproject commit 9306464417522aa8b25672b324a3bd5e9dec3395 diff --git a/src/mesh/generated/portnums.pb.h b/src/mesh/generated/portnums.pb.h index 8f261c947..496324a86 100644 --- a/src/mesh/generated/portnums.pb.h +++ b/src/mesh/generated/portnums.pb.h @@ -18,10 +18,10 @@ typedef enum _PortNum { PortNum_NODEINFO_APP = 4, PortNum_REPLY_APP = 32, PortNum_IP_TUNNEL_APP = 33, - PortNum_ENVIRONMENTAL_MEASUREMENT_APP = 67, PortNum_SERIAL_APP = 64, PortNum_STORE_FORWARD_APP = 65, PortNum_RANGE_TEST_APP = 66, + PortNum_ENVIRONMENTAL_MEASUREMENT_APP = 67, PortNum_PRIVATE_APP = 256, PortNum_ATAK_FORWARDER = 257 } PortNum; From ae76ce4024b2976ccd88e2b874e8a96f3984f52a Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Sun, 21 Feb 2021 16:46:46 -0500 Subject: [PATCH 06/14] Implement interface for plugins to have custom UI Frames --- src/graphics/Screen.cpp | 31 ++++++++++ src/mesh/MeshPlugin.cpp | 16 ++++- src/mesh/MeshPlugin.h | 15 ++++- .../esp32/EnvironmentalMeasurementPlugin.cpp | 60 +++++++++++++++---- .../esp32/EnvironmentalMeasurementPlugin.h | 15 +++++ 5 files changed, 125 insertions(+), 12 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 40ea25237..d0a235e8c 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -64,6 +64,10 @@ uint8_t imgBattery[16] = {0xFF, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, 0x81, // Threshold values for the GPS lock accuracy bar display uint32_t dopThresholds[5] = {2000, 1000, 500, 200, 100}; +// At some point, we're going to ask all of the plugins if they would like to display a screen frame +// we'll need to hold onto pointers for the plugins that can draw a frame. +std::vector pluginFrames; + // Stores the last 4 of our hardware ID, to make finding the device for pairing easier static char ourId[5]; @@ -144,6 +148,14 @@ static void drawSleepScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int drawIconScreen("Sleeping...", display, state, x, y); } +static void drawPluginFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + DEBUG_MSG("Drawing Plugin Frame %d\n\n", state->currentFrame); + MeshPlugin &pi = *pluginFrames.at(state->currentFrame); + pi.drawFrame(display,state,x,y); + +} + static void drawFrameBluetooth(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { display->setTextAlignment(TEXT_ALIGN_CENTER); @@ -887,6 +899,11 @@ void Screen::setFrames() DEBUG_MSG("showing standard frames\n"); showingNormalScreen = true; + pluginFrames = MeshPlugin::GetMeshPluginsWithUIFrames(); + DEBUG_MSG("Showing %d plugin frames\n", pluginFrames.size()); + int totalFrameCount = MAX_NUM_NODES + NUM_EXTRA_FRAMES + pluginFrames.size(); + DEBUG_MSG("Total frame count: %d\n", totalFrameCount); + // We don't show the node info our our node (if we have it yet - we should) size_t numnodes = nodeStatus->getNumTotal(); if (numnodes > 0) @@ -894,6 +911,18 @@ void Screen::setFrames() size_t numframes = 0; + // put all of the plugin frames first. + // this is a little bit of a dirty hack; since we're going to call + // the same drawPluginFrame handler here for all of these plugin frames + // and then we'll just assume that the state->currentFrame value + // is the same offset into the pluginFrames vector + // so that we can invoke the plugin's callback + for (auto i = pluginFrames.begin(); i != pluginFrames.end(); ++i) { + normalFrames[numframes++] = drawPluginFrame; + } + + DEBUG_MSG("Added plugins. numframes: %d", numframes); + // If we have a critical fault, show it first if (myNodeInfo.error_code) normalFrames[numframes++] = drawCriticalFaultFrame; @@ -922,6 +951,8 @@ void Screen::setFrames() } #endif + DEBUG_MSG("Finished building frames. numframes: %d\n", numframes); + ui.setFrames(normalFrames, numframes); ui.enableAllIndicators(); diff --git a/src/mesh/MeshPlugin.cpp b/src/mesh/MeshPlugin.cpp index ebaee49a6..006ce571b 100644 --- a/src/mesh/MeshPlugin.cpp +++ b/src/mesh/MeshPlugin.cpp @@ -75,4 +75,18 @@ void MeshPlugin::sendResponse(const MeshPacket &req) { void setReplyTo(MeshPacket *p, const MeshPacket &to) { p->to = to.from; p->want_ack = to.want_ack; -} \ No newline at end of file +} + +std::vector MeshPlugin::GetMeshPluginsWithUIFrames() { + + std::vector pluginsWithUIFrames; + for (auto i = plugins->begin(); i != plugins->end(); ++i) { + auto &pi = **i; + if ( pi.wantUIFrame()) { + DEBUG_MSG("Plugin wants a UI Frame\n"); + pluginsWithUIFrames.push_back(&pi); + } + } + return pluginsWithUIFrames; + +} diff --git a/src/mesh/MeshPlugin.h b/src/mesh/MeshPlugin.h index 01af58114..a5fa48445 100644 --- a/src/mesh/MeshPlugin.h +++ b/src/mesh/MeshPlugin.h @@ -2,6 +2,8 @@ #include "mesh/MeshTypes.h" #include +#include +#include /** A baseclass for any mesh "plugin". * * A plugin allows you to add new features to meshtastic device code, without needing to know messaging details. @@ -14,7 +16,7 @@ */ class MeshPlugin { - static std::vector *plugins; + static std::vector *plugins; public: /** Constructor @@ -28,6 +30,10 @@ class MeshPlugin */ static void callPlugins(const MeshPacket &mp); + static std::vector GetMeshPluginsWithUIFrames(); + + virtual void drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { return; } + protected: const char *name; @@ -61,6 +67,13 @@ class MeshPlugin * so that subclasses can (optionally) send a response back to the original sender. */ virtual MeshPacket *allocReply() { return NULL; } + /*** + * @return true if you want to be alloced a UI screen frame + */ + virtual bool wantUIFrame() { return false; } + + + private: /** Messages can be received that have the want_response bit set. If set, this callback will be invoked diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 1e6aed778..1d8ecfab7 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -7,6 +7,8 @@ #include "main.h" #include "../mesh/generated/environmental_measurement.pb.h" #include +#include +#include EnvironmentalMeasurementPlugin *environmentalMeasurementPlugin; EnvironmentalMeasurementPluginRadio *environmentalMeasurementPluginRadio; @@ -17,7 +19,7 @@ uint32_t sensor_read_error_count = 0; #define DHT_11_GPIO_PIN 13 //TODO: Make a related radioconfig preference to allow less-frequent reads -#define ENVIRONMENTAL_MEASUREMENT_APP_ENABLED false // DISABLED by default; set this to true if you want to use the plugin +#define ENVIRONMENTAL_MEASUREMENT_APP_ENABLED true // DISABLED by default; set this to true if you want to use the plugin #define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 #define SENSOR_READ_ERROR_COUNT_THRESHOLD 5 #define SENSOR_READ_MULTIPLIER 3 @@ -26,6 +28,24 @@ uint32_t sensor_read_error_count = 0; DHT dht(DHT_11_GPIO_PIN,DHT11); + +#ifdef HAS_EINK +// The screen is bigger so use bigger fonts +#define FONT_SMALL ArialMT_Plain_16 +#define FONT_MEDIUM ArialMT_Plain_24 +#define FONT_LARGE ArialMT_Plain_24 +#else +#define FONT_SMALL ArialMT_Plain_10 +#define FONT_MEDIUM ArialMT_Plain_16 +#define FONT_LARGE ArialMT_Plain_24 +#endif + +#define fontHeight(font) ((font)[1] + 1) // height is position 1 + +#define FONT_HEIGHT_SMALL fontHeight(FONT_SMALL) +#define FONT_HEIGHT_MEDIUM fontHeight(FONT_MEDIUM) + + int32_t EnvironmentalMeasurementPlugin::runOnce() { #ifndef NO_ESP32 if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ @@ -70,6 +90,28 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { #endif } +void EnvironmentalMeasurementPluginRadio::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) +{ + display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(FONT_MEDIUM); + display->drawString(x, y, "Environment"); + display->setFont(FONT_SMALL); + display->drawString(x, y += fontHeight(FONT_MEDIUM), lastSender+": T:"+ String(lastMeasurement.temperature,2) + " H:" + String(lastMeasurement.relative_humidity,2)); + +} + +String GetSenderName(const MeshPacket &mp) { + String sender; + + if (nodeDB.getNode(mp.from)){ + sender = nodeDB.getNode(mp.from)->user.short_name; + } + else { + sender = "UNK"; + } + return sender; +} + bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacket &mp, const EnvironmentalMeasurement &p) { if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ @@ -77,26 +119,24 @@ bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacke return false; } bool wasBroadcast = mp.to == NODENUM_BROADCAST; - String sender; + + String sender = GetSenderName(mp); - if (nodeDB.getNode(mp.from)){ - sender = nodeDB.getNode(mp.from)->user.short_name; - } - else { - sender = "UNK"; - } // Show new nodes on LCD screen if (DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN && wasBroadcast) { - String lcd = String("Env Measured: ") + sender + "\n" + + String lcd = String("Env Measured: ") +sender + "\n" + "T: " + p.temperature + "\n" + "H: " + p.relative_humidity + "\n"; screen->print(lcd.c_str()); } DEBUG_MSG("-----------------------------------------\n"); - DEBUG_MSG("EnvironmentalMeasurement: Received data from %s\n",sender); + DEBUG_MSG("EnvironmentalMeasurement: Received data from %s\n", sender); DEBUG_MSG("EnvironmentalMeasurement->relative_humidity: %f\n", p.relative_humidity); DEBUG_MSG("EnvironmentalMeasurement->temperature: %f\n", p.temperature); + + lastMeasurement = p; + lastSender = sender; return false; // Let others look at this message also if they want } diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h index 31581b31b..8e9d968ba 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h @@ -1,6 +1,8 @@ #pragma once #include "ProtobufPlugin.h" #include "../mesh/generated/environmental_measurement.pb.h" +#include +#include class EnvironmentalMeasurementPlugin : private concurrency::OSThread @@ -31,6 +33,8 @@ class EnvironmentalMeasurementPluginRadio : public ProtobufPlugin Date: Sun, 21 Feb 2021 16:49:35 -0500 Subject: [PATCH 07/14] fix typo --- src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 1d8ecfab7..6d8938fe8 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -71,7 +71,7 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { // so just do what we intend to do on the interval if(sensor_read_error_count > SENSOR_READ_ERROR_COUNT_THRESHOLD) { - DEBUG_MSG("EEnvironmentalMeasurement: DISABLED; The SENSOR_READ_ERROR_COUNT_THRESHOLD has been exceed: %d\n",SENSOR_READ_ERROR_COUNT_THRESHOLD); + DEBUG_MSG("EnvironmentalMeasurement: DISABLED; The SENSOR_READ_ERROR_COUNT_THRESHOLD has been exceed: %d\n",SENSOR_READ_ERROR_COUNT_THRESHOLD); return(FAILED_STATE_SENSOR_READ_MULTIPLIER * DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); } else if (sensor_read_error_count > 0){ From efaf66947902e70787f7a67ccca9b018c21433e5 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 19:50:51 -0500 Subject: [PATCH 08/14] update Environmental Measurement plugin to use radio config prefs --- proto | 2 +- src/mesh/generated/deviceonly.pb.h | 4 +- src/mesh/generated/mesh.pb.h | 26 +++++++--- .../esp32/EnvironmentalMeasurementPlugin.cpp | 48 +++++++++++++------ 4 files changed, 56 insertions(+), 24 deletions(-) diff --git a/proto b/proto index 930646441..040f62989 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 9306464417522aa8b25672b324a3bd5e9dec3395 +Subproject commit 040f6298976839120b07ee8a34e11494a370d401 diff --git a/src/mesh/generated/deviceonly.pb.h b/src/mesh/generated/deviceonly.pb.h index 99d838d39..45d2bf563 100644 --- a/src/mesh/generated/deviceonly.pb.h +++ b/src/mesh/generated/deviceonly.pb.h @@ -80,10 +80,10 @@ extern const pb_msgdesc_t DeviceState_msg; #define DeviceState_fields &DeviceState_msg /* Maximum encoded size of messages (where known) */ -#define DeviceState_size 6266 +#define DeviceState_size 6290 #ifdef __cplusplus } /* extern "C" */ #endif -#endif \ No newline at end of file +#endif diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index 397a313ea..f0e149e1f 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -208,6 +208,10 @@ typedef struct _RadioConfig_UserPreferences { bool range_test_plugin_save; bool store_forward_plugin_enabled; uint32_t store_forward_plugin_records; + bool environmental_measurement_plugin_enabled; + uint32_t environmental_measurement_plugin_read_error_count_threshold; + uint32_t environmental_measurement_plugin_update_interval; + uint32_t environmental_measurement_plugin_recovery_interval; } RadioConfig_UserPreferences; typedef struct _RouteDiscovery { @@ -360,7 +364,7 @@ extern "C" { #define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0} #define MyNodeInfo_init_default {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0} #define LogRecord_init_default {"", 0, "", _LogRecord_Level_MIN} @@ -374,7 +378,7 @@ extern "C" { #define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0} #define MyNodeInfo_init_zero {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0} #define LogRecord_init_zero {"", 0, "", _LogRecord_Level_MIN} @@ -460,6 +464,10 @@ extern "C" { #define RadioConfig_UserPreferences_range_test_plugin_save_tag 134 #define RadioConfig_UserPreferences_store_forward_plugin_enabled_tag 136 #define RadioConfig_UserPreferences_store_forward_plugin_records_tag 137 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_enabled_tag 140 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_read_error_count_threshold_tag 141 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_update_interval_tag 142 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_recovery_interval_tag 143 #define RouteDiscovery_route_tag 2 #define User_id_tag 1 #define User_long_name_tag 2 @@ -641,7 +649,11 @@ X(a, STATIC, SINGULAR, BOOL, range_test_plugin_enabled, 132) \ X(a, STATIC, SINGULAR, UINT32, range_test_plugin_sender, 133) \ X(a, STATIC, SINGULAR, BOOL, range_test_plugin_save, 134) \ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_enabled, 136) \ -X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_records, 137) +X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_records, 137) \ +X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_enabled, 140) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_read_error_count_threshold, 141) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_update_interval, 142) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_recovery_interval, 143) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -753,13 +765,13 @@ extern const pb_msgdesc_t ToRadio_msg; #define SubPacket_size 275 #define MeshPacket_size 322 #define ChannelSettings_size 95 -#define RadioConfig_size 405 -#define RadioConfig_UserPreferences_size 305 +#define RadioConfig_size 429 +#define RadioConfig_UserPreferences_size 329 #define NodeInfo_size 132 #define MyNodeInfo_size 106 #define LogRecord_size 81 -#define FromRadio_size 414 -#define ToRadio_size 409 +#define FromRadio_size 438 +#define ToRadio_size 433 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 6d8938fe8..785fa75a0 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -18,11 +18,7 @@ EnvironmentalMeasurementPlugin::EnvironmentalMeasurementPlugin() : concurrency:: uint32_t sensor_read_error_count = 0; #define DHT_11_GPIO_PIN 13 -//TODO: Make a related radioconfig preference to allow less-frequent reads -#define ENVIRONMENTAL_MEASUREMENT_APP_ENABLED true // DISABLED by default; set this to true if you want to use the plugin -#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 -#define SENSOR_READ_ERROR_COUNT_THRESHOLD 5 -#define SENSOR_READ_MULTIPLIER 3 +#define DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS 1000 // Some sensors (the DHT11) have a minimum required duration between read attempts #define FAILED_STATE_SENSOR_READ_MULTIPLIER 10 #define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true @@ -47,11 +43,22 @@ DHT dht(DHT_11_GPIO_PIN,DHT11); int32_t EnvironmentalMeasurementPlugin::runOnce() { -#ifndef NO_ESP32 - if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ +#ifndef NO_ESP32 // this only works on ESP32 devices + + /* + Uncomment the preferences below if you want to use the plugin + without having to configure it from the PythonAPI or WebUI. + */ + /*radioConfig.preferences.environmental_measurement_plugin_enabled = 1; + radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5; + radioConfig.preferences.environmental_measurement_plugin_update_interval = 30; + radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600;*/ + + if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ // If this plugin is not enabled, don't waste any OSThread time on it return (INT32_MAX); } + if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup DEBUG_MSG("EnvironmentalMeasurement: Initializing as sender\n"); @@ -69,13 +76,26 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { else { // this is not the first time OSThread library has called this function // so just do what we intend to do on the interval - if(sensor_read_error_count > SENSOR_READ_ERROR_COUNT_THRESHOLD) + if(sensor_read_error_count > radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold) { - DEBUG_MSG("EnvironmentalMeasurement: DISABLED; The SENSOR_READ_ERROR_COUNT_THRESHOLD has been exceed: %d\n",SENSOR_READ_ERROR_COUNT_THRESHOLD); - return(FAILED_STATE_SENSOR_READ_MULTIPLIER * DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); + if (radioConfig.preferences.environmental_measurement_plugin_recovery_interval > 0 ) { + DEBUG_MSG( + "EnvironmentalMeasurement: TEMPORARILY DISABLED; The environmental_measurement_plugin_read_error_count_threshold has been exceed: %d. Will retry reads in %d seconds\n", + radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold, + radioConfig.preferences.environmental_measurement_plugin_recovery_interval); + return(radioConfig.preferences.environmental_measurement_plugin_recovery_interval*1000); + } + DEBUG_MSG( + "EnvironmentalMeasurement: DISABLED; The environmental_measurement_plugin_read_error_count_threshold has been exceed: %d. Reads will not be retried until after device reset\n", + radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold); + return(INT32_MAX); + + } else if (sensor_read_error_count > 0){ - DEBUG_MSG("EnvironmentalMeasurement: There have been %d sensor read failures.\n",sensor_read_error_count); + DEBUG_MSG("EnvironmentalMeasurement: There have been %d sensor read failures. Will retry %d more times\n", + sensor_read_error_count, + radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold-sensor_read_error_count); } if (! environmentalMeasurementPluginRadio->sendOurEnvironmentalMeasurement() ){ // if we failed to read the sensor, then try again @@ -85,8 +105,8 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { } // The return of runOnce is an int32 representing the desired number of // miliseconds until the function should be called again by the - // OSThread library. - return(SENSOR_READ_MULTIPLIER * DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); + // OSThread library. Multiply the preference value by 1000 to convert seconds to miliseconds + return(radioConfig.preferences.environmental_measurement_plugin_update_interval * 1000); #endif } @@ -114,7 +134,7 @@ String GetSenderName(const MeshPacket &mp) { bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacket &mp, const EnvironmentalMeasurement &p) { - if (!ENVIRONMENTAL_MEASUREMENT_APP_ENABLED){ + if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ // If this plugin is not enabled, don't handle the packet, and allow other plugins to consume return false; } From b62b01fe7c3166dc14c9a83f0a9461c0c98d1f69 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 20:18:36 -0500 Subject: [PATCH 09/14] consume the additional details from OLEDDisplayUiState to handle transitions to/from plugin screens better It's still a bit janky, but should work https://github.com/meshtastic/esp8266-oled-ssd1306/pull/2 --- src/graphics/Screen.cpp | 20 +++++++++++++++++-- .../esp32/EnvironmentalMeasurementPlugin.cpp | 4 ++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index d0a235e8c..c21c4335d 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -150,8 +150,24 @@ static void drawSleepScreen(OLEDDisplay *display, OLEDDisplayUiState *state, int static void drawPluginFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { - DEBUG_MSG("Drawing Plugin Frame %d\n\n", state->currentFrame); - MeshPlugin &pi = *pluginFrames.at(state->currentFrame); + uint8_t plugin_frame; + // there's a little but in the UI transition code + // where it invokes the function at the correct offset + // in the array of "drawScreen" functions; however, + // the passed-state doesn't quite reflect the "current" + // screen, so we have to detect it. + if (state->frameState == IN_TRANSITION && state->transitionFrameRelationship == INCOMING) { + // if we're transitioning from the end of the frame list back around to the first + // frame, then we want this to be `0` + plugin_frame = state->transitionFrameTarget; + } + else { + // otherwise, just display the plugin frame that's aligned with the current frame + plugin_frame = state->currentFrame; + DEBUG_MSG("Screen is not in transition. Frame: %d\n\n", plugin_frame); + } + DEBUG_MSG("Drawing Plugin Frame %d\n\n", plugin_frame); + MeshPlugin &pi = *pluginFrames.at(plugin_frame); pi.drawFrame(display,state,x,y); } diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 785fa75a0..4add55f8c 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -49,10 +49,10 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { Uncomment the preferences below if you want to use the plugin without having to configure it from the PythonAPI or WebUI. */ - /*radioConfig.preferences.environmental_measurement_plugin_enabled = 1; + radioConfig.preferences.environmental_measurement_plugin_enabled = 1; radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5; radioConfig.preferences.environmental_measurement_plugin_update_interval = 30; - radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600;*/ + radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600; if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ // If this plugin is not enabled, don't waste any OSThread time on it From 0c9df6ccbdea89a2216dc11ccd3df2780f7d8378 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 20:33:42 -0500 Subject: [PATCH 10/14] disable the app by default --- src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 4add55f8c..785fa75a0 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -49,10 +49,10 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { Uncomment the preferences below if you want to use the plugin without having to configure it from the PythonAPI or WebUI. */ - radioConfig.preferences.environmental_measurement_plugin_enabled = 1; + /*radioConfig.preferences.environmental_measurement_plugin_enabled = 1; radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5; radioConfig.preferences.environmental_measurement_plugin_update_interval = 30; - radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600; + radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600;*/ if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ // If this plugin is not enabled, don't waste any OSThread time on it From 3f1ada29ac8532152d67b59810c90791b966d4e0 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 20:47:35 -0500 Subject: [PATCH 11/14] support independently enabling/disabling the on-device screen and actual measurement --- proto | 2 +- src/mesh/generated/deviceonly.pb.h | 2 +- src/mesh/generated/mesh.pb.h | 33 ++++++++++--------- .../esp32/EnvironmentalMeasurementPlugin.cpp | 33 ++++++++++++++----- .../esp32/EnvironmentalMeasurementPlugin.h | 4 +-- 5 files changed, 46 insertions(+), 28 deletions(-) diff --git a/proto b/proto index 040f62989..d70f6f6f6 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit 040f6298976839120b07ee8a34e11494a370d401 +Subproject commit d70f6f6f669df79c9423795caf34adbd28967e19 diff --git a/src/mesh/generated/deviceonly.pb.h b/src/mesh/generated/deviceonly.pb.h index 45d2bf563..0e933b968 100644 --- a/src/mesh/generated/deviceonly.pb.h +++ b/src/mesh/generated/deviceonly.pb.h @@ -80,7 +80,7 @@ extern const pb_msgdesc_t DeviceState_msg; #define DeviceState_fields &DeviceState_msg /* Maximum encoded size of messages (where known) */ -#define DeviceState_size 6290 +#define DeviceState_size 6293 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/mesh.pb.h b/src/mesh/generated/mesh.pb.h index f0e149e1f..edc74a908 100644 --- a/src/mesh/generated/mesh.pb.h +++ b/src/mesh/generated/mesh.pb.h @@ -208,7 +208,8 @@ typedef struct _RadioConfig_UserPreferences { bool range_test_plugin_save; bool store_forward_plugin_enabled; uint32_t store_forward_plugin_records; - bool environmental_measurement_plugin_enabled; + bool environmental_measurement_plugin_measurement_enabled; + bool environmental_measurement_plugin_screen_enabled; uint32_t environmental_measurement_plugin_read_error_count_threshold; uint32_t environmental_measurement_plugin_update_interval; uint32_t environmental_measurement_plugin_recovery_interval; @@ -364,7 +365,7 @@ extern "C" { #define MeshPacket_init_default {0, 0, 0, {SubPacket_init_default}, 0, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_default {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define RadioConfig_init_default {false, RadioConfig_UserPreferences_init_default, false, ChannelSettings_init_default} -#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_default {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_default {0, false, User_init_default, false, Position_init_default, 0, 0} #define MyNodeInfo_init_default {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0} #define LogRecord_init_default {"", 0, "", _LogRecord_Level_MIN} @@ -378,7 +379,7 @@ extern "C" { #define MeshPacket_init_zero {0, 0, 0, {SubPacket_init_zero}, 0, 0, 0, 0, 0, 0, _MeshPacket_Priority_MIN} #define ChannelSettings_init_zero {0, _ChannelSettings_ModemConfig_MIN, {0, {0}}, "", 0, 0, 0, 0, 0, 0, 0} #define RadioConfig_init_zero {false, RadioConfig_UserPreferences_init_zero, false, ChannelSettings_init_zero} -#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} +#define RadioConfig_UserPreferences_init_zero {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "", "", 0, _RegionCode_MIN, _ChargeCurrent_MIN, _LocationSharing_MIN, _GpsOperation_MIN, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0}, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} #define NodeInfo_init_zero {0, false, User_init_zero, false, Position_init_zero, 0, 0} #define MyNodeInfo_init_zero {0, 0, 0, "", "", "", _CriticalErrorCode_MIN, 0, 0, 0, 0, 0, 0, 0} #define LogRecord_init_zero {"", 0, "", _LogRecord_Level_MIN} @@ -464,10 +465,11 @@ extern "C" { #define RadioConfig_UserPreferences_range_test_plugin_save_tag 134 #define RadioConfig_UserPreferences_store_forward_plugin_enabled_tag 136 #define RadioConfig_UserPreferences_store_forward_plugin_records_tag 137 -#define RadioConfig_UserPreferences_environmental_measurement_plugin_enabled_tag 140 -#define RadioConfig_UserPreferences_environmental_measurement_plugin_read_error_count_threshold_tag 141 -#define RadioConfig_UserPreferences_environmental_measurement_plugin_update_interval_tag 142 -#define RadioConfig_UserPreferences_environmental_measurement_plugin_recovery_interval_tag 143 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_measurement_enabled_tag 140 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_screen_enabled_tag 141 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_read_error_count_threshold_tag 142 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_update_interval_tag 143 +#define RadioConfig_UserPreferences_environmental_measurement_plugin_recovery_interval_tag 144 #define RouteDiscovery_route_tag 2 #define User_id_tag 1 #define User_long_name_tag 2 @@ -650,10 +652,11 @@ X(a, STATIC, SINGULAR, UINT32, range_test_plugin_sender, 133) \ X(a, STATIC, SINGULAR, BOOL, range_test_plugin_save, 134) \ X(a, STATIC, SINGULAR, BOOL, store_forward_plugin_enabled, 136) \ X(a, STATIC, SINGULAR, UINT32, store_forward_plugin_records, 137) \ -X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_enabled, 140) \ -X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_read_error_count_threshold, 141) \ -X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_update_interval, 142) \ -X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_recovery_interval, 143) +X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_measurement_enabled, 140) \ +X(a, STATIC, SINGULAR, BOOL, environmental_measurement_plugin_screen_enabled, 141) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_read_error_count_threshold, 142) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_update_interval, 143) \ +X(a, STATIC, SINGULAR, UINT32, environmental_measurement_plugin_recovery_interval, 144) #define RadioConfig_UserPreferences_CALLBACK NULL #define RadioConfig_UserPreferences_DEFAULT NULL @@ -765,13 +768,13 @@ extern const pb_msgdesc_t ToRadio_msg; #define SubPacket_size 275 #define MeshPacket_size 322 #define ChannelSettings_size 95 -#define RadioConfig_size 429 -#define RadioConfig_UserPreferences_size 329 +#define RadioConfig_size 432 +#define RadioConfig_UserPreferences_size 332 #define NodeInfo_size 132 #define MyNodeInfo_size 106 #define LogRecord_size 81 -#define FromRadio_size 438 -#define ToRadio_size 433 +#define FromRadio_size 441 +#define ToRadio_size 436 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp index 785fa75a0..2d706150d 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.cpp @@ -49,19 +49,20 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { Uncomment the preferences below if you want to use the plugin without having to configure it from the PythonAPI or WebUI. */ - /*radioConfig.preferences.environmental_measurement_plugin_enabled = 1; + /*radioConfig.preferences.environmental_measurement_plugin_measurement_enabled = 1; + radioConfig.preferences.environmental_measurement_plugin_screen_enabled = 1; radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold = 5; radioConfig.preferences.environmental_measurement_plugin_update_interval = 30; radioConfig.preferences.environmental_measurement_plugin_recovery_interval = 600;*/ - if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ - // If this plugin is not enabled, don't waste any OSThread time on it + if (! (radioConfig.preferences.environmental_measurement_plugin_measurement_enabled || radioConfig.preferences.environmental_measurement_plugin_screen_enabled)){ + // If this plugin is not enabled, and the user doesn't want the display screen don't waste any OSThread time on it return (INT32_MAX); } if (firstTime) { // This is the first time the OSThread library has called this function, so do some setup - DEBUG_MSG("EnvironmentalMeasurement: Initializing as sender\n"); + DEBUG_MSG("EnvironmentalMeasurement: Initializing\n"); environmentalMeasurementPluginRadio = new EnvironmentalMeasurementPluginRadio(); firstTime = 0; // begin reading measurements from the sensor @@ -70,10 +71,22 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { // returning the interval here means that the next time OSThread // calls our plugin, we'll run the other branch of this if statement // and actually do a "sendOurEnvironmentalMeasurement()" - dht.begin(); - return(DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); + if (radioConfig.preferences.environmental_measurement_plugin_measurement_enabled) + { + // it's possible to have this plugin enabled, only for displaying values on the screen. + // therefore, we should only enable the sensor loop if measurement is also enabled + dht.begin(); + return(DHT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS); + } + return (INT32_MAX); } else { + if (!radioConfig.preferences.environmental_measurement_plugin_measurement_enabled) + { + // if we somehow got to a second run of this plugin with measurement disabled, then just wait forever + // I can't imagine we'd ever get here though. + return (INT32_MAX); + } // this is not the first time OSThread library has called this function // so just do what we intend to do on the interval if(sensor_read_error_count > radioConfig.preferences.environmental_measurement_plugin_read_error_count_threshold) @@ -110,6 +123,10 @@ int32_t EnvironmentalMeasurementPlugin::runOnce() { #endif } +bool EnvironmentalMeasurementPluginRadio::wantUIFrame() { + return radioConfig.preferences.environmental_measurement_plugin_screen_enabled; +} + void EnvironmentalMeasurementPluginRadio::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) { display->setTextAlignment(TEXT_ALIGN_LEFT); @@ -134,8 +151,8 @@ String GetSenderName(const MeshPacket &mp) { bool EnvironmentalMeasurementPluginRadio::handleReceivedProtobuf(const MeshPacket &mp, const EnvironmentalMeasurement &p) { - if (!radioConfig.preferences.environmental_measurement_plugin_enabled){ - // If this plugin is not enabled, don't handle the packet, and allow other plugins to consume + if (!(radioConfig.preferences.environmental_measurement_plugin_measurement_enabled || radioConfig.preferences.environmental_measurement_plugin_screen_enabled)){ + // If this plugin is not enabled in any capacity, don't handle the packet, and allow other plugins to consume return false; } bool wasBroadcast = mp.to == NODENUM_BROADCAST; diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h index 8e9d968ba..8184f6cb3 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h @@ -44,9 +44,7 @@ class EnvironmentalMeasurementPluginRadio : public ProtobufPlugin Date: Mon, 22 Feb 2021 20:52:10 -0500 Subject: [PATCH 12/14] add missing newline --- src/graphics/Screen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index c21c4335d..80fd807cf 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -937,7 +937,7 @@ void Screen::setFrames() normalFrames[numframes++] = drawPluginFrame; } - DEBUG_MSG("Added plugins. numframes: %d", numframes); + DEBUG_MSG("Added plugins. numframes: %d\n", numframes); // If we have a critical fault, show it first if (myNodeInfo.error_code) From 3a91da5e52496ca5fd21871489efabef42255b43 Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 21:00:05 -0500 Subject: [PATCH 13/14] remove UI render comment log spam --- src/graphics/Screen.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 80fd807cf..8f974a4c0 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -164,9 +164,9 @@ static void drawPluginFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int else { // otherwise, just display the plugin frame that's aligned with the current frame plugin_frame = state->currentFrame; - DEBUG_MSG("Screen is not in transition. Frame: %d\n\n", plugin_frame); + //DEBUG_MSG("Screen is not in transition. Frame: %d\n\n", plugin_frame); } - DEBUG_MSG("Drawing Plugin Frame %d\n\n", plugin_frame); + //DEBUG_MSG("Drawing Plugin Frame %d\n\n", plugin_frame); MeshPlugin &pi = *pluginFrames.at(plugin_frame); pi.drawFrame(display,state,x,y); From ec41c11e584f67f7351e6cd83f0c837f12273f2a Mon Sep 17 00:00:00 2001 From: Charles Crossan Date: Mon, 22 Feb 2021 21:00:41 -0500 Subject: [PATCH 14/14] initialize the last measurement values to something obviously "unread" --- src/plugins/esp32/EnvironmentalMeasurementPlugin.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h index 8184f6cb3..19d73914b 100644 --- a/src/plugins/esp32/EnvironmentalMeasurementPlugin.h +++ b/src/plugins/esp32/EnvironmentalMeasurementPlugin.h @@ -27,7 +27,12 @@ class EnvironmentalMeasurementPluginRadio : public ProtobufPlugin