diff --git a/frontend/device/android/powerd.lua b/frontend/device/android/powerd.lua index 60d7c5c8f..ce2e44e58 100644 --- a/frontend/device/android/powerd.lua +++ b/frontend/device/android/powerd.lua @@ -1,6 +1,4 @@ local BasePowerD = require("device/generic/powerd") -local Event = require("ui/event") -local UIManager local _, android = pcall(require, "android") local AndroidPowerD = BasePowerD:new{ @@ -8,13 +6,6 @@ local AndroidPowerD = BasePowerD:new{ fl_max = 100, } --- Let the footer know of the change -local function broadcastLightChanges() - if UIManager then - UIManager:broadcastEvent(Event:new("FrontlightStateChanged")) - end -end - function AndroidPowerD:frontlightIntensityHW() return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max) end @@ -66,8 +57,6 @@ function AndroidPowerD:turnOffFrontlightHW() return end android.setScreenBrightness(self.fl_min) - self.is_fl_on = false - broadcastLightChanges() end function AndroidPowerD:turnOnFrontlightHW() @@ -78,13 +67,6 @@ function AndroidPowerD:turnOnFrontlightHW() android.enableFrontlightSwitch() android.setScreenBrightness(math.floor(self.fl_intensity * self.bright_diff / self.fl_max)) - - self.is_fl_on = true - broadcastLightChanges() -end - -function AndroidPowerD:UIManagerReadyHW(uimgr) - UIManager = uimgr end return AndroidPowerD diff --git a/frontend/device/generic/powerd.lua b/frontend/device/generic/powerd.lua index e97dc8e79..24625aa6f 100644 --- a/frontend/device/generic/powerd.lua +++ b/frontend/device/generic/powerd.lua @@ -59,8 +59,21 @@ function BasePowerD:isAuxChargingHW() return false end function BasePowerD:isAuxChargedHW() return false end function BasePowerD:frontlightIntensityHW() return 0 end function BasePowerD:isFrontlightOnHW() return self.fl_intensity > self.fl_min end -function BasePowerD:turnOffFrontlightHW(done_callback) self:setIntensityHW(self.fl_min) end -function BasePowerD:turnOnFrontlightHW(done_callback) self:setIntensityHW(self.fl_intensity) end --- @fixme: what if fl_intensity == fl_min (c.f., kindle)? +--- @note: done_callback is used to display Notifications, +--- some implementations *may* need to handle it themselves because of timing constraints, +--- in which case they should return *true* here, so that the public API knows not to consume the callback early. +function BasePowerD:turnOffFrontlightHW(done_callback) + self:setIntensityHW(self.fl_min) + + -- Nothing fancy required, so we leave done_callback handling to the public API + return false +end +function BasePowerD:turnOnFrontlightHW(done_callback) + --- @fixme: what if fl_intensity == fl_min (c.f., kindle)? + self:setIntensityHW(self.fl_intensity) + + return false +end function BasePowerD:frontlightWarmthHW() return 0 end -- Anything that needs to be done before doing a real hardware suspend. -- (Such as turning the front light off). @@ -121,9 +134,12 @@ end function BasePowerD:turnOffFrontlight(done_callback) if not self.device:hasFrontlight() then return end if self:isFrontlightOff() then return false end - self:turnOffFrontlightHW(done_callback) + local cb_handled = self:turnOffFrontlightHW(done_callback) self.is_fl_on = false self:stateChanged() + if not cb_handled and done_callback then + done_callback() + end return true end @@ -131,9 +147,12 @@ function BasePowerD:turnOnFrontlight(done_callback) if not self.device:hasFrontlight() then return end if self:isFrontlightOn() then return false end if self.fl_intensity == self.fl_min then return false end --- @fixme what the hell? - self:turnOnFrontlightHW(done_callback) + local cb_handled = self:turnOnFrontlightHW(done_callback) self.is_fl_on = true self:stateChanged() + if not cb_handled and done_callback then + done_callback() + end return true end diff --git a/frontend/device/kobo/powerd.lua b/frontend/device/kobo/powerd.lua index ea38cb00a..5cb63d98d 100644 --- a/frontend/device/kobo/powerd.lua +++ b/frontend/device/kobo/powerd.lua @@ -364,6 +364,9 @@ function KoboPowerD:turnOffFrontlightHW(done_callback) -- If UIManager is not initialized yet, just turn it off immediately self:setIntensityHW(self.fl_min) end + + -- We consume done_callback ourselves, make sure Generic's PowerD gets the memo + return true end -- Similar functionality as `Kobo:turnOnFrontlightHW`, but the other way around ;). @@ -410,6 +413,9 @@ function KoboPowerD:turnOnFrontlightHW(done_callback) -- If UIManager is not initialized yet, just turn it on immediately self:setIntensityHW(self.fl_intensity) end + + -- We consume done_callback ourselves, make sure Generic's PowerD gets the memo + return true end -- Turn off front light before suspend.