[Kobo] Don't send a flood a FrontlightStateChanged events during the FL ramps (#6667)

* Only send a single FrontlightStateChanged event on toggle

Prevents the ReaderFooter refresh from going wonky
This commit is contained in:
NiLuJe
2020-09-17 19:49:03 +02:00
committed by GitHub
parent 2afec592f8
commit f1918cdfbb
2 changed files with 8 additions and 6 deletions

View File

@@ -141,11 +141,11 @@ function BasePowerD:isCharging()
return self:isChargingHW()
end
function BasePowerD:_setIntensity(intensity)
function BasePowerD:_setIntensity(intensity, silent)
self:setIntensityHW(intensity)
-- BasePowerD is loaded before UIManager. So we cannot broadcast events before UIManager has
-- been loaded.
if package.loaded["ui/uimanager"] ~= nil then
-- BasePowerD is loaded before UIManager. So we cannot broadcast events before UIManager has been loaded.
-- NOTE: If silent is set, inhibit the Event (useful for platforms that do a ramp-up/ramp-down on toggle).
if not silent and package.loaded["ui/uimanager"] ~= nil then
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))

View File

@@ -327,7 +327,8 @@ function KoboPowerD:turnOffFrontlightHW()
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:_setIntensity(math.floor(self.fl_intensity - ((self.fl_intensity / 5) * i)))
-- NOTE: Make sure _setIntensity doesn't send a FrontlightStateChanged event for those!
self:_setIntensity(math.floor(self.fl_intensity - ((self.fl_intensity / 5) * i)), true)
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then
@@ -366,7 +367,8 @@ function KoboPowerD:turnOnFrontlightHW()
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
self:_setIntensity(math.ceil(self.fl_min + ((self.fl_intensity / 5) * i)))
-- NOTE: Make sure _setIntensity doesn't send a FrontlightStateChanged event for those!
self:_setIntensity(math.ceil(self.fl_min + ((self.fl_intensity / 5) * i)), true)
--- @note: Newer devices appear to block slightly longer on FL ioctls/sysfs, so only sleep on older devices,
--- otherwise we get a jump and not a ramp ;).
if not self.device:hasNaturalLight() then