From 152ee087a8b12743d03d18dfa4b8eb6f2a4fed0e Mon Sep 17 00:00:00 2001 From: ezdiy Date: Thu, 17 Sep 2020 11:36:58 +0200 Subject: [PATCH] Pocketbook: Fix frontlight handling. (#6663) Account for InkView 5.x having different API for on/off states. --- base | 2 +- frontend/device/pocketbook/powerd.lua | 41 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/base b/base index ccdb28ddd..f146a4f4e 160000 --- a/base +++ b/base @@ -1 +1 @@ -Subproject commit ccdb28ddda0deb6dc585318bf9942b6bdb25cc1c +Subproject commit f146a4f4ec0c1debefbe30d03ca6229c4f95452b diff --git a/frontend/device/pocketbook/powerd.lua b/frontend/device/pocketbook/powerd.lua index 7f1268ecc..8f3d3b233 100644 --- a/frontend/device/pocketbook/powerd.lua +++ b/frontend/device/pocketbook/powerd.lua @@ -2,16 +2,6 @@ local BasePowerD = require("device/generic/powerd") local ffi = require("ffi") local inkview = ffi.load("inkview") -ffi.cdef[[ -void OpenScreen(); -int GetFrontlightState(void); -int GetFrontlightColor(void); -void SetFrontlightState(int flstate); -void SetFrontlightColor(int color); -int GetBatteryPower(); -int IsCharging(); -]] - local PocketBookPowerD = BasePowerD:new{ is_charging = nil, fl_warmth = nil, @@ -32,18 +22,45 @@ function PocketBookPowerD:init() end function PocketBookPowerD:frontlightIntensityHW() + -- 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() if not self.device:hasFrontlight() then return 0 end - return inkview.GetFrontlightState() + if self:isFrontlightOff() then return 0 end + return self:frontlightIntensityHW() end function PocketBookPowerD:setIntensityHW(intensity) + local v2api = pcall(function() + inkview.SetFrontlightEnabled(intensity == 0 and 0 or 1) + end) if intensity == 0 then - inkview.SetFrontlightState(-1) + -- -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 else inkview.SetFrontlightState(intensity) end end +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 + function PocketBookPowerD:setWarmth(level) if self.fl_warmth then self.fl_warmth = level or self.fl_warmth