Fix units tpms not compiling (#2994)

* add defines for unit types
* fix compilation, units usage and variables names
This commit is contained in:
gullradriel
2026-02-16 15:50:27 +01:00
committed by GitHub
parent 83a4580353
commit e17f4c4ab4
3 changed files with 25 additions and 27 deletions
+8 -9
View File
@@ -47,14 +47,13 @@ std::string id(tpms::TransponderID id) {
} }
std::string pressure(Pressure pressure) { std::string pressure(Pressure pressure) {
return to_string_dec_int( return to_string_dec_int(pressure_unit == PRESSURE_UNIT_PSI ? pressure.psi() : pressure_unit == PRESSURE_UNIT_BAR ? pressure.bar()
format::units_pressure == format::PressureUnit::PSI ? pressure.psi() : format::units_pressure == format::PressureUnit::BAR ? pressure.bar() : pressure.kilopascal(),
: pressure.kilopascal(), 3);
3);
} }
std::string temperature(Temperature temperature) { std::string temperature(Temperature temperature) {
return to_string_dec_int(units_fahr ? temperature.fahrenheit() : temperature.celsius(), 3); return to_string_dec_int(temp_unit == TEMP_UNIT_CELSIUS ? temperature.celsius() : temperature.fahrenheit(), 3);
} }
std::string flags(tpms::Flags flags) { std::string flags(tpms::Flags flags) {
@@ -125,16 +124,16 @@ 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_pressure = static_cast<format::PressureUnit>(i); format::pressure_unit = (uint8_t)i;
update_view(); update_view();
}; };
options_pressure.set_selected_index(static_cast<int>(format::units_pressure), true); options_pressure.set_selected_index(format::pressure_unit, 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::temp_unit = (uint8_t)i;
update_view(); update_view();
}; };
options_temperature.set_selected_index(format::units_fahr, true); options_temperature.set_selected_index(format::temp_unit, true);
logger = std::make_unique<TPMSLogger>(); logger = std::make_unique<TPMSLogger>();
if (logger) { if (logger) {
+10 -17
View File
@@ -42,16 +42,9 @@ namespace ui::external_app::tpmsrx {
namespace format { namespace format {
enum class PressureUnit : int { static uint8_t pressure_unit{PRESSURE_UNIT_KPA};
kPa = 0, static uint8_t temp_unit{TEMP_UNIT_CELSIUS};
PSI = 1, } // namespace format
BAR = 2,
};
static PressureUnit units_pressure{PressureUnit::kPa};
static bool units_fahr{false};
} /* namespace format */
struct TPMSRecentEntry { struct TPMSRecentEntry {
using Key = std::pair<tpms::Reading::Type, tpms::TransponderID>; using Key = std::pair<tpms::Reading::Type, tpms::TransponderID>;
@@ -123,8 +116,8 @@ class TPMSAppView : public View {
"rx_tpms", "rx_tpms",
app_settings::Mode::RX, app_settings::Mode::RX,
{ {
{"units_pressure"sv, &format::units_pressure}, {"pressure_unit"sv, &format::pressure_unit},
{"units_fahr"sv, &format::units_fahr}, {"temp_unit"sv, &format::temp_unit},
}}; }};
MessageHandlerRegistration message_handler_packet{ MessageHandlerRegistration message_handler_packet{
@@ -161,15 +154,15 @@ class TPMSAppView : public View {
OptionsField options_pressure{ OptionsField options_pressure{
{6 * 8, UI_POS_Y(0)}, {6 * 8, UI_POS_Y(0)},
4, 4,
{{"kPa", static_cast<int>(PressureUnit::kPa)}, {{"kPa", PRESSURE_UNIT_KPA},
{"PSI", static_cast<int>(PressureUnit::PSI)}, {"PSI", PRESSURE_UNIT_PSI},
{"BAR", static_cast<int>(PressureUnit::BAR)}}}; {"BAR", PRESSURE_UNIT_BAR}}};
OptionsField options_temperature{ OptionsField options_temperature{
{10 * 8, UI_POS_Y(0)}, {10 * 8, UI_POS_Y(0)},
2, 2,
{{STR_DEGREES_C, 0}, {{STR_DEGREES_C, TEMP_UNIT_CELSIUS},
{STR_DEGREES_F, 1}}}; {STR_DEGREES_F, TEMP_UNIT_FAHRENHEIT}}};
RFAmpField field_rf_amp{ RFAmpField field_rf_amp{
{13 * 8, UI_POS_Y(0)}}; {13 * 8, UI_POS_Y(0)}};
+6
View File
@@ -22,6 +22,12 @@
#ifndef __UNITS_H__ #ifndef __UNITS_H__
#define __UNITS_H__ #define __UNITS_H__
#define TEMP_UNIT_CELSIUS 0
#define TEMP_UNIT_FAHRENHEIT 1
#define PRESSURE_UNIT_KPA 2
#define PRESSURE_UNIT_BAR 3
#define PRESSURE_UNIT_PSI 4
#include <cstdint> #include <cstdint>
#define STR_DEGREES_C "\xB0\x43" // ºC - 0xB0 is degree ° symbol in our 8x16 font, 0x43 is "C" #define STR_DEGREES_C "\xB0\x43" // ºC - 0xB0 is degree ° symbol in our 8x16 font, 0x43 is "C"