View Single Post
Old 02-25-2018, 06:35 PM   #47
cola
Junior Member
cola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toyscola shares his or her toys
 
Posts: 5
Karma: 5814
Join Date: Feb 2018
Device: Kobo Aura H2O2
Okay, I got it to work I think. The code seems to be written on the premise that the machine is going to tell you if a finger has been taken off. That doesn't seem to be true for the H2O2. It has event logs like this for single touch events:

Spoiler:
02/25/18-17:45:49 DEBUG input event => type: 3, code: 57(nil), value: 0, time: 568.374986
02/25/18-17:45:49 DEBUG input event => type: 3, code: 59(SleepCover), value: 0, time: 568.374989
02/25/18-17:45:49 DEBUG input event => type: 3, code: 53(nil), value: 739, time: 568.374992
02/25/18-17:45:49 DEBUG input event => type: 3, code: 54(nil), value: 534, time: 568.374995
02/25/18-17:45:49 DEBUG input event => type: 3, code: 58(nil), value: 22, time: 568.374996
02/25/18-17:45:49 DEBUG input event => type: 3, code: 48(nil), value: 0, time: 568.375000
02/25/18-17:45:49 DEBUG input event => type: 3, code: 49(nil), value: 0, time: 568.375001
02/25/18-17:45:49 DEBUG input event => type: 3, code: 52(nil), value: 0, time: 568.375002
02/25/18-17:45:49 DEBUG input event => type: 0, code: 2(nil), value: 0, time: 568.375004
02/25/18-17:45:49 DEBUG input event => type: 0, code: 0(nil), value: 0, time: 568.375038

But when a finger leaves the screen, it doesn't send anything with an id of -1, it just stops reporting that finger. If there are no fingers on the screen, it sends one SYN_REPORT message:

02/25/18-17:45:49 DEBUG input event => type: 0, code: 0(nil), value: 0, time: 568.579338

by itself without any ABS events.

So, I changed Input:handleTouchEv so that it always passed every slot to feedEvent, and set all the ids to -1 after it passed them. Also, I turned off the thing that subtracts one from every id in adjustTouchAlyssum. That seems to work for single touch. The function now looks like this:

Spoiler:
Code:
function Input:handleTouchEv(ev)
    if 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
    elseif 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
            self.MTSlots = {}
            for _, slot in pairs(self.ev_slots) do
                table.insert(self.MTSlots, slot)
            end
            -- feed ev in all slots to state machine
            local touch_ges = self.gesture_detector:feedEvent(self.MTSlots)
            self.MTSlots = {}
            for _, slot in pairs(self.ev_slots) do
                slot.id = -1
            end
            if touch_ges then
                self:gestureAdjustHook(touch_ges)
                return Event:new("Gesture",
                    self.gesture_detector:adjustGesCoordinate(touch_ges)
                )
            end
        end
    end
end
in input.lua and
Code:
local adjustTouchAlyssum = function(self, ev)
    ev.time = TimeVal:now()
end
in device.lua (removing the if part)

I also added touch_mirrored_x=false, to the device section.

This makes touch work, although I seem to have broken the hold gesture.

By the way, this might explain why the two-finger procedure worked:
Spoiler:
The first tap had id 0 - 1 = -1, the second one had id 1 - 1 = 0, and when you took your finger off, all that was left was a tap with id "-1", which was what the machine was looking for to tell it that your finger had left the screen! And I guess it looked at the coordinates of that event to tell it where the tap had been, which is why the first finger is the place where the tap registered. That also explains why dragging or holding followed the second finger.

Last edited by cola; 02-25-2018 at 06:51 PM. Reason: come to think of it, this probably explains why the thing with two fingers registered as a one-finger tap
cola is offline   Reply With Quote