diff options
author | Riku Isokoski <riksu9000@gmail.com> | 2021-08-01 11:47:26 +0300 |
---|---|---|
committer | Riku Isokoski <riksu9000@gmail.com> | 2021-08-01 11:47:26 +0300 |
commit | 5bdef365f2b8f8e0ba06d04216749205a5bba50d (patch) | |
tree | b0260cd863c37ca1cee57fd813647706e2d07f77 /src/displayapp/screens/BatteryInfo.cpp | |
parent | 9e8dd9a1e63523f4e3ed322978e5b5e079c50375 (diff) | |
parent | 514481ef7f9c71ad816b31d979c6ab39ce9380dd (diff) |
Merge branch 'develop' into HEAD
Diffstat (limited to 'src/displayapp/screens/BatteryInfo.cpp')
-rw-r--r-- | src/displayapp/screens/BatteryInfo.cpp | 93 |
1 files changed, 20 insertions, 73 deletions
diff --git a/src/displayapp/screens/BatteryInfo.cpp b/src/displayapp/screens/BatteryInfo.cpp index 1ab8b0ad..0ab47ebf 100644 --- a/src/displayapp/screens/BatteryInfo.cpp +++ b/src/displayapp/screens/BatteryInfo.cpp @@ -9,11 +9,6 @@ static void lv_update_task(struct _lv_task_t* task) { user_data->UpdateScreen(); } -static void lv_anim_task(struct _lv_task_t* task) { - auto user_data = static_cast<BatteryInfo*>(task->user_data); - user_data->UpdateAnim(); -} - BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Battery& batteryController) : Screen(app), batteryController {batteryController} { @@ -24,12 +19,12 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont lv_obj_set_size(charging_bar, 200, 15); lv_bar_set_range(charging_bar, 0, 100); lv_obj_align(charging_bar, nullptr, LV_ALIGN_CENTER, 0, 10); - lv_bar_set_anim_time(charging_bar, 2000); + lv_bar_set_anim_time(charging_bar, 1000); lv_obj_set_style_local_radius(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, lv_color_hex(0x222222)); lv_obj_set_style_local_bg_opa(charging_bar, LV_BAR_PART_BG, LV_STATE_DEFAULT, LV_OPA_100); lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, lv_color_hex(0xFF0000)); - lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_OFF); + lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON); status = lv_label_create(lv_scr_act(), nullptr); lv_label_set_text_static(status, "Reading Battery status"); @@ -38,24 +33,13 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont percent = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_font(percent, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76); - if (batteryPercent >= 0) { - lv_label_set_text_fmt(percent, "%02i%%", batteryPercent); - } else { - lv_label_set_text(percent, "--%"); - } + lv_label_set_text_fmt(percent, "%02i%%", batteryPercent); lv_label_set_align(percent, LV_LABEL_ALIGN_LEFT); lv_obj_align(percent, nullptr, LV_ALIGN_CENTER, 0, -60); - // hack to not use the flot functions from printf - uint8_t batteryVoltageBytes[2]; - batteryVoltageBytes[1] = static_cast<uint8_t>(batteryVoltage); // truncate whole numbers - batteryVoltageBytes[0] = - static_cast<uint8_t>((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over - // - voltage = lv_label_create(lv_scr_act(), nullptr); lv_obj_set_style_local_text_color(voltage, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0xC6A600)); - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltageBytes[1], batteryVoltageBytes[0]); + lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); lv_label_set_align(voltage, LV_LABEL_ALIGN_CENTER); lv_obj_align(voltage, nullptr, LV_ALIGN_CENTER, 0, 95); @@ -65,40 +49,15 @@ BatteryInfo::BatteryInfo(Pinetime::Applications::DisplayApp* app, Pinetime::Cont lv_obj_set_pos(backgroundLabel, 0, 0); lv_label_set_text_static(backgroundLabel, ""); - taskUpdate = lv_task_create(lv_update_task, 500000, LV_TASK_PRIO_LOW, this); - taskAnim = lv_task_create(lv_anim_task, 1000, LV_TASK_PRIO_LOW, this); + taskUpdate = lv_task_create(lv_update_task, 5000, LV_TASK_PRIO_LOW, this); UpdateScreen(); } BatteryInfo::~BatteryInfo() { lv_task_del(taskUpdate); - lv_task_del(taskAnim); lv_obj_clean(lv_scr_act()); } -void BatteryInfo::UpdateAnim() { - batteryPercent = batteryController.PercentRemaining(); - - if (batteryPercent >= 0) { - if (batteryController.IsCharging() and batteryPercent < 100) { - animation += 1; - if (animation >= 100) { - animation = 0; - } - - } else { - if (animation > batteryPercent) { - animation--; - } - if (animation < batteryPercent) { - animation++; - } - } - - lv_bar_set_value(charging_bar, animation, LV_ANIM_OFF); - } -} - void BatteryInfo::UpdateScreen() { batteryController.Update(); @@ -106,39 +65,27 @@ void BatteryInfo::UpdateScreen() { batteryPercent = batteryController.PercentRemaining(); batteryVoltage = batteryController.Voltage(); - if (batteryPercent >= 0) { - if (batteryController.IsCharging() and batteryPercent < 100) { - lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); - lv_label_set_text_static(status, "Battery charging"); - } else if (batteryPercent == 100) { - lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); - lv_label_set_text_static(status, "Battery is fully charged"); - } else if (batteryPercent < 10) { - lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW); - lv_label_set_text_static(status, "Battery is low"); - } else { - lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN); - lv_label_set_text_static(status, "Battery discharging"); - } - - lv_label_set_text_fmt(percent, "%02i%%", batteryPercent); - + if (batteryController.IsCharging() and batteryPercent < 100) { + lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_RED); + lv_label_set_text_static(status, "Charging"); + } else if (batteryPercent == 100) { + lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_BLUE); + lv_label_set_text_static(status, "Fully charged"); + } else if (batteryPercent < 10) { + lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_YELLOW); + lv_label_set_text_static(status, "Battery low"); } else { - lv_label_set_text_static(status, "Reading Battery status"); - lv_label_set_text(percent, "--%"); + lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC, LV_STATE_DEFAULT, LV_COLOR_GREEN); + lv_label_set_text_static(status, "Discharging"); } + lv_label_set_text_fmt(percent, "%02i%%", batteryPercent); + lv_obj_align(status, charging_bar, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); - // hack to not use the flot functions from printf - uint8_t batteryVoltageBytes[2]; - batteryVoltageBytes[1] = static_cast<uint8_t>(batteryVoltage); // truncate whole numbers - batteryVoltageBytes[0] = - static_cast<uint8_t>((batteryVoltage - batteryVoltageBytes[1]) * 100); // remove whole part of flt and shift 2 places over - // - lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltageBytes[1], batteryVoltageBytes[0]); + lv_label_set_text_fmt(voltage, "%1i.%02i volts", batteryVoltage / 1000, batteryVoltage % 1000 / 10); + lv_bar_set_value(charging_bar, batteryPercent, LV_ANIM_ON); } bool BatteryInfo::Refresh() { - return running; } |