From 33946aa732b183cf52a92dfb1961b4194f900caf Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Mon, 15 Apr 2019 20:06:24 +0200 Subject: [PATCH] Some FL regression fixes after #4901 (#4921) * Make hasNaturalLight* caps safe to call without a device check. (fix #4919) Make it clear that it's expecting the NTX implementation, though. * Don't turn the FL on on resume if it was off on suspend * Make sure turnOn/turnOff actually updates hw_intensity in the process where it matters, instead of just in a short lived fork ;). (fix #4923) --- frontend/apps/reader/modules/readerfooter.lua | 2 +- frontend/device/generic/device.lua | 2 ++ frontend/device/kobo/powerd.lua | 36 ++++++++++++++++--- plugins/kobolight.koplugin/main.lua | 2 +- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/frontend/apps/reader/modules/readerfooter.lua b/frontend/apps/reader/modules/readerfooter.lua index f1680d150..005312468 100644 --- a/frontend/apps/reader/modules/readerfooter.lua +++ b/frontend/apps/reader/modules/readerfooter.lua @@ -747,7 +747,7 @@ end function ReaderFooter:onFrontlightStateChanged() if self.settings.frontlight then - self:updateFooter() + self:updateFooter(true) end end diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index 1de7dd9b8..67a74b3ec 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -27,6 +27,8 @@ local Device = { hasWifiManager = no, isTouchDevice = no, hasFrontlight = no, + hasNaturalLight = no, -- FL warmth implementation specific to NTX boards (Kobo, Cervantes) + hasNaturalLightMixer = no, -- Same, but only found on newer boards needsTouchScreenProbe = no, hasClipboard = yes, -- generic internal clipboard on all devices hasEinkScreen = yes, diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index d942d1178..c13e51a98 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -21,6 +21,7 @@ local KoboPowerD = BasePowerD:new{ fl_warmth = nil, auto_warmth = false, max_warmth_hour = 23, + fl_was_on = nil, } -- TODO: Remove KOBO_LIGHT_ON_START @@ -148,8 +149,9 @@ function KoboPowerD:init() -- Use setIntensity to ensure it sets fl_intensity, and because we don't want the ramping behavior of turnOn self:setIntensity(self:frontlightIntensityHW()) else - -- Use setIntensityHW so as *NOT* to set fl_intensity, so toggle will still work. - self:setIntensityHW(0) + -- Use _setIntensity for setIntensityHW so as *NOT* to set fl_intensity, so toggle will still work, + -- plus the FrontlightStateChanged event. + self:_setIntensity(0) end end end @@ -293,7 +295,7 @@ function KoboPowerD:isChargingHW() end function KoboPowerD:turnOffFrontlightHW() - if self:isFrontlightOff() then + if not self:isFrontlightOnHW() then return end local util = require("ffi/util") @@ -308,9 +310,20 @@ function KoboPowerD:turnOffFrontlightHW() end end end, false, true) + -- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL, + -- 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 + self:_decideFrontlightState() + -- And let the footer know of the change + if package.loaded["ui/uimanager"] ~= nil then + local Event = require("ui/event") + local UIManager = require("ui/uimanager") + UIManager:broadcastEvent(Event:new("FrontlightStateChanged")) + end end function KoboPowerD:turnOnFrontlightHW() - if self:isFrontlightOn() then + if self:isFrontlightOnHW() then return end local util = require("ffi/util") @@ -324,11 +337,24 @@ function KoboPowerD:turnOnFrontlightHW() end end end, false, true) + -- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL, + -- 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 + self:_decideFrontlightState() + -- And let the footer know of the change + if package.loaded["ui/uimanager"] ~= nil then + local Event = require("ui/event") + local UIManager = require("ui/uimanager") + UIManager:broadcastEvent(Event:new("FrontlightStateChanged")) + end end -- Turn off front light before suspend. function KoboPowerD:beforeSuspend() if self.fl == nil then return end + -- Remember the current frontlight state + self.fl_was_on = self:isFrontlightOnHW() -- Turn off the frontlight self:turnOffFrontlight() end @@ -336,6 +362,8 @@ end -- Restore front light state after resume. function KoboPowerD:afterResume() if self.fl == nil then return end + -- Don't bother if the light was already off on suspend + if not self.fl_was_on then return end -- Update AutoWarmth state if self.fl_warmth ~= nil and self.auto_warmth then self:calculateAutoWarmth() diff --git a/plugins/kobolight.koplugin/main.lua b/plugins/kobolight.koplugin/main.lua index 46b946470..a8b665619 100644 --- a/plugins/kobolight.koplugin/main.lua +++ b/plugins/kobolight.koplugin/main.lua @@ -1,7 +1,7 @@ local Device = require("device") local with_frontlight = (Device:isCervantes() or Device:isKindle() or Device:isKobo()) and Device:hasFrontlight() -local with_natural_light = (Device:isCervantes() or Device:isKobo()) and Device:hasNaturalLight() +local with_natural_light = Device:hasNaturalLight() if not (with_frontlight or Device:isSDL()) then return { disabled = true, } end