[feat, Kobo] Autoshutdown (#5335)

The methods used here will likely work on most embedded devices, which is why I put them in their own WakeupMgr interface/scheduler module, separate from Kobo.

See https://www.mobileread.com/forums/showthread.php?p=3886403#post3886403 for more context.

Fixes #3806.
This commit is contained in:
Frans de Jonge
2019-09-12 14:15:08 +02:00
committed by GitHub
parent 9163a85b3c
commit e257c4e45e
10 changed files with 503 additions and 164 deletions

View File

@@ -386,7 +386,7 @@ function UIManager:close(widget, refreshtype, refreshregion, refreshdither)
end
-- schedule an execution task, task queue is in ascendant order
function UIManager:schedule(time, action)
function UIManager:schedule(time, action, ...)
local p, s, e = 1, 1, #self._task_queue
if e ~= 0 then
local us = time[1] * MILLION + time[2]
@@ -416,7 +416,11 @@ function UIManager:schedule(time, action)
end
until e < s
end
table.insert(self._task_queue, p, { time = time, action = action })
table.insert(self._task_queue, p, {
time = time,
action = action,
args = {...},
})
self._task_queue_dirty = true
end
dbg:guard(UIManager, 'schedule',
@@ -426,7 +430,7 @@ dbg:guard(UIManager, 'schedule',
end)
--- Schedules task in a certain amount of seconds (fractions allowed) from now.
function UIManager:scheduleIn(seconds, action)
function UIManager:scheduleIn(seconds, action, ...)
local when = { util.gettime() }
local s = math.floor(seconds)
local usecs = (seconds - s) * MILLION
@@ -436,7 +440,7 @@ function UIManager:scheduleIn(seconds, action)
when[1] = when[1] + 1
when[2] = when[2] - MILLION
end
self:schedule(when, action)
self:schedule(when, action, ...)
end
dbg:guard(UIManager, 'scheduleIn',
function(self, seconds, action)
@@ -743,7 +747,7 @@ function UIManager:_checkTasks()
-- task is pending to be executed right now. do it.
-- NOTE: be careful that task.action() might modify
-- _task_queue here. So need to avoid race condition
task.action()
task.action(unpack(task.args or {}))
else
-- queue is sorted in ascendant order, safe to assume all items
-- are future tasks for now