Slightly refector device & powerd component, remove some magic code

pull/1854/head
zijiehe 8 years ago
parent 2d7d7f8b8b
commit a183c1c64b

@ -1 +1 @@
Subproject commit 4c41adf0d224b9170fd506c2fcdf639c7b6bc062
Subproject commit 5131b24d461bc2d000df545c74c546a6e420e64a

@ -33,7 +33,8 @@ local Device = {
-- some devices have part of their screen covered by the bezel
viewport = nil,
-- enforce portrait orientation on display, no matter how configured at startup
-- enforce portrait orientation on display, no matter how configured at
-- startup
isAlwaysPortrait = no,
-- needs full screen refresh when resumed from screensaver?
needsScreenRefreshAfterResume = yes,
@ -100,47 +101,41 @@ end
function Device:onPowerEvent(ev)
local Screensaver = require("ui/screensaver")
if (ev == "Power" or ev == "Suspend") and not self.screen_saver_mode then
self.powerd:beforeSuspend()
local UIManager = require("ui/uimanager")
-- flushing settings first in case the screensaver takes too long time that
-- flushing has no chance to run
-- flushing settings first in case the screensaver takes too long time
-- that flushing has no chance to run
UIManager:sendEvent(Event:new("FlushSettings"))
DEBUG("Suspending...")
-- always suspend in portrait mode
self.orig_rotation_mode = self.screen:getRotationMode()
self.screen:setRotationMode(0)
Screensaver:show()
self:prepareSuspend()
self.screen:refreshFull()
self.screen_saver_mode = true
UIManager:scheduleIn(10, self.suspend)
elseif (ev == "Power" or ev == "Resume") and self.screen_saver_mode then
DEBUG("Resuming...")
self:resume()
-- restore to previous rotation mode
self.screen:setRotationMode(self.orig_rotation_mode)
self:resume()
local UIManager = require("ui/uimanager")
UIManager:unschedule(self.suspend)
if self:needsScreenRefreshAfterResume() then
self.screen:refreshFull()
end
self.screen_saver_mode = false
self.powerd:refreshCapacity()
Screensaver:close()
self.powerd:afterResume()
end
end
function Device:prepareSuspend()
if self.powerd and self.powerd.fl ~= nil then
-- in no case should the frontlight be turned on in suspend mode
self.powerd.fl:sleep()
end
self.screen:refreshFull()
self.screen_saver_mode = true
end
function Device:suspend()
end
-- Hardware function to suspend the device
function Device:suspend() end
function Device:resume()
local UIManager = require("ui/uimanager")
UIManager:unschedule(self.suspend)
if self:needsScreenRefreshAfterResume() then
self.screen:refreshFull()
end
self.screen_saver_mode = false
self.powerd:refreshCapacity()
end
-- Hardware function to resume the device
function Device:resume() end
function Device:usbPlugIn()
if self.charging_mode == false and self.screen_saver_mode == false then

@ -22,8 +22,12 @@ function BasePowerD:toggleFrontlight() end
function BasePowerD:setIntensityHW() end
function BasePowerD:getCapacityHW() return "0" end
function BasePowerD:isChargingHW() end
function BasePowerD:suspendHW() end
function BasePowerD:wakeUpHW() end
-- Anything needs to be done before do a real hardware suspend. Such as turn off
-- front light.
function BasePowerD:beforeSuspend() end
-- Anything needs to be done after do a real hardware resume. Such as resume
-- front light state.
function BasePowerD:afterResume() end
function BasePowerD:read_int_file(file)
local fd = io.open(file, "r")
@ -68,7 +72,8 @@ function BasePowerD:getCapacity()
end
function BasePowerD:refreshCapacity()
-- We want our next getCapacity call to actually pull up to date info instead of a cached value ;)
-- We want our next getCapacity call to actually pull up to date info
-- instead of a cached value ;)
self.capacity_pulled_count = self.capacity_cached_count
end
@ -76,12 +81,4 @@ function BasePowerD:isCharging()
return self:isChargingHW()
end
function BasePowerD:suspend()
return self:suspendHW()
end
function BasePowerD:wakeUp()
return self:wakeUpHW()
end
return BasePowerD

@ -143,15 +143,6 @@ end
function Kobo:resume()
os.execute("echo 0 > /sys/power/state-extended")
if self.powerd then
if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then
self.powerd:setIntensity(math.max(math.min(KOBO_LIGHT_ON_START,100),0))
elseif self.powerd.fl ~= nil then
self.powerd.fl:restore()
end
end
Generic.resume(self)
end
-------------- device probe ------------
@ -175,6 +166,3 @@ elseif codename == "alyssum" then
else
error("unrecognized Kobo model "..codename)
end

@ -60,4 +60,22 @@ function KoboPowerD:isChargingHW()
return self.is_charging
end
-- Turn off front light before suspend.
function KoboPowerD:beforeSuspend()
if self.flState then
assert(self.fl ~= nil)
self.fl:setBrightness(0)
end
end
-- Restore front light state after resume.
function KoboPowerD:afterResume()
if KOBO_LIGHT_ON_START and tonumber(KOBO_LIGHT_ON_START) > -1 then
self:setIntensity(math.min(KOBO_LIGHT_ON_START, 100))
elseif self.flState then
assert(self.fl ~= nil)
self.fl:setBrightness(self.flIntensity)
end
end
return KoboPowerD

Loading…
Cancel
Save