mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
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:
@@ -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, ...)
|
||||
|
||||
Reference in New Issue
Block a user