From 64b58a3c5dbcc4ccb74882748af6949573dc750d Mon Sep 17 00:00:00 2001 From: Eiswolf-BG <37225519+Eiswolf-BG@users.noreply.github.com> Date: Tue, 11 Aug 2026 23:49:45 +0200 Subject: [PATCH] Respect Metric/Imperial unit setting in radar range button, ring labels, aircraft list, nearest airport, and stats Five places ignored the Units setting (Menu > Units) and always showed fixed metric values even when Imperial was selected: the radar range button (now km/nm), the radar's ring distance labels (now km/nm), the aircraft list's altitude/distance columns (now m+km or ft+nm), the Location Presets screen's nearest-airport distance (now km/nm), and the Stats screen's highest-altitude-today line (now m or ft). The range button had already been touched previously but used "mi" instead of "nm" - aligned to nm here for consistency with the other distance displays, which all pair with km rather than miles. The radar detail panel's simultaneous multi-unit display and the climb/descent rate (always ft/min, aviation convention) are intentionally left unchanged. Co-Authored-By: Claude Sonnet 5 --- src/aircraft_list_screen.cpp | 19 +++++++++++++++++-- src/location_presets_screen.cpp | 9 ++++++++- src/radar_screen.cpp | 20 +++++++++++++------- src/stats_screen.cpp | 10 +++++++++- 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/aircraft_list_screen.cpp b/src/aircraft_list_screen.cpp index 76958ff..27810a4 100644 --- a/src/aircraft_list_screen.cpp +++ b/src/aircraft_list_screen.cpp @@ -9,6 +9,8 @@ #include "menu_stars.h" #include "config.h" #include "i18n.h" +#include "units.h" +#include "location_manager.h" #include #include @@ -124,6 +126,11 @@ bool run(TFT_eSPI& tft) { Rect rowRects[ROWS_VISIBLE]; uint8_t visibleRowCount = 0; + // Einheiten-Einstellung (Menue > Einheiten) einmal vor der Schleife + // lesen statt pro Zeile - vorher zeigten Hoehe/Distanz hier immer + // fest ft/km, auch bei Imperial eingestellt. + bool listMetric = LocationManager::useMetricUnits(); + if (count == 0) { tft.setTextColor(TFT_DARKGREY, TFT_BLACK); tft.setCursor(10, LIST_TOP + 14); @@ -154,12 +161,20 @@ bool run(TFT_eSPI& tft) { tft.drawString(label, r.x + 6, midY); char buf[24]; - snprintf(buf, sizeof(buf), "%.0fft", (float)a.altBaroFt); + if (listMetric) { + snprintf(buf, sizeof(buf), "%.0fm", Units::feetToMeters((float)a.altBaroFt)); + } else { + snprintf(buf, sizeof(buf), "%.0fft", (float)a.altBaroFt); + } tft.setTextColor(colorForAltitude(a.altBaroFt), TFT_BLACK); tft.setTextDatum(MR_DATUM); tft.drawString(buf, r.x + r.w - 62, midY); - snprintf(buf, sizeof(buf), "%.0fkm", a.distanceKm); + if (listMetric) { + snprintf(buf, sizeof(buf), "%.0fkm", a.distanceKm); + } else { + snprintf(buf, sizeof(buf), "%.0fnm", Units::kmToNm(a.distanceKm)); + } tft.setTextColor(TFT_GREEN, TFT_BLACK); tft.setTextDatum(MR_DATUM); tft.drawString(buf, r.x + r.w - 6, midY); diff --git a/src/location_presets_screen.cpp b/src/location_presets_screen.cpp index d741d50..670b7ec 100644 --- a/src/location_presets_screen.cpp +++ b/src/location_presets_screen.cpp @@ -7,6 +7,7 @@ #include "menu_stars.h" #include "config.h" #include "i18n.h" +#include "units.h" namespace LocationPresetsScreen { @@ -602,8 +603,14 @@ void run(TFT_eSPI& tft) { } nearest = AirportLookup::findNearest(activeLat, activeLon); if (nearest.found) { + // Respektiert jetzt die Einheiten-Einstellung (Menue > + // Einheiten) - vorher immer "(XX km)", auch bei Imperial. char buf[48]; - snprintf(buf, sizeof(buf), "%s %s (%.0f km)", nearest.icao, nearest.name, nearest.distanceKm); + if (LocationManager::useMetricUnits()) { + snprintf(buf, sizeof(buf), "%s %s (%.0f km)", nearest.icao, nearest.name, nearest.distanceKm); + } else { + snprintf(buf, sizeof(buf), "%s %s (%.0f nm)", nearest.icao, nearest.name, Units::kmToNm(nearest.distanceKm)); + } String line = String(I18n::t(StringId::LOCATION_NEAREST_AIRPORT_PREFIX)) + buf; setupMarquee(tft, line, AIRPORT_LINE_W); drawMarquee(tft, AIRPORT_LINE_X, airportLineY, AIRPORT_LINE_W, 20); diff --git a/src/radar_screen.cpp b/src/radar_screen.cpp index 399eb48..e5f8861 100644 --- a/src/radar_screen.cpp +++ b/src/radar_screen.cpp @@ -471,10 +471,16 @@ namespace { gfx.drawString("S", L.cx, L.cy + L.radius - 10); gfx.drawString("E", L.cx + L.radius - 10, L.cy); gfx.drawString("W", L.cx - L.radius + 10, L.cy); + // Ring-Beschriftungen (Zwischenabstaende) respektieren jetzt die + // Einheiten-Einstellung (Menue > Einheiten) - vorher immer in km, + // auch wenn Imperial (nm) eingestellt war. Gleiches Umrechnungs- + // Muster wie beim Range-Button unten und der Legende oben. + bool metric = LocationManager::useMetricUnits(); + float displayRange = metric ? rangeKm : Units::kmToNm(rangeKm); char ringLabel[8]; - snprintf(ringLabel, sizeof(ringLabel), "%.0f", rangeKm / 3); + snprintf(ringLabel, sizeof(ringLabel), "%.0f", displayRange / 3); gfx.drawString(ringLabel, L.cx, L.cy - L.radius / 3); - snprintf(ringLabel, sizeof(ringLabel), "%.0f", rangeKm * 2 / 3); + snprintf(ringLabel, sizeof(ringLabel), "%.0f", displayRange * 2 / 3); gfx.drawString(ringLabel, L.cx, L.cy - L.radius * 2 / 3); gfx.setTextDatum(TL_DATUM); } @@ -779,14 +785,14 @@ void render(TFT_eSPI& tft, int16_t top) { int16_t infoTextW = L.rangeBtn.x - INFO_TEXT_X - INFO_TEXT_GAP; drawInfoMarquee(tft, INFO_TEXT_X, infoTextY, infoTextW); + // Respektiert jetzt die Einheiten-Einstellung (Menue > Einheiten) - + // vorher immer "XXkm", auch bei Imperial (dort jetzt "XXnm"). char rangeLabel[8]; - // Zeigt km bei Metrisch, mi bei Imperial (Menue > Einheiten) - - // gleiches Muster wie drawLegend() weiter oben, statt fest immer - // km anzuzeigen. - if (LocationManager::useMetricUnits()) { + bool rangeMetric = LocationManager::useMetricUnits(); + if (rangeMetric) { snprintf(rangeLabel, sizeof(rangeLabel), "%.0fkm", rangeKm); } else { - snprintf(rangeLabel, sizeof(rangeLabel), "%.0fmi", Units::kmToMi(rangeKm)); + snprintf(rangeLabel, sizeof(rangeLabel), "%.0fnm", Units::kmToNm(rangeKm)); } drawButton(tft, L.rangeBtn, rangeLabel); diff --git a/src/stats_screen.cpp b/src/stats_screen.cpp index 7758319..c902350 100644 --- a/src/stats_screen.cpp +++ b/src/stats_screen.cpp @@ -4,6 +4,8 @@ #include "menu_stars.h" #include "config.h" #include "i18n.h" +#include "units.h" +#include "location_manager.h" namespace StatsScreen { @@ -98,8 +100,14 @@ void run(TFT_eSPI& tft) { if (topAlt.found) { String csign = topAlt.callsign[0] ? String(topAlt.callsign) : "?"; + // Respektiert jetzt die Einheiten-Einstellung (Menue > Einheiten) + // - vorher immer "(XXXX ft)", auch bei Metrisch eingestellt. char altBuf[24]; - snprintf(altBuf, sizeof(altBuf), "%s (%ld ft)", csign.c_str(), (long)topAlt.altitudeFt); + if (LocationManager::useMetricUnits()) { + snprintf(altBuf, sizeof(altBuf), "%s (%ldm)", csign.c_str(), (long)Units::feetToMeters((float)topAlt.altitudeFt)); + } else { + snprintf(altBuf, sizeof(altBuf), "%s (%ld ft)", csign.c_str(), (long)topAlt.altitudeFt); + } drawStatRow(tft, TOP_ALT_Y, I18n::t(StringId::STATS_TOP_ALTITUDE_PREFIX), String(altBuf)); }