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
|
|
|
fl_warmth = nil,
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
function PocketBookPowerD:init()
|
2017-10-03 12:59:41 +00:00
|
|
|
-- needed for SetFrontlightState / GetFrontlightState
|
2020-08-23 00:20:48 +00:00
|
|
|
if self.device:hasNaturalLight() then
|
|
|
|
local color = inkview.GetFrontlightColor()
|
|
|
|
self.fl_warmth = color >= 0 and color or 0
|
|
|
|
end
|
2017-10-03 12:59:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function PocketBookPowerD:frontlightIntensityHW()
|
2020-09-17 09:36:58 +00:00
|
|
|
-- Always update fl_intensity (and perhaps fl_warmth) from the OS value whenever queried (its fast).
|
|
|
|
-- This way koreader setting can stay in sync even if the value is changed behind its back.
|
|
|
|
self.fl_intensity = math.max(0, inkview.GetFrontlightState())
|
|
|
|
if self.fl_warmth then
|
|
|
|
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
|
|
|
|
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
|
|
|
|
|
2020-08-19 20:41:10 +00:00
|
|
|
function PocketBookPowerD:setWarmth(level)
|
2020-08-23 00:20:48 +00:00
|
|
|
if self.fl_warmth then
|
|
|
|
self.fl_warmth = level or self.fl_warmth
|
|
|
|
inkview.SetFrontlightColor(self.fl_warmth)
|
|
|
|
end
|
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
|
|
|
|
|
|
|
|
return PocketBookPowerD
|