From 3fa01a197573072268854b3434fd05d65564fc90 Mon Sep 17 00:00:00 2001 From: CTCaer Date: Sat, 4 Jun 2022 22:03:47 +0300 Subject: [PATCH] hekate: fix a bug in low battery monitor Do not try to deinit display if it's not enabled. Can happen if LBM disables display to reserve power while charging and user presses both VOL buttons to exit the mode. --- bootloader/main.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/bootloader/main.c b/bootloader/main.c index 2c11224..b29c0ce 100644 --- a/bootloader/main.c +++ b/bootloader/main.c @@ -1211,6 +1211,7 @@ static void _check_low_battery() enough_battery = charge_status ? 3250 : 3000; + // If battery voltage is enough, exit. if (batt_volt > enough_battery || !batt_volt) goto out; @@ -1243,6 +1244,7 @@ static void _check_low_battery() max17050_get_property(MAX17050_AvgVCELL, &batt_volt); enough_battery = current_charge_status ? 3250 : 3000; + // If battery voltage is enough, exit. if (batt_volt > enough_battery) break; @@ -1258,17 +1260,21 @@ static void _check_low_battery() // Check if it's time to turn off display. if (screen_on && timer < get_tmr_ms()) { + // If battery is not charging, power off. if (!current_charge_status) { max77620_low_battery_monitor_config(true); + + // Handle full hw deinit and power off. power_set_state(POWER_OFF_RESET); } + // If charging, just disable display. display_end(); screen_on = false; } - // Check if charging status changed or Power button was pressed. + // Check if charging status changed or Power button was pressed and enable display. if ((charge_status != current_charge_status) || (btn_wait_timeout_single(0, BTN_POWER) & BTN_POWER)) { if (!screen_on) @@ -1299,7 +1305,8 @@ static void _check_low_battery() charge_status = current_charge_status; } - display_end(); + if (screen_on) + display_end(); free(battery_icon); free(charging_icon);