support for battery if any + TPMS app to ext (#2129)

* batt initial
* batt widgets
* settings modify
* batt info screen
* ability to hide icon
* battView
* redo tmps
* hide curr + charge if no data
* fix flashing
This commit is contained in:
Totoo 2024-04-29 17:38:27 +02:00 committed by GitHub
parent f572b00391
commit f6a2d21624
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 767 additions and 44 deletions

View file

@ -84,6 +84,7 @@
#include "ui_weatherstation.hpp"
#include "ui_subghzd.hpp"
#include "ui_whipcalc.hpp"
#include "ui_battinfo.hpp"
#include "ui_external_items_menu_loader.hpp"
// #include "acars_app.hpp"
@ -334,6 +335,9 @@ SystemStatusView::SystemStatusView(
refresh();
};
battery_icon.on_select = [this]() { on_battery_details(); };
battery_text.on_select = [this]() { on_battery_details(); };
button_fake_brightness.on_select = [this](ImageButton&) {
set_dirty();
pmem::toggle_fake_brightness_level();
@ -370,6 +374,26 @@ SystemStatusView::SystemStatusView(
refresh();
}
// when battery icon / text is clicked
void SystemStatusView::on_battery_details() {
if (!nav_.is_valid()) return;
if (batt_info_up) return;
batt_info_up = true;
nav_.push<BattinfoView>();
nav_.set_on_pop([this]() {
batt_info_up = false;
});
}
void SystemStatusView::on_battery_data(const BatteryStateMessage* msg) {
if (!pmem::ui_hide_numeric_battery()) {
battery_text.set_battery(msg->percent, msg->on_charger);
}
if (!pmem::ui_hide_battery_icon()) {
battery_icon.set_battery(msg->percent, msg->on_charger);
};
}
void SystemStatusView::refresh() {
// NB: Order of insertion is the display order Left->Right.
// TODO: Might be better to support hide and only add once.
@ -386,8 +410,20 @@ void SystemStatusView::refresh() {
if (audio::speaker_disable_supported() && !pmem::ui_hide_speaker()) status_icons.add(&toggle_speaker);
if (!pmem::ui_hide_fake_brightness()) status_icons.add(&button_fake_brightness);
if (battery::BatteryManagement::isDetected()) {
uint8_t percent = battery::BatteryManagement::getPercent();
if (!pmem::ui_hide_battery_icon()) {
status_icons.add(&battery_icon);
battery_text.set_battery(percent, false); // got an on select, that may pop up the details of the battery.
};
if (!pmem::ui_hide_numeric_battery()) {
status_icons.add(&battery_text);
battery_text.set_battery(percent, false);
}
}
if (!pmem::ui_hide_sd_card()) status_icons.add(&sd_card_status_view);
status_icons.update_layout();
// Clock status
@ -667,8 +703,9 @@ void NavigationView::display_modal(
const std::string& title,
const std::string& message,
modal_t type,
std::function<void(bool)> on_choice) {
push<ModalMessageView>(title, message, type, on_choice);
std::function<void(bool)> on_choice,
bool compact) {
push<ModalMessageView>(title, message, type, on_choice, compact);
}
void NavigationView::free_view() {
@ -997,11 +1034,13 @@ ModalMessageView::ModalMessageView(
const std::string& title,
const std::string& message,
modal_t type,
std::function<void(bool)> on_choice)
std::function<void(bool)> on_choice,
bool compact)
: title_{title},
message_{message},
type_{type},
on_choice_{on_choice} {
on_choice_{on_choice},
compact{compact} {
if (type == INFO) {
add_child(&button_ok);
button_ok.on_select = [this, &nav](Button&) {
@ -1034,13 +1073,13 @@ ModalMessageView::ModalMessageView(
}
void ModalMessageView::paint(Painter& painter) {
portapack::display.drawBMP({100, 48}, modal_warning_bmp, false);
if (!compact) portapack::display.drawBMP({100, 48}, modal_warning_bmp, false);
// Break lines.
auto lines = split_string(message_, '\n');
for (size_t i = 0; i < lines.size(); ++i) {
painter.draw_string(
{1 * 8, (Coord)(120 + (i * 16))},
{1 * 8, (Coord)(((compact) ? 8 * 3 : 120) + (i * 16))},
style(),
lines[i]);
}