User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Touch device producing strange event sequencies

Sun Sep 20, 2015 8:39 pm

Unless you have at least some understanding of this page http://www.mjmwired.net/kernel/Document ... otocol.txt stop reading NOW !

In an attempt to get a good understanding of the multitouch events that come from the /dev/inupt/eventsX device I've written a Finite State Machine (FSM) to track the messages and the state of each of the tracking slots.
However my FSM keeps telling me it is receiving unexpected events for the state it is in.

Most of the time I'm seeing sequences like this:

Tracking ID assigned to slot.
X coordinate set for slot
Y coordinate set for slot
SYN (1)
X coordinate set for slot
Y coordinate set for slot
Tracking ID set to -1 for the slot.
SYN (2)

SYN (1) can be used to create a "finger on" event at the given coordinates.
SYN (2) can be used to create a "finger off" event at the given coordinates.


But sometimes I see sequences like this :

Tracking ID assigned to slot.
X coordinate set for slot
Tracking ID set to -1 for the slot.
SYN

Since a pair of X and Y coordinates have not been received for the slot neither a "finger on" nor "finger off" event can be generated even though a touch has occurred.

Has anyone else seen things like this ? As far as I can tell I'm not dropping any events.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1442
Joined: Sat Sep 10, 2011 11:43 am

Re: Touch device producing strange event sequencies

Mon Sep 21, 2015 1:21 pm

That just means that the Y coordinate has not changed

For the event system the SYN is just a syncronisation event (i.e. an event saying that everything has now been updated... If you are currently at x=4, y=5 and the see a move to x=5 y=7 then it's perfectly valid to send

X coordinate set for slot
SYN
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Mon Sep 21, 2015 1:35 pm

Thanks for the reply :-)
gsh wrote:That just means that the Y coordinate has not changed
For the event system the SYN is just a syncronisation event (i.e. an event saying that everything has now been updated... If you are currently at x=4, y=5 and the see a move to x=5 y=7 then it's perfectly valid to send
X coordinate set for slot
SYN
Yes, I see that happening lots of times and it is easy to cope with in my FSM.

Unfortunatley it's not the problem. What I see is situations where no Y value has been received for the slot since the tracking ID was assigned! I've seen it happen with a touch quite distant to the previous touch for the same slot (i.e. the one coordinate that is set is very different to the previous last set value). I wonder if this is just a very short tap and the hardware only has time to measure one axis before the finger is lifted ?

I can make my FSM ignore these sequencies, but it seems like I'll have to handle lots of message messages in unexpected states, which makes the state meaningless on the face of it and should not be necessary.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1442
Joined: Sat Sep 10, 2011 11:43 am

Re: Touch device producing strange event sequencies

Mon Sep 21, 2015 1:51 pm

Can you post the output of evtest for such an event?

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Mon Sep 21, 2015 3:04 pm

gsh wrote:Can you post the output of evtest for such an event?

Gordon
Not easily, but I can give you the debug output from my FSM which is currently programmed to stop the program when it detects these sequences. But It will be tomorrow evening before I get a chance to
capture some output as I'm out demoing PIs this evening :-)

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Wed Sep 23, 2015 7:27 pm

I forgot I was out on Tuesday evening as well !
Below is an extract of the output from my FSM just before it detected the odd sequence...

Code: Select all

ABS_MT_SLOT  0
	State = SYNED Event = OTHER_SLOT data = 0
deselSlot called for slot 1
	State = SYNED Event = SLOT data = 0
ignore called for slot 0
EV_ABS ABS_MT_POSITION_Y 132 slot 0
	State = SYNED Event = POSITION_Y data = 132
updateY called for slot 0
EV_SYN
	State = UPDATED Event = SYN data = 0
doNthSYN called for slot 0
ABS_MT_SLOT  2
setSlot called for slot 2
EV_ABS ABS_MT_TRACKING_ID 70 SLOT 2
	State = SLOT_SET Event = TRACKING_ON data = 70
setTracking called for slot 2
EV_ABS ABS_MT_POSITION_Y 215 slot 2
	State = ID_SET Event = POSITION_Y data = 215
setY called for slot 2
EV_SYN

The last few messages received were
ABS_MT_SLOT 2
EV_ABS ABS_MT_TRACKING_ID 70
EV_ABS ABS_MT_POSITION_Y 215
EV_SYN

If you want the raw byte stream from the device I can add that to the output.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Thu Sep 24, 2015 8:31 pm

I've put the state transition diagram for my FSM on my web site in http://www.peteronion.org.uk/MultiTouch ... chSTD2.odg
SYN(1st) generates the equivalent of a "button pressed at X,Y" mouse event.
SYN(Nth) generates the equivalent of mouse moved events.
SYN(Last) generates the equivalent of "button released" mouse events.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1442
Joined: Sat Sep 10, 2011 11:43 am

Re: Touch device producing strange event sequencies

Thu Sep 24, 2015 8:35 pm

Can you just post the events from evtest? It matches 1:1 to the code and is much easier to diagnose

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Thu Sep 24, 2015 8:43 pm

gsh wrote:Can you just post the events from evtest? It matches 1:1 to the code and is much easier to diagnose
Gordon
Not easily because I don't have anyway to find the erroneous sequences without writing code to parse the evtest output to drive my FSM.
The protocol message names and symbols are included in the output I posted.
PeterO

PS: I can make my output look more like evtest output, would that do ?

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1442
Joined: Sat Sep 10, 2011 11:43 am

Re: Touch device producing strange event sequencies

Fri Sep 25, 2015 8:06 am

As long as it matches the correct event names from the linux input event list then it would be fine... You should be able to run both at the same time and then stop the evtest when your FSM notices the problem

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Fri Sep 25, 2015 8:49 am

gsh wrote:As long as it matches the correct event names from the linux input event list then it would be fine... You should be able to run both at the same time and then stop the evtest when your FSM notices the problem
Gordon
I tried that once, but it doesn't work very well. The faults are quite rare so you need to be moving multiple fingers about for a while before it "trips" and my reaction time means that a few screens full of evtest output has gone past after the
actual problem. Manually searching back was very tedious and error prone.

I'll modify my program's output to match with evtest's output as close as I can.

PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1442
Joined: Sat Sep 10, 2011 11:43 am

Re: Touch device producing strange event sequencies

Fri Sep 25, 2015 3:57 pm

how about

my_program_which_exits_on_error; killall evtest &

evtest /dev/input/event2 > somefile.txt


If you mod your code to exit when it sees the error it will execute the killall when it exits meaning the offending problem must be near the end of the output of evtest

Gordon
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Fri Sep 25, 2015 4:00 pm

I'll shall give that a try 8-)
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

User avatar
PeterO
Posts: 5068
Joined: Sun Jul 22, 2012 4:14 pm

Re: Touch device producing strange event sequencies

Fri Sep 25, 2015 6:51 pm

It worked perfectly :-)

Code: Select all

Event: time 1443206651.637721, -------------- SYN_REPORT ------------
Event: time 1443206651.667721, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1
Event: time 1443206651.667721, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 435
Event: time 1443206651.667721, type 3 (EV_ABS), code 0 (ABS_X), value 435
Event: time 1443206651.667721, -------------- SYN_REPORT ------------
Event: time 1443206651.697717, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1                   <<<<<<<<<< Slot 1 tracking stopped
Event: time 1443206651.697717, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 1443206651.697717, -------------- SYN_REPORT ------------
Event: time 1443206651.757714, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0
Event: time 1443206651.757714, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 1172
Event: time 1443206651.757714, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 742
Event: time 1443206651.757714, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 419
Event: time 1443206651.757714, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 1
Event: time 1443206651.757714, type 3 (EV_ABS), code 0 (ABS_X), value 742
Event: time 1443206651.757714, type 3 (EV_ABS), code 1 (ABS_Y), value 419
Event: time 1443206651.757714, -------------- SYN_REPORT ------------
Event: time 1443206651.787759, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 741
Event: time 1443206651.787759, type 3 (EV_ABS), code 54 (ABS_MT_POSITION_Y), value 418
Event: time 1443206651.787759, type 3 (EV_ABS), code 0 (ABS_X), value 741
Event: time 1443206651.787759, type 3 (EV_ABS), code 1 (ABS_Y), value 418
Event: time 1443206651.787759, -------------- SYN_REPORT ------------
Event: time 1443206651.817721, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1                   <<<<<<<<<  Slot 1 tracking started
Event: time 1443206651.817721, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value 1173
Event: time 1443206651.817721, type 3 (EV_ABS), code 53 (ABS_MT_POSITION_X), value 442
Event: time 1443206651.817721, -------------- SYN_REPORT ------------                       <<<<<<<<<<<<<<  SYN with only X position set 
Event: time 1443206651.907711, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 0
Event: time 1443206651.907711, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1443206651.907711, type 3 (EV_ABS), code 47 (ABS_MT_SLOT), value 1
Event: time 1443206651.907711, type 3 (EV_ABS), code 57 (ABS_MT_TRACKING_ID), value -1
Event: time 1443206651.907711, type 1 (EV_KEY), code 330 (BTN_TOUCH), value 0
Event: time 1443206651.907711, -------------- SYN_REPORT ------------

HTH
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

Return to “Official Foundation Display”