AltStatusBar: take the PowerCover into account in the battery level (#8741)

Don't show [+] in top status line when device is charging
from a power cover, but the sum of both battery levels.
This commit is contained in:
zwim
2022-02-01 21:15:49 +01:00
committed by GitHub
parent c1c89dd611
commit 43f14b313f
2 changed files with 22 additions and 4 deletions

View File

@@ -1106,12 +1106,30 @@ function ReaderRolling:updateBatteryState()
if self.view.view_mode == "page" and self.cre_top_bar_enabled then
logger.dbg("update battery state")
local powerd = Device:getPowerDevice()
local main_batt_lvl = powerd:getCapacity()
-- -1 is CR_BATTERY_STATE_CHARGING @ crengine/crengine/include/lvdocview.h
local state = powerd:isCharging() and -1 or powerd:getCapacity()
local state = powerd:isCharging() and -1 or main_batt_lvl
if powerd.device:hasAuxBattery() and powerd:isAuxBatteryConnected() and
not powerd:isAuxCharging() then
-- The first few reads after connecting to the PowerCover may fail, so default to zero
local aux_batt_lvl = powerd:getAuxCapacity()
-- If aux_battery not charging, but present -> don't show '[ + ]' in header
-- but show the average (as both battery have the same maximum capacity).
if G_reader_settings:readSetting("cre_header_battery_percent") ~= 0 then
-- if percentage is wanted, show the total capacity of reader plus power-cover
state = main_batt_lvl + aux_batt_lvl
else
-- if icon is wanted, show the total average capacity of reader and power-cover
-- (as this is the shows graphically what capacity is left in total)
state = math.floor((main_batt_lvl + aux_batt_lvl) / 2)
end
end
if state then
self.ui.document:setBatteryState(state)
end
return state
end
return 0
end
function ReaderRolling:handleEngineCallback(ev, ...)