From a17ddaa951fa3a46a3ac1acf9e5380b6042610ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 6 Oct 2022 17:24:08 +0200 Subject: [PATCH 1/4] Use small font for freetext messages --- src/modules/CannedMessageModule.cpp | 4 ++-- src/modules/CannedMessageModule.h | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index d91a40453..a24e9585d 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -379,13 +379,13 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->drawString(10 + x, 0 + y + FONT_HEIGHT_SMALL, "Canned Message\nModule disabled."); }else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { display->setTextAlignment(TEXT_ALIGN_LEFT); - display->setFont(FONT_MEDIUM); + display->setFont(FONT_SMALL); display->drawString(0 + x, 0 + y, "To: Broadcast"); // used chars right aligned char buffer[9]; sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length()); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); - display->drawString(0 + x, 0 + y + FONT_HEIGHT_MEDIUM, cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor)); + display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL, cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor)); } else { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 8858714ef..784e40fc1 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -9,7 +9,6 @@ enum cannedMessageModuleRunState CANNED_MESSAGE_RUN_STATE_INACTIVE, CANNED_MESSAGE_RUN_STATE_ACTIVE, CANNED_MESSAGE_RUN_STATE_FREETEXT, - CANNED_MESSAGE_RUN_STATE_MATRIX, CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE, CANNED_MESSAGE_RUN_STATE_ACTION_SELECT, CANNED_MESSAGE_RUN_STATE_ACTION_UP, From 1d09beb8a78b39181083bf6236f4efc2ee1c1242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 6 Oct 2022 18:40:31 +0200 Subject: [PATCH 2/4] word wrap long input and fix compiler warnings --- src/input/kbI2cBase.cpp | 2 +- src/modules/CannedMessageModule.cpp | 2 +- variants/m5stack_core/platformio.ini | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/input/kbI2cBase.cpp b/src/input/kbI2cBase.cpp index 2066e12ad..332dfde0d 100644 --- a/src/input/kbI2cBase.cpp +++ b/src/input/kbI2cBase.cpp @@ -17,7 +17,7 @@ uint8_t read_from_14004(uint8_t reg, uint8_t *data, uint8_t length) Wire.write(reg); Wire.endTransmission(); // stop transmitting delay(20); - Wire.requestFrom(CARDKB_ADDR, length); + Wire.requestFrom(CARDKB_ADDR, (int)length); int i = 0; while ( Wire.available() ) // slave may send less than requested { diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index a24e9585d..1df8d2604 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -385,7 +385,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st char buffer[9]; sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length()); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); - display->drawString(0 + x, 0 + y + FONT_HEIGHT_SMALL, cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor)); + display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor)); } else { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); diff --git a/variants/m5stack_core/platformio.ini b/variants/m5stack_core/platformio.ini index dd9bd0f71..d1cda8fd8 100644 --- a/variants/m5stack_core/platformio.ini +++ b/variants/m5stack_core/platformio.ini @@ -23,6 +23,7 @@ build_flags = -DTFT_BL=32 -DSPI_FREQUENCY=40000000 -DSPI_READ_FREQUENCY=16000000 + -DDISABLE_ALL_LIBRARY_WARNINGS lib_ignore = m5stack-core lib_deps = From 7cda61ca017a74314508a9bd6fbf522244cfcb08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Thu, 6 Oct 2022 22:34:55 +0200 Subject: [PATCH 3/4] - preliminary work for node selection - show sending screen on immediate click --- src/modules/CannedMessageModule.cpp | 14 ++++++++++---- src/modules/CannedMessageModule.h | 4 +++- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 1df8d2604..51f196ca1 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -235,12 +235,11 @@ int32_t CannedMessageModule::runOnce() } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { if (this->payload == CANNED_MESSAGE_RUN_STATE_FREETEXT) { if (this->freetext.length() > 0) { - sendText(NODENUM_BROADCAST, this->freetext.c_str(), true); + sendText(this->dest, this->freetext.c_str(), true); this->runState = CANNED_MESSAGE_RUN_STATE_SENDING_ACTIVE; } else { DEBUG_MSG("Reset message is empty.\n"); this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; - e.frameChanged = true; } } else { if ((this->messagesCount > this->currentMessageIndex) && (strlen(this->messages[this->currentMessageIndex]) > 0)) { @@ -249,9 +248,9 @@ int32_t CannedMessageModule::runOnce() } else { DEBUG_MSG("Reset message is empty.\n"); this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; - e.frameChanged = true; } } + e.frameChanged = true; this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; @@ -287,7 +286,7 @@ int32_t CannedMessageModule::runOnce() this->cursor++; } break; - case 8: // backspace + case 0x08: // backspace if (this->freetext.length() > 0) { if(this->cursor == this->freetext.length()) { this->freetext = this->freetext.substring(0, this->freetext.length() - 1); @@ -297,6 +296,13 @@ int32_t CannedMessageModule::runOnce() this->cursor--; } break; + case 0x09: // tab + if(this->destSelect) { + this->destSelect = false; + } else { + this->destSelect = true; + } + break; default: if(this->cursor == this->freetext.length()) { this->freetext += this->payload; diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 784e40fc1..0de8fee1b 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -73,9 +73,11 @@ class CannedMessageModule : int currentMessageIndex = -1; cannedMessageModuleRunState runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; - char payload; + char payload = 0x00; unsigned int cursor = 0; String freetext = ""; // Text Buffer for Freetext Editor + bool destSelect = false; // Freetext Editor Mode + NodeNum dest = NODENUM_BROADCAST; char messageStore[CANNED_MESSAGE_MODULE_MESSAGES_SIZE+1]; char *messages[CANNED_MESSAGE_MODULE_MESSAGE_MAX_COUNT]; From a5761069caaa9e5242f039dc38ab88ec61652ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Fri, 7 Oct 2022 18:40:15 +0200 Subject: [PATCH 4/4] Finalize destination selection. Primary Channel only for now. --- src/modules/CannedMessageModule.cpp | 76 ++++++++++++++++++++++++++--- src/modules/CannedMessageModule.h | 1 + 2 files changed, 71 insertions(+), 6 deletions(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 51f196ca1..2a8c793c5 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -2,6 +2,7 @@ #if HAS_SCREEN #include "CannedMessageModule.h" #include "FSCommon.h" +#include "NodeDB.h" #include "MeshService.h" #include "PowerFSM.h" // neede for button bypass #include "mesh/generated/cannedmessages.pb.h" @@ -222,6 +223,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; + this->destSelect = false; this->notifyObservers(&e); } else if (((this->runState == CANNED_MESSAGE_RUN_STATE_ACTIVE) || (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT)) && (millis() - this->lastTouchMillis) > INACTIVATE_AFTER_MS) { // Reset module @@ -230,6 +232,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; + this->destSelect = false; this->runState = CANNED_MESSAGE_RUN_STATE_INACTIVE; this->notifyObservers(&e); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_SELECT) { @@ -254,6 +257,7 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = -1; this->freetext = ""; // clear freetext this->cursor = 0; + this->destSelect = false; this->notifyObservers(&e); return 2000; } else if ((this->runState != CANNED_MESSAGE_RUN_STATE_FREETEXT) && (this->currentMessageIndex == -1)) { @@ -265,25 +269,67 @@ int32_t CannedMessageModule::runOnce() this->currentMessageIndex = getPrevIndex(); this->freetext = ""; // clear freetext this->cursor = 0; + this->destSelect = false; this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; DEBUG_MSG("MOVE UP (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_ACTION_DOWN) { this->currentMessageIndex = this->getNextIndex(); this->freetext = ""; // clear freetext this->cursor = 0; + this->destSelect = false; this->runState = CANNED_MESSAGE_RUN_STATE_ACTIVE; DEBUG_MSG("MOVE DOWN (%d):%s\n", this->currentMessageIndex, this->getCurrentMessage()); } else if (this->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { e.frameChanged = true; switch (this->payload) { case 0xb4: // left - if (this->cursor > 0) { - this->cursor--; + if (this->destSelect){ + size_t numNodes = nodeDB.getNumNodes(); + if(this->dest == NODENUM_BROADCAST) { + this->dest = nodeDB.getNodeNum(); + DEBUG_MSG("Replacing NodeNum_BROADCAST with %x\n",nodeDB.getNodeNum()); + } + for (int i = 0; i < numNodes; i++) { + DEBUG_MSG("Considering %x\n",nodeDB.getNodeByIndex(i)->num); + if (nodeDB.getNodeByIndex(i)->num == this->dest) { + DEBUG_MSG("Match - advance %i-\n",i); + this->dest = (i > 0) ? nodeDB.getNodeByIndex(i-1)->num : nodeDB.getNodeByIndex(numNodes-1)->num; + break; + } + } + if(this->dest == nodeDB.getNodeNum()) { + this->dest = NODENUM_BROADCAST; + DEBUG_MSG("Replacing %x with NodeNum_BROADCAST\n",nodeDB.getNodeNum()); + } + }else{ + if (this->cursor > 0) { + this->cursor--; + } } break; case 0xb7: // right - if (this->cursor < this->freetext.length()) { - this->cursor++; + if (this->destSelect){ + size_t numNodes = nodeDB.getNumNodes(); + if(this->dest == NODENUM_BROADCAST) { + this->dest = nodeDB.getNodeNum(); + DEBUG_MSG("Replacing NodeNum_BROADCAST with %x\n",nodeDB.getNodeNum()); + } + for (int i = 0; i < numNodes; i++) { + DEBUG_MSG("Considering %x\n",nodeDB.getNodeByIndex(i)->num); + if (nodeDB.getNodeByIndex(i)->num == this->dest) { + DEBUG_MSG("Match - advance %i+\n",i); + this->dest = (i < numNodes-1) ? nodeDB.getNodeByIndex(i+1)->num : nodeDB.getNodeByIndex(0)->num; + break; + } + } + if(this->dest == nodeDB.getNodeNum()) { + this->dest = NODENUM_BROADCAST; + DEBUG_MSG("Replacing %x with NodeNum_BROADCAST\n",nodeDB.getNodeNum()); + } + }else{ + if (this->cursor < this->freetext.length()) { + this->cursor++; + } } break; case 0x08: // backspace @@ -345,6 +391,19 @@ const char *CannedMessageModule::getNextMessage() { return this->messages[this->getNextIndex()]; } +const char* CannedMessageModule::getNodeName(NodeNum node) { + if (node == NODENUM_BROADCAST){ + return "Broadcast"; + }else{ + NodeInfo *info = nodeDB.getNode(node); + if(info != NULL) { + return info->user.long_name; + }else{ + return "Unknown"; + } + } +} + bool CannedMessageModule::shouldDraw() { if (!moduleConfig.canned_message.enabled) { @@ -386,11 +445,16 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st }else if (cannedMessageModule->runState == CANNED_MESSAGE_RUN_STATE_FREETEXT) { display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); - display->drawString(0 + x, 0 + y, "To: Broadcast"); + if (this->destSelect) { + display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); + display->setColor(BLACK); + } + char buffer[50]; + display->drawStringf(0 + x, 0 + y, buffer, "To: %s", cannedMessageModule->getNodeName(this->dest)); // used chars right aligned - char buffer[9]; sprintf(buffer, "%d left", Constants_DATA_PAYLOAD_LEN - this->freetext.length()); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); + display->setColor(WHITE); display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), cannedMessageModule->drawWithCursor(cannedMessageModule->freetext, cannedMessageModule->cursor)); } else { display->setTextAlignment(TEXT_ALIGN_LEFT); diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 0de8fee1b..b9ef5c413 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -35,6 +35,7 @@ class CannedMessageModule : const char* getCurrentMessage(); const char* getPrevMessage(); const char* getNextMessage(); + const char* getNodeName(NodeNum node); bool shouldDraw(); void eventUp(); void eventDown();