From 2bcf608654facd685321779b339584644a1ecc5d Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 28 Jun 2025 08:19:31 -0500 Subject: [PATCH 1/2] Last second fixes (#7156) * Ditch the 30 second delay for button presses * Only order strictly weakly * Too many comments! * Only sort the populated meshNodes --- src/input/ButtonThread.cpp | 11 ++++++----- src/mesh/NodeDB.cpp | 33 ++++++++++++++++----------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/input/ButtonThread.cpp b/src/input/ButtonThread.cpp index da9878fa4..ad667f003 100644 --- a/src/input/ButtonThread.cpp +++ b/src/input/ButtonThread.cpp @@ -58,15 +58,15 @@ bool ButtonThread::initButton(const ButtonConfig &config) userButton.attachLongPressStart( [](void *callerThread) -> void { ButtonThread *thread = (ButtonThread *)callerThread; - if (millis() > 30000) // hold off 30s after boot - thread->btnEvent = BUTTON_EVENT_LONG_PRESSED; + // if (millis() > 30000) // hold off 30s after boot + thread->btnEvent = BUTTON_EVENT_LONG_PRESSED; }, this); userButton.attachLongPressStop( [](void *callerThread) -> void { ButtonThread *thread = (ButtonThread *)callerThread; - if (millis() > 30000) // hold off 30s after boot - thread->btnEvent = BUTTON_EVENT_LONG_RELEASED; + // if (millis() > 30000) // hold off 30s after boot + thread->btnEvent = BUTTON_EVENT_LONG_RELEASED; }, this); } @@ -254,7 +254,8 @@ int32_t ButtonThread::runOnce() case BUTTON_EVENT_LONG_RELEASED: { LOG_INFO("LONG PRESS RELEASE"); - if (_longLongPress != INPUT_BROKER_NONE && (millis() - buttonPressStartTime) >= _longLongPressTime) { + if (millis() > 30000 && _longLongPress != INPUT_BROKER_NONE && + (millis() - buttonPressStartTime) >= _longLongPressTime) { evt.inputEvent = _longLongPress; this->notifyObservers(&evt); } diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index cc3639f19..8990d4b4f 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1694,23 +1694,22 @@ void NodeDB::sortMeshDB() { if (!Throttle::isWithinTimespanMs(lastSort, 1000 * 5)) { lastSort = millis(); - std::sort(meshNodes->begin(), meshNodes->end(), [](const meshtastic_NodeInfoLite &a, const meshtastic_NodeInfoLite &b) { - if (a.num == myNodeInfo.my_node_num) { - return true; - } - if (b.num == myNodeInfo.my_node_num) { - return false; - } - bool aFav = a.is_favorite; - bool bFav = b.is_favorite; - if (aFav != bFav) - return aFav; - if (a.last_heard == 0 || a.last_heard == UINT32_MAX) - return false; - if (b.last_heard == 0 || b.last_heard == UINT32_MAX) - return true; - return a.last_heard > b.last_heard; - }); + std::sort(meshNodes->begin(), meshNodes->begin() + numMeshNodes, + [](const meshtastic_NodeInfoLite &a, const meshtastic_NodeInfoLite &b) { + if (a.num == myNodeInfo.my_node_num) { + return true; + } + if (b.num == myNodeInfo.my_node_num) { + return false; + } + bool aFav = a.is_favorite; + bool bFav = b.is_favorite; + if (aFav != bFav) + return aFav; + if (a.last_heard != b.last_heard) + return a.last_heard > b.last_heard; + return a.num > b.num; + }); } } From b6a13f1114ed2c259881fd8761832a5aaae97d3b Mon Sep 17 00:00:00 2001 From: Jonathan Bennett Date: Sat, 28 Jun 2025 22:54:03 -0500 Subject: [PATCH 2/2] Add check for theoretically impossible comparison, and drop nodenum comparison (#7165) --- src/mesh/NodeDB.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 8990d4b4f..bd4911a9b 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -1696,6 +1696,8 @@ void NodeDB::sortMeshDB() lastSort = millis(); std::sort(meshNodes->begin(), meshNodes->begin() + numMeshNodes, [](const meshtastic_NodeInfoLite &a, const meshtastic_NodeInfoLite &b) { + if (a.num == myNodeInfo.my_node_num && b.num == myNodeInfo.my_node_num) // in theory impossible + return false; if (a.num == myNodeInfo.my_node_num) { return true; } @@ -1706,9 +1708,7 @@ void NodeDB::sortMeshDB() bool bFav = b.is_favorite; if (aFav != bFav) return aFav; - if (a.last_heard != b.last_heard) - return a.last_heard > b.last_heard; - return a.num > b.num; + return a.last_heard > b.last_heard; }); } }