2016-04-03 04:52:30 +00:00
|
|
|
describe("device module", function()
|
2017-08-08 20:35:40 +00:00
|
|
|
-- luacheck: push ignore
|
2016-04-03 04:52:30 +00:00
|
|
|
local mock_fb, mock_input
|
2016-08-13 10:47:38 +00:00
|
|
|
local iopen = io.open
|
|
|
|
local osgetenv = os.getenv
|
2021-04-13 15:53:15 +00:00
|
|
|
local ffi, C
|
2016-08-13 10:47:38 +00:00
|
|
|
|
2016-04-03 04:52:30 +00:00
|
|
|
setup(function()
|
|
|
|
mock_fb = {
|
|
|
|
new = function()
|
|
|
|
return {
|
2021-05-13 11:05:05 +00:00
|
|
|
getRawSize = function() return {w = 600, h = 800} end,
|
2016-04-03 04:52:30 +00:00
|
|
|
getWidth = function() return 600 end,
|
|
|
|
getDPI = function() return 72 end,
|
2016-08-13 10:47:38 +00:00
|
|
|
setViewport = function() end,
|
|
|
|
getRotationMode = function() return 0 end,
|
|
|
|
getScreenMode = function() return "portrait" end,
|
|
|
|
setRotationMode = function() end,
|
2022-09-04 00:38:27 +00:00
|
|
|
scaleByDPI = function(this, dp) return math.ceil(dp * this:getDPI() / 160) end,
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
}
|
|
|
|
require("commonrequire")
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unloadAll()
|
2021-04-13 15:53:15 +00:00
|
|
|
ffi = require("ffi")
|
|
|
|
C = ffi.C
|
|
|
|
require("ffi/linux_input_h")
|
2019-02-18 16:01:00 +00:00
|
|
|
require("document/canvascontext"):init(require("device"))
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
before_each(function()
|
|
|
|
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
|
|
|
|
mock_input = require('device/input')
|
|
|
|
stub(mock_input, "open")
|
|
|
|
stub(os, "getenv")
|
|
|
|
stub(os, "execute")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
mock_input.open:revert()
|
|
|
|
os.getenv:revert()
|
|
|
|
os.execute:revert()
|
|
|
|
|
|
|
|
os.getenv = osgetenv
|
|
|
|
io.open = iopen
|
|
|
|
end)
|
|
|
|
|
2016-04-03 04:52:30 +00:00
|
|
|
describe("kobo", function()
|
2016-05-24 05:38:08 +00:00
|
|
|
local TimeVal
|
2016-09-12 04:41:56 +00:00
|
|
|
local NickelConf
|
2016-04-03 04:52:30 +00:00
|
|
|
setup(function()
|
2016-05-24 05:38:08 +00:00
|
|
|
TimeVal = require("ui/timeval")
|
2016-09-12 04:41:56 +00:00
|
|
|
NickelConf = require("device/kobo/nickel_conf")
|
|
|
|
end)
|
|
|
|
|
|
|
|
before_each(function()
|
|
|
|
stub(NickelConf.frontLightLevel, "get")
|
|
|
|
NickelConf.frontLightLevel.get.returns(0)
|
|
|
|
stub(NickelConf.frontLightState, "get")
|
|
|
|
end)
|
|
|
|
|
|
|
|
after_each(function()
|
|
|
|
NickelConf.frontLightLevel.get:revert()
|
|
|
|
NickelConf.frontLightState.get:revert()
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should initialize properly on Kobo dahlia", function()
|
|
|
|
os.getenv.returns("dahlia")
|
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
|
|
|
|
kobo_dev:init()
|
|
|
|
assert.is.same("Kobo_dahlia", kobo_dev.model)
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for input in trilogy", function()
|
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
else
|
2018-05-10 10:26:07 +00:00
|
|
|
return osgetenv(key)
|
2016-04-03 04:52:30 +00:00
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
package.loaded['device/kobo/device'] = nil
|
2016-04-03 04:52:30 +00:00
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
|
|
|
|
assert.is.same("Kobo_trilogy", kobo_dev.model)
|
|
|
|
assert.truthy(kobo_dev:needsTouchScreenProbe())
|
|
|
|
G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
|
|
|
|
kobo_dev:touchScreenProbe()
|
|
|
|
local x, y = Screen:getWidth()-5, 10
|
|
|
|
-- mirror x, then switch_xy
|
|
|
|
local ev_x = {
|
2021-04-13 15:53:15 +00:00
|
|
|
type = C.EV_ABS,
|
|
|
|
code = C.ABS_X,
|
2016-04-03 04:52:30 +00:00
|
|
|
value = y,
|
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
* Port delay computations to TimeVal
* Fixed delay computations to handle time warps (large and negative deltas).
* Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
* Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
* Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
* The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
a clock source that is *NOT* MONOTONIC.
AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
* Use the <linux/input.h> FFI module instead of re-declaring every constant
* Fixed (verbose) debug logging of input events to actually translate said constants properly.
* Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
* Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
* Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
* Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
* Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
* New methods:
* Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
* Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
* Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
* Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
because very few time has passed.
The only code left that does live syscalls does it because it's actually necessary for accuracy,
and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
* Fix it so that settings are actually honored.
* Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.
* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
2021-03-30 00:57:59 +00:00
|
|
|
time = TimeVal:realtime(),
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
local ev_y = {
|
2021-04-13 15:53:15 +00:00
|
|
|
type = C.EV_ABS,
|
|
|
|
code = C.ABS_Y,
|
2016-04-03 04:52:30 +00:00
|
|
|
value = Screen:getWidth()-x,
|
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
* Port delay computations to TimeVal
* Fixed delay computations to handle time warps (large and negative deltas).
* Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
* Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
* Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
* The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
a clock source that is *NOT* MONOTONIC.
AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
* Use the <linux/input.h> FFI module instead of re-declaring every constant
* Fixed (verbose) debug logging of input events to actually translate said constants properly.
* Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
* Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
* Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
* Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
* Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
* New methods:
* Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
* Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
* Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
* Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
because very few time has passed.
The only code left that does live syscalls does it because it's actually necessary for accuracy,
and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
* Fix it so that settings are actually honored.
* Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.
* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
2021-03-30 00:57:59 +00:00
|
|
|
time = TimeVal:realtime(),
|
2016-04-03 04:52:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_x)
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_y)
|
|
|
|
assert.is.same(x, ev_y.value)
|
2021-04-13 15:53:15 +00:00
|
|
|
assert.is.same(C.ABS_X, ev_y.code)
|
2016-04-03 04:52:30 +00:00
|
|
|
assert.is.same(y, ev_x.value)
|
2021-04-13 15:53:15 +00:00
|
|
|
assert.is.same(C.ABS_Y, ev_x.code)
|
2016-04-03 04:52:30 +00:00
|
|
|
|
2016-05-24 05:38:08 +00:00
|
|
|
-- reset eventAdjustHook
|
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function()
|
2020-10-18 13:57:42 +00:00
|
|
|
-- This has no more value since #6798 as ev time can now stay
|
|
|
|
-- non-epoch. Adjustments are made on first event handled, and
|
|
|
|
-- have only effects when handling long-press (so, the long-press
|
|
|
|
-- for dict lookup tests with test this).
|
|
|
|
-- We just check here it still works with non-epoch ev time, as previous test
|
2016-05-24 05:38:08 +00:00
|
|
|
os.getenv.invokes(function(key)
|
|
|
|
if key == "PRODUCT" then
|
|
|
|
return "trilogy"
|
|
|
|
else
|
2018-05-10 10:26:07 +00:00
|
|
|
return osgetenv(key)
|
2016-05-24 05:38:08 +00:00
|
|
|
end
|
|
|
|
end)
|
2019-01-08 01:59:47 +00:00
|
|
|
|
|
|
|
package.loaded['device/kobo/device'] = nil
|
2016-05-24 05:38:08 +00:00
|
|
|
local kobo_dev = require("device/kobo/device")
|
|
|
|
kobo_dev:init()
|
|
|
|
local Screen = kobo_dev.screen
|
|
|
|
|
|
|
|
assert.is.same("Kobo_trilogy", kobo_dev.model)
|
2019-01-08 01:59:47 +00:00
|
|
|
assert.truthy(kobo_dev:needsTouchScreenProbe())
|
|
|
|
kobo_dev:touchScreenProbe()
|
2016-05-24 05:38:08 +00:00
|
|
|
local x, y = Screen:getWidth()-5, 10
|
|
|
|
local ev_x = {
|
2021-04-13 15:53:15 +00:00
|
|
|
type = C.EV_ABS,
|
|
|
|
code = C.ABS_X,
|
2020-10-18 13:57:42 +00:00
|
|
|
value = y,
|
2016-05-24 05:38:08 +00:00
|
|
|
time = {sec = 1000}
|
|
|
|
}
|
|
|
|
local ev_y = {
|
2021-04-13 15:53:15 +00:00
|
|
|
type = C.EV_ABS,
|
|
|
|
code = C.ABS_Y,
|
2020-10-18 13:57:42 +00:00
|
|
|
value = Screen:getWidth()-x,
|
2016-05-24 05:38:08 +00:00
|
|
|
time = {sec = 1000}
|
|
|
|
}
|
|
|
|
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_x)
|
|
|
|
kobo_dev.input:eventAdjustHook(ev_y)
|
2020-10-18 13:57:42 +00:00
|
|
|
assert.is.same(x, ev_y.value)
|
2021-04-13 15:53:15 +00:00
|
|
|
assert.is.same(C.ABS_X, ev_y.code)
|
2020-10-18 13:57:42 +00:00
|
|
|
assert.is.same(y, ev_x.value)
|
2021-04-13 15:53:15 +00:00
|
|
|
assert.is.same(C.ABS_Y, ev_x.code)
|
2016-05-24 05:38:08 +00:00
|
|
|
|
2019-01-08 01:59:47 +00:00
|
|
|
-- reset eventAdjustHook
|
2016-05-24 05:38:08 +00:00
|
|
|
kobo_dev.input.eventAdjustHook = function() end
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
2016-05-02 08:35:06 +00:00
|
|
|
|
|
|
|
it("should flush book settings before suspend", function()
|
|
|
|
local sample_pdf = "spec/front/unit/data/tall.pdf"
|
|
|
|
local ReaderUI = require("apps/reader/readerui")
|
|
|
|
local Device = require("device")
|
|
|
|
|
|
|
|
NickelConf.frontLightLevel.get.returns(1)
|
|
|
|
NickelConf.frontLightState.get.returns(0)
|
|
|
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(Device, "suspend")
|
|
|
|
stub(Device.powerd, "beforeSuspend")
|
|
|
|
stub(Device, "isKobo")
|
|
|
|
|
|
|
|
Device.isKobo.returns(true)
|
|
|
|
UIManager:init()
|
|
|
|
|
|
|
|
ReaderUI:doShowReader(sample_pdf)
|
|
|
|
local readerui = ReaderUI._getRunningInstance()
|
|
|
|
stub(readerui, "onFlushSettings")
|
|
|
|
UIManager.event_handlers["PowerPress"]()
|
|
|
|
UIManager.event_handlers["PowerRelease"]()
|
|
|
|
assert.stub(readerui.onFlushSettings).was_called()
|
|
|
|
|
|
|
|
Device.suspend:revert()
|
|
|
|
Device.powerd.beforeSuspend:revert()
|
|
|
|
Device.isKobo:revert()
|
2016-08-12 06:05:18 +00:00
|
|
|
readerui.onFlushSettings:revert()
|
2016-05-02 08:35:06 +00:00
|
|
|
readerui:onClose()
|
|
|
|
end)
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
describe("kindle", function()
|
2016-08-11 09:12:55 +00:00
|
|
|
it("should initialize voyage without error", function()
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
2019-07-19 21:16:25 +00:00
|
|
|
read = function() return "B013XX" end,
|
2016-08-13 10:47:38 +00:00
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
local kindle_dev = require('device/kindle/device')
|
2016-04-26 07:16:27 +00:00
|
|
|
assert.is.same(kindle_dev.model, "KindleVoyage")
|
|
|
|
kindle_dev:init()
|
|
|
|
assert.is.same(kindle_dev.input.event_map[104], "LPgBack")
|
|
|
|
assert.is.same(kindle_dev.input.event_map[109], "LPgFwd")
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_min, 0)
|
2020-03-26 03:56:34 +00:00
|
|
|
-- NOTE: fl_max + 1 since #5989
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_max, 25)
|
2016-04-26 07:16:27 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("should toggle frontlight", function()
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
2019-07-19 21:16:25 +00:00
|
|
|
read = function() return "B013XX" end,
|
2016-08-13 10:47:38 +00:00
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
elseif filename == "/sys/class/backlight/max77696-bl/brightness" then
|
|
|
|
return {
|
2021-01-16 03:41:46 +00:00
|
|
|
read = function() return 12 end,
|
2016-08-13 10:47:38 +00:00
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
2016-04-26 07:16:27 +00:00
|
|
|
|
|
|
|
local kindle_dev = require("device/kindle/device")
|
|
|
|
kindle_dev:init()
|
|
|
|
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 12)
|
|
|
|
kindle_dev.powerd:setIntensity(5)
|
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
|
|
|
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
|
|
|
assert.stub(os.execute).was_called_with(
|
2021-04-24 23:15:38 +00:00
|
|
|
"printf '%s' 0 > /sys/class/backlight/max77696-bl/brightness")
|
2018-12-10 21:10:35 +00:00
|
|
|
-- Here be shenanigans: we don't override powerd's fl_intensity when we turn the light off,
|
|
|
|
-- so that we can properly turn it back on at the previous intensity ;)
|
2016-04-26 07:16:27 +00:00
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
2018-12-10 21:10:35 +00:00
|
|
|
-- But if we were to cat /sys/class/backlight/max77696-bl/brightness, it should now be 0.
|
2016-04-26 07:16:27 +00:00
|
|
|
|
|
|
|
kindle_dev.powerd:toggleFrontlight()
|
2018-12-10 21:10:35 +00:00
|
|
|
assert.is.same(kindle_dev.powerd.fl_intensity, 5)
|
|
|
|
-- And /sys/class/backlight/max77696-bl/brightness is now !0
|
|
|
|
-- (exact value is HW-dependent, each model has a different curve, we let lipc do the work for us).
|
2016-08-13 10:47:38 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("oasis should interpret orientation event", function()
|
2017-06-23 17:04:11 +00:00
|
|
|
package.unload('device/kindle/device')
|
2016-08-13 10:47:38 +00:00
|
|
|
io.open = function(filename, mode)
|
|
|
|
if filename == "/proc/usid" then
|
|
|
|
return {
|
|
|
|
read = function()
|
2019-07-19 21:16:25 +00:00
|
|
|
return "G0B0GCXXX"
|
2016-08-13 10:47:38 +00:00
|
|
|
end,
|
|
|
|
close = function() end
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return iopen(filename, mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
mock_ffi_input = require('ffi/input')
|
|
|
|
stub(mock_ffi_input, "waitForEvent")
|
The great Input/GestureDetector/TimeVal spring cleanup (a.k.a., a saner main loop) (#7415)
* ReaderDictionary: Port delay computations to TimeVal
* ReaderHighlight: Port delay computations to TimeVal
* ReaderView: Port delay computations to TimeVal
* Android: Reset gesture detection state on APP_CMD_TERM_WINDOW.
This prevents potentially being stuck in bogus gesture states when switching apps.
* GestureDetector:
* Port delay computations to TimeVal
* Fixed delay computations to handle time warps (large and negative deltas).
* Simplified timed callback handling to invalidate timers much earlier, preventing accumulating useless timers that no longer have any chance of ever detecting a gesture.
* Fixed state clearing to handle the actual effective slots, instead of hard-coding slot 0 & slot 1.
* Simplified timed callback handling in general, and added support for a timerfd backend for better performance and accuracy.
* The improved timed callback handling allows us to detect and honor (as much as possible) the three possible clock sources usable by Linux evdev events.
The only case where synthetic timestamps are used (and that only to handle timed callbacks) is limited to non-timerfd platforms where input events use
a clock source that is *NOT* MONOTONIC.
AFAICT, that's pretty much... PocketBook, and that's it?
* Input:
* Use the <linux/input.h> FFI module instead of re-declaring every constant
* Fixed (verbose) debug logging of input events to actually translate said constants properly.
* Completely reset gesture detection state on suspend. This should prevent bogus gesture detection on resume.
* Refactored the waitEvent loop to make it easier to comprehend (hopefully) and much more efficient.
Of specific note, it no longer does a crazy select spam every 100µs, instead computing and relying on sane timeouts,
as afforded by switching the UI event/input loop to the MONOTONIC time base, and the refactored timed callbacks in GestureDetector.
* reMarkable: Stopped enforcing synthetic timestamps on input events, as it should no longer be necessary.
* TimeVal:
* Refactored and simplified, especially as far as metamethods are concerned (based on <bsd/sys/time.h>).
* Added a host of new methods to query the various POSIX clock sources, and made :now default to MONOTONIC.
* Removed the debug guard in __sub, as time going backwards can be a perfectly normal occurrence.
* New methods:
* Clock sources: :realtime, :monotonic, :monotonic_coarse, :realtime_coarse, :boottime
* Utility: :tonumber, :tousecs, :tomsecs, :fromnumber, :isPositive, :isZero
* UIManager:
* Ported event loop & scheduling to TimeVal, and switched to the MONOTONIC time base.
This ensures reliable and consistent scheduling, as time is ensured never to go backwards.
* Added a :getTime() method, that returns a cached TimeVal:now(), updated at the top of every UI frame.
It's used throughout the codebase to cadge a syscall in circumstances where we are guaranteed that a syscall would return a mostly identical value,
because very few time has passed.
The only code left that does live syscalls does it because it's actually necessary for accuracy,
and the only code left that does that in a REALTIME time base is code that *actually* deals with calendar time (e.g., Statistics).
* DictQuickLookup: Port delay computations to TimeVal
* FootNoteWidget: Port delay computations to TimeVal
* HTMLBoxWidget: Port delay computations to TimeVal
* Notification: Port delay computations to TimeVal
* TextBoxWidget: Port delay computations to TimeVal
* AutoSuspend: Port to TimeVal
* AutoTurn:
* Fix it so that settings are actually honored.
* Port to TimeVal
* BackgroundRunner: Port to TimeVal
* Calibre: Port benchmarking code to TimeVal
* BookInfoManager: Removed unnecessary yield in the metadata extraction subprocess now that subprocesses get scheduled properly.
* All in all, these changes reduced the CPU cost of a single tap by a factor of ten (!), and got rid of an insane amount of weird poll/wakeup cycles that must have been hell on CPU schedulers and batteries..
2021-03-30 00:57:59 +00:00
|
|
|
mock_ffi_input.waitForEvent.returns(true, {
|
2021-04-02 23:48:35 +00:00
|
|
|
{
|
2021-04-13 15:53:15 +00:00
|
|
|
type = C.EV_ABS,
|
2021-04-02 23:48:35 +00:00
|
|
|
time = {
|
|
|
|
usec = 450565,
|
|
|
|
sec = 1471081881
|
|
|
|
},
|
2021-04-13 15:53:15 +00:00
|
|
|
code = 24, -- C.ABS_PRESSURE -> ABS_OASIS_ORIENTATION
|
2021-04-02 23:48:35 +00:00
|
|
|
value = 16
|
|
|
|
}
|
2016-08-13 10:47:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
local UIManager = require("ui/uimanager")
|
|
|
|
stub(UIManager, "onRotation")
|
|
|
|
|
|
|
|
local kindle_dev = require('device/kindle/device')
|
|
|
|
assert.is.same("KindleOasis", kindle_dev.model)
|
|
|
|
kindle_dev:init()
|
2020-07-09 17:11:44 +00:00
|
|
|
kindle_dev:lockGSensor(true)
|
2016-08-13 10:47:38 +00:00
|
|
|
|
|
|
|
kindle_dev.input:waitEvent()
|
|
|
|
assert.stub(UIManager.onRotation).was_called()
|
2016-04-26 07:16:27 +00:00
|
|
|
|
2016-08-13 10:47:38 +00:00
|
|
|
mock_ffi_input.waitForEvent:revert()
|
|
|
|
UIManager.onRotation:revert()
|
2016-04-26 07:16:27 +00:00
|
|
|
end)
|
|
|
|
end)
|
2017-08-08 20:35:40 +00:00
|
|
|
-- luacheck: pop
|
2016-04-03 04:52:30 +00:00
|
|
|
end)
|