From 4a29aef19ee131b83795c898f73f48cb9b78b170 Mon Sep 17 00:00:00 2001 From: Balazs Kelemen <10376327+prampec@users.noreply.github.com> Date: Tue, 4 Jan 2022 20:41:45 +0100 Subject: [PATCH] Show previous and next message in list. --- src/graphics/Screen.cpp | 6 ++++- src/plugins/CannedMessagePlugin.cpp | 30 +++++------------------ src/plugins/CannedMessagePlugin.h | 38 ++++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 28 deletions(-) diff --git a/src/graphics/Screen.cpp b/src/graphics/Screen.cpp index 22bfb8afb..8c33e6fb4 100644 --- a/src/graphics/Screen.cpp +++ b/src/graphics/Screen.cpp @@ -291,8 +291,12 @@ static void drawCannedMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *sta displayedNodeNum = 0; // Not currently showing a node pane display->setTextAlignment(TEXT_ALIGN_LEFT); + display->setFont(FONT_SMALL); + display->drawString(0 + x, 0 + y, cannedMessagePlugin->getPrevMessage()); display->setFont(FONT_MEDIUM); - display->drawString(0 + x, 0 + y, cannedMessagePlugin->getCurrentSelection()); + display->drawString(0 + x, 0 + y + 8, cannedMessagePlugin->getCurrentMessage()); + display->setFont(FONT_SMALL); + display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage()); // the max length of this buffer is much longer than we can possibly print // static char tempBuf[96]; diff --git a/src/plugins/CannedMessagePlugin.cpp b/src/plugins/CannedMessagePlugin.cpp index b104460b4..f880b4548 100644 --- a/src/plugins/CannedMessagePlugin.cpp +++ b/src/plugins/CannedMessagePlugin.cpp @@ -70,7 +70,7 @@ int32_t CannedMessagePlugin::runOnce() { this->currentMessageIndex = 0; DEBUG_MSG("First touch. Current message:%s\n", - this->getCurrentSelection()); + this->getCurrentMessage()); } else if (this->action == ACTION_PRESSED) { @@ -81,41 +81,23 @@ int32_t CannedMessagePlugin::runOnce() } else if (this->action == ACTION_UP) { - if (this->currentMessageIndex <= 0) - { - this->currentMessageIndex = - sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN - 1; - } - else - { - this->currentMessageIndex -= 1; - } + this->currentMessageIndex = getPrevIndex(); DEBUG_MSG("MOVE UP. Current message:%s\n", - this->getCurrentSelection()); + this->getCurrentMessage()); } else if (this->action == ACTION_DOWN) { - if (this->currentMessageIndex >= - (sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN) - 1) - { - this->currentMessageIndex = 0; - } - else - { - this->currentMessageIndex += 1; - } + this->currentMessageIndex = this->getNextIndex(); DEBUG_MSG("MOVE DOWN. Current message:%s\n", - this->getCurrentSelection()); + this->getCurrentMessage()); } if (this->action != ACTION_NONE) { this->action = ACTION_NONE; this->notifyObservers(NULL); } - DEBUG_MSG("Current selection index:%d\n", - this->currentMessageIndex); - return 3000; + return 30000; } void CannedMessagePlugin::select() diff --git a/src/plugins/CannedMessagePlugin.h b/src/plugins/CannedMessagePlugin.h index 437726205..4cf9a9120 100644 --- a/src/plugins/CannedMessagePlugin.h +++ b/src/plugins/CannedMessagePlugin.h @@ -45,10 +45,18 @@ class CannedMessagePlugin : void select(); void directionA(); void directionB(); - String getCurrentSelection() + String getCurrentMessage() { return cannedMessagePluginMessages[this->currentMessageIndex]; } + String getPrevMessage() + { + return cannedMessagePluginMessages[this->getPrevIndex()]; + } + String getNextMessage() + { + return cannedMessagePluginMessages[this->getNextIndex()]; + } bool shouldDraw() { return currentMessageIndex != -1; @@ -58,13 +66,37 @@ class CannedMessagePlugin : virtual int32_t runOnce(); - MeshPacket *preparePacket(); - void sendText( NodeNum dest, const char* message, bool wantReplies); + int getNextIndex() + { + if (this->currentMessageIndex >= + (sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN) - 1) + { + return 0; + } + else + { + return this->currentMessageIndex + 1; + } + } + + int getPrevIndex() + { + if (this->currentMessageIndex <= 0) + { + return + sizeof(cannedMessagePluginMessages) / CANNED_MESSAGE_PLUGIN_MESSAGE_MAX_LEN - 1; + } + else + { + return this->currentMessageIndex - 1; + } + } + // TODO: make this configurable volatile cannedMessagePluginActionType cwRotationMeaning = ACTION_UP;