From 0b9f19916e1f9f142265d2efbae8fd71b3af4288 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 1 Oct 2024 15:33:03 +0200 Subject: [PATCH] Improved battery calculations for devices without dedicated PMU --- Display.h | 12 ++++++++++-- Power.h | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Display.h b/Display.h index d849d85..8dfa0e8 100644 --- a/Display.h +++ b/Display.h @@ -266,14 +266,22 @@ void draw_battery_bars(int px, int py) { if (battery_ready) { if (battery_installed) { float battery_value = battery_percent; + + // Disable charging state display for now, since + // boards without dedicated PMU are completely + // unreliable for determining actual charging state. + bool disable_charge_status = false; + if (battery_indeterminate && battery_state == BATTERY_STATE_CHARGING) { + disable_charge_status = true; + } - if (battery_state == BATTERY_STATE_CHARGING) { + if (battery_state == BATTERY_STATE_CHARGING && !disable_charge_status) { battery_value = charge_tick; charge_tick += 3; if (charge_tick > 100) charge_tick = 0; } - if (battery_indeterminate && battery_state == BATTERY_STATE_CHARGING) { + if (battery_indeterminate && battery_state == BATTERY_STATE_CHARGING && !disable_charge_status) { stat_area.fillRect(px-2, py-2, 18, 7, SSD1306_BLACK); stat_area.drawBitmap(px-2, py-2, bm_plug, 17, 7, SSD1306_WHITE, SSD1306_BLACK); } else { diff --git a/Power.h b/Power.h index 1f70da6..5112f50 100644 --- a/Power.h +++ b/Power.h @@ -121,7 +121,7 @@ void measure_battery() { } } else { if (bat_voltage_dropping == true) { - if (bat_delay_diff > 0.008) { + if (bat_delay_diff > 0.01) { bat_voltage_dropping = false; bat_state_change_v = battery_voltage; // SerialBT.printf("STATE CHANGE to CHARGE at delta=%.3fv. State change v is now %.3fv.\n", bat_delay_diff, bat_state_change_v);