mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #386 from Markismus/MultitouchKoboAura
Multitouch kobo aura
This commit is contained in:
@@ -50,9 +50,9 @@ local GestureDetector = {
|
||||
HOLD_INTERVAL = 1000 * 1000,
|
||||
SWIPE_INTERVAL = 900 * 1000,
|
||||
-- distance parameters
|
||||
DOUBLE_TAP_DISTANCE = 50,
|
||||
TWO_FINGER_TAP_REGION = 20,
|
||||
PAN_THRESHOLD = 50,
|
||||
DOUBLE_TAP_DISTANCE = 50 * Screen:getDPI() / 167,
|
||||
TWO_FINGER_TAP_REGION = 20 * Screen:getDPI() / 167,
|
||||
PAN_THRESHOLD = 50 * Screen:getDPI() / 167,
|
||||
-- pinch/spread direction table
|
||||
DIRECTION_TABLE = {
|
||||
east = "horizontal",
|
||||
|
||||
@@ -30,6 +30,9 @@ local ABS_PRESSURE = 24
|
||||
|
||||
-- For multi-touch events (ABS.code).
|
||||
local ABS_MT_SLOT = 47
|
||||
local ABS_MT_TOUCH_MAJOR = 48
|
||||
local ABS_MT_WIDTH_MAJOR = 50
|
||||
|
||||
local ABS_MT_POSITION_X = 53
|
||||
local ABS_MT_POSITION_Y = 54
|
||||
local ABS_MT_TRACKING_ID = 57
|
||||
@@ -385,6 +388,16 @@ function Input:init()
|
||||
os.exit(-1)
|
||||
end
|
||||
end
|
||||
|
||||
if Device:getModel() ~= 'Kobo_phoenix' then
|
||||
function Input:handleTouchEv(ev)
|
||||
return Input:handleTypeBTouchEv(ev)
|
||||
end
|
||||
else
|
||||
function Input:handleTouchEv(ev)
|
||||
return Input:handlePhoenixTouchEv(ev)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
@@ -532,7 +545,7 @@ the full state of each initiated contact has to reside in the receiving
|
||||
end. Upon receiving an MT event, one simply updates the appropriate
|
||||
attribute of the current slot.
|
||||
--]]
|
||||
function Input:handleTouchEv(ev)
|
||||
function Input:handleTypeBTouchEv(ev)
|
||||
if ev.type == EV_SYN then
|
||||
if ev.code == SYN_REPORT then
|
||||
for _, MTSlot in pairs(self.MTSlots) do
|
||||
@@ -581,6 +594,73 @@ function Input:handleTouchEv(ev)
|
||||
end
|
||||
end
|
||||
|
||||
function Input:handlePhoenixTouchEv(ev)
|
||||
-- Hack on handleTouchEV for the Kobo Aura
|
||||
if ev.type == EV_SYN then
|
||||
if ev.code == SYN_REPORT then
|
||||
for _, MTSlot in pairs(self.MTSlots) do
|
||||
self:setMtSlot(MTSlot.slot, "timev", TimeVal:new(ev.time))
|
||||
end
|
||||
-- feed ev in all slots to state machine
|
||||
local touch_ges = GestureDetector:feedEvent(self.MTSlots)
|
||||
self.MTSlots = {}
|
||||
if touch_ges then
|
||||
return Event:new("Gesture",
|
||||
GestureDetector:adjustGesCoordinate(touch_ges)
|
||||
)
|
||||
end
|
||||
end
|
||||
elseif ev.type == EV_ABS and ev.code ~= ABS_MT_TOUCH_MAJOR and ev.code ~= ABS_MT_WIDTH_MAJOR then
|
||||
if #self.MTSlots == 0 then
|
||||
table.insert(self.MTSlots, self:getMtSlot(self.cur_slot))
|
||||
-- I have to add id's without events for the AURA.
|
||||
self:setMtSlot(self.cur_slot, "id", 0)
|
||||
end
|
||||
-- I have changed ABS_MT_SLOT to ABS_MT_TRACKING_ID
|
||||
if ev.code == ABS_MT_TRACKING_ID then
|
||||
if self.cur_slot ~= ev.value then
|
||||
table.insert(self.MTSlots, self:getMtSlot(ev.value))
|
||||
-- I have to add id's without events for the AURA. Since there are only two
|
||||
-- ID's 0 and 1 and it's not 0,
|
||||
self:setMtSlot(ev.value, "id", 1)
|
||||
end
|
||||
self.cur_slot = ev.value
|
||||
-- ABS_MT_TRACKING_ID is no longer used for assigning id's.
|
||||
-- elseif ev.code == ABS_MT_TRACKING_ID then
|
||||
-- self:setCurrentMtSlot("id", ev.value)
|
||||
elseif ev.code == ABS_MT_POSITION_X then
|
||||
self:setCurrentMtSlot("x", ev.value)
|
||||
elseif ev.code == ABS_MT_POSITION_Y then
|
||||
self:setCurrentMtSlot("y", ev.value)
|
||||
|
||||
-- code to emulate mt protocol on kobos
|
||||
-- we "confirm" abs_x, abs_y only when pressure ~= 0
|
||||
---[[
|
||||
elseif ev.code == ABS_X then
|
||||
self:setCurrentMtSlot("abs_x", ev.value)
|
||||
elseif ev.code == ABS_Y then
|
||||
self:setCurrentMtSlot("abs_y", ev.value)
|
||||
--]]
|
||||
elseif ev.code == ABS_PRESSURE then
|
||||
if ev.value ~= 0 then
|
||||
-- Single tap events only use slot 0.
|
||||
self:setMtSlot(0, "id", 1)
|
||||
--Unnecessary for Aura
|
||||
--self:confirmAbsxy()
|
||||
else
|
||||
--Unnecessary for Aura
|
||||
--self:cleanAbsxy()
|
||||
-- Pressure 0 events only invalidate slot 0.
|
||||
self:setMtSlot(0, "id", -1)
|
||||
-- If there are 2 slots active, invalidates slot 2.
|
||||
if #self.MTSlots == 2 then
|
||||
self:setMtSlot(1, "id", -1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Input:waitEvent(timeout_us, timeout_s)
|
||||
-- wrapper for input.waitForEvents that will retry for some cases
|
||||
local ok, ev
|
||||
|
||||
Reference in New Issue
Block a user