From c4cea53a40aa9935ed163ff6c94624c3984d2c34 Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Thu, 4 Jun 2026 15:46:57 +0200 Subject: [PATCH] polish(nav): tidy parseLatLon precision + ping-menu edge cases - geo::parseLatLon now rounds lat/lon in double (matching the Add-by-coords form) instead of through a float cast that lost ~1 m near 1e8. - NearbyScreen: preserve the ping menu's selected row across a rebuild instead of snapping back to "Send" when a result line arrives. - NearbyScreen: guard the ping-menu input path so a vanished contact (selectedStoredPubKey == false) closes the popup rather than acting on an uninitialised pub-key buffer. Co-Authored-By: Claude Opus 4.8 --- examples/companion_radio/GeoUtils.h | 4 ++-- examples/companion_radio/ui-new/NearbyScreen.h | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/companion_radio/GeoUtils.h b/examples/companion_radio/GeoUtils.h index 5175ad5f..45988f50 100644 --- a/examples/companion_radio/GeoUtils.h +++ b/examples/companion_radio/GeoUtils.h @@ -94,8 +94,8 @@ static inline bool parseLatLon(const char* text, int32_t& lat_1e6, int32_t& lon_ if (end2 == q) continue; if (la < -90.0 || la > 90.0 || lo < -180.0 || lo > 180.0) continue; - lat_1e6 = (int32_t)lroundf((float)(la * 1e6)); - lon_1e6 = (int32_t)lroundf((float)(lo * 1e6)); + lat_1e6 = (int32_t)(la * 1e6 + (la < 0 ? -0.5 : 0.5)); // round in double — float loses ~1m at 1e8 + lon_1e6 = (int32_t)(lo * 1e6 + (lo < 0 ? -0.5 : 0.5)); if (label && label_n > 0 && tag) { // label only from a tagged share const char* s = end2; while (*s == ' ') s++; diff --git a/examples/companion_radio/ui-new/NearbyScreen.h b/examples/companion_radio/ui-new/NearbyScreen.h index f94fb21e..1fe30d84 100644 --- a/examples/companion_radio/ui-new/NearbyScreen.h +++ b/examples/companion_radio/ui-new/NearbyScreen.h @@ -182,11 +182,13 @@ class NearbyScreen : public UIScreen { } void rebuildPingMenu() { + int keep = _ping_menu._sel; // preserve selection across a rebuild _ping_menu.begin("Ping", 4); _ping_menu.addItem("Send"); if (_ping_time_str[0]) _ping_menu.addItem(_ping_time_str); if (_ping_snr_out_str[0]) _ping_menu.addItem(_ping_snr_out_str); if (_ping_snr_back_str[0]) _ping_menu.addItem(_ping_snr_back_str); + if (keep > 0 && keep < _ping_menu._count) _ping_menu._sel = keep; } void openPingMenu() { rebuildPingMenu(); } @@ -684,8 +686,9 @@ public: // Ping popup (opened from Options) consumes input while active. if (_ping_menu.active) { - uint8_t pk[PUB_KEY_SIZE]; selectedStoredPubKey(pk); - handlePingMenuInput(c, pk); + uint8_t pk[PUB_KEY_SIZE]; + if (selectedStoredPubKey(pk)) handlePingMenuInput(c, pk); // guard: never send to a stale/garbage key + else closePingMenu(); return true; }