Tyre pressures show in bar by default; Settings → Display offers kPa and psi as well. Display only: the car reports kPa and the server keeps storing kPa. A "Power, 5-min average" card under Power: the time-weighted mean battery power over the last five minutes, standing included, from the same samples as the 5-minute range. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QLJfZQZeAKAwSqViTmLzki
41 lines
1.1 KiB
Java
41 lines
1.1 KiB
Java
package com.evsuite.abrp;
|
|
|
|
import java.util.Locale;
|
|
|
|
/**
|
|
* The unit tyre pressures are shown in. The car reports kPa; this only changes the display.
|
|
* Android-free, unit-tested.
|
|
*/
|
|
enum PressureUnit {
|
|
BAR("bar", "%.1f bar", 0.01),
|
|
KPA("kPa", "%.0f kPa", 1.0),
|
|
PSI("psi", "%.1f psi", 0.145038);
|
|
|
|
static final String PREF_KEY = "tire_pressure_unit";
|
|
static final PressureUnit DEFAULT = BAR;
|
|
|
|
final String label;
|
|
private final String pattern;
|
|
private final double perKpa;
|
|
|
|
PressureUnit(String label, String pattern, double perKpa) {
|
|
this.label = label;
|
|
this.pattern = pattern;
|
|
this.perKpa = perKpa;
|
|
}
|
|
|
|
/** A reading in this unit, or a dash for none. */
|
|
String format(Float kpa) {
|
|
if (kpa == null || kpa.isNaN() || kpa.isInfinite()) return "—";
|
|
return String.format(Locale.US, pattern, kpa * perKpa);
|
|
}
|
|
|
|
/** The stored choice; anything unknown falls back to bar. */
|
|
static PressureUnit fromPref(String name) {
|
|
for (PressureUnit u : values()) {
|
|
if (u.name().equals(name)) return u;
|
|
}
|
|
return DEFAULT;
|
|
}
|
|
}
|