mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-13 16:54:04 +00:00
Merge pull request #874 from NotherNgineer/next
TPMS app enhancement to support Celsius/Fahrenheit toggling #873
This commit is contained in:
@@ -35,6 +35,7 @@ namespace tpms {
|
|||||||
namespace format {
|
namespace format {
|
||||||
|
|
||||||
static bool use_kpa = true;
|
static bool use_kpa = true;
|
||||||
|
static bool use_celsius = true;
|
||||||
|
|
||||||
std::string type(Reading::Type type) {
|
std::string type(Reading::Type type) {
|
||||||
return to_string_dec_uint(toUType(type), 2);
|
return to_string_dec_uint(toUType(type), 2);
|
||||||
@@ -45,15 +46,11 @@ std::string id(TransponderID id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string pressure(Pressure pressure) {
|
std::string pressure(Pressure pressure) {
|
||||||
if(use_kpa){
|
return to_string_dec_int(use_kpa? pressure.kilopascal():pressure.psi(), 3);
|
||||||
return to_string_dec_int(pressure.kilopascal(), 3);
|
|
||||||
}
|
|
||||||
return to_string_dec_int(pressure.psi(), 3);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string temperature(Temperature temperature) {
|
std::string temperature(Temperature temperature) {
|
||||||
return to_string_dec_int(temperature.celsius(), 3);
|
return to_string_dec_int(use_celsius? temperature.celsius():temperature.fahrenheit(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string flags(Flags flags) {
|
std::string flags(Flags flags) {
|
||||||
@@ -111,15 +108,15 @@ void RecentEntriesTable<TPMSRecentEntries>::draw(
|
|||||||
std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id);
|
std::string line = tpms::format::type(entry.type) + " " + tpms::format::id(entry.id);
|
||||||
|
|
||||||
if( entry.last_pressure.is_valid() ) {
|
if( entry.last_pressure.is_valid() ) {
|
||||||
line += " " + tpms::format::pressure(entry.last_pressure.value());
|
line += " " + tpms::format::pressure(entry.last_pressure.value());
|
||||||
} else {
|
} else {
|
||||||
line += " " " ";
|
line += " " " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( entry.last_temperature.is_valid() ) {
|
if( entry.last_temperature.is_valid() ) {
|
||||||
line += " " + tpms::format::temperature(entry.last_temperature.value());
|
line += " " + tpms::format::temperature(entry.last_temperature.value());
|
||||||
} else {
|
} else {
|
||||||
line += " " " ";
|
line += " " " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
if( entry.received_count > 999 ) {
|
if( entry.received_count > 999 ) {
|
||||||
@@ -145,10 +142,12 @@ TPMSAppView::TPMSAppView(NavigationView&) {
|
|||||||
&rssi,
|
&rssi,
|
||||||
&channel,
|
&channel,
|
||||||
&options_band,
|
&options_band,
|
||||||
|
&options_pressure,
|
||||||
|
&options_temperature,
|
||||||
&field_rf_amp,
|
&field_rf_amp,
|
||||||
&field_lna,
|
&field_lna,
|
||||||
&field_vga,
|
&field_vga,
|
||||||
&options_type,
|
&recent_entries_view
|
||||||
});
|
});
|
||||||
|
|
||||||
// load app settings
|
// load app settings
|
||||||
@@ -181,16 +180,19 @@ TPMSAppView::TPMSAppView(NavigationView&) {
|
|||||||
};
|
};
|
||||||
options_band.set_by_value(target_frequency());
|
options_band.set_by_value(target_frequency());
|
||||||
|
|
||||||
options_type.on_change = [this](size_t, int32_t i) {
|
options_pressure.on_change = [this](size_t, int32_t i) {
|
||||||
if (i == 0){
|
tpms::format::use_kpa = !i;
|
||||||
tpms::format::use_kpa = true;
|
update_view();
|
||||||
} else if (i == 1){
|
|
||||||
tpms::format::use_kpa = false;
|
|
||||||
}
|
|
||||||
update_type();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
options_type.set_selected_index(0, true);
|
options_pressure.set_selected_index(0, true);
|
||||||
|
|
||||||
|
options_temperature.on_change = [this](size_t, int32_t i) {
|
||||||
|
tpms::format::use_celsius = !i;
|
||||||
|
update_view();
|
||||||
|
};
|
||||||
|
|
||||||
|
options_temperature.set_selected_index(0, true);
|
||||||
|
|
||||||
logger = std::make_unique<TPMSLogger>();
|
logger = std::make_unique<TPMSLogger>();
|
||||||
if( logger ) {
|
if( logger ) {
|
||||||
@@ -214,16 +216,8 @@ void TPMSAppView::focus() {
|
|||||||
options_band.focus();
|
options_band.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::update_type() {
|
void TPMSAppView::update_view() {
|
||||||
if (tpms::format::use_kpa){
|
recent_entries_view.set_parent_rect(view_normal_rect);
|
||||||
remove_child(&recent_entries_view_psi);
|
|
||||||
add_child(&recent_entries_view_kpa);
|
|
||||||
recent_entries_view_kpa.set_parent_rect(view_normal_rect);
|
|
||||||
} else {
|
|
||||||
remove_child(&recent_entries_view_kpa);
|
|
||||||
add_child(&recent_entries_view_psi);
|
|
||||||
recent_entries_view_psi.set_parent_rect(view_normal_rect);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
|
void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
|
||||||
@@ -231,7 +225,7 @@ void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
|
|||||||
|
|
||||||
view_normal_rect = { 0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height };
|
view_normal_rect = { 0, header_height, new_parent_rect.width(), new_parent_rect.height() - header_height };
|
||||||
|
|
||||||
update_type();
|
update_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::on_packet(const tpms::Packet& packet) {
|
void TPMSAppView::on_packet(const tpms::Packet& packet) {
|
||||||
@@ -244,23 +238,13 @@ void TPMSAppView::on_packet(const tpms::Packet& packet) {
|
|||||||
const auto reading = reading_opt.value();
|
const auto reading = reading_opt.value();
|
||||||
auto& entry = ::on_packet(recent, TPMSRecentEntry::Key { reading.type(), reading.id() });
|
auto& entry = ::on_packet(recent, TPMSRecentEntry::Key { reading.type(), reading.id() });
|
||||||
entry.update(reading);
|
entry.update(reading);
|
||||||
|
recent_entries_view.set_dirty();
|
||||||
if(tpms::format::use_kpa){
|
|
||||||
recent_entries_view_kpa.set_dirty();
|
|
||||||
} else {
|
|
||||||
recent_entries_view_psi.set_dirty();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::on_show_list() {
|
void TPMSAppView::on_show_list() {
|
||||||
if(tpms::format::use_kpa){
|
recent_entries_view.hidden(false);
|
||||||
recent_entries_view_kpa.hidden(false);
|
recent_entries_view.focus();
|
||||||
recent_entries_view_kpa.focus();
|
|
||||||
} else {
|
|
||||||
recent_entries_view_psi.hidden(false);
|
|
||||||
recent_entries_view_psi.focus();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::on_band_changed(const uint32_t new_band_frequency) {
|
void TPMSAppView::on_band_changed(const uint32_t new_band_frequency) {
|
||||||
|
@@ -144,7 +144,7 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
OptionsField options_type {
|
OptionsField options_pressure {
|
||||||
{ 5 * 8, 0 * 16 },
|
{ 5 * 8, 0 * 16 },
|
||||||
3,
|
3,
|
||||||
{
|
{
|
||||||
@@ -153,6 +153,15 @@ private:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
OptionsField options_temperature {
|
||||||
|
{ 9 * 8, 0 * 16 },
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
{ "C", 0 },
|
||||||
|
{ "F", 1 }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
RFAmpField field_rf_amp {
|
RFAmpField field_rf_amp {
|
||||||
{ 13 * 8, 0 * 16 }
|
{ 13 * 8, 0 * 16 }
|
||||||
};
|
};
|
||||||
@@ -168,31 +177,21 @@ private:
|
|||||||
TPMSRecentEntries recent { };
|
TPMSRecentEntries recent { };
|
||||||
std::unique_ptr<TPMSLogger> logger { };
|
std::unique_ptr<TPMSLogger> logger { };
|
||||||
|
|
||||||
const RecentEntriesColumns columns_kpa { {
|
const RecentEntriesColumns columns { {
|
||||||
{ "Tp", 2 },
|
{ "Tp", 2 },
|
||||||
{ "ID", 8 },
|
{ "ID", 8 },
|
||||||
{ "kPa", 3 },
|
{ "Pres", 4 },
|
||||||
{ "C", 3 },
|
{ "Temp", 4 },
|
||||||
{ "Cnt", 3 },
|
{ "Cnt", 3 },
|
||||||
{ "Fl", 2 },
|
{ "Fl", 2 },
|
||||||
} };
|
} };
|
||||||
TPMSRecentEntriesView recent_entries_view_kpa { columns_kpa, recent };
|
TPMSRecentEntriesView recent_entries_view { columns, recent };
|
||||||
|
|
||||||
const RecentEntriesColumns columns_psi { {
|
|
||||||
{ "Tp", 2 },
|
|
||||||
{ "ID", 8 },
|
|
||||||
{ "PSI", 3 },
|
|
||||||
{ "C", 3 },
|
|
||||||
{ "Cnt", 3 },
|
|
||||||
{ "Fl", 2 },
|
|
||||||
} };
|
|
||||||
TPMSRecentEntriesView recent_entries_view_psi { columns_psi, recent };
|
|
||||||
|
|
||||||
uint32_t target_frequency_ = initial_target_frequency;
|
uint32_t target_frequency_ = initial_target_frequency;
|
||||||
|
|
||||||
void on_packet(const tpms::Packet& packet);
|
void on_packet(const tpms::Packet& packet);
|
||||||
void on_show_list();
|
void on_show_list();
|
||||||
void update_type();
|
void update_view();
|
||||||
|
|
||||||
void on_band_changed(const uint32_t new_band_frequency);
|
void on_band_changed(const uint32_t new_band_frequency);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user