2
0
mirror of https://github.com/koreader/koreader synced 2024-11-11 19:11:14 +00:00

Multitouch for Kobo Aura

Signed-off-by: Markismus <zulde.zuldemans@gmail.com>
This commit is contained in:
Markismus 2013-12-04 13:02:19 +01:00
parent ecd8949e85
commit b26b0729b9

View File

@ -35,6 +35,12 @@ local ABS_MT_POSITION_Y = 54
local ABS_MT_TRACKING_ID = 57
local ABS_MT_PRESSURE = 58
local dev_mod = Device:getModel()
local Phoenix = false
if dev_mod == 'Kobo_phoenix' then Phoenix = true end
print(_("Phoenix "))
print(Phoenix)
--[[
an interface for key presses
]]
@ -278,7 +284,7 @@ function Input:init()
-- SDL key codes
self.event_map = self.sdl_event_map
else
local dev_mod = Device:getModel()
--local dev_mod = Device:getModel()
if not Device:isKobo() then
input.open("fake_events")
end
@ -318,6 +324,12 @@ function Input:init()
Device:setTouchInputDev("/dev/input/event1")
input.open("/dev/input/event0") -- Light button and sleep slider
print(_("Auto-detected Kobo"))
print(_("Device model "..dev_mod))
print(_("firmware revision "..firm_rev ))
print(_("Screen Height "..Screen:getHeight() ))
print(_("Screen Width "..Screen:getWidth() ))
print(_("Screen DPI programmed "..Screen:getDPI() ))
self:adjustKoboEventMap()
if dev_mod ~= 'Kobo_trilogy' then
function Input:eventAdjustHook(ev)
@ -532,6 +544,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)
if ev.type == EV_SYN then
if ev.code == SYN_REPORT then
@ -580,6 +593,123 @@ function Input:handleTouchEv(ev)
end
end
end
--]]
function Input:handleTouchEv(ev)
-- local dev_mod = Device:getModel()
if Phoenix then
-- 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 ~= 48 and ev.code ~= 50 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
-- Orignal handleTouchEV for all others
else 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 then
if #self.MTSlots == 0 then
table.insert(self.MTSlots, self:getMtSlot(self.cur_slot))
end
if ev.code == ABS_MT_SLOT then
if self.cur_slot ~= ev.value then
table.insert(self.MTSlots, self:getMtSlot(ev.value))
end
self.cur_slot = ev.value
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
self:setCurrentMtSlot("id", 1)
self:confirmAbsxy()
else
self:cleanAbsxy()
self:setCurrentMtSlot("id", -1)
end
end
end
end
end
function Input:waitEvent(timeout_us, timeout_s)
-- wrapper for input.waitForEvents that will retry for some cases