Merge pull request #2042 from koreader/houqp-master

automatically set proper ev timeval for kobo touch
pull/2032/head v2016.05.29-nightly
Huang Xin 8 years ago
commit e3ff96d108

@ -103,19 +103,19 @@ brew install nasm binutils libtool autoconf automake sdl2
``` ```
A recent version of Android SDK/NDK and `ant` are needed in order to build A recent version of Android SDK/NDK and `ant` are needed in order to build
Koreader for Android devices. KOReader for Android devices.
``` ```
sudo apt-get install ant sudo apt-get install ant
``` ```
In order to build Koreader package for Ubuntu Touch, the `click` package management In order to build KOReader package for Ubuntu Touch, the `click` package management
tool is needed, Ubuntu users can install it with: tool is needed, Ubuntu users can install it with:
``` ```
sudo apt-get install click sudo apt-get install click
``` ```
You might also need SDL library packages if you want to compile and run You might also need SDL library packages if you want to compile and run
Koreader on Linux PC. Fedora users can install `SDL` and `SDL-devel` package. KOReader on Linux PC. Fedora users can install `SDL` and `SDL-devel` package.
Ubuntu users probably need to install `libsdl2-dev` package: Ubuntu users probably need to install `libsdl2-dev` package:
Getting the source Getting the source
@ -179,7 +179,7 @@ If you want to compile the emulator for Windows run:
./kodev build win32 ./kodev build win32
``` ```
To run Koreader on your developing machine: To run KOReader on your developing machine:
``` ```
./kodev run ./kodev run
``` ```
@ -190,11 +190,15 @@ To run unit tests:
./kodev test front ./kodev test front
``` ```
NOTE: Extra dependencies for tests: busted and ansicolors from luarocks
To run Lua static analysis: To run Lua static analysis:
``` ```
make static-check 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 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 a proper testing environment. Briefly, you need to install `luarocks` and
then install `busted` with `luarocks`. The "eng" language data file for then install `busted` with `luarocks`. The "eng" language data file for
@ -218,7 +222,7 @@ Translation
=========== ===========
Please refer to [l10n's README][l10n-readme] to grab the latest translations Please refer to [l10n's README][l10n-readme] to grab the latest translations
from [the Koreader project on Transifex][koreader-transifex] with this command: from [the KOReader project on Transifex][koreader-transifex] with this command:
``` ```
make po make po
``` ```

@ -1 +1 @@
Subproject commit 02ba8e1073de9b39c157e297e73a1e6e45d07552 Subproject commit 8aef7200f14a2410d06042ba46fd4ceb1c179aad

@ -214,13 +214,6 @@ function Input:adjustTouchTranslate(ev, by)
end end
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) function Input:setTimeout(cb, tv_out)
local item = { local item = {
callback = cb, callback = cb,

@ -1,4 +1,5 @@
local Generic = require("device/generic/device") local Generic = require("device/generic/device")
local TimeVal = require("ui/timeval")
local Geom = require("ui/geometry") local Geom = require("ui/geometry")
local dbg = require("dbg") local dbg = require("dbg")
@ -26,6 +27,10 @@ local KoboTrilogy = Kobo:new{
model = "Kobo_trilogy", model = "Kobo_trilogy",
needsTouchScreenProbe = yes, needsTouchScreenProbe = yes,
touch_switch_xy = false, 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, hasKeys = yes,
} }
@ -133,6 +138,31 @@ function Kobo:init()
end end
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() function Kobo:initEventAdjustHooks()
-- it's called KOBO_TOUCH_MIRRORED in defaults.lua, but what it -- it's called KOBO_TOUCH_MIRRORED in defaults.lua, but what it
-- actually did in its original implementation was to switch X/Y. -- actually did in its original implementation was to switch X/Y.
@ -153,7 +183,13 @@ function Kobo:initEventAdjustHooks()
end end
if self.touch_alyssum_protocol then 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 end
if self.touch_phoenix_protocol then if self.touch_phoenix_protocol then

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

@ -15,7 +15,9 @@ describe("device module", function()
end) end)
describe("kobo", function() describe("kobo", function()
local TimeVal
setup(function() setup(function()
TimeVal = require("ui/timeval")
mock_fb = { mock_fb = {
new = function() new = function()
return { return {
@ -63,6 +65,7 @@ describe("device module", function()
kobo_dev:init() kobo_dev:init()
local Screen = kobo_dev.screen local Screen = kobo_dev.screen
kobo_dev.touch_probe_ev_epoch_time = false
assert.is.same("Kobo_trilogy", kobo_dev.model) assert.is.same("Kobo_trilogy", kobo_dev.model)
assert.truthy(kobo_dev:needsTouchScreenProbe()) assert.truthy(kobo_dev:needsTouchScreenProbe())
G_reader_settings:saveSetting("kobo_touch_switch_xy", true) G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
@ -93,6 +96,63 @@ describe("device module", function()
package.loaded['ffi/framebuffer_mxcfb'] = nil package.loaded['ffi/framebuffer_mxcfb'] = nil
os.getenv:revert() os.getenv:revert()
mock_input.open: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) end)
it("should flush book settings before suspend", function() it("should flush book settings before suspend", function()

Loading…
Cancel
Save