mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Partial fix for 3477 (#3568)
Partial, as it will safe the state when suspending the reader by pressing the power-button. However, it will still not safe the state when Pocketbooks autoPowerOff-Feature kicks in, as this does not create an event (e.g. no EVT_BACKGROUND) of any kind. * Clean up device.lua * Save state on suspend
This commit is contained in:
committed by
Frans de Jonge
parent
22a8cfde7c
commit
88c03c08d1
@@ -57,24 +57,52 @@ local PocketBook = Generic:new{
|
||||
}
|
||||
|
||||
function PocketBook:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[KEY_MENU] = "Menu",
|
||||
[KEY_PREV] = "LPgBack",
|
||||
[KEY_NEXT] = "LPgFwd",
|
||||
},
|
||||
handleMiscEv = function(this, ev)
|
||||
if ev.code == EVT_BACKGROUND then
|
||||
self.isInBackGround = true
|
||||
return "Suspend"
|
||||
elseif ev.code == EVT_FOREGROUND then
|
||||
if self.isInBackGround then
|
||||
self.isInBackGround = false
|
||||
return "Resume"
|
||||
end
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
-- in contrast to kobo/kindle, pocketbook-devices do not use linux/input
|
||||
-- events directly. To be able to use input.lua nevertheless, we make
|
||||
-- inkview-events look like linux/input events or handle them directly
|
||||
-- here.
|
||||
-- Unhandled events will leave Input:waitEvent() as "GenericInput"
|
||||
self.input:registerEventAdjustHook(function(_input, ev)
|
||||
if ev.type == EVT_KEYDOWN or ev.type == EVT_KEYUP then
|
||||
ev.code = ev.code
|
||||
ev.value = ev.type == EVT_KEYDOWN and 1 or 0
|
||||
ev.type = 1 -- EV_KEY
|
||||
elseif ev.type == EVT_BACKGROUND then
|
||||
self.isInBackGround = true
|
||||
self:onPowerEvent("Power")
|
||||
elseif self.isInBackGround and ev.type == EVT_FOREGROUND then
|
||||
self.isInBackGround = false
|
||||
self:onPowerEvent("Power")
|
||||
elseif ev.type == EVT_EXIT then
|
||||
-- auto shutdown event from inkview framework, gracefully close
|
||||
-- everything and let the framework shutdown the device
|
||||
ev.type = 1 -- linux/input.h Key-Event
|
||||
end
|
||||
|
||||
-- handle EVT_BACKGROUND and EVT_FOREGROUND as MiscEvent as this makes
|
||||
-- it easy to return a string directly which can be used in
|
||||
-- uimanager.lua as event_handler index.
|
||||
if ev.type == EVT_BACKGROUND or ev.type == EVT_FOREGROUND then
|
||||
ev.code = ev.type
|
||||
ev.type = 4 -- handle as MiscEvent, see above
|
||||
end
|
||||
|
||||
-- auto shutdown event from inkview framework, gracefully close
|
||||
-- everything and let the framework shutdown the device
|
||||
if ev.type == EVT_EXIT then
|
||||
require("ui/uimanager"):broadcastEvent(
|
||||
require("ui/event"):new("Close"))
|
||||
elseif not self.isInBackGround and ev.type == EVT_FOREGROUND then
|
||||
self.screen:refreshPartial()
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -84,6 +112,8 @@ function PocketBook:init()
|
||||
Generic.init(self)
|
||||
end
|
||||
|
||||
function PocketBook:supportsScreensaver() return true end
|
||||
|
||||
function PocketBook:setDateTime(year, month, day, hour, min, sec)
|
||||
if hour == nil or min == nil then return true end
|
||||
local command
|
||||
@@ -163,77 +193,6 @@ local PocketBook623 = PocketBook:new{
|
||||
emu_events_dev = "/var/dev/shm/emu_events",
|
||||
}
|
||||
|
||||
function PocketBook840:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[24] = "LPgBack",
|
||||
[25] = "LPgFwd",
|
||||
[1002] = "Power",
|
||||
}
|
||||
}
|
||||
PocketBook.init(self)
|
||||
end
|
||||
|
||||
function PocketBook631:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[23] = "Menu",
|
||||
[24] = "LPgBack",
|
||||
[25] = "LPgFwd",
|
||||
[1002] = "Power",
|
||||
}
|
||||
}
|
||||
PocketBook.init(self)
|
||||
end
|
||||
|
||||
function PocketBook626:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[24] = "LPgBack",
|
||||
[25] = "LPgFwd",
|
||||
[1002] = "Power",
|
||||
}
|
||||
}
|
||||
PocketBook.init(self)
|
||||
end
|
||||
|
||||
function PocketBook624:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[24] = "LPgBack",
|
||||
[25] = "LPgFwd",
|
||||
[1002] = "Power",
|
||||
}
|
||||
}
|
||||
PocketBook.init(self)
|
||||
end
|
||||
|
||||
function PocketBook623:init()
|
||||
self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/pocketbook/powerd"):new{device = self}
|
||||
self.input = require("device/input"):new{
|
||||
device = self,
|
||||
event_map = {
|
||||
[24] = "LPgBack",
|
||||
[25] = "LPgFwd",
|
||||
[1002] = "Power",
|
||||
}
|
||||
}
|
||||
PocketBook.init(self)
|
||||
end
|
||||
|
||||
logger.info('SoftwareVersion: ', PocketBook:getSoftwareVersion())
|
||||
|
||||
local codename = PocketBook:getDeviceModel()
|
||||
|
||||
@@ -74,6 +74,16 @@ function UIManager:init()
|
||||
Device:reboot()
|
||||
end)
|
||||
end
|
||||
if Device:isPocketBook() then
|
||||
self.event_handlers["Suspend"] = function()
|
||||
self:_beforeSuspend()
|
||||
Device:onPowerEvent("Power")
|
||||
end
|
||||
self.event_handlers["Resume"] = function()
|
||||
Device:onPowerEvent("Power")
|
||||
self:_afterResume()
|
||||
end
|
||||
end
|
||||
if Device:isKobo() then
|
||||
-- We do not want auto suspend procedure to waste battery during
|
||||
-- suspend. So let's unschedule it when suspending, and restart it after
|
||||
|
||||
Reference in New Issue
Block a user