FrontLight: fix footer update on FL on/off toggle (#6664)

move state change event to higher level function so it will be called after powerd.is_fl_on is updated.

makes _setIntensity redundant so get rid of it

obsoletes #6667
reviewable/pr6692/r1
yparitcher 4 years ago committed by GitHub
parent 9e96fdfb5f
commit 3e063498fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,8 +32,8 @@ function BasePowerD:setDissmisBatteryStatus(status) self.battery_warning = statu
function BasePowerD:isChargingHW() return false end
function BasePowerD:frontlightIntensityHW() return 0 end
function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end
function BasePowerD:turnOffFrontlightHW() self:_setIntensity(self.fl_min) end
function BasePowerD:turnOnFrontlightHW() self:_setIntensity(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)?
function BasePowerD:turnOffFrontlightHW() self:setIntensityHW(self.fl_min) end
function BasePowerD:turnOnFrontlightHW() self:setIntensityHW(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)?
-- Anything needs to be done before do a real hardware suspend. Such as turn off
-- front light.
function BasePowerD:beforeSuspend() end
@ -79,6 +79,7 @@ function BasePowerD:turnOffFrontlight()
if self:isFrontlightOff() then return false end
self:turnOffFrontlightHW()
self.is_fl_on = false
self:stateChanged()
return true
end
@ -89,6 +90,7 @@ function BasePowerD:turnOnFrontlight()
if self.fl_intensity == self.fl_min then return false end --- @fixme what the hell?
self:turnOnFrontlightHW()
self.is_fl_on = true
self:stateChanged()
return true
end
@ -125,7 +127,8 @@ function BasePowerD:setIntensity(intensity)
self.fl_intensity = self:normalizeIntensity(intensity)
self:_decideFrontlightState()
logger.dbg("set light intensity", self.fl_intensity)
self:_setIntensity(self.fl_intensity)
self:setIntensityHW(self.fl_intensity)
self:stateChanged()
return true
end
@ -141,11 +144,9 @@ function BasePowerD:isCharging()
return self:isChargingHW()
end
function BasePowerD:_setIntensity(intensity, silent)
self:setIntensityHW(intensity)
function BasePowerD:stateChanged()
-- 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
if package.loaded["ui/uimanager"] ~= nil then
local Event = require("ui/event")
local UIManager = require("ui/uimanager")
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))

@ -21,7 +21,7 @@ function KindlePowerD:init()
end
-- If we start with the light off (fl_intensity is fl_min), ensure a toggle will set it to the lowest "on" step,
-- and that we update fl_intensity (by using setIntensity and not _setIntensity).
-- and that we update fl_intensity (by using setIntensity and not setIntensityHW).
function KindlePowerD:turnOnFrontlightHW()
self:setIntensity(self.fl_intensity == self.fl_min and self.fl_min + 1 or self.fl_intensity)
end
@ -32,6 +32,7 @@ function BasePowerD:turnOnFrontlight()
if self:isFrontlightOn() then return false end
self:turnOnFrontlightHW()
self.is_fl_on = true
self:stateChanged()
return true
end

@ -327,8 +327,7 @@ function KoboPowerD:turnOffFrontlightHW()
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
-- 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)
self:setIntensityHW(math.floor(self.fl_intensity - ((self.fl_intensity / 5) * i)))
--- @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
@ -338,21 +337,15 @@ function KoboPowerD:turnOffFrontlightHW()
end
end
end, false, true)
-- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL,
-- NOTE: This is essentially what setIntensityHW 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
-- NOTE: And don't forget to update sysfs_light, too, as a real _setIntensity would via setBrightness
-- NOTE: And don't forget to update sysfs_light, too, as a real setIntensityHW would via setBrightness
if self.fl then
self.fl.current_brightness = self.fl_min
end
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()
@ -367,8 +360,7 @@ function KoboPowerD:turnOnFrontlightHW()
end
ffiUtil.runInSubProcess(function()
for i = 1,5 do
-- 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)
self:setIntensityHW(math.ceil(self.fl_min + ((self.fl_intensity / 5) * i)))
--- @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
@ -378,21 +370,15 @@ function KoboPowerD:turnOnFrontlightHW()
end
end
end, false, true)
-- NOTE: This is essentially what _setIntensity does, except we don't actually touch the FL,
-- NOTE: This is essentially what setIntensityHW 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
-- NOTE: And don't forget to update sysfs_light, too, as a real _setIntensity would via setBrightness
-- NOTE: And don't forget to update sysfs_light, too, as a real setIntensityHW would via setBrightness
if self.fl then
self.fl.current_brightness = self.fl_intensity
end
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.

@ -11,6 +11,10 @@ local SDLPowerD = BasePowerD:new{
fl_warmth_max = 100,
}
function SDLPowerD:frontlightIntensityHW()
return self.hw_intensity
end
function SDLPowerD:setIntensityHW(intensity)
require("logger").info("set brightness to", intensity)
self.hw_intensity = intensity or self.hw_intensity

Loading…
Cancel
Save