diff --git a/frontend/device/generic/powerd.lua b/frontend/device/generic/powerd.lua index 1ca552f4a..8870154e0 100644 --- a/frontend/device/generic/powerd.lua +++ b/frontend/device/generic/powerd.lua @@ -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")) diff --git a/frontend/device/kindle/powerd.lua b/frontend/device/kindle/powerd.lua index e40d1771a..15140089a 100644 --- a/frontend/device/kindle/powerd.lua +++ b/frontend/device/kindle/powerd.lua @@ -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 diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index 918733e9e..8d5569f26 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -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. diff --git a/frontend/device/sdl/powerd.lua b/frontend/device/sdl/powerd.lua index db363b291..77263b400 100644 --- a/frontend/device/sdl/powerd.lua +++ b/frontend/device/sdl/powerd.lua @@ -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