Input: Minor cleanups (#7542)

* TimeVal: Log the results of the COARSE probes in debug logs
* GestureDetector: Print details of failed clock probes in debug logs
* GestureDetector: Skip the BOOTTIME probe when CLOCK_BOOTTIME is unsupported.
* Input: Decode ABS_DISTANCE events in debug logs
* Get rid of duplicated <linux/input.h> constants, use the FFI module everywhere (re #7536)
* Kobo: Get rid of the `touch_alyssum_protocol` quirk. Replace it by setting `main_finger_slot` to `1`, like on the H2O.
pull/7546/head
NiLuJe 3 years ago committed by GitHub
parent b6b332e311
commit f2e90f505b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1 +1 @@
Subproject commit 50e93546edffb91b9b0b5e89ec2bac03bc61a4dd Subproject commit 52d5705f57249f1a07b15a65bb0fd22fa16f3a2d

@ -396,7 +396,8 @@ function GestureDetector:probeClockSource(timev)
-- Finally, BOOTTIME -- Finally, BOOTTIME
local boottime = TimeVal:boottime() local boottime = TimeVal:boottime()
if timev >= boottime - threshold and timev <= boottime + threshold then -- NOTE: It was implemented in Linux 2.6.39, so, reject 0, which would mean it's unsupported...
if not boottime:isZero() and timev >= boottime - threshold and timev <= boottime + threshold then
self.clock_id = C.CLOCK_BOOTTIME self.clock_id = C.CLOCK_BOOTTIME
logger.info("GestureDetector:probeClockSource: Touch event timestamps appear to use CLOCK_BOOTTIME") logger.info("GestureDetector:probeClockSource: Touch event timestamps appear to use CLOCK_BOOTTIME")
return return
@ -405,6 +406,11 @@ function GestureDetector:probeClockSource(timev)
-- If we're here, the detection was inconclusive :/ -- If we're here, the detection was inconclusive :/
self.clock_id = -1 self.clock_id = -1
logger.info("GestureDetector:probeClockSource: Touch event clock source detection was inconclusive") logger.info("GestureDetector:probeClockSource: Touch event clock source detection was inconclusive")
-- Print all all the gory details in debug mode when this happens...
logger.dbg("Input frame :", timev:tonumber())
logger.dbg("CLOCK_REALTIME :", realtime:tonumber())
logger.dbg("CLOCK_MONOTONIC:", monotonic:tonumber())
logger.dbg("CLOCK_BOOTTIME :", boottime:tonumber())
end end
function GestureDetector:getClockSource() function GestureDetector:getClockSource()

@ -94,6 +94,7 @@ local linux_evdev_abs_code_map = {
[C.ABS_X] = "ABS_X", [C.ABS_X] = "ABS_X",
[C.ABS_Y] = "ABS_Y", [C.ABS_Y] = "ABS_Y",
[C.ABS_PRESSURE] = "ABS_PRESSURE", [C.ABS_PRESSURE] = "ABS_PRESSURE",
[C.ABS_DISTANCE] = "ABS_DISTANCE",
[C.ABS_MT_SLOT] = "ABS_MT_SLOT", [C.ABS_MT_SLOT] = "ABS_MT_SLOT",
[C.ABS_MT_TOUCH_MAJOR] = "ABS_MT_TOUCH_MAJOR", [C.ABS_MT_TOUCH_MAJOR] = "ABS_MT_TOUCH_MAJOR",
[C.ABS_MT_TOUCH_MINOR] = "ABS_MT_TOUCH_MINOR", [C.ABS_MT_TOUCH_MINOR] = "ABS_MT_TOUCH_MINOR",

@ -95,7 +95,8 @@ local KoboDahlia = Kobo:new{
hasFrontlight = yes, hasFrontlight = yes,
touch_phoenix_protocol = true, touch_phoenix_protocol = true,
-- There's no slot 0, the first finger gets assigned slot 1, and the second slot 2. -- There's no slot 0, the first finger gets assigned slot 1, and the second slot 2.
-- NOTE: Could be queried at runtime via EVIOCGABS on ABS_MT_TRACKING_ID (minimum field). -- NOTE: Could be queried at runtime via EVIOCGABS on C.ABS_MT_TRACKING_ID (minimum field).
-- Used to be handled via an adjustTouchAlyssum hook that just mangled ABS_MT_TRACKING_ID values.
main_finger_slot = 1, main_finger_slot = 1,
display_dpi = 265, display_dpi = 265,
-- the bezel covers the top 11 pixels: -- the bezel covers the top 11 pixels:
@ -184,7 +185,7 @@ local KoboAlyssum = Kobo:new{
model = "Kobo_alyssum", model = "Kobo_alyssum",
hasFrontlight = yes, hasFrontlight = yes,
touch_phoenix_protocol = true, touch_phoenix_protocol = true,
touch_alyssum_protocol = true, main_finger_slot = 1,
display_dpi = 300, display_dpi = 300,
} }
@ -192,7 +193,7 @@ local KoboAlyssum = Kobo:new{
local KoboPika = Kobo:new{ local KoboPika = Kobo:new{
model = "Kobo_pika", model = "Kobo_pika",
touch_phoenix_protocol = true, touch_phoenix_protocol = true,
touch_alyssum_protocol = true, main_finger_slot = 1,
} }
-- Kobo Clara HD: -- Kobo Clara HD:
@ -460,14 +461,6 @@ end
function Kobo:supportsScreensaver() return true end function Kobo:supportsScreensaver() return true end
local ABS_MT_TRACKING_ID = 57
local EV_ABS = 3
local adjustTouchAlyssum = function(self, ev)
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.
@ -487,10 +480,6 @@ function Kobo:initEventAdjustHooks()
) )
end end
if self.touch_alyssum_protocol then
self.input:registerEventAdjustHook(adjustTouchAlyssum)
end
if self.touch_snow_protocol then if self.touch_snow_protocol then
self.input.snow_protocol = true self.input.snow_protocol = true
end end

@ -3,6 +3,9 @@ local PluginShare = require("pluginshare")
local ffi = require("ffi") local ffi = require("ffi")
local logger = require("logger") local logger = require("logger")
local C = ffi.C
require("ffi/linux_input_h")
local function yes() return true end local function yes() return true end
local function no() return false end local function no() return false end
@ -21,19 +24,13 @@ local SonyPRSTUX = Generic:new{
-- sony's driver does not inform of ID, so we overwrite the TOUCH_MAJOR -- sony's driver does not inform of ID, so we overwrite the TOUCH_MAJOR
-- event to fake an ID event. a width == 0 means the finger was lift. -- event to fake an ID event. a width == 0 means the finger was lifted.
-- after all events are received, we reset the counter -- after all events are received, we reset the counter
local next_touch_id = 0 local next_touch_id = 0
local ABS_MT_TRACKING_ID = 57
local ABS_MT_TOUCH_MAJOR = 48
local EV_SYN = 0
local EV_ABS = 3
local SYN_REPORT = 0
local SYN_MT_REPORT = 2
local adjustTouchEvt = function(self, ev) local adjustTouchEvt = function(self, ev)
if ev.type == EV_ABS and ev.code == ABS_MT_TOUCH_MAJOR then if ev.type == C.EV_ABS and ev.code == C.ABS_MT_TOUCH_MAJOR then
ev.code = ABS_MT_TRACKING_ID ev.code = C.ABS_MT_TRACKING_ID
if ev.value ~= 0 then if ev.value ~= 0 then
ev.value = next_touch_id ev.value = next_touch_id
else else
@ -42,13 +39,13 @@ local adjustTouchEvt = function(self, ev)
next_touch_id = next_touch_id + 1 next_touch_id = next_touch_id + 1
logger.dbg('adjusted id: ', ev.value) logger.dbg("adjusted id: ", ev.value)
elseif ev.type == EV_SYN and ev.code == SYN_REPORT then elseif ev.type == C.EV_SYN and ev.code == C.SYN_REPORT then
next_touch_id = 0 next_touch_id = 0
logger.dbg('reset id: ', ev.code, ev.value) logger.dbg("reset id: ", ev.code, ev.value)
ev.code = SYN_MT_REPORT ev.code = C.SYN_MT_REPORT
elseif ev.type == EV_SYN and ev.code == SYN_MT_REPORT then elseif ev.type == C.EV_SYN and ev.code == C.SYN_MT_REPORT then
ev.code = SYN_REPORT ev.code = C.SYN_REPORT
end end
end end
@ -84,7 +81,7 @@ function SonyPRSTUX:setDateTime(year, month, day, hour, min, sec)
command = string.format("date -s '%d:%d'",hour, min) command = string.format("date -s '%d:%d'",hour, min)
end end
if os.execute(command) == 0 then if os.execute(command) == 0 then
os.execute('hwclock -u -w') os.execute("hwclock -u -w")
return true return true
else else
return false return false
@ -198,7 +195,7 @@ local SonyPRSTUX_T2 = SonyPRSTUX:new{
display_dpi = 166, display_dpi = 166,
} }
logger.info('SoftwareVersion: ', SonyPRSTUX:getSoftwareVersion()) logger.info("SoftwareVersion: ", SonyPRSTUX:getSoftwareVersion())
local codename = SonyPRSTUX:getDeviceModel() local codename = SonyPRSTUX:getDeviceModel()

@ -14,6 +14,7 @@ A simple module to module to compare and do arithmetic with time values.
local ffi = require("ffi") local ffi = require("ffi")
require("ffi/posix_h") require("ffi/posix_h")
local logger = require("logger")
local util = require("ffi/util") local util = require("ffi/util")
local C = ffi.C local C = ffi.C
@ -35,11 +36,13 @@ if ffi.os == "Linux" then
PREFERRED_MONOTONIC_CLOCKID = C.CLOCK_MONOTONIC_COARSE PREFERRED_MONOTONIC_CLOCKID = C.CLOCK_MONOTONIC_COARSE
end end
end end
logger.dbg("TimeVal: Preferred MONOTONIC clock source is", PREFERRED_MONOTONIC_CLOCKID == C.CLOCK_MONOTONIC_COARSE and "CLOCK_MONOTONIC_COARSE" or "CLOCK_MONOTONIC")
if C.clock_getres(C.CLOCK_REALTIME_COARSE, probe_ts) == 0 then if C.clock_getres(C.CLOCK_REALTIME_COARSE, probe_ts) == 0 then
if probe_ts.tv_sec == 0 and probe_ts.tv_nsec <= 1000000 then if probe_ts.tv_sec == 0 and probe_ts.tv_nsec <= 1000000 then
PREFERRED_REALTIME_CLOCKID = C.CLOCK_REALTIME_COARSE PREFERRED_REALTIME_CLOCKID = C.CLOCK_REALTIME_COARSE
end end
end end
logger.dbg("TimeVal: Preferred REALTIME clock source is", PREFERRED_REALTIME_CLOCKID == C.CLOCK_REALTIME_COARSE and "CLOCK_REALTIME_COARSE" or "CLOCK_REALTIME")
probe_ts = nil --luacheck: ignore probe_ts = nil --luacheck: ignore
end end

@ -3,6 +3,7 @@ describe("device module", function()
local mock_fb, mock_input local mock_fb, mock_input
local iopen = io.open local iopen = io.open
local osgetenv = os.getenv local osgetenv = os.getenv
local ffi, C
setup(function() setup(function()
mock_fb = { mock_fb = {
@ -20,6 +21,9 @@ describe("device module", function()
} }
require("commonrequire") require("commonrequire")
package.unloadAll() package.unloadAll()
ffi = require("ffi")
C = ffi.C
require("ffi/linux_input_h")
require("document/canvascontext"):init(require("device")) require("document/canvascontext"):init(require("device"))
end) end)
@ -86,19 +90,16 @@ describe("device module", function()
G_reader_settings:saveSetting("kobo_touch_switch_xy", true) G_reader_settings:saveSetting("kobo_touch_switch_xy", true)
kobo_dev:touchScreenProbe() kobo_dev:touchScreenProbe()
local x, y = Screen:getWidth()-5, 10 local x, y = Screen:getWidth()-5, 10
local EV_ABS = 3
local ABS_X = 00
local ABS_Y = 01
-- mirror x, then switch_xy -- mirror x, then switch_xy
local ev_x = { local ev_x = {
type = EV_ABS, type = C.EV_ABS,
code = ABS_X, code = C.ABS_X,
value = y, value = y,
time = TimeVal:realtime(), time = TimeVal:realtime(),
} }
local ev_y = { local ev_y = {
type = EV_ABS, type = C.EV_ABS,
code = ABS_Y, code = C.ABS_Y,
value = Screen:getWidth()-x, value = Screen:getWidth()-x,
time = TimeVal:realtime(), time = TimeVal:realtime(),
} }
@ -106,9 +107,9 @@ describe("device module", function()
kobo_dev.input:eventAdjustHook(ev_x) kobo_dev.input:eventAdjustHook(ev_x)
kobo_dev.input:eventAdjustHook(ev_y) kobo_dev.input:eventAdjustHook(ev_y)
assert.is.same(x, ev_y.value) assert.is.same(x, ev_y.value)
assert.is.same(ABS_X, ev_y.code) assert.is.same(C.ABS_X, ev_y.code)
assert.is.same(y, ev_x.value) assert.is.same(y, ev_x.value)
assert.is.same(ABS_Y, ev_x.code) assert.is.same(C.ABS_Y, ev_x.code)
-- reset eventAdjustHook -- reset eventAdjustHook
kobo_dev.input.eventAdjustHook = function() end kobo_dev.input.eventAdjustHook = function() end
@ -137,18 +138,15 @@ describe("device module", function()
assert.truthy(kobo_dev:needsTouchScreenProbe()) assert.truthy(kobo_dev:needsTouchScreenProbe())
kobo_dev:touchScreenProbe() kobo_dev:touchScreenProbe()
local x, y = Screen:getWidth()-5, 10 local x, y = Screen:getWidth()-5, 10
local EV_ABS = 3
local ABS_X = 00
local ABS_Y = 01
local ev_x = { local ev_x = {
type = EV_ABS, type = C.EV_ABS,
code = ABS_X, code = C.ABS_X,
value = y, value = y,
time = {sec = 1000} time = {sec = 1000}
} }
local ev_y = { local ev_y = {
type = EV_ABS, type = C.EV_ABS,
code = ABS_Y, code = C.ABS_Y,
value = Screen:getWidth()-x, value = Screen:getWidth()-x,
time = {sec = 1000} time = {sec = 1000}
} }
@ -156,9 +154,9 @@ describe("device module", function()
kobo_dev.input:eventAdjustHook(ev_x) kobo_dev.input:eventAdjustHook(ev_x)
kobo_dev.input:eventAdjustHook(ev_y) kobo_dev.input:eventAdjustHook(ev_y)
assert.is.same(x, ev_y.value) assert.is.same(x, ev_y.value)
assert.is.same(ABS_X, ev_y.code) assert.is.same(C.ABS_X, ev_y.code)
assert.is.same(y, ev_x.value) assert.is.same(y, ev_x.value)
assert.is.same(ABS_Y, ev_x.code) assert.is.same(C.ABS_Y, ev_x.code)
-- reset eventAdjustHook -- reset eventAdjustHook
kobo_dev.input.eventAdjustHook = function() end kobo_dev.input.eventAdjustHook = function() end
@ -275,12 +273,12 @@ describe("device module", function()
stub(mock_ffi_input, "waitForEvent") stub(mock_ffi_input, "waitForEvent")
mock_ffi_input.waitForEvent.returns(true, { mock_ffi_input.waitForEvent.returns(true, {
{ {
type = 3, type = C.EV_ABS,
time = { time = {
usec = 450565, usec = 450565,
sec = 1471081881 sec = 1471081881
}, },
code = 24, code = 24, -- C.ABS_PRESSURE -> ABS_OASIS_ORIENTATION
value = 16 value = 16
} }
}) })

@ -1,7 +1,11 @@
describe("input module", function() describe("input module", function()
local Input local Input
local ffi, C
setup(function() setup(function()
require("commonrequire") require("commonrequire")
ffi = require("ffi")
C = ffi.C
require("ffi/linux_input_h")
Input = require("device/input") Input = require("device/input")
end) end)
@ -40,36 +44,36 @@ Event: time 1510346969.076908, -------------- SYN_REPORT ------------
it("should set cur_slot correctly", function() it("should set cur_slot correctly", function()
local ev local ev
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 57, code = C.ABS_MT_TRACKING_ID,
value = 1, value = 1,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(1, Input.cur_slot) assert.is_equal(1, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 48, code = C.ABS_MT_TOUCH_MAJOR,
value = 1, value = 1,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(1, Input.cur_slot) assert.is_equal(1, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 50, code = C.ABS_MT_WIDTH_MAJOR,
value = 1, value = 1,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(1, Input.cur_slot) assert.is_equal(1, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 53, code = C.ABS_MT_POSITION_X,
value = 1012, value = 1012,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(1, Input.cur_slot) assert.is_equal(1, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 54, code = C.ABS_MT_POSITION_Y,
value = 914, value = 914,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
@ -79,8 +83,8 @@ Event: time 1510346969.076908, -------------- SYN_REPORT ------------
-- depends on gesture_detector -- depends on gesture_detector
--[[ --[[
ev = { ev = {
type = 0, type = C.EV_SYN,
code = 0, code = C.SYN_REPORT,
value = 0, value = 0,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
@ -89,36 +93,36 @@ Event: time 1510346969.076908, -------------- SYN_REPORT ------------
-- this value=2 stuff doesn't happen IRL, just testing logic -- this value=2 stuff doesn't happen IRL, just testing logic
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 57, code = C.ABS_MT_TRACKING_ID,
value = 2, value = 2,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(2, Input.cur_slot) assert.is_equal(2, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 48, code = C.ABS_MT_TOUCH_MAJOR,
value = 2, value = 2,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(2, Input.cur_slot) assert.is_equal(2, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 50, code = C.ABS_MT_WIDTH_MAJOR,
value = 2, value = 2,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(2, Input.cur_slot) assert.is_equal(2, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 53, code = C.ABS_MT_POSITION_X,
value = 1012, value = 1012,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)
assert.is_equal(2, Input.cur_slot) assert.is_equal(2, Input.cur_slot)
ev = { ev = {
type = 3, type = C.EV_ABS,
code = 54, code = C.ABS_MT_POSITION_Y,
value = 914, value = 914,
} }
Input:handleTouchEvPhoenix(ev) Input:handleTouchEvPhoenix(ev)

Loading…
Cancel
Save