From c8d43cd33c4408c26693058490690bc65419010c Mon Sep 17 00:00:00 2001 From: Qingping Hou Date: Mon, 10 Dec 2012 20:58:16 -0500 Subject: [PATCH] add Input:eventAdjustHook(ev) so we can adjust input event for KT on the fly. the touch input event coordinates in KT ranges from 0-4095 instead of the screen size. --- frontend/ui/geometry.lua | 4 ++++ frontend/ui/gesturedetector.lua | 14 -------------- frontend/ui/inputevent.lua | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/frontend/ui/geometry.lua b/frontend/ui/geometry.lua index b50a07d85..3eefdbd75 100644 --- a/frontend/ui/geometry.lua +++ b/frontend/ui/geometry.lua @@ -274,4 +274,8 @@ function math.roundAwayFromZero(num) end end +function math.round(num) + return math.floor(num + 0.5) +end + diff --git a/frontend/ui/gesturedetector.lua b/frontend/ui/gesturedetector.lua index 9d1fc01bb..0c7f4d902 100644 --- a/frontend/ui/gesturedetector.lua +++ b/frontend/ui/gesturedetector.lua @@ -1,18 +1,5 @@ require "ui/geometry" --- Synchronization events (SYN.code). -SYN_REPORT = 0 -SYN_CONFIG = 1 -SYN_MT_REPORT = 2 - --- For multi-touch events (ABS.code). -ABS_MT_SLOT = 47 -ABS_MT_POSITION_X = 53 -ABS_MT_POSITION_Y = 54 -ABS_MT_TRACKING_ID = 57 -ABS_MT_PRESSURE = 58 - - GestureRange = { ges = nil, range = nil, @@ -207,7 +194,6 @@ function GestureDetector:tapState(ev) sec = 0, usec = self.HOLD_INTERVAL } Input:setTimeout(function() - print("hold timer", self.state == self.tapState) if self.state == self.tapState then -- timer set in tapState, so we switch to hold return self:switchState("holdState") diff --git a/frontend/ui/inputevent.lua b/frontend/ui/inputevent.lua index a7b52f590..8866cd0fb 100644 --- a/frontend/ui/inputevent.lua +++ b/frontend/ui/inputevent.lua @@ -14,6 +14,19 @@ EVENT_VALUE_KEY_PRESS = 1 EVENT_VALUE_KEY_REPEAT = 2 EVENT_VALUE_KEY_RELEASE = 0 +-- Synchronization events (SYN.code). +SYN_REPORT = 0 +SYN_CONFIG = 1 +SYN_MT_REPORT = 2 + +-- For multi-touch events (ABS.code). +ABS_MT_SLOT = 47 +ABS_MT_POSITION_X = 53 +ABS_MT_POSITION_Y = 54 +ABS_MT_TRACKING_ID = 57 +ABS_MT_PRESSURE = 58 + + --[[ an interface for key presses @@ -253,6 +266,16 @@ function Input:init() elseif dev_mod == "KindleTouch" then input.open("/dev/input/event2") -- Home button input.open("/dev/input/event3") -- touchscreen + -- update event hook + function Input:eventAdjustHook(ev) + if ev.type == EV_ABS then + if ev.code == ABS_MT_POSITION_X then + ev.code = math.round(ev.code * (600/4095)) + elseif ev.code == ABS_MT_POSITION_Y then + ev.code = math.round(ev.code * (800/4095)) + end + end + end print("Auto-detected Kindle Touch") elseif dev_mod == "Kindle4" then print("Auto-detected Kindle 4") @@ -271,6 +294,15 @@ function Input:init() end end +--[[ +different device models shoudl overload this method if +necessary to make event compatible to KPV. +--]] +function Input:eventAdjustHook(ev) + -- do nothing by default + return ev +end + function Input:adjustKindle4EventMap() self.event_map[193] = "LPgBack" self.event_map[104] = "LPgFwd" @@ -342,6 +374,7 @@ function Input:waitEvent(timeout_us, timeout_s) end end if ok and ev then + ev = self:eventAdjustHook(ev) if ev.type == EV_KEY then local keycode = self.event_map[ev.code] if not keycode then