feat: add BAR unit support to TPMS RX app (#2988)

- Add bar() conversion method to Pressure class
- Convert pressure units system from boolean to enum (kPa, PSI, BAR)
- Add BAR option to pressure unit selector in UI
- Update settings manager to persist pressure unit preference
- Use ternary operators for compact pressure formatting
This commit is contained in:
Hoite Prins
2026-02-16 14:55:12 +01:00
committed by GitHub
parent 794daf5257
commit 00f40bf171
3 changed files with 22 additions and 8 deletions
+6 -3
View File
@@ -47,7 +47,10 @@ std::string id(tpms::TransponderID id) {
} }
std::string pressure(Pressure pressure) { std::string pressure(Pressure pressure) {
return to_string_dec_int(units_psi ? pressure.psi() : pressure.kilopascal(), 3); return to_string_dec_int(
format::units_pressure == format::PressureUnit::PSI ? pressure.psi() : format::units_pressure == format::PressureUnit::BAR ? pressure.bar()
: pressure.kilopascal(),
3);
} }
std::string temperature(Temperature temperature) { std::string temperature(Temperature temperature) {
@@ -122,10 +125,10 @@ TPMSAppView::TPMSAppView(NavigationView&) {
options_band.set_by_value(receiver_model.target_frequency()); options_band.set_by_value(receiver_model.target_frequency());
options_pressure.on_change = [this](size_t, int32_t i) { options_pressure.on_change = [this](size_t, int32_t i) {
format::units_psi = (bool)i; format::units_pressure = static_cast<format::PressureUnit>(i);
update_view(); update_view();
}; };
options_pressure.set_selected_index(format::units_psi, true); options_pressure.set_selected_index(static_cast<int>(format::units_pressure), true);
options_temperature.on_change = [this](size_t, int32_t i) { options_temperature.on_change = [this](size_t, int32_t i) {
format::units_fahr = (bool)i; format::units_fahr = (bool)i;
+12 -5
View File
@@ -42,7 +42,13 @@ namespace ui::external_app::tpmsrx {
namespace format { namespace format {
static bool units_psi{false}; enum class PressureUnit : int {
kPa = 0,
PSI = 1,
BAR = 2,
};
static PressureUnit units_pressure{PressureUnit::kPa};
static bool units_fahr{false}; static bool units_fahr{false};
} /* namespace format */ } /* namespace format */
@@ -117,7 +123,7 @@ class TPMSAppView : public View {
"rx_tpms", "rx_tpms",
app_settings::Mode::RX, app_settings::Mode::RX,
{ {
{"units_psi"sv, &format::units_psi}, {"units_pressure"sv, &format::units_pressure},
{"units_fahr"sv, &format::units_fahr}, {"units_fahr"sv, &format::units_fahr},
}}; }};
@@ -154,9 +160,10 @@ class TPMSAppView : public View {
OptionsField options_pressure{ OptionsField options_pressure{
{6 * 8, UI_POS_Y(0)}, {6 * 8, UI_POS_Y(0)},
3, 4,
{{"kPa", 0}, {{"kPa", static_cast<int>(PressureUnit::kPa)},
{"PSI", 1}}}; {"PSI", static_cast<int>(PressureUnit::PSI)},
{"BAR", static_cast<int>(PressureUnit::BAR)}}};
OptionsField options_temperature{ OptionsField options_temperature{
{10 * 8, UI_POS_Y(0)}, {10 * 8, UI_POS_Y(0)},
+4
View File
@@ -48,6 +48,10 @@ class Pressure {
return kpa_ * 1000 / 6895; return kpa_ * 1000 / 6895;
} }
int bar() const {
return kpa_ / 100;
}
private: private:
int16_t kpa_; int16_t kpa_;
}; };