automatically adjust ev time for kobo touch

pull/2042/head
Qingping Hou 8 years ago
parent 76b58c38e7
commit 82a3e0f9ad

@ -190,11 +190,15 @@ To run unit tests:
./kodev test front
```
NOTE: Extra dependencies for tests: busted and ansicolors from luarocks
To run Lua static analysis:
```
make static-check
```
NOTE: Extra dependencies for tests: luacheck from luarocks
You may need to checkout the [travis config file][travis-conf] to setup up
a proper testing environment. Briefly, you need to install `luarocks` and
then install `busted` with `luarocks`. The "eng" language data file for

@ -214,13 +214,6 @@ function Input:adjustTouchTranslate(ev, by)
end
end
function Input:adjustTouchAlyssum(ev)
ev.time = TimeVal:now()
if ev.type == EV_ABS and ev.code == ABS_MT_TRACKING_ID then
ev.value = ev.value - 1
end
end
function Input:setTimeout(cb, tv_out)
local item = {
callback = cb,

@ -1,4 +1,5 @@
local Generic = require("device/generic/device")
local TimeVal = require("ui/timeval")
local Geom = require("ui/geometry")
local dbg = require("dbg")
@ -26,6 +27,10 @@ local KoboTrilogy = Kobo:new{
model = "Kobo_trilogy",
needsTouchScreenProbe = yes,
touch_switch_xy = false,
-- Some Kobo Touch models' kernel does not generate touch event with epoch
-- timestamp. This flag will probe for those models and setup event adjust
-- hook accordingly
touch_probe_ev_epoch_time = true,
hasKeys = yes,
}
@ -133,6 +138,31 @@ function Kobo:init()
end
end
local probeEvEpochTime
-- this function will update itself after the first touch event
probeEvEpochTime = function(self, ev)
-- this check should work if the device has uptime less than 10 years
if ev.time.sec <= 315569260 then
-- time is seconds since boot, force it to epoch
probeEvEpochTime = function(_, _ev)
_ev.time = TimeVal:now()
end
probeEvEpochTime(nil, ev)
else
-- time is already epoch time, no need to do anything
probeEvEpochTime = function(_, _) end
end
end
local ABS_MT_TRACKING_ID = 57
local EV_ABS = 3
local adjustTouchAlyssum = function(self, ev)
ev.time = TimeVal:now()
if ev.type == EV_ABS and ev.code == ABS_MT_TRACKING_ID then
ev.value = ev.value - 1
end
end
function Kobo:initEventAdjustHooks()
-- it's called KOBO_TOUCH_MIRRORED in defaults.lua, but what it
-- actually did in its original implementation was to switch X/Y.
@ -153,7 +183,13 @@ function Kobo:initEventAdjustHooks()
end
if self.touch_alyssum_protocol then
self.input:registerEventAdjustHook(self.input.adjustTouchAlyssum)
self.input:registerEventAdjustHook(adjustTouchAlyssum)
end
if self.touch_probe_ev_epoch_time then
self.input:registerEventAdjustHook(function(_, ev)
probeEvEpochTime(_, ev)
end)
end
if self.touch_phoenix_protocol then

@ -321,7 +321,8 @@ OPTIONS:
if [ ! -z "$2" ]; then
test_path="${test_path}/$2"
fi
busted --lua="./luajit ${opts}" \
busted --lua="./luajit" ${opts} \
--no-auto-insulate \
--lazy \
-o "./spec/$1/unit/verbose_print" \

@ -15,7 +15,9 @@ describe("device module", function()
end)
describe("kobo", function()
local TimeVal
setup(function()
TimeVal = require("ui/timeval")
mock_fb = {
new = function()
return {
@ -63,6 +65,7 @@ describe("device module", function()
kobo_dev:init()
local Screen = kobo_dev.screen
kobo_dev.touch_probe_ev_epoch_time = false
assert.is.same("Kobo_trilogy", kobo_dev.model)
assert.truthy(kobo_dev:needsTouchScreenProbe())
G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
@ -93,6 +96,63 @@ describe("device module", function()
package.loaded['ffi/framebuffer_mxcfb'] = nil
os.getenv:revert()
mock_input.open:revert()
-- reset eventAdjustHook
kobo_dev.input.eventAdjustHook = function() end
kobo_dev.touch_probe_ev_epoch_time = true
end)
it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function()
local saved_getenv = os.getenv
stub(os, "getenv")
os.getenv.invokes(function(key)
if key == "PRODUCT" then
return "trilogy"
else
return saved_getenv(key)
end
end)
package.loaded['device/kobo/device'] = nil
package.loaded['ffi/framebuffer_mxcfb'] = mock_fb
mock_input = require('device/input')
stub(mock_input, "open")
local kobo_dev = require("device/kobo/device")
kobo_dev:init()
local Screen = kobo_dev.screen
assert.is.same("Kobo_trilogy", kobo_dev.model)
local x, y = Screen:getWidth()-5, 10
local EV_ABS = 3
local ABS_X = 00
local ABS_Y = 01
-- mirror x, then switch_xy
local ev_x = {
type = EV_ABS,
code = ABS_X,
value = x,
time = {sec = 1000}
}
local ev_y = {
type = EV_ABS,
code = ABS_Y,
value = y,
time = {sec = 1000}
}
assert.truthy(kobo_dev.touch_probe_ev_epoch_time)
G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
kobo_dev:touchScreenProbe()
kobo_dev.input:eventAdjustHook(ev_x)
kobo_dev.input:eventAdjustHook(ev_y)
local cur_sec = TimeVal:now().sec
assert.truthy(cur_sec - ev_x.time.sec < 10)
assert.truthy(cur_sec - ev_y.time.sec < 10)
package.loaded['ffi/framebuffer_mxcfb'] = nil
os.getenv:revert()
mock_input.open:revert()
kobo_dev.input.eventAdjustHook = function() end
end)
it("should flush book settings before suspend", function()

Loading…
Cancel
Save