2014-10-30 18:42:18 +00:00
|
|
|
local BasePowerD = require("device/generic/powerd")
|
2022-03-14 18:56:18 +00:00
|
|
|
local Math = require("optmath")
|
2016-01-07 14:30:28 +00:00
|
|
|
local NickelConf = require("device/kobo/nickel_conf")
|
2018-10-27 20:49:18 +00:00
|
|
|
local SysfsLight = require ("device/sysfs_light")
|
2020-09-15 18:39:32 +00:00
|
|
|
local ffiUtil = require("ffi/util")
|
2021-03-07 20:56:52 +00:00
|
|
|
local RTC = require("ffi/rtc")
|
2014-01-04 13:38:07 +00:00
|
|
|
|
2017-09-04 19:05:05 +00:00
|
|
|
-- Here, we only deal with the real hw intensity.
|
|
|
|
-- Dealing with toggling and remembering/restoring
|
|
|
|
-- previous intensity when toggling/untoggling is done
|
|
|
|
-- by BasePowerD.
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
local KoboPowerD = BasePowerD:new{
|
2017-08-29 15:37:08 +00:00
|
|
|
fl_min = 0, fl_max = 100,
|
2014-03-13 13:52:43 +00:00
|
|
|
fl = nil,
|
2016-03-02 06:59:48 +00:00
|
|
|
|
2021-07-21 16:12:58 +00:00
|
|
|
battery_sysfs = nil,
|
2022-01-15 22:36:46 +00:00
|
|
|
aux_battery_sysfs = nil,
|
2018-12-28 03:32:42 +00:00
|
|
|
fl_warmth_min = 0, fl_warmth_max = 100,
|
2019-04-15 18:06:24 +00:00
|
|
|
fl_was_on = nil,
|
2014-01-04 13:38:07 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 23:10:50 +00:00
|
|
|
--- @todo Remove G_defaults:readSetting("KOBO_LIGHT_ON_START")
|
2017-06-29 06:23:32 +00:00
|
|
|
function KoboPowerD:_syncKoboLightOnStart()
|
2017-09-04 19:05:05 +00:00
|
|
|
local new_intensity = nil
|
|
|
|
local is_frontlight_on = nil
|
2018-02-04 11:38:48 +00:00
|
|
|
local new_warmth = nil
|
2022-09-27 23:10:50 +00:00
|
|
|
local kobo_light_on_start = tonumber(G_defaults:readSetting("KOBO_LIGHT_ON_START"))
|
2023-02-06 10:33:42 +00:00
|
|
|
|
2017-06-29 06:23:32 +00:00
|
|
|
if kobo_light_on_start then
|
|
|
|
if kobo_light_on_start > 0 then
|
|
|
|
new_intensity = math.min(kobo_light_on_start, 100)
|
|
|
|
is_frontlight_on = true
|
|
|
|
elseif kobo_light_on_start == 0 then
|
|
|
|
new_intensity = 0
|
|
|
|
is_frontlight_on = false
|
2017-09-04 19:05:05 +00:00
|
|
|
elseif kobo_light_on_start == -2 then -- get values from NickelConf
|
|
|
|
new_intensity = NickelConf.frontLightLevel.get()
|
|
|
|
is_frontlight_on = NickelConf.frontLightState:get()
|
2018-02-04 11:38:48 +00:00
|
|
|
if self.fl_warmth ~= nil then
|
|
|
|
local new_color = NickelConf.colorSetting.get()
|
|
|
|
if new_color ~= nil then
|
2018-12-28 03:32:42 +00:00
|
|
|
-- ColorSetting is stored as a color temperature scale in Kelvin,
|
|
|
|
-- from 1500 to 6400
|
2022-03-14 18:56:18 +00:00
|
|
|
-- so normalize this to [0, 100] on our end.
|
2022-10-10 20:21:27 +00:00
|
|
|
new_warmth = (100 - Math.round((new_color - 1500) * (1/49)))
|
2018-02-04 11:38:48 +00:00
|
|
|
end
|
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
if is_frontlight_on == nil then
|
|
|
|
-- this device does not support frontlight toggle,
|
|
|
|
-- we set the value based on frontlight intensity.
|
|
|
|
if new_intensity > 0 then
|
|
|
|
is_frontlight_on = true
|
|
|
|
else
|
|
|
|
is_frontlight_on = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if is_frontlight_on == false and new_intensity == 0 then
|
|
|
|
-- frontlight was toggled off in nickel, and we have no
|
|
|
|
-- level-before-toggle-off (firmware without "FrontLightState"):
|
|
|
|
-- use the one from koreader settings
|
|
|
|
new_intensity = G_reader_settings:readSetting("frontlight_intensity")
|
|
|
|
end
|
2017-06-29 06:23:32 +00:00
|
|
|
else -- if kobo_light_on_start == -1 or other unexpected value then
|
2017-09-04 19:05:05 +00:00
|
|
|
-- As we can't read value from the OS or hardware, use last values
|
|
|
|
-- stored in koreader settings
|
|
|
|
new_intensity = G_reader_settings:readSetting("frontlight_intensity")
|
|
|
|
is_frontlight_on = G_reader_settings:readSetting("is_frontlight_on")
|
2018-02-04 11:38:48 +00:00
|
|
|
if self.fl_warmth ~= nil then
|
|
|
|
new_warmth = G_reader_settings:readSetting("frontlight_warmth")
|
|
|
|
end
|
2017-06-29 06:23:32 +00:00
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if new_intensity ~= nil then
|
|
|
|
self.hw_intensity = new_intensity
|
|
|
|
end
|
|
|
|
if is_frontlight_on ~= nil then
|
|
|
|
-- will only be used to give initial state to BasePowerD:_decideFrontlightState()
|
|
|
|
self.initial_is_fl_on = is_frontlight_on
|
|
|
|
end
|
2021-09-25 21:24:34 +00:00
|
|
|
|
|
|
|
if new_warmth ~= nil then
|
2018-02-04 11:38:48 +00:00
|
|
|
self.fl_warmth = new_warmth
|
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
|
|
|
|
-- In any case frontlight is off, ensure intensity is non-zero so untoggle works
|
|
|
|
if self.initial_is_fl_on == false and self.hw_intensity == 0 then
|
|
|
|
self.hw_intensity = 1
|
2017-06-29 06:23:32 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
function KoboPowerD:init()
|
2021-07-21 16:12:58 +00:00
|
|
|
-- Setup the sysfs paths
|
|
|
|
self.batt_capacity_file = self.battery_sysfs .. "/capacity"
|
|
|
|
self.is_charging_file = self.battery_sysfs .. "/status"
|
|
|
|
|
2022-01-15 22:36:46 +00:00
|
|
|
if self.device:hasAuxBattery() then
|
|
|
|
self.aux_batt_capacity_file = self.aux_battery_sysfs .. "/cilix_bat_capacity"
|
|
|
|
self.aux_batt_connected_file = self.aux_battery_sysfs .. "/cilix_conn" -- or "active"
|
|
|
|
self.aux_batt_charging_file = self.aux_battery_sysfs .. "/charge_status" -- "usb_conn" would not allow us to detect the "Full" state
|
|
|
|
|
|
|
|
self.getAuxCapacityHW = function(this)
|
2022-01-16 18:08:42 +00:00
|
|
|
-- NOTE: The first few reads after connecting to the PowerCover may fail, in which case,
|
|
|
|
-- we pass that detail along to PowerD so that it may retry the call sooner.
|
|
|
|
return this:unchecked_read_int_file(this.aux_batt_capacity_file)
|
2022-01-15 22:36:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.isAuxBatteryConnectedHW = function(this)
|
2022-03-14 19:05:07 +00:00
|
|
|
-- aux_batt_connected_file shows us:
|
|
|
|
-- 0 if power cover is not connected
|
|
|
|
-- 1 if the power cover is connected
|
|
|
|
-- 1 or sometimes -1 if the power cover is connected without a charger
|
|
|
|
return this:read_int_file(this.aux_batt_connected_file) ~= 0
|
2022-01-15 22:36:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.isAuxChargingHW = function(this)
|
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).
2022-05-01 21:41:08 +00:00
|
|
|
-- 0 when discharging
|
2022-01-15 22:36:46 +00:00
|
|
|
-- 3 when full
|
2022-01-16 18:08:42 +00:00
|
|
|
-- 2 when charging via DCP
|
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).
2022-05-01 21:41:08 +00:00
|
|
|
return this:read_int_file(this.aux_batt_charging_file) ~= 0
|
|
|
|
end
|
|
|
|
|
|
|
|
self.isAuxChargedHW = function(this)
|
|
|
|
return this:read_int_file(this.aux_batt_charging_file) == 3
|
2022-01-15 22:36:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-04 19:05:05 +00:00
|
|
|
-- Default values in case self:_syncKoboLightOnStart() does not find
|
|
|
|
-- any previously saved setting (and for unit tests where it will
|
|
|
|
-- not be called)
|
|
|
|
self.hw_intensity = 20
|
|
|
|
self.initial_is_fl_on = true
|
|
|
|
|
2019-04-08 21:05:08 +00:00
|
|
|
if self.device:hasFrontlight() then
|
2018-12-28 03:32:42 +00:00
|
|
|
-- If this device has natural light (currently only KA1 & Forma)
|
|
|
|
-- Use the SysFS interface, and ioctl otherwise.
|
|
|
|
-- NOTE: On the Forma, nickel still appears to prefer using ntx_io to handle the FL,
|
|
|
|
-- but it does use sysfs for the NL...
|
2019-04-08 21:05:08 +00:00
|
|
|
if self.device:hasNaturalLight() then
|
2018-03-11 09:35:36 +00:00
|
|
|
local nl_config = G_reader_settings:readSetting("natural_light_config")
|
|
|
|
if nl_config then
|
2022-03-14 18:56:18 +00:00
|
|
|
for key, val in pairs(nl_config) do
|
2018-03-11 09:35:36 +00:00
|
|
|
self.device.frontlight_settings[key] = val
|
|
|
|
end
|
|
|
|
end
|
2018-12-28 03:32:42 +00:00
|
|
|
-- Does this device's NaturalLight use a custom scale?
|
2019-09-22 00:11:18 +00:00
|
|
|
self.fl_warmth_min = self.device.frontlight_settings.nl_min or self.fl_warmth_min
|
|
|
|
self.fl_warmth_max = self.device.frontlight_settings.nl_max or self.fl_warmth_max
|
2023-02-06 10:33:42 +00:00
|
|
|
-- Generic does it *after* init, but we're going to need it *now*...
|
|
|
|
self.warmth_scale = 100 / self.fl_warmth_max
|
2019-09-22 00:11:18 +00:00
|
|
|
-- If this device has a mixer, we can use the ioctl for brightness control, as it's much lower latency.
|
|
|
|
if self.device:hasNaturalLightMixer() then
|
|
|
|
local kobolight = require("ffi/kobolight")
|
|
|
|
local ok, light = pcall(kobolight.open)
|
|
|
|
if ok then
|
|
|
|
self.device.frontlight_settings.frontlight_ioctl = light
|
|
|
|
end
|
|
|
|
end
|
2018-03-02 22:03:00 +00:00
|
|
|
self.fl = SysfsLight:new(self.device.frontlight_settings)
|
2018-02-04 11:35:14 +00:00
|
|
|
self.fl_warmth = 0
|
2017-06-29 06:23:32 +00:00
|
|
|
self:_syncKoboLightOnStart()
|
2018-02-04 11:35:14 +00:00
|
|
|
else
|
|
|
|
local kobolight = require("ffi/kobolight")
|
|
|
|
local ok, light = pcall(kobolight.open)
|
|
|
|
if ok then
|
|
|
|
self.fl = light
|
|
|
|
self:_syncKoboLightOnStart()
|
|
|
|
end
|
2016-03-02 06:59:48 +00:00
|
|
|
end
|
2019-04-08 21:05:08 +00:00
|
|
|
-- See discussion in https://github.com/koreader/koreader/issues/3118#issuecomment-334995879
|
|
|
|
-- for the reasoning behind this bit of insanity.
|
|
|
|
if self:isFrontlightOnHW() then
|
2019-04-12 20:46:10 +00:00
|
|
|
-- On devices with a mixer, setIntensity will *only* set the FL, so, ensure we honor the warmth, too.
|
|
|
|
if self.device:hasNaturalLightMixer() then
|
2023-02-06 10:33:42 +00:00
|
|
|
self:setWarmth(self.fl_warmth, true)
|
2019-04-12 20:46:10 +00:00
|
|
|
end
|
2019-04-08 21:05:08 +00:00
|
|
|
-- Use setIntensity to ensure it sets fl_intensity, and because we don't want the ramping behavior of turnOn
|
|
|
|
self:setIntensity(self:frontlightIntensityHW())
|
|
|
|
else
|
2019-05-05 20:08:53 +00:00
|
|
|
-- Use setBrightness so as *NOT* to set hw_intensity, so toggle will still (mostly) work.
|
2019-04-15 22:04:29 +00:00
|
|
|
self.fl:setBrightness(0)
|
|
|
|
-- And make sure the fact that we started with the FL off propagates as best as possible.
|
|
|
|
self.initial_is_fl_on = false
|
|
|
|
-- NOTE: BasePowerD's init sets fl_intensity to hw_intensity right after this,
|
|
|
|
-- so, instead of simply setting hw_intensity to either 1 or fl_min or fl_intensity, depending on user preference,
|
|
|
|
-- we jump through a couple of hoops in turnOnFrontlightHW to recover from the first quirky toggle...
|
2019-04-08 21:05:08 +00:00
|
|
|
end
|
2014-12-02 10:15:23 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2017-09-04 19:05:05 +00:00
|
|
|
function KoboPowerD:saveSettings()
|
2019-04-08 21:05:08 +00:00
|
|
|
if self.device:hasFrontlight() then
|
2017-09-15 18:05:46 +00:00
|
|
|
-- Store BasePowerD values into settings (and not our hw_intensity, so
|
|
|
|
-- that if frontlight was toggled off, we save and restore the previous
|
|
|
|
-- untoggled intensity and toggle state at next startup)
|
|
|
|
local cur_intensity = self.fl_intensity
|
2019-09-01 19:25:32 +00:00
|
|
|
-- If we're shutting down straight from suspend then the frontlight won't
|
|
|
|
-- be turned on but we still want to save its state.
|
2019-09-11 16:11:24 +00:00
|
|
|
local cur_is_fl_on = self.is_fl_on or self.fl_was_on or false
|
2018-02-04 11:38:48 +00:00
|
|
|
local cur_warmth = self.fl_warmth
|
2017-09-15 18:05:46 +00:00
|
|
|
-- Save intensity to koreader settings
|
|
|
|
G_reader_settings:saveSetting("frontlight_intensity", cur_intensity)
|
|
|
|
G_reader_settings:saveSetting("is_frontlight_on", cur_is_fl_on)
|
2018-02-04 11:38:48 +00:00
|
|
|
if cur_warmth ~= nil then
|
|
|
|
G_reader_settings:saveSetting("frontlight_warmth", cur_warmth)
|
|
|
|
end
|
2017-09-15 18:05:46 +00:00
|
|
|
-- And to "Kobo eReader.conf" if needed
|
2022-09-27 23:10:50 +00:00
|
|
|
if G_defaults:readSetting("KOBO_SYNC_BRIGHTNESS_WITH_NICKEL") then
|
2017-09-15 18:05:46 +00:00
|
|
|
if NickelConf.frontLightState.get() ~= nil then
|
|
|
|
if NickelConf.frontLightState.get() ~= cur_is_fl_on then
|
|
|
|
NickelConf.frontLightState.set(cur_is_fl_on)
|
|
|
|
end
|
|
|
|
else -- no support for frontlight state
|
|
|
|
if not cur_is_fl_on then -- if toggled off, save intensity as 0
|
|
|
|
cur_intensity = self.fl_min
|
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
end
|
2017-09-15 18:05:46 +00:00
|
|
|
if NickelConf.frontLightLevel.get() ~= cur_intensity then
|
|
|
|
NickelConf.frontLightLevel.set(cur_intensity)
|
2017-09-04 19:05:05 +00:00
|
|
|
end
|
2018-02-04 11:38:48 +00:00
|
|
|
if cur_warmth ~= nil then
|
|
|
|
local warmth_rescaled = (100 - cur_warmth) * 49 + 1500
|
|
|
|
if NickelConf.colorSetting.get() ~= warmth_rescaled then
|
|
|
|
NickelConf.colorSetting.set(warmth_rescaled)
|
|
|
|
end
|
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
end
|
2014-03-13 13:52:43 +00:00
|
|
|
end
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2017-06-14 17:32:16 +00:00
|
|
|
function KoboPowerD:frontlightIntensityHW()
|
2017-09-04 19:05:05 +00:00
|
|
|
return self.hw_intensity
|
2017-06-14 17:32:16 +00:00
|
|
|
end
|
|
|
|
|
2017-06-22 02:10:44 +00:00
|
|
|
function KoboPowerD:isFrontlightOnHW()
|
2017-09-04 19:05:05 +00:00
|
|
|
if self.initial_is_fl_on ~= nil then -- happens only once after init()
|
|
|
|
-- give initial state to BasePowerD, which will
|
|
|
|
-- reset our self.hw_intensity to 0 if self.initial_is_fl_on is false
|
|
|
|
local ret = self.initial_is_fl_on
|
|
|
|
self.initial_is_fl_on = nil
|
|
|
|
return ret
|
2017-06-22 02:10:44 +00:00
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
return self.hw_intensity > 0
|
2017-06-22 02:10:44 +00:00
|
|
|
end
|
|
|
|
|
2017-06-14 17:32:16 +00:00
|
|
|
function KoboPowerD:setIntensityHW(intensity)
|
|
|
|
if self.fl == nil then return end
|
2019-10-11 18:37:18 +00:00
|
|
|
if self.fl_warmth == nil or self.device:hasNaturalLightMixer() then
|
|
|
|
-- We either don't have NL, or we have a mixer: we only want to set the intensity (c.f., #5429)
|
|
|
|
self.fl:setBrightness(intensity)
|
|
|
|
else
|
|
|
|
-- Not having a mixer sucks, we always have to set intensity combined w/ warmth (#5465)
|
|
|
|
self.fl:setNaturalBrightness(intensity, self.fl_warmth)
|
|
|
|
end
|
2017-09-04 19:05:05 +00:00
|
|
|
self.hw_intensity = intensity
|
|
|
|
-- Now that we have set intensity, we need to let BasePowerD
|
|
|
|
-- know about possibly changed frontlight state (if we came
|
|
|
|
-- from light toggled off to some intensity > 0).
|
|
|
|
self:_decideFrontlightState()
|
2014-01-04 13:38:07 +00:00
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
-- NOTE: We *can* actually read this from the system (as well as frontlight level, since Mk. 7),
|
|
|
|
-- but this is already a huge mess, so, keep ignoring it...
|
|
|
|
function KoboPowerD:frontlightWarmthHW()
|
|
|
|
return self.fl_warmth
|
|
|
|
end
|
|
|
|
|
|
|
|
function KoboPowerD:setWarmthHW(warmth)
|
2018-02-04 11:35:14 +00:00
|
|
|
if self.fl == nil then return end
|
2019-04-21 18:46:29 +00:00
|
|
|
-- Don't turn the light back on on legacy NaturalLight devices just for the sake of setting the warmth!
|
|
|
|
-- That's because we can only set warmth independently of brightness on devices with a mixer.
|
|
|
|
-- On older ones, calling setWarmth *will* actually set the brightness, too!
|
|
|
|
if self.device:hasNaturalLightMixer() or self:isFrontlightOnHW() then
|
2022-03-14 18:56:18 +00:00
|
|
|
self.fl:setWarmth(warmth)
|
2019-04-21 18:46:29 +00:00
|
|
|
end
|
2018-03-31 13:46:41 +00:00
|
|
|
end
|
|
|
|
|
2014-01-04 16:29:41 +00:00
|
|
|
function KoboPowerD:getCapacityHW()
|
2017-03-24 06:36:15 +00:00
|
|
|
return self:read_int_file(self.batt_capacity_file)
|
2014-01-04 16:29:41 +00:00
|
|
|
end
|
|
|
|
|
2022-05-06 17:19:55 +00:00
|
|
|
-- NOTE: Match the behavior of the ntx_io _Is_USB_plugged ioctl!
|
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).
2022-05-01 21:41:08 +00:00
|
|
|
-- (Otherwise, a device that is fully charged, but still plugged in will no longer be flagged as charging).
|
2014-01-04 16:29:41 +00:00
|
|
|
function KoboPowerD:isChargingHW()
|
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).
2022-05-01 21:41:08 +00:00
|
|
|
return self:read_str_file(self.is_charging_file) ~= "Discharging"
|
|
|
|
end
|
|
|
|
|
|
|
|
function KoboPowerD:isChargedHW()
|
|
|
|
-- On sunxi, the proper "Full" status is reported, while older kernels (even Mk. 9) report "Not charging"
|
|
|
|
-- c.f., POWER_SUPPLY_PROP_STATUS in ricoh61x_batt_get_prop @ drivers/power/ricoh619-battery.c
|
|
|
|
-- (or drivers/power/supply/ricoh619-battery.c on newer kernels).
|
|
|
|
local status = self:read_str_file(self.is_charging_file)
|
|
|
|
if status == "Full" then
|
|
|
|
return true
|
|
|
|
elseif status == "Not charging" and self:getCapacity() == 100 then
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
2014-01-04 16:29:41 +00:00
|
|
|
end
|
|
|
|
|
2019-04-08 21:05:08 +00:00
|
|
|
function KoboPowerD:turnOffFrontlightHW()
|
2019-04-15 18:06:24 +00:00
|
|
|
if not self:isFrontlightOnHW() then
|
2019-04-08 21:05:08 +00:00
|
|
|
return
|
|
|
|
end
|
2020-09-15 18:39:32 +00:00
|
|
|
ffiUtil.runInSubProcess(function()
|
2022-10-23 19:55:13 +00:00
|
|
|
for i = 1, 5 do
|
|
|
|
-- NOTE: Do *not* switch to (self.fl_intensity * (1/5) * i) here, it may lead to rounding errors,
|
|
|
|
-- which is problematic paired w/ math.floor because it doesn't round towards zero,
|
|
|
|
-- which means we may end up passing -1 to setIntensityHW, which will fail,
|
|
|
|
-- because we're bypassing the clamping usually done by setIntensity...
|
|
|
|
self:setIntensityHW(math.floor(self.fl_intensity - (self.fl_intensity / 5 * i)))
|
2019-09-24 18:27:28 +00:00
|
|
|
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
|
|
|
|
--- otherwise we get a jump and not a ramp ;).
|
|
|
|
if not self.device:hasNaturalLight() then
|
2019-04-08 21:05:08 +00:00
|
|
|
if (i < 5) then
|
2020-09-15 18:39:32 +00:00
|
|
|
ffiUtil.usleep(35 * 1000)
|
2019-04-08 21:05:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, false, true)
|
2020-09-21 01:48:06 +00:00
|
|
|
-- NOTE: This is essentially what setIntensityHW does, except we don't actually touch the FL,
|
2019-04-15 18:06:24 +00:00
|
|
|
-- we only sync the state of the main process with the final state of what we're doing in the forks.
|
|
|
|
-- And update hw_intensity in our actual process ;).
|
|
|
|
self.hw_intensity = self.fl_min
|
2020-09-21 01:48:06 +00:00
|
|
|
-- NOTE: And don't forget to update sysfs_light, too, as a real setIntensityHW would via setBrightness
|
2019-05-05 20:08:53 +00:00
|
|
|
if self.fl then
|
|
|
|
self.fl.current_brightness = self.fl_min
|
|
|
|
end
|
2019-04-15 18:06:24 +00:00
|
|
|
self:_decideFrontlightState()
|
2019-04-08 21:05:08 +00:00
|
|
|
end
|
2020-08-25 12:42:39 +00:00
|
|
|
|
2019-04-08 21:05:08 +00:00
|
|
|
function KoboPowerD:turnOnFrontlightHW()
|
2019-04-15 22:04:29 +00:00
|
|
|
-- NOTE: Insane workaround for the first toggle after a startup with the FL off.
|
|
|
|
-- The light is actually off, but hw_intensity couldn't have been set to a sane value because of a number of interactions.
|
|
|
|
-- So, fix it now, so we pass the isFrontlightOnHW check (which checks if hw_intensity > fl_min).
|
|
|
|
if (self.is_fl_on == false and self.hw_intensity > self.fl_min and self.hw_intensity == self.fl_intensity) then
|
|
|
|
self.hw_intensity = self.fl_min
|
|
|
|
end
|
2019-04-15 18:06:24 +00:00
|
|
|
if self:isFrontlightOnHW() then
|
2019-04-08 21:05:08 +00:00
|
|
|
return
|
|
|
|
end
|
2020-09-15 18:39:32 +00:00
|
|
|
ffiUtil.runInSubProcess(function()
|
2022-10-23 19:55:13 +00:00
|
|
|
for i = 1, 5 do
|
|
|
|
self:setIntensityHW(math.ceil(self.fl_min + (self.fl_intensity / 5 * i)))
|
2019-09-24 18:27:28 +00:00
|
|
|
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
|
|
|
|
--- otherwise we get a jump and not a ramp ;).
|
|
|
|
if not self.device:hasNaturalLight() then
|
2019-04-08 21:05:08 +00:00
|
|
|
if (i < 5) then
|
2020-09-15 18:39:32 +00:00
|
|
|
ffiUtil.usleep(35 * 1000)
|
2019-04-08 21:05:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end, false, true)
|
2020-09-21 01:48:06 +00:00
|
|
|
-- NOTE: This is essentially what setIntensityHW does, except we don't actually touch the FL,
|
2019-04-15 18:06:24 +00:00
|
|
|
-- we only sync the state of the main process with the final state of what we're doing in the forks.
|
|
|
|
-- And update hw_intensity in our actual process ;).
|
|
|
|
self.hw_intensity = self.fl_intensity
|
2020-09-21 01:48:06 +00:00
|
|
|
-- NOTE: And don't forget to update sysfs_light, too, as a real setIntensityHW would via setBrightness
|
2019-05-05 20:08:53 +00:00
|
|
|
if self.fl then
|
|
|
|
self.fl.current_brightness = self.fl_intensity
|
|
|
|
end
|
2019-04-15 18:06:24 +00:00
|
|
|
self:_decideFrontlightState()
|
2019-04-08 21:05:08 +00:00
|
|
|
end
|
|
|
|
|
2016-02-26 09:46:23 +00:00
|
|
|
-- Turn off front light before suspend.
|
|
|
|
function KoboPowerD:beforeSuspend()
|
2017-09-04 19:05:05 +00:00
|
|
|
if self.fl == nil then return end
|
2019-04-15 18:06:24 +00:00
|
|
|
-- Remember the current frontlight state
|
2019-04-15 22:04:29 +00:00
|
|
|
self.fl_was_on = self.is_fl_on
|
2019-04-08 21:05:08 +00:00
|
|
|
-- Turn off the frontlight
|
|
|
|
self:turnOffFrontlight()
|
2016-02-26 09:46:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Restore front light state after resume.
|
|
|
|
function KoboPowerD:afterResume()
|
2017-09-04 19:05:05 +00:00
|
|
|
if self.fl == nil then return end
|
2019-04-15 18:06:24 +00:00
|
|
|
-- Don't bother if the light was already off on suspend
|
|
|
|
if not self.fl_was_on then return end
|
2019-04-08 21:05:08 +00:00
|
|
|
-- Turn the frontlight back on
|
|
|
|
self:turnOnFrontlight()
|
2021-03-07 20:56:52 +00:00
|
|
|
|
|
|
|
-- Set the system clock to the hardware clock's time.
|
|
|
|
RTC:HCToSys()
|
2016-02-26 09:46:23 +00:00
|
|
|
end
|
|
|
|
|
2014-01-04 13:38:07 +00:00
|
|
|
return KoboPowerD
|