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 <noreply@anthropic.com>
This commit is contained in:
Eiswolf-BG
2026-08-11 23:49:45 +02:00
parent bb7eb10cc8
commit 64b58a3c5d
4 changed files with 47 additions and 11 deletions

View File

@@ -9,6 +9,8 @@
#include "menu_stars.h"
#include "config.h"
#include "i18n.h"
#include "units.h"
#include "location_manager.h"
#include <algorithm>
#include <cstring>
@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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));
}