From b26b0729b900f4e5814015632ef1b83c346ccda0 Mon Sep 17 00:00:00 2001 From: Markismus Date: Wed, 4 Dec 2013 13:02:19 +0100 Subject: [PATCH 1/5] Multitouch for Kobo Aura Signed-off-by: Markismus --- frontend/ui/input.lua | 132 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index f1dbf97b4..aa434ab6d 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -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 From acf152563063089872e9ef0f12fcb74319f41ae6 Mon Sep 17 00:00:00 2001 From: Markismus Date: Wed, 4 Dec 2013 13:13:46 +0100 Subject: [PATCH 2/5] Signed-off-by: Markismus --- frontend/ui/gesturedetector.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/ui/gesturedetector.lua b/frontend/ui/gesturedetector.lua index cfe0e8b5a..3c9f2df10 100644 --- a/frontend/ui/gesturedetector.lua +++ b/frontend/ui/gesturedetector.lua @@ -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", From 6f5c0d86cd19ddd3c85a4c7f169098b4326666a3 Mon Sep 17 00:00:00 2001 From: Markismus Date: Wed, 4 Dec 2013 15:57:03 +0100 Subject: [PATCH 3/5] Signed-off-by: Markismus --- frontend/ui/input.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index aa434ab6d..9e4494277 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -38,8 +38,6 @@ 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 From 37b6f5e041c1576b63e77623b945ab47b1f79d36 Mon Sep 17 00:00:00 2001 From: Markismus Date: Wed, 4 Dec 2013 16:17:53 +0100 Subject: [PATCH 4/5] Signed-off-by: Markismus --- frontend/ui/input.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index 9e4494277..69931f63d 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -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 @@ -322,11 +325,6 @@ 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 @@ -610,7 +608,7 @@ function Input:handleTouchEv(ev) ) end end - elseif ev.type == EV_ABS and ev.code ~= 48 and ev.code ~= 50 then + 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. From 64f77c42104ff1faa9e25f58c0a9588d840def2d Mon Sep 17 00:00:00 2001 From: chrox Date: Wed, 4 Dec 2013 23:22:49 +0800 Subject: [PATCH 5/5] refactoring handleTouchEv --- frontend/ui/input.lua | 184 ++++++++++++++++-------------------------- 1 file changed, 69 insertions(+), 115 deletions(-) diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index 69931f63d..691529b9e 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -38,10 +38,6 @@ 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 - --[[ an interface for key presses ]] @@ -285,7 +281,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 @@ -325,7 +321,6 @@ function Input:init() Device:setTouchInputDev("/dev/input/event1") input.open("/dev/input/event0") -- Light button and sleep slider print(_("Auto-detected Kobo")) - self:adjustKoboEventMap() if dev_mod ~= 'Kobo_trilogy' then function Input:eventAdjustHook(ev) @@ -393,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 --[[ @@ -540,8 +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 @@ -589,122 +593,72 @@ 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 ~= 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 - ---[[ +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 + 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 - -- 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 end function Input:waitEvent(timeout_us, timeout_s)