From bdd5b4f1ab317ba7a3bbab472b06743bc4df74f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Sevilla?= <24dasemu@gmail.com> Date: Tue, 13 Oct 2026 13:14:19 +0000 Subject: [PATCH] fix: resume imported GPX guidance after a confirmed detour --- README.md | 2 +- app/build.gradle.kts | 4 +- .../kotlin/dev/navframe/core/RouteGuidance.kt | 31 ++++++++-- .../dev/navframe/core/RouteGuidanceTest.kt | 61 +++++++++++++++++++ docs/IMPORTED_ROUTES.md | 2 +- 5 files changed, 92 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3a91435..ae887de 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ NavFrame is an experimental Android navigation app that renders its own 480×240 The owner has confirmed static and synthetic NavFrame frames on a Xiaomi 11 Lite 5G NE running Android 14 and a 2026 Yamaha MT-07, and the bundled Asturias map working offline on the phone. On 2026-10-12, the owner reported that the latest version displayed the map on the TFT for about 20 minutes, then showed `Mapa no disponible` in La Corredoria (Oviedo) for the rest of the trip while the phone map continued working. An offline map was installed. The exact installed build, diagnostic code and background state were not recorded; the cause is under investigation. This establishes a successful map display followed by a persistent failure, not sustained TFT reliability. -The current checkout is version 0.13.5. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided. +The current checkout is version 0.13.6. The 0.13 series adds voice/routing language selection for Spanish, English, German, French, and Italian, plus a system-language option; unsupported system locales resolve to English. Speech still depends on the Android TextToSpeech engine and its installed voice data. The app includes offline map and place data for Asturias, plus installable regional packages. Worldwide regions can be discovered and built on demand through the [regional package workflow](docs/GLOBAL_OFFLINE.md); this is not complete worldwide coverage. Installed packages currently provide map and local place/camera data. Offline route calculation, global camera completeness, and complete worldwide font coverage are not provided. Route calculation and address search use configurable online services. Spoken output uses the selected language when Android provides voice data; voice availability and offline behavior depend on the device's TextToSpeech engine. Physical validation of route guidance, voice playback, camera alerts, sustained TFT map rendering, and a 30-minute screen-off session remains pending unless a newer test report says otherwise. diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f0b7c41..2574c92 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -15,8 +15,8 @@ android { applicationId = "dev.navframe.app" minSdk = 26 targetSdk = 35 - versionName = "0.13.5" - versionCode = 21 + versionName = "0.13.6" + versionCode = 22 } if (hasReleaseSigning) { signingConfigs.create("production") { diff --git a/core/src/main/kotlin/dev/navframe/core/RouteGuidance.kt b/core/src/main/kotlin/dev/navframe/core/RouteGuidance.kt index 4f88552..14122e9 100644 --- a/core/src/main/kotlin/dev/navframe/core/RouteGuidance.kt +++ b/core/src/main/kotlin/dev/navframe/core/RouteGuidance.kt @@ -32,6 +32,9 @@ class RouteGuidanceTracker(private val route: RouteResult, private val config: G private var lastTimestamp: Long? = null private val outside = SustainedFixes() private val arrival = SustainedFixes() + private val rejoin = SustainedFixes() + private var importedDeviation = false + private var rejoinProgress: Double? = null private var arrived = false private var needsRecovery = false private var lastState: NavigationState? = null @@ -45,7 +48,7 @@ class RouteGuidanceTracker(private val route: RouteResult, private val config: G fix.accuracyMeters.isFinite() && fix.accuracyMeters in 0f..config.maxAccuracyMeters && (lastNow == null || nowMs >= lastNow!!) if (!usable) { - outside.reset(); arrival.reset() + outside.reset(); arrival.reset(); rejoin.reset(); rejoinProgress = null needsRecovery = lastPoint != null return remember(base.copy(speed = 0f, navigationStatus = NavigationStatus.GPS_LOST)) } @@ -54,7 +57,7 @@ class RouteGuidanceTracker(private val route: RouteResult, private val config: G if (arrived) return remember(base.copy(speed = 0f, remainingDistanceMeters = 0, etaEpochMillis = if (route.imported) null else epochMs, navigationStatus = NavigationStatus.ARRIVED)) if (needsRecovery || lastNow?.let { nowMs - it > config.maxFixAgeMs } == true) { - outside.reset(); arrival.reset() + outside.reset(); arrival.reset(); rejoin.reset(); rejoinProgress = null needsRecovery = false acquired = false lastPoint = fix.position @@ -71,11 +74,30 @@ class RouteGuidanceTracker(private val route: RouteResult, private val config: G lastNow = nowMs lastTimestamp = fix.timestampMs if (jumped) { - outside.reset(); arrival.reset() + outside.reset(); arrival.reset(); rejoin.reset(); rejoinProgress = null return remember(base.copy(speed = 0f, navigationStatus = NavigationStatus.GPS_LOST)) } - val projection = line.project(fix.position, progress, forwardAllowance) + var projection = line.project(fix.position, progress, forwardAllowance) val outsideThreshold = max(config.offRouteMeters, fix.accuracyMeters * 2.0) + if (route.imported && importedDeviation) { + // A detour may rejoin anywhere on the original trace, including behind progress. + // Require stable fresh fixes before widening the normal crossing-safe progress window. + val candidate = line.project(fix.position, 0.0, line.total) + val candidateProgress = candidate.local + val stable = candidateProgress != null && candidate.localDistance <= outsideThreshold && + (rejoinProgress == null || abs(candidateProgress - rejoinProgress!!) <= movementAllowance) + val confirmed = rejoin.observe(stable, distinct, nowMs, 3, 2_000) + rejoinProgress = candidateProgress.takeIf { stable } + if (!confirmed) { + arrival.reset() + return remember(base.copy(navigationStatus = NavigationStatus.OFF_ROUTE)) + } + progress = requireNotNull(candidateProgress) + acquired = true + importedDeviation = false + outside.reset(); rejoin.reset(); rejoinProgress = null + projection = candidate + } val offRoute = outside.observe(projection.localDistance > outsideThreshold, distinct, nowMs, config.offRouteFixes, config.offRouteDurationMs) // Freeze progress during inaccurate projection, so driving parallel to the road does not advance turns. @@ -84,6 +106,7 @@ class RouteGuidanceTracker(private val route: RouteResult, private val config: G acquired = true } if (offRoute) { + if (route.imported) importedDeviation = true arrival.reset() return remember(base.copy(navigationStatus = NavigationStatus.OFF_ROUTE)) } diff --git a/core/src/test/kotlin/dev/navframe/core/RouteGuidanceTest.kt b/core/src/test/kotlin/dev/navframe/core/RouteGuidanceTest.kt index 356d1ea..b4bd3d4 100644 --- a/core/src/test/kotlin/dev/navframe/core/RouteGuidanceTest.kt +++ b/core/src/test/kotlin/dev/navframe/core/RouteGuidanceTest.kt @@ -2,6 +2,7 @@ package dev.navframe.core import org.junit.Assert.* import org.junit.Test +import kotlin.math.abs class RouteGuidanceTest { // Equatorial segments are ~111.2m each; original route duration is 30 seconds. @@ -220,6 +221,66 @@ class RouteGuidanceTest { assertEquals(initial.remainingDistanceMeters, reversed.remainingDistanceMeters) } + private val importedTrace = RouteResult( + listOf(GeoPoint(0.0, 0.0), GeoPoint(0.0, 0.02)), emptyList(), 2224, 0, imported = true) + + private fun deviatedImportedTracker(): RouteGuidanceTracker { + val tracker = RouteGuidanceTracker(importedTrace) + tracker.update(fix(lon = 0.005), 0, 0) + tracker.update(fix(lat = -0.0007, lon = 0.005, time = 2), 3_000, 0) + tracker.update(fix(lat = -0.0007, lon = 0.005, time = 3), 6_000, 0) + val deviated = tracker.update(fix(lat = -0.0007, lon = 0.005, time = 4), 9_000, 0) + assertEquals(NavigationStatus.OFF_ROUTE, deviated.navigationStatus) + assertSame(importedTrace, deviated.route) + return tracker + } + + @Test fun `imported detour rejoins ahead or behind frozen progress without replacing trace`() { + for (longitude in listOf(0.012, 0.002)) { + val tracker = deviatedImportedTracker() + // The isolated relocation is rejected. Stable fixes then reacquire the original trace. + assertEquals(NavigationStatus.GPS_LOST, + tracker.update(fix(lon = longitude, time = 5), 10_000, 0).navigationStatus) + for (i in 6L..7L) { + assertEquals(NavigationStatus.OFF_ROUTE, + tracker.update(fix(lon = longitude, time = i), (i + 5) * 1_000, 0).navigationStatus) + } + val resumed = tracker.update(fix(lon = longitude, time = 8), 13_000, 0) + assertEquals(NavigationStatus.NAVIGATING, resumed.navigationStatus) + assertTrue(abs(((0.02 - longitude) * 111_195) - resumed.remainingDistanceMeters!!) < 1) + assertSame(importedTrace, resumed.route) + assertNull(resumed.nextManeuver) + assertNull(resumed.etaEpochMillis) + } + } + + @Test fun `repeated stale and inaccurate fixes cannot confirm imported rejoin`() { + val tracker = deviatedImportedTracker() + tracker.update(fix(lon = 0.012, time = 5), 10_000, 0) + val candidate = fix(lon = 0.012, time = 6) + assertEquals(NavigationStatus.OFF_ROUTE, tracker.update(candidate, 11_000, 0).navigationStatus) + assertEquals(NavigationStatus.OFF_ROUTE, tracker.update(candidate, 14_000, 0).navigationStatus) + assertEquals(NavigationStatus.GPS_LOST, + tracker.update(fix(lon = 0.012, time = 7, accuracy = 40f), 15_000, 0).navigationStatus) + assertEquals(NavigationStatus.GPS_LOST, + tracker.update(fix(lon = 0.012, time = 8), 16_000, 0, 15_001).navigationStatus) + tracker.update(fix(lon = 0.012, time = 9), 17_000, 0) + tracker.update(fix(lon = 0.012, time = 10), 18_000, 0) + tracker.update(fix(lon = 0.012, time = 11), 19_000, 0) + assertEquals(NavigationStatus.NAVIGATING, + tracker.update(fix(lon = 0.012, time = 12), 20_000, 0).navigationStatus) + } + + @Test fun `imported crossing preserves progress until deviation is sustained`() { + val crossing = importedTrace.copy(geometry = listOf(GeoPoint(0.0, 0.0), GeoPoint(0.0, 0.002), + GeoPoint(0.002, 0.002), GeoPoint(0.002, 0.0), GeoPoint(0.0, 0.0), GeoPoint(0.0, -0.002))) + val tracker = RouteGuidanceTracker(crossing) + val initial = tracker.update(fix(), 0, 0) + val next = tracker.update(fix(lon = -0.00005, time = 2), 1_000, 0) + assertEquals(initial.remainingDistanceMeters, next.remainingDistanceMeters) + assertEquals(NavigationStatus.NAVIGATING, next.navigationStatus) + } + @Test fun `maneuver arrows use type rather than translated prose`() { assertEquals(ManeuverDirection.LEFT, maneuverDirection(15)) assertEquals(ManeuverDirection.RIGHT, maneuverDirection(10)) diff --git a/docs/IMPORTED_ROUTES.md b/docs/IMPORTED_ROUTES.md index e5b5ff7..699e033 100644 --- a/docs/IMPORTED_ROUTES.md +++ b/docs/IMPORTED_ROUTES.md @@ -14,7 +14,7 @@ Files are limited to 5 MiB, 10,000 trace points and 64 XML nesting levels. Coord The original coordinates are retained locally in memory and drawn on the phone and TFT. GPX import does not send the file or its coordinates to a routing server. It works with the installed offline map; online background tiles still require a connection when no offline map is selected. Standard trace points do not establish legal roads, surface quality, reliable turns or travel time. -The display says **Sigue el trazado GPX**. It shows progress, remaining distance, sustained deviations and arrival using the existing GPS guidance policy. It does not invent turn instructions, speak turn announcements, show an ETA, or automatically reroute away from the imported trace. On a deviation, return to the trace using the map and road signs. Manual recalculation also preserves the trace. +The display says **Sigue el trazado GPX**. It shows progress, remaining distance, sustained deviations and arrival using the existing GPS guidance policy. It does not invent turn instructions, speak turn announcements, show an ETA, or automatically reroute away from the imported trace. On a deviation, return to the trace using the map and road signs. Manual recalculation also preserves the trace. After a confirmed deviation, three fresh, stable GPS fixes spanning at least two seconds automatically resume progress at the nearest point of the original trace, whether you rejoin ahead of or behind the previous position. GPS jumps and inaccurate fixes cannot confirm a rejoin. The imported route is not persisted across process death or device reboot: reload the original document to resume. The document remains in its selected provider; the app does not request long-term file access or copy the GPX into its own storage. Map diagnostics do not include route coordinates, document paths or route names.