From ea9c71ecd9fa3ae7e6e686237722bbaf5fc3eefc Mon Sep 17 00:00:00 2001 From: HarukiToreda <116696711+HarukiToreda@users.noreply.github.com> Date: Fri, 30 May 2025 02:11:04 -0400 Subject: [PATCH] Unified header for sending. --- src/modules/CannedMessageModule.cpp | 55 +++++++++++------------------ src/modules/CannedMessageModule.h | 4 +-- 2 files changed, 21 insertions(+), 38 deletions(-) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index 0759da668..0e75bd360 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -138,6 +138,21 @@ int CannedMessageModule::splitConfiguredMessages() return this->messagesCount; } +void CannedMessageModule::drawHeader(OLEDDisplay *display, int16_t x, int16_t y, char* buffer) { + if (display->getWidth() > 128) { + if (this->dest == NODENUM_BROADCAST) { + display->drawStringf(x, y, buffer, "To: Broadcast@%s", channels.getName(this->channel)); + } else { + display->drawStringf(x, y, buffer, "To: %s@%s", getNodeName(this->dest), channels.getName(this->channel)); + } + } else { + if (this->dest == NODENUM_BROADCAST) { + display->drawStringf(x, y, buffer, "To: Broadc@%.5s", channels.getName(this->channel)); + } else { + display->drawStringf(x, y, buffer, "To: %.5s@%.5s", getNodeName(this->dest), channels.getName(this->channel)); + } + } +} void CannedMessageModule::resetSearch() { LOG_INFO("Resetting search, restoring full destination list"); @@ -1560,33 +1575,17 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st display->setTextAlignment(TEXT_ALIGN_LEFT); display->setFont(FONT_SMALL); - if (this->destSelect != CANNED_MESSAGE_DESTINATION_TYPE_NONE) { - display->fillRect(0 + x, 0 + y, x + display->getWidth(), y + FONT_HEIGHT_SMALL); - display->setColor(BLACK); - } - - switch (this->destSelect) { - case CANNED_MESSAGE_DESTINATION_TYPE_NODE: - display->drawStringf(0 + x, 0 + y, buffer, "To: >%s<@%s", getNodeName(this->dest), channels.getName(this->channel)); - break; - case CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL: - display->drawStringf(0 + x, 0 + y, buffer, "To: %s@>%s<", getNodeName(this->dest), channels.getName(this->channel)); - break; - default: - if (display->getWidth() > 128) { - display->drawStringf(0 + x, 0 + y, buffer, "To: %s@%s", getNodeName(this->dest), channels.getName(this->channel)); - } else { - display->drawStringf(0 + x, 0 + y, buffer, "To: %.5s@%.5s", getNodeName(this->dest), channels.getName(this->channel)); - } - break; - } + // --- Draw node/channel header at the top --- + drawHeader(display, x, y, buffer); + // --- Char count right-aligned --- if (this->destSelect == CANNED_MESSAGE_DESTINATION_TYPE_NONE) { uint16_t charsLeft = meshtastic_Constants_DATA_PAYLOAD_LEN - this->freetext.length() - (moduleConfig.canned_message.send_bell ? 1 : 0); snprintf(buffer, sizeof(buffer), "%d left", charsLeft); display->drawString(x + display->getWidth() - display->getStringWidth(buffer), y + 0, buffer); } + // --- Draw Free Text input, shifted down --- display->setColor(WHITE); display->drawStringMaxWidth(0 + x, 0 + y + FONT_HEIGHT_SMALL, x + display->getWidth(), drawWithCursor(this->freetext, this->cursor)); @@ -1602,21 +1601,7 @@ void CannedMessageModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *st const int rowSpacing = FONT_HEIGHT_SMALL - 4; // Draw header (To: ...) - switch (this->destSelect) { - case CANNED_MESSAGE_DESTINATION_TYPE_NODE: - display->drawStringf(x + 0, y + 0, buffer, "To: >%s<@%s", getNodeName(this->dest), channels.getName(this->channel)); - break; - case CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL: - display->drawStringf(x + 0, y + 0, buffer, "To: %s@>%s<", getNodeName(this->dest), channels.getName(this->channel)); - break; - default: - if (display->getWidth() > 128) { - display->drawStringf(x + 0, y + 0, buffer, "To: %s@%s", getNodeName(this->dest), channels.getName(this->channel)); - } else { - display->drawStringf(x + 0, y + 0, buffer, "To: %.5s@%.5s", getNodeName(this->dest), channels.getName(this->channel)); - } - break; - } + drawHeader(display, x, y, buffer); // Shift message list upward by 3 pixels to reduce spacing between header and first message const int listYOffset = y + FONT_HEIGHT_SMALL - 3; diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 7511bab31..2b524692b 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -24,7 +24,6 @@ enum cannedMessageModuleRunState { enum cannedMessageDestinationType { CANNED_MESSAGE_DESTINATION_TYPE_NONE, CANNED_MESSAGE_DESTINATION_TYPE_NODE, - CANNED_MESSAGE_DESTINATION_TYPE_CHANNEL }; enum CannedMessageModuleIconType { shift, backspace, space, enter }; @@ -102,6 +101,7 @@ protected: // === Transmission === void sendText(NodeNum dest, ChannelIndex channel, const char *message, bool wantReplies); + void drawHeader(OLEDDisplay *display, int16_t x, int16_t y, char* buffer); int splitConfiguredMessages(); int getNextIndex(); int getPrevIndex(); @@ -162,8 +162,6 @@ private: NodeNum incoming = NODENUM_BROADCAST; // Source node from which last ACK/NACK was received NodeNum lastSentNode = 0; // Tracks the most recent node we sent a message to (for UI display) ChannelIndex channel = 0; // Channel index used when sending a message - uint8_t numChannels = 0; // Total number of channels available for selection - ChannelIndex indexChannels[MAX_NUM_CHANNELS] = {0}; // Cached channel indices available for this node bool ack = false; // True = ACK received, False = NACK or failed bool waitingForAck = false; // True if we're expecting an ACK and should monitor routing packets