mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #1854 from Hzj-jie/master
Slightly refector device & powerd component, remove some magic code
This commit is contained in:
2
base
2
base
Submodule base updated: 4c41adf0d2...5131b24d46
@@ -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
|
||||
-- Hardware function to suspend the device
|
||||
function Device:suspend() end
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user