From 5107531425675421bb893496c0227fad3e2dd77c Mon Sep 17 00:00:00 2001 From: HarukiToreda <116696711+HarukiToreda@users.noreply.github.com> Date: Thu, 31 Jul 2025 08:36:03 -0400 Subject: [PATCH] Remember destination fix (#7427) * T-watch screen misalignment fix * Trunk fix * Rember Last Receipient Node or channel When a new freetext or preset message is sent and a destination is selected, the next message would forget the previously selected destination and would need to be selected again. With this fix it will remember the last destination selected until changed again. * Fix for reply function to remember last messaged * trunk check --------- Co-authored-by: Jonathan Bennett Co-authored-by: Jason P Co-authored-by: Ben Meadors --- src/modules/CannedMessageModule.cpp | 41 +++++++++++++++++++++++++++++ src/modules/CannedMessageModule.h | 1 + 2 files changed, 42 insertions(+) diff --git a/src/modules/CannedMessageModule.cpp b/src/modules/CannedMessageModule.cpp index f7846ebbf..b6cb1b0e3 100644 --- a/src/modules/CannedMessageModule.cpp +++ b/src/modules/CannedMessageModule.cpp @@ -40,6 +40,9 @@ extern ScanI2C::DeviceAddress cardkb_found; extern bool graphics::isMuted; static const char *cannedMessagesConfigFile = "/prefs/cannedConf.proto"; +static NodeNum lastDest = NODENUM_BROADCAST; +static uint8_t lastChannel = 0; +static bool lastDestSet = false; meshtastic_CannedMessageModuleConfig cannedMessageModuleConfig; @@ -63,8 +66,18 @@ CannedMessageModule::CannedMessageModule() void CannedMessageModule::LaunchWithDestination(NodeNum newDest, uint8_t newChannel) { + // Use the requested destination, unless it's "broadcast" and we have a previous node/channel + if (newDest == NODENUM_BROADCAST && lastDestSet) { + newDest = lastDest; + newChannel = lastChannel; + } dest = newDest; channel = newChannel; + lastDest = dest; + lastChannel = channel; + lastDestSet = true; + + // Rest of function unchanged... // Always select the first real canned message on activation int firstRealMsgIdx = 0; for (int i = 0; i < messagesCount; ++i) { @@ -84,10 +97,28 @@ void CannedMessageModule::LaunchWithDestination(NodeNum newDest, uint8_t newChan notifyObservers(&e); } +void CannedMessageModule::LaunchRepeatDestination() +{ + if (!lastDestSet) { + LaunchWithDestination(NODENUM_BROADCAST, 0); + } else { + LaunchWithDestination(lastDest, lastChannel); + } +} + void CannedMessageModule::LaunchFreetextWithDestination(NodeNum newDest, uint8_t newChannel) { + // Use the requested destination, unless it's "broadcast" and we have a previous node/channel + if (newDest == NODENUM_BROADCAST && lastDestSet) { + newDest = lastDest; + newChannel = lastChannel; + } dest = newDest; channel = newChannel; + lastDest = dest; + lastChannel = channel; + lastDestSet = true; + runState = CANNED_MESSAGE_RUN_STATE_FREETEXT; requestFocus(); UIFrameEvent e; @@ -479,6 +510,9 @@ int CannedMessageModule::handleDestinationSelectionInput(const InputEvent *event if (destIndex < static_cast(activeChannelIndices.size())) { dest = NODENUM_BROADCAST; channel = activeChannelIndices[destIndex]; + lastDest = dest; + lastChannel = channel; + lastDestSet = true; } else { int nodeIndex = destIndex - static_cast(activeChannelIndices.size()); if (nodeIndex >= 0 && nodeIndex < static_cast(filteredNodes.size())) { @@ -486,6 +520,10 @@ int CannedMessageModule::handleDestinationSelectionInput(const InputEvent *event if (selectedNode) { dest = selectedNode->num; channel = selectedNode->channel; + // Already saves here, but for clarity, also: + lastDest = dest; + lastChannel = channel; + lastDestSet = true; } } } @@ -846,6 +884,9 @@ int CannedMessageModule::handleEmotePickerInput(const InputEvent *event) void CannedMessageModule::sendText(NodeNum dest, ChannelIndex channel, const char *message, bool wantReplies) { + lastDest = dest; + lastChannel = channel; + lastDestSet = true; // === Prepare packet === meshtastic_MeshPacket *p = allocDataPacket(); p->to = dest; diff --git a/src/modules/CannedMessageModule.h b/src/modules/CannedMessageModule.h index 55a0a1185..5b0481ac7 100644 --- a/src/modules/CannedMessageModule.h +++ b/src/modules/CannedMessageModule.h @@ -59,6 +59,7 @@ class CannedMessageModule : public SinglePortModule, public Observable