Show battery voltage in top bar

This commit is contained in:
jacqueline
2023-10-03 09:52:30 +11:00
parent 3df4cc9e3d
commit f2bad894cd
3 changed files with 7 additions and 3 deletions
+1
View File
@@ -84,6 +84,7 @@ auto Battery::Update() -> void {
state_ = BatteryState{
.percent = percent,
.millivolts = mV,
.is_charging = is_charging,
};
EmitEvent();
+1
View File
@@ -25,6 +25,7 @@ class Battery {
struct BatteryState {
uint_fast8_t percent;
uint32_t millivolts;
bool is_charging;
bool operator==(const BatteryState& other) const {
+5 -3
View File
@@ -82,11 +82,13 @@ TopBar::TopBar(lv_obj_t* parent,
bindings_.push_back(model.battery_state.onChangedAndNow(
[=](const battery::Battery::BatteryState& state) {
std::ostringstream voltage;
voltage << (state.millivolts / 1000) << "."
<< (state.millivolts / 100 % 10) << "V";
if (state.is_charging) {
lv_label_set_text(charging, "+");
} else {
lv_label_set_text(charging, "");
voltage << "+";
}
lv_label_set_text(charging, voltage.str().c_str());
if (state.percent >= 95) {
lv_img_set_src(battery, &kIconBatteryFull);