|
|
|
local UIManager -- will be updated when available
|
|
|
|
local Math = require("optmath")
|
|
|
|
local logger = require("logger")
|
|
|
|
local time = require("ui/time")
|
|
|
|
local BasePowerD = {
|
|
|
|
fl_min = 0, -- min frontlight intensity
|
|
|
|
fl_max = 10, -- max frontlight intensity
|
|
|
|
fl_intensity = nil, -- frontlight intensity
|
|
|
|
fl_warmth_min = 0, -- min warmth level
|
|
|
|
fl_warmth_max = 100, -- max warmth level
|
|
|
|
fl_warmth = nil, -- warmth level
|
|
|
|
batt_capacity = 0, -- battery capacity
|
|
|
|
aux_batt_capacity = 0, -- auxiliary battery capacity
|
|
|
|
device = nil, -- device object
|
|
|
|
|
|
|
|
last_capacity_pull_time = time.s(-61), -- timestamp of last pull
|
|
|
|
last_aux_capacity_pull_time = time.s(-61), -- timestamp of last pull
|
|
|
|
|
|
|
|
is_fl_on = false, -- whether the frontlight is on
|
|
|
|
}
|
|
|
|
|
|
|
|
function BasePowerD:new(o)
|
|
|
|
o = o or {}
|
|
|
|
setmetatable(o, self)
|
|
|
|
self.__index = self
|
|
|
|
assert(o.fl_min < o.fl_max)
|
|
|
|
if o.init then o:init() end
|
|
|
|
if o.device and o.device:hasFrontlight() then
|
|
|
|
o.fl_intensity = o:frontlightIntensityHW()
|
|
|
|
o:_decideFrontlightState()
|
|
|
|
end
|
|
|
|
--- @note: Post-init, as the min/max values may be computed at runtime on some platforms
|
|
|
|
assert(o.fl_warmth_min < o.fl_warmth_max)
|
|
|
|
-- For historical reasons, the *public* PowerD warmth API always expects warmth to be in the [0...100] range...
|
|
|
|
self.warmth_scale = 100 / o.fl_warmth_max
|
|
|
|
--- @note: Some platforms cannot actually read fl/warmth level from the HW,
|
|
|
|
-- in which case the implementation should just return self.fl_warmth (c.f., kobo).
|
|
|
|
if o.device and o.device:hasNaturalLight() then
|
|
|
|
o.fl_warmth = o:frontlightWarmthHW()
|
|
|
|
end
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:readyUI()
|
|
|
|
UIManager = require("ui/uimanager")
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:init() end
|
|
|
|
function BasePowerD:setIntensityHW(intensity) end
|
|
|
|
--- @note: Unlike the "public" setWarmth, this one takes a value in the *native* scale!
|
|
|
|
function BasePowerD:setWarmthHW(warmth) end
|
|
|
|
function BasePowerD:getCapacityHW() return 0 end
|
|
|
|
function BasePowerD:getAuxCapacityHW() return 0 end
|
|
|
|
function BasePowerD:isAuxBatteryConnectedHW() return false end
|
|
|
|
function BasePowerD:getDismissBatteryStatus() return self.battery_warning end
|
|
|
|
function BasePowerD:setDismissBatteryStatus(status) self.battery_warning = status end
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
--- @note: Should ideally return true as long as the device is plugged in, even once the battery is full...
|
|
|
|
function BasePowerD:isChargingHW() return false end
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
--- @note: ...at which point this should start returning true (i.e., plugged in & fully charged).
|
|
|
|
function BasePowerD:isChargedHW() return false end
|
|
|
|
function BasePowerD:isAuxChargingHW() return false end
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
function BasePowerD:isAuxChargedHW() return false end
|
|
|
|
function BasePowerD:frontlightIntensityHW() return 0 end
|
|
|
|
function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end
|
|
|
|
function BasePowerD:turnOffFrontlightHW() self:setIntensityHW(self.fl_min) end
|
|
|
|
function BasePowerD:turnOnFrontlightHW() self:setIntensityHW(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)?
|
|
|
|
function BasePowerD:frontlightWarmthHW() return 0 end
|
|
|
|
-- Anything that needs to be done before doing a real hardware suspend.
|
|
|
|
-- (Such as turning the front light off).
|
|
|
|
function BasePowerD:beforeSuspend() end
|
|
|
|
-- Anything that needs to be done after doing a real hardware resume.
|
|
|
|
-- (Such as restoring front light state).
|
|
|
|
function BasePowerD:afterResume() end
|
|
|
|
|
|
|
|
function BasePowerD:isFrontlightOn()
|
|
|
|
assert(self ~= nil)
|
|
|
|
return self.is_fl_on
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:_decideFrontlightState()
|
|
|
|
assert(self ~= nil)
|
|
|
|
assert(self.device:hasFrontlight())
|
|
|
|
self.is_fl_on = self:isFrontlightOnHW()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:isFrontlightOff()
|
|
|
|
return not self:isFrontlightOn()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:frontlightIntensity()
|
|
|
|
assert(self ~= nil)
|
|
|
|
if not self.device:hasFrontlight() then return 0 end
|
|
|
|
if self:isFrontlightOff() then return 0 end
|
|
|
|
--- @note: We assume that nothing other than us will set the frontlight level,
|
|
|
|
--- so we only actually query the HW during initialization.
|
|
|
|
--- (Also, some platforms do not actually have any way of querying the HW).
|
|
|
|
return self.fl_intensity
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:toggleFrontlight()
|
|
|
|
assert(self ~= nil)
|
|
|
|
if not self.device:hasFrontlight() then return false end
|
|
|
|
if self:isFrontlightOn() then
|
|
|
|
return self:turnOffFrontlight()
|
|
|
|
else
|
|
|
|
return self:turnOnFrontlight()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:turnOffFrontlight()
|
|
|
|
assert(self ~= nil)
|
|
|
|
if not self.device:hasFrontlight() then return end
|
|
|
|
if self:isFrontlightOff() then return false end
|
|
|
|
self:turnOffFrontlightHW()
|
|
|
|
self.is_fl_on = false
|
|
|
|
self:stateChanged()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:turnOnFrontlight()
|
|
|
|
assert(self ~= nil)
|
|
|
|
if not self.device:hasFrontlight() then return end
|
|
|
|
if self:isFrontlightOn() then return false end
|
|
|
|
if self.fl_intensity == self.fl_min then return false end --- @fixme what the hell?
|
|
|
|
self:turnOnFrontlightHW()
|
|
|
|
self.is_fl_on = true
|
|
|
|
self:stateChanged()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:frontlightWarmth()
|
|
|
|
assert(self ~= nil)
|
|
|
|
if not self.device:hasNaturalLight() then
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
--- @note: No live query, much like frontlightIntensity
|
|
|
|
return self.fl_warmth
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:read_int_file(file)
|
|
|
|
local fd = io.open(file, "r")
|
|
|
|
if fd then
|
|
|
|
local int = fd:read("*number")
|
|
|
|
fd:close()
|
|
|
|
return int or 0
|
|
|
|
else
|
|
|
|
return 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:unchecked_read_int_file(file)
|
|
|
|
local fd = io.open(file, "r")
|
|
|
|
if fd then
|
|
|
|
local int = fd:read("*number")
|
|
|
|
fd:close()
|
|
|
|
return int
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:read_str_file(file)
|
|
|
|
local fd = io.open(file, "r")
|
|
|
|
if fd then
|
|
|
|
local str = fd:read("*line")
|
|
|
|
fd:close()
|
|
|
|
return str
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:normalizeIntensity(intensity)
|
|
|
|
intensity = intensity < self.fl_min and self.fl_min or intensity
|
|
|
|
return intensity > self.fl_max and self.fl_max or intensity
|
|
|
|
end
|
|
|
|
|
|
|
|
--- @note: Takes an intensity in the native scale (i.e., [self.fl_min, self.fl_max])
|
|
|
|
function BasePowerD:setIntensity(intensity)
|
|
|
|
if not self.device:hasFrontlight() then return false end
|
|
|
|
if intensity == self:frontlightIntensity() then return false end
|
|
|
|
self.fl_intensity = self:normalizeIntensity(intensity)
|
|
|
|
self:_decideFrontlightState()
|
|
|
|
logger.dbg("set light intensity", self.fl_intensity)
|
|
|
|
self:setIntensityHW(self.fl_intensity)
|
|
|
|
self:stateChanged()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:normalizeWarmth(warmth)
|
|
|
|
warmth = warmth < 0 and 0 or warmth
|
|
|
|
return warmth > 100 and 100 or warmth
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:toNativeWarmth(ko_warmth)
|
|
|
|
return Math.round(ko_warmth / self.warmth_scale)
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:fromNativeWarmth(nat_warmth)
|
|
|
|
return Math.round(nat_warmth * self.warmth_scale)
|
|
|
|
end
|
|
|
|
|
|
|
|
--- @note: Takes a warmth in the *KOReader* scale (i.e., [0, 100], *sic*)
|
|
|
|
function BasePowerD:setWarmth(warmth, force_setting)
|
|
|
|
if not self.device:hasNaturalLight() then return false end
|
|
|
|
if not force_setting and warmth == self:frontlightWarmth() then return false end
|
|
|
|
-- Which means that fl_warmth is *also* in the KOReader scale (unlike fl_intensity)
|
|
|
|
self.fl_warmth = self:normalizeWarmth(warmth)
|
|
|
|
local nat_warmth = self:toNativeWarmth(self.fl_warmth)
|
|
|
|
logger.dbg("set light warmth", self.fl_warmth, "->", nat_warmth)
|
|
|
|
self:setWarmthHW(nat_warmth)
|
|
|
|
self:stateChanged()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:getCapacity()
|
|
|
|
-- BasePowerD is loaded before UIManager.
|
|
|
|
-- Nothing *currently* calls this before UIManager is actually loaded, but future-proof this anyway.
|
|
|
|
local now
|
|
|
|
if UIManager then
|
|
|
|
now = UIManager:getElapsedTimeSinceBoot()
|
|
|
|
else
|
|
|
|
-- Add time the device was in standby and suspend
|
|
|
|
now = time.now() + self.device.total_standby_time + self.device.total_suspend_time
|
|
|
|
end
|
|
|
|
|
|
|
|
if now - self.last_capacity_pull_time >= time.s(60) then
|
|
|
|
self.batt_capacity = self:getCapacityHW()
|
|
|
|
self.last_capacity_pull_time = now
|
|
|
|
end
|
|
|
|
return self.batt_capacity
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:isCharging()
|
|
|
|
return self:isChargingHW()
|
|
|
|
end
|
|
|
|
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
function BasePowerD:isCharged()
|
|
|
|
return self:isChargedHW()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:getAuxCapacity()
|
|
|
|
local now
|
|
|
|
|
|
|
|
if UIManager then
|
|
|
|
now = UIManager:getElapsedTimeSinceBoot()
|
|
|
|
else
|
|
|
|
-- Add time the device was in standby and suspend
|
|
|
|
now = time.now() + self.device.total_standby_time + self.device.total_suspend_time
|
|
|
|
end
|
|
|
|
|
|
|
|
if now - self.last_aux_capacity_pull_time >= time.s(60) then
|
|
|
|
local aux_batt_capa = self:getAuxCapacityHW()
|
|
|
|
-- If the read failed, don't update our cache, and retry next time.
|
|
|
|
if aux_batt_capa then
|
|
|
|
self.aux_batt_capacity = aux_batt_capa
|
|
|
|
self.last_aux_capacity_pull_time = now
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return self.aux_batt_capacity
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:invalidateCapacityCache()
|
|
|
|
self.last_capacity_pull_time = time.s(-61)
|
|
|
|
self.last_aux_capacity_pull_time = self.last_capacity_pull_time
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:isAuxCharging()
|
|
|
|
return self:isAuxChargingHW()
|
|
|
|
end
|
|
|
|
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
function BasePowerD:isAuxCharged()
|
|
|
|
return self:isAuxChargedHW()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:isAuxBatteryConnected()
|
|
|
|
return self:isAuxBatteryConnectedHW()
|
|
|
|
end
|
|
|
|
|
|
|
|
function BasePowerD:stateChanged()
|
|
|
|
-- BasePowerD is loaded before UIManager. So we cannot broadcast events before UIManager has been loaded.
|
|
|
|
if UIManager then
|
|
|
|
local Event = require("ui/event")
|
|
|
|
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Silly helper to avoid code duplication ;).
|
A host of low power states related tweaks (#9036)
* Disable all non power management related input during suspend. (This prevents wonky touch events from being tripped when closing a sleep cover on an already-in-suspend device, among other things).
* Kobo: Use our WakeupMgr instance, not the class.
* WakupMgr: split `removeTask` in two:
* `removeTask`, which *only* takes a queue index as input, and only removes a single task. Greatly simplifies the function (i.e., it's just a `table.remove`).
* `removeTasks`, which takes an epoch or a cb ref, and removes *every* task that matches.
* Both of these will also *always* re-schedule the next task (if any) on exit, since we can have multiple WakeupMgr tasks queued, but we can only have a single RTC wake alarm set ;).
* `wakeupAction` now takes a `proximity` argument, which it passes on to its `validateWakeupAlarmByProximity` call, allowing call sites to avoir having to duplicate that call themselves when they want to use a custom proximity window.
* `wakeupAction` now re-schedules the next task (if any) on exit.
* Simplify `Kobo:checkUnexpectedWakeup`, by removing the duplicate `WakerupMgr:validateWakeupAlarmByProximity` call, now that we can pass a proximity window to `WakeuoMgr:wakeupAction`.
* The various network activity timeouts are now halved when autostandby is enabled.
* Autostandby: get rid of the dummy deadline_guard task, as it's no longer necessary since #9009.
* UIManager: The previous change allows us to simplify `getNextTaskTimes` into a simpler `getNextTaskTime` variant, getting rid of a table & a loop.
* ReaderFooter & ReaderHeader: Make sure we only perform a single refresh when exiting standby.
* Kobo: Rewrite sysfs writes to use ANSI C via FFI instead of stdio via Lua, as it obscured some common error cases (e.g., EBUSY on /sys/power/state).
* Kobo: Simplify `suspend`, now that we have sane error handling in sysfs writes.
* Kobo.powerd: Change `isCharging` & `isAuxCharging` behavior to match the behavior of the NTX ioctl (i.e., Charging == Plugged-in). This has the added benefit of making the AutoSuspend checks behave sensibly in the "fully-charged but still plugged in" scenario (because being plugged in is enough to break PM on `!canPowerSaveWhileCharging` devices).
* AutoSuspend: Disable our `AllowStandby` handler when auto standby is disabled, so as to not interfere with other modules using `UIManager:allowStandby` (fix #9038).
* PowerD: Allow platforms to implement `isCharged`, indicating that the battery is full while still plugged in to a power source (battery icon becomes a power plug icon).
* Kobo.powerd: Implement `isCharged`, and kill charging LEDs once battery is full.
* Kindle.powerd: Implement `isCharged` on post-Wario devices. (`isCharging` is still true in that state, as it ought to).
2 years ago
|
|
|
function BasePowerD:getBatterySymbol(is_charged, is_charging, capacity)
|
|
|
|
if is_charged then
|
|
|
|
return ""
|
|
|
|
elseif is_charging then
|
|
|
|
return ""
|
|
|
|
else
|
|
|
|
if capacity >= 100 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 90 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 80 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 70 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 60 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 50 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 40 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 30 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 20 then
|
|
|
|
return ""
|
|
|
|
elseif capacity >= 10 then
|
|
|
|
return ""
|
|
|
|
else
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return BasePowerD
|