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.
This commit is contained in:
Qingping Hou
2012-12-10 20:58:16 -05:00
parent e80987c430
commit c8d43cd33c
3 changed files with 37 additions and 14 deletions

View File

@@ -274,4 +274,8 @@ function math.roundAwayFromZero(num)
end
end
function math.round(num)
return math.floor(num + 0.5)
end

View File

@@ -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")

View File

@@ -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