From 1ff3b3326c718b038e5e9fca6cc1f9ad2903e19b Mon Sep 17 00:00:00 2001 From: Balazs Kelemen <10376327+prampec@users.noreply.github.com> Date: Tue, 18 Jan 2022 23:15:54 +0100 Subject: [PATCH 1/2] Temporary fix on canned messages total length. --- src/input/RotaryEncoderInterruptBase.cpp | 4 ++-- src/mesh/generated/admin.pb.h | 2 +- src/mesh/generated/radioconfig.pb.h | 28 +++++++++++----------- src/plugins/CannedMessagePlugin.cpp | 30 ++++++++++++++---------- src/plugins/CannedMessagePlugin.h | 12 +++++++--- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/input/RotaryEncoderInterruptBase.cpp b/src/input/RotaryEncoderInterruptBase.cpp index ba825080f..6330233bb 100644 --- a/src/input/RotaryEncoderInterruptBase.cpp +++ b/src/input/RotaryEncoderInterruptBase.cpp @@ -39,7 +39,7 @@ void RotaryEncoderInterruptBase::init( int32_t RotaryEncoderInterruptBase::runOnce() { InputEvent e; - e.inputEvent = InputEventChar_NULL; + e.inputEvent = InputEventChar_KEY_NONE; e.source = this->_originName; if (this->action == ROTARY_ACTION_PRESSED) @@ -58,7 +58,7 @@ int32_t RotaryEncoderInterruptBase::runOnce() e.inputEvent = this->_eventCcw; } - if (e.inputEvent != InputEventChar_NULL) + if (e.inputEvent != InputEventChar_KEY_NONE) { this->notifyObservers(&e); } diff --git a/src/mesh/generated/admin.pb.h b/src/mesh/generated/admin.pb.h index 2468faa85..a8ce6d4b8 100644 --- a/src/mesh/generated/admin.pb.h +++ b/src/mesh/generated/admin.pb.h @@ -86,7 +86,7 @@ extern const pb_msgdesc_t AdminMessage_msg; #define AdminMessage_fields &AdminMessage_msg /* Maximum encoded size of messages (where known) */ -#define AdminMessage_size 1619 +#define AdminMessage_size 795 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/mesh/generated/radioconfig.pb.h b/src/mesh/generated/radioconfig.pb.h index b6718ab47..c48224585 100644 --- a/src/mesh/generated/radioconfig.pb.h +++ b/src/mesh/generated/radioconfig.pb.h @@ -80,14 +80,14 @@ typedef enum _PositionFlags { } PositionFlags; typedef enum _InputEventChar { - InputEventChar_NULL = 0, - InputEventChar_UP = 17, - InputEventChar_DOWN = 18, - InputEventChar_LEFT = 19, - InputEventChar_RIGHT = 20, - InputEventChar_SELECT = 10, - InputEventChar_BACK = 27, - InputEventChar_CANCEL = 24 + InputEventChar_KEY_NONE = 0, + InputEventChar_KEY_UP = 17, + InputEventChar_KEY_DOWN = 18, + InputEventChar_KEY_LEFT = 19, + InputEventChar_KEY_RIGHT = 20, + InputEventChar_KEY_SELECT = 10, + InputEventChar_KEY_BACK = 27, + InputEventChar_KEY_CANCEL = 24 } InputEventChar; typedef enum _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType { @@ -180,7 +180,7 @@ typedef struct _RadioConfig_UserPreferences { InputEventChar rotary1_event_press; bool canned_message_plugin_enabled; char canned_message_plugin_allow_input_source[16]; - char canned_message_plugin_messages[1024]; + char canned_message_plugin_messages[200]; bool canned_message_plugin_send_bell; } RadioConfig_UserPreferences; @@ -215,9 +215,9 @@ typedef struct _RadioConfig { #define _PositionFlags_MAX PositionFlags_POS_TIMESTAMP #define _PositionFlags_ARRAYSIZE ((PositionFlags)(PositionFlags_POS_TIMESTAMP+1)) -#define _InputEventChar_MIN InputEventChar_NULL -#define _InputEventChar_MAX InputEventChar_BACK -#define _InputEventChar_ARRAYSIZE ((InputEventChar)(InputEventChar_BACK+1)) +#define _InputEventChar_MIN InputEventChar_KEY_NONE +#define _InputEventChar_MAX InputEventChar_KEY_BACK +#define _InputEventChar_ARRAYSIZE ((InputEventChar)(InputEventChar_KEY_BACK+1)) #define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MIN RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT11 #define _RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_MAX RadioConfig_UserPreferences_EnvironmentalMeasurementSensorType_DHT22 @@ -418,8 +418,8 @@ extern const pb_msgdesc_t RadioConfig_UserPreferences_msg; #define RadioConfig_UserPreferences_fields &RadioConfig_UserPreferences_msg /* Maximum encoded size of messages (where known) */ -#define RadioConfig_size 1616 -#define RadioConfig_UserPreferences_size 1613 +#define RadioConfig_size 792 +#define RadioConfig_UserPreferences_size 789 #ifdef __cplusplus } /* extern "C" */ diff --git a/src/plugins/CannedMessagePlugin.cpp b/src/plugins/CannedMessagePlugin.cpp index 7a950e3b8..7de29a2b2 100644 --- a/src/plugins/CannedMessagePlugin.cpp +++ b/src/plugins/CannedMessagePlugin.cpp @@ -30,7 +30,7 @@ CannedMessagePlugin::CannedMessagePlugin() /** * @brief Items in array this->messages will be set to be pointing on the right - * starting points of the string radioConfig.preferences.canned_message_plugin_messages + * starting points of the string this->messageStore * * @return int Returns the number of messages found. */ @@ -38,17 +38,23 @@ int CannedMessagePlugin::splitConfiguredMessages() { int messageIndex = 0; int i = 0; + + strncpy( + this->messageStore, + radioConfig.preferences.canned_message_plugin_messages, + CANNED_MESSAGE_PLUGIN_MESSAGES_SIZE); + this->messages[messageIndex++] = - radioConfig.preferences.canned_message_plugin_messages; + this->messageStore; int upTo = - strlen(radioConfig.preferences.canned_message_plugin_messages) - 1; + strlen(this->messageStore) - 1; while (i < upTo) { - if (radioConfig.preferences.canned_message_plugin_messages[i] == '|') + if (this->messageStore[i] == '|') { // Message ending found, replace it with string-end character. - radioConfig.preferences.canned_message_plugin_messages[i] = '\0'; + this->messageStore[i] = '\0'; DEBUG_MSG("CannedMessage %d is: '%s'\n", messageIndex-1, this->messages[messageIndex-1]); @@ -60,7 +66,7 @@ int CannedMessagePlugin::splitConfiguredMessages() // Next message starts after pipe (|) just found. this->messages[messageIndex++] = - (radioConfig.preferences.canned_message_plugin_messages + i + 1); + (this->messageStore + i + 1); } i += 1; } @@ -90,19 +96,19 @@ int CannedMessagePlugin::handleInputEvent(const InputEvent *event) } bool validEvent = false; - if (event->inputEvent == static_cast(InputEventChar_UP)) + if (event->inputEvent == static_cast(InputEventChar_KEY_UP)) { DEBUG_MSG("Canned message event UP\n"); this->action = CANNED_MESSAGE_ACTION_UP; validEvent = true; } - if (event->inputEvent == static_cast(InputEventChar_DOWN)) + if (event->inputEvent == static_cast(InputEventChar_KEY_DOWN)) { DEBUG_MSG("Canned message event DOWN\n"); this->action = CANNED_MESSAGE_ACTION_DOWN; validEvent = true; } - if (event->inputEvent == static_cast(InputEventChar_SELECT)) + if (event->inputEvent == static_cast(InputEventChar_KEY_SELECT)) { DEBUG_MSG("Canned message event Select\n"); this->action = CANNED_MESSAGE_ACTION_SELECT; @@ -206,15 +212,15 @@ int32_t CannedMessagePlugin::runOnce() return 30000; // TODO: should return MAX_VAL } -String CannedMessagePlugin::getCurrentMessage() +const char* CannedMessagePlugin::getCurrentMessage() { return this->messages[this->currentMessageIndex]; } -String CannedMessagePlugin::getPrevMessage() +const char* CannedMessagePlugin::getPrevMessage() { return this->messages[this->getPrevIndex()]; } -String CannedMessagePlugin::getNextMessage() +const char* CannedMessagePlugin::getNextMessage() { return this->messages[this->getNextIndex()]; } diff --git a/src/plugins/CannedMessagePlugin.h b/src/plugins/CannedMessagePlugin.h index eab516b85..5a5947d8a 100644 --- a/src/plugins/CannedMessagePlugin.h +++ b/src/plugins/CannedMessagePlugin.h @@ -18,6 +18,11 @@ enum cannedMessagePluginSendigState #define CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT 50 +/** + * Due to config-packet size restrictions we cannot have user configuration bigger + * than Constants_DATA_PAYLOAD_LEN bytes. + */ +#define CANNED_MESSAGE_PLUGIN_MESSAGES_SIZE 200 class CannedMessagePlugin : public SinglePortPlugin, @@ -29,9 +34,9 @@ class CannedMessagePlugin : this, &CannedMessagePlugin::handleInputEvent); public: CannedMessagePlugin(); - String getCurrentMessage(); - String getPrevMessage(); - String getNextMessage(); + const char* getCurrentMessage(); + const char* getPrevMessage(); + const char* getNextMessage(); bool shouldDraw(); cannedMessagePluginSendigState getSendingState(); void eventUp(); @@ -61,6 +66,7 @@ class CannedMessagePlugin : int currentMessageIndex = -1; cannedMessagePluginSendigState sendingState = SENDING_STATE_NONE; + char messageStore[CANNED_MESSAGE_PLUGIN_MESSAGES_SIZE]; char *messages[CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT]; int messagesCount = 0; unsigned long lastTouchMillis = 0; From 53399f06e597c8bf132654164c5238a080430130 Mon Sep 17 00:00:00 2001 From: Balazs Kelemen <10376327+prampec@users.noreply.github.com> Date: Wed, 19 Jan 2022 09:55:06 +0100 Subject: [PATCH 2/2] Canned message plugin status fix. --- src/plugins/CannedMessagePlugin.cpp | 110 ++++++++++++++-------------- src/plugins/CannedMessagePlugin.h | 22 ++---- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/src/plugins/CannedMessagePlugin.cpp b/src/plugins/CannedMessagePlugin.cpp index 7de29a2b2..b209187ad 100644 --- a/src/plugins/CannedMessagePlugin.cpp +++ b/src/plugins/CannedMessagePlugin.cpp @@ -99,19 +99,19 @@ int CannedMessagePlugin::handleInputEvent(const InputEvent *event) if (event->inputEvent == static_cast(InputEventChar_KEY_UP)) { DEBUG_MSG("Canned message event UP\n"); - this->action = CANNED_MESSAGE_ACTION_UP; + this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_UP; validEvent = true; } if (event->inputEvent == static_cast(InputEventChar_KEY_DOWN)) { DEBUG_MSG("Canned message event DOWN\n"); - this->action = CANNED_MESSAGE_ACTION_DOWN; + this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_DOWN; validEvent = true; } if (event->inputEvent == static_cast(InputEventChar_KEY_SELECT)) { DEBUG_MSG("Canned message event Select\n"); - this->action = CANNED_MESSAGE_ACTION_SELECT; + this->runState = CANNED_MESSAGE_RUN_STATE_ACTION_SELECT; validEvent = true; } @@ -151,63 +151,69 @@ void CannedMessagePlugin::sendText(NodeNum dest, int32_t CannedMessagePlugin::runOnce() { - if (!radioConfig.preferences.canned_message_plugin_enabled) + if ((!radioConfig.preferences.canned_message_plugin_enabled) + || (this->runState == CANNED_MESSAGE_RUN_STATE_INACTIVE)) { return 30000; // TODO: should return MAX_VAL } DEBUG_MSG("Check status\n"); UIFrameEvent e = {false, true}; - if (this->sendingState == SENDING_STATE_ACTIVE) + if (this->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) { // TODO: might have some feedback of sendig state - this->sendingState = SENDING_STATE_NONE; + this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; e.frameChanged = true; - this->notifyObservers(&e); - } - else if ((this->action != CANNED_MESSAGE_ACTION_NONE) - && (this->currentMessageIndex == -1)) - { - this->currentMessageIndex = 0; - DEBUG_MSG("First touch.\n"); - e.frameChanged = true; - } - else if (this->action == CANNED_MESSAGE_ACTION_SELECT) - { - sendText( - NODENUM_BROADCAST, - this->messages[this->currentMessageIndex], - true); - this->sendingState = SENDING_STATE_ACTIVE; this->currentMessageIndex = -1; this->notifyObservers(&e); - return 2000; } - else if (this->action == CANNED_MESSAGE_ACTION_UP) - { - this->currentMessageIndex = getPrevIndex(); - DEBUG_MSG("MOVE UP"); - } - else if (this->action == CANNED_MESSAGE_ACTION_DOWN) - { - this->currentMessageIndex = this->getNextIndex(); - DEBUG_MSG("MOVE DOWN"); - } - if (this->action != CANNED_MESSAGE_ACTION_NONE) - { - this->lastTouchMillis = millis(); - this->action = CANNED_MESSAGE_ACTION_NONE; - this->notifyObservers(&e); - return INACTIVATE_AFTER_MS; - } - if ((millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) + else if ( + (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) + && (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) { // Reset plugin DEBUG_MSG("Reset due the lack of activity.\n"); e.frameChanged = true; this->currentMessageIndex = -1; - this->sendingState = SENDING_STATE_NONE; + this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; this->notifyObservers(&e); } + else if (this->currentMessageIndex == -1) + { + this->currentMessageIndex = 0; + DEBUG_MSG("First touch.\n"); + e.frameChanged = true; + this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; + } + else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) + { + sendText( + NODENUM_BROADCAST, + this->messages[this->currentMessageIndex], + true); + this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; + this->currentMessageIndex = -1; + this->notifyObservers(&e); + return 2000; + } + else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_UP) + { + this->currentMessageIndex = getPrevIndex(); + this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; + DEBUG_MSG("MOVE UP\n"); + } + else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) + { + this->currentMessageIndex = this->getNextIndex(); + this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; + DEBUG_MSG("MOVE DOWN\n"); + } + + if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) + { + this->lastTouchMillis = millis(); + this->notifyObservers(&e); + return INACTIVATE_AFTER_MS; + } return 30000; // TODO: should return MAX_VAL } @@ -230,11 +236,7 @@ bool CannedMessagePlugin::shouldDraw() { return false; } - return (currentMessageIndex != -1) || (this->sendingState != SENDING_STATE_NONE); -} -cannedMessagePluginSendigState CannedMessagePlugin::getSendingState() -{ - return this->sendingState; + return (currentMessageIndex != -1) || (this->runState != CANNED_MESSAGE_RUN_STATE_INACTIVE); } int CannedMessagePlugin::getNextIndex() @@ -266,7 +268,13 @@ void CannedMessagePlugin::drawFrame( { displayedNodeNum = 0; // Not currently showing a node pane - if (cannedMessagePlugin->getSendingState() == SENDING_STATE_NONE) + if (cannedMessagePlugin->runState == CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE) + { + display->setTextAlignment(TEXT_ALIGN_CENTER); + display->setFont(FONT_MEDIUM); + display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending..."); + } + else { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); @@ -276,11 +284,5 @@ void CannedMessagePlugin::drawFrame( display->setFont(FONT_SMALL); display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage()); } - else - { - display->setTextAlignment(TEXT_ALIGN_CENTER); - display->setFont(FONT_MEDIUM); - display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending..."); - } } diff --git a/src/plugins/CannedMessagePlugin.h b/src/plugins/CannedMessagePlugin.h index 5a5947d8a..b65c0b1a4 100644 --- a/src/plugins/CannedMessagePlugin.h +++ b/src/plugins/CannedMessagePlugin.h @@ -2,18 +2,14 @@ #include "SinglePortPlugin.h" #include "input/InputBroker.h" -enum cannedMessagePluginActionType +enum cannedMessagePluginRunState { - CANNED_MESSAGE_ACTION_NONE, - CANNED_MESSAGE_ACTION_SELECT, - CANNED_MESSAGE_ACTION_UP, - CANNED_MESSAGE_ACTION_DOWN -}; - -enum cannedMessagePluginSendigState -{ - SENDING_STATE_NONE, - SENDING_STATE_ACTIVE + CANNED_MESSAGE_RUN_STATE_INACTIVE, + CANNED_MESSAGE_RUN_STATE_ACTIVE, + CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE, + CANNED_MESSAGE_RUN_STATE_ACTION_SELECT, + CANNED_MESSAGE_RUN_STATE_ACTION_UP, + CANNED_MESSAGE_RUN_STATE_ACTION_DOWN }; @@ -38,7 +34,6 @@ class CannedMessagePlugin : const char* getPrevMessage(); const char* getNextMessage(); bool shouldDraw(); - cannedMessagePluginSendigState getSendingState(); void eventUp(); void eventDown(); void eventSelect(); @@ -62,9 +57,8 @@ class CannedMessagePlugin : virtual void drawFrame( OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y); - volatile cannedMessagePluginActionType action = CANNED_MESSAGE_ACTION_NONE; int currentMessageIndex = -1; - cannedMessagePluginSendigState sendingState = SENDING_STATE_NONE; + cannedMessagePluginRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; char messageStore[CANNED_MESSAGE_PLUGIN_MESSAGES_SIZE]; char *messages[CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_COUNT];