refactor: one copy of shared logic and widgets; GPS is asked for, not switched on silently

Duplicates found between the L1 and L2 frontends, and inside the L2 one:
- geo::fmtLocShare / fmtLatLon / turnDeg / isAhead (GeoUtils.h): the [LOC]
  text was built in five places, the turn angle and its "ahead" threshold in
  both navigations, coordinates by hand in nine. Tested.
- LiveShareEngine::setEnabled: live share was switched in three places.
- L1 waypoint share uses WaypointModel::shareText; Trail's "Share my pos"
  goes through UITask::quickShareMyLocation, so it now sends to a running
  live-share session as the home Map page does.
- L2 Widgets.h: switchCreate (one switch size, was four), switchRow with a
  state and callback (16 hand-wired copies), switchRowOpens (Bluetooth, WiFi,
  GPS), primaryButton (one height for Save / Measure / New area / Update).

GPS: with it off, starting the trail, live share or track back, sharing or
marking a position, or centring the map asks first ("GPS is off") on both
L1 and L2; Cancel leaves it undone. A share or a mark waits for a fresh fix
(a switched-off module may still report its last one), which also fixes the
L1 "Share my pos" sending a stale position. SOS still turns the GPS on itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jakub
2026-11-02 10:32:23 +01:00
co-authored by Claude Opus 5.5
parent 781a480aef
commit ada5b8e545
35 changed files with 301 additions and 208 deletions
+27
View File
@@ -176,6 +176,33 @@ TEST(SosText, OnlyAnSosWithAPositionIsTakenForOne) {
EXPECT_FALSE(geo::parseSos("SOSNA 50.06143,19.93658", lat, lon));
}
// The [LOC] share every sender builds, and what the receiver reads back.
TEST(GeoText, LocationShareRoundTrips) {
char t[64];
geo::fmtLocShare(t, sizeof(t), 50061430, -19936580);
EXPECT_STREQ(t, "[LOC]50.06143,-19.93658");
geo::fmtLocShare(t, sizeof(t), 50061430, -19936580, "Hiker");
EXPECT_STREQ(t, "[LOC]50.06143,-19.93658 Hiker");
int32_t lat = 0, lon = 0;
ASSERT_TRUE(geo::parseLocShare(t, lat, lon));
EXPECT_EQ(lat, 50061430);
EXPECT_EQ(lon, -19936580);
geo::fmtLatLon(t, sizeof(t), 50061430, 19936580, true);
EXPECT_STREQ(t, "50.06143, 19.93658");
ASSERT_TRUE(geo::parseLatLon(t, lat, lon)); // an edited value reads back
EXPECT_EQ(lon, 19936580);
}
TEST(GeoText, TurnIsTheShortWayRound) {
EXPECT_EQ(geo::turnDeg(90, 0), 90);
EXPECT_EQ(geo::turnDeg(0, 90), -90);
EXPECT_EQ(geo::turnDeg(10, 350), 20);
EXPECT_EQ(geo::turnDeg(350, 10), -20);
EXPECT_EQ(geo::turnDeg(180, 0), -180);
EXPECT_TRUE(geo::isAhead(geo::turnDeg(5, 355)));
EXPECT_FALSE(geo::isAhead(geo::turnDeg(20, 0)));
}
TEST(SosText, NoGpsIsRecognisedOnItsOwn) {
char t[64];
SosEngine::compose(t, sizeof(t), SosEngine::NOWHERE, 0, 0, nullptr, -1, "14:32", "");