2015-01-17 15:54:49 +00:00
|
|
|
local BasePowerD = require("device/generic/powerd")
|
|
|
|
local ffi = require("ffi")
|
2017-10-03 12:59:41 +00:00
|
|
|
local inkview = ffi.load("inkview")
|
2015-01-17 15:54:49 +00:00
|
|
|
|
|
|
|
local PocketBookPowerD = BasePowerD:new{
|
|
|
|
is_charging = nil,
|
2020-08-19 20:41:10 +00:00
|
|
|
|
2017-10-03 12:59:41 +00:00
|
|
|
fl_min = 0,
|
|
|
|
fl_max = 100,
|
2020-08-19 20:41:10 +00:00
|
|
|
fl_warmth_min = 0,
|
|
|
|
fl_warmth_max = 100,
|
2015-01-17 15:54:49 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 12:59:41 +00:00
|
|
|
function PocketBookPowerD:frontlightIntensityHW()
|
2022-03-14 18:56:18 +00:00
|
|
|
-- Always update fl_intensity (and perhaps fl_warmth) from the OS value whenever queried (it's fast).
|
|
|
|
-- This way koreader settings can stay in sync even if the value is changed behind its back.
|
2020-09-17 09:36:58 +00:00
|
|
|
self.fl_intensity = math.max(0, inkview.GetFrontlightState())
|
2022-03-14 18:56:18 +00:00
|
|
|
if self.device:hasNaturalLight() then
|
2020-09-17 09:36:58 +00:00
|
|
|
self.fl_warmth = math.max(0, inkview.GetFrontlightColor())
|
|
|
|
end
|
|
|
|
return self.fl_intensity
|
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBookPowerD:frontlightIntensity()
|
2019-04-08 21:05:08 +00:00
|
|
|
if not self.device:hasFrontlight() then return 0 end
|
2020-09-17 09:36:58 +00:00
|
|
|
if self:isFrontlightOff() then return 0 end
|
2022-03-14 18:56:18 +00:00
|
|
|
--- @note: We actually have a working frontlightIntensityHW implementation,
|
|
|
|
--- use it instead of returning a cached self.fl_intensity like BasePowerD.
|
2020-09-17 09:36:58 +00:00
|
|
|
return self:frontlightIntensityHW()
|
2017-10-03 12:59:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBookPowerD:setIntensityHW(intensity)
|
2020-09-17 09:36:58 +00:00
|
|
|
local v2api = pcall(function()
|
|
|
|
inkview.SetFrontlightEnabled(intensity == 0 and 0 or 1)
|
|
|
|
end)
|
2017-10-03 12:59:41 +00:00
|
|
|
if intensity == 0 then
|
2020-09-17 09:36:58 +00:00
|
|
|
-- -1 is valid only for the old api, on newer firmwares that's just a bogus brightness level
|
|
|
|
if not v2api then
|
|
|
|
inkview.SetFrontlightState(-1)
|
|
|
|
end
|
2017-10-03 12:59:41 +00:00
|
|
|
else
|
|
|
|
inkview.SetFrontlightState(intensity)
|
|
|
|
end
|
2015-01-17 15:54:49 +00:00
|
|
|
end
|
|
|
|
|
2020-09-17 09:36:58 +00:00
|
|
|
function PocketBookPowerD:isFrontlightOn()
|
|
|
|
if not self.device:hasFrontlight() then return false end
|
|
|
|
-- Query directly instead of assuming from cached value.
|
|
|
|
local enabled = inkview.GetFrontlightState() >= 0
|
|
|
|
pcall(function()
|
|
|
|
enabled = inkview.GetFrontlightEnabled() > 0
|
|
|
|
end)
|
|
|
|
return enabled
|
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
function PocketBookPowerD:setWarmthHW(level)
|
|
|
|
return inkview.SetFrontlightColor(level)
|
2021-09-02 20:44:22 +00:00
|
|
|
end
|
|
|
|
|
2022-03-14 18:56:18 +00:00
|
|
|
function PocketBookPowerD:frontlightWarmthHW()
|
|
|
|
return inkview.GetFrontlightColor()
|
2020-08-19 20:41:10 +00:00
|
|
|
end
|
|
|
|
|
2015-01-17 15:54:49 +00:00
|
|
|
function PocketBookPowerD:getCapacityHW()
|
2017-10-22 15:49:48 +00:00
|
|
|
return inkview.GetBatteryPower()
|
2015-01-17 15:54:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBookPowerD:isChargingHW()
|
2017-10-22 15:49:48 +00:00
|
|
|
if inkview.IsCharging() > 0 then
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2015-01-17 15:54:49 +00:00
|
|
|
end
|
|
|
|
|
2023-05-18 21:13:43 +00:00
|
|
|
function PocketBookPowerD:beforeSuspend()
|
|
|
|
-- Inhibit user input and emit the Suspend event.
|
|
|
|
self.device:_beforeSuspend()
|
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBookPowerD:afterResume()
|
|
|
|
self:invalidateCapacityCache()
|
|
|
|
|
|
|
|
-- Restore user input and emit the Resume event.
|
|
|
|
self.device:_afterResume()
|
|
|
|
end
|
|
|
|
|
2015-01-17 15:54:49 +00:00
|
|
|
return PocketBookPowerD
|