In order to stabilize the battery reading,

I modified the process to make 5 consecutive readings,
as the process is asynchronous,
there is no interference in the main process.
This commit is contained in:
Joaquim
2021-04-16 16:15:38 +01:00
parent c0c37877b5
commit 3c413bdd52
5 changed files with 40 additions and 16 deletions

View File

@@ -84,7 +84,7 @@ void BatteryInfo::UpdateAnim() {
batteryPercent = batteryController.PercentRemaining();
if ( batteryPercent >= 0 ) {
if ( batteryController.IsCharging() ) {
if ( batteryController.IsCharging() and batteryPercent < 100 ) {
animation +=1;
if (animation >= 100) {
animation = 0;
@@ -111,12 +111,17 @@ void BatteryInfo::UpdateScreen() {
batteryVoltage = batteryController.Voltage();
if ( batteryPercent >= 0 ) {
if ( batteryController.IsCharging() ) {
lv_obj_set_style_local_bg_color(charging_bar, LV_BAR_PART_INDIC , LV_STATE_DEFAULT, lv_color_hex(0xFF0000));
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_hex(0x00FF00));
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");
}