Skip to content

Commit

Permalink
Some FL regression fixes after #4901 (#4921)
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
NiLuJe committed Apr 15, 2019
1 parent 7e06db9 commit 33946aa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 6 deletions.
2 changes: 1 addition & 1 deletion frontend/apps/reader/modules/readerfooter.lua
Expand Up @@ -747,7 +747,7 @@ end

function ReaderFooter:onFrontlightStateChanged()
if self.settings.frontlight then
self:updateFooter()
self:updateFooter(true)
end
end

Expand Down
2 changes: 2 additions & 0 deletions frontend/device/generic/device.lua
Expand Up @@ -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,
Expand Down
36 changes: 32 additions & 4 deletions frontend/device/kobo/powerd.lua
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand All @@ -324,18 +337,33 @@ 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

-- 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()
Expand Down
2 changes: 1 addition & 1 deletion 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
Expand Down

0 comments on commit 33946aa

Please sign in to comment.