RPi 4B HDMI Component Touchscreen

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 8.

Moderator: Benj

Post Reply
David_Challenge
Posts: 9
Joined: Tue Oct 06, 2020 4:49 pm
Contact:

RPi 4B HDMI Component Touchscreen

Post by David_Challenge »

I am using the Raspberry Pi 4B with official 7" touchscreen.

I have got the Raspberry Pi HDMI display component working in Flowcode 8 to display a background with variables printing on it.

Now I want to read the touchscreen position either using component macro 'GetTouchCoordinates' which I think is blocking so the program waits until the screen is touched or 'ReadTouchCoordinates' which allows the program to continue.

My sample program increases a counter every 0.5 seconds which is displayed.

When I used 'GetTouchCoordinates' the program paused until the screen was touched so I think it is in some way registering touches.

When I use 'ReadTouchCoordinates' and display the coordinates the coordinates never change from values 400 for X and 240 for Y wherever the screen is touched and if it is not touched.

Test program is attached.

Any ideas?
Attachments
RPi_Test_3.fcfx
(13.21 KiB) Downloaded 125 times

David_Challenge
Posts: 9
Joined: Tue Oct 06, 2020 4:49 pm
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by David_Challenge »

Testing further I have partly answered my question:

Component macro 'GetTouchCoordinates' waits until the touchscreen is touched then continues, I cannot decipher what the return value is though and the documentation does not help.

If you use component macro 'ReadTouchCoordinates' after 'GetTouchCoordinates' return then you get meaningful X and Y coordinates of the touch position. Again the documentation does not give much clue though on the values but some experimentation will give answers.

You cannot just use 'ReadTouchCoordinates' in a loop to check for a press as it does not return touch coordinates.

So this does not really solve my requirement to be 'doing something', eg displaying values on screen, whilst waiting for a touch because 'GetTouchCoordinates' is blocking.

There does not seem to be a way of interrupting on touch either which would be the obvious solution.

Any ideas?

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by LeighM »

Sorry for the delay in answering.
I was hoping to look at this issue later this morning.
I'll be back ...

David_Challenge
Posts: 9
Joined: Tue Oct 06, 2020 4:49 pm
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by David_Challenge »

OK thanks

Attached is my latest test program
Attachments
RPi_Tester.fcfx
(13.91 KiB) Downloaded 122 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by LeighM »

Hi,

Thanks for the spot with this,
GetTouchCoordinates was indeed blocking (when no mouse/touch movement)
I've now fixed this and an update should be available soon.

The 'hover hints' of the functions give information about usage, but not very detailed.

As you have found, GetTouchCoordinates should be called first.
It returns a non-zero value if there has been movement since the last call to it.
The return value includes flags, which indicate: bit 0 = left mouse button, bit 1 = right mouse button, bit 2 = centre button
(I'm not sure what returns are in the case of a touch panel, I don't currently have a touch screen to check)

So, in the case of a non-zero return, the function ReadTouchCoordinates should then be called to get the x and y co-ordinates.

Hence GetTouchCoordinates should be called in the main loop, and then action taken if it returns non-zero.

Interrupts/callbacks might be something for the future.

Hope that helps.
Look out for the update.
Leigh

David_Challenge
Posts: 9
Joined: Tue Oct 06, 2020 4:49 pm
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by David_Challenge »

Hi Leigh

Thanks for the component update which I have done.

I am getting further but all is not right with the touch screen part of the component.

Running the flowcode 8 program attached which checks the touchscreen every 100mS I display the 'GetTouchCoordinate' flag and the 'ReadToucCoordinate' X and Y values.

The flag is sensible, it changes bit 0 when touching the screen.

The X and Y coordinates though behave oddly as they continually change, and I don't mean a bit of jitter, they drift.

Attached is a link to a video of touch screen in action. You can see that the first touch gives totally different results to the second touch in approximately the same place and keeps changing.

https://drive.google.com/file/d/1Yq56Pj ... sp=sharing
Attachments
RPi_Tester.fcfx
(16.44 KiB) Downloaded 126 times

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by LeighM »

Thanks for the info.

I've made some changes and attached an updated component,
if you could please drop this into the following directory on your PC
and then retry
C:\ProgramData\MatrixTSL\FlowcodeV8\Components

As before, GetTouchCoordinates should be called first, this will return non-zero if there is a mouse/touch change.
The value returned is a set of flags, it looks like some extra flags have been added in recent OS updates,
so I'm not entirely sure yet what they all mean. The bits 0,1,2 still indicate mouse buttons.
It looks like bit 3 (i.e. value = 8 ) indicates mouse/touch movement.
So I now only update the x and y position when this flag is set and hopefully this will fix the issue.

As an additional feature I have now also added another function - ReadTouchData
This can be called in the same way as ReadTouchCoordinates, i.e. after GetTouchCoordinates
ReadTouchData however returns the raw data from the mouse/touch event.
This is actually the same flags, but the x and y values are the differential movement values (+ve or -ve from the last point).

This is the raw data from the mouse driver.
ReadTouchCoordinates attempts to convert this into an on screen coordinate.


Thanks
Leigh
Attachments
GLCD_RPI.fcpx
(11.24 KiB) Downloaded 125 times

David_Challenge
Posts: 9
Joined: Tue Oct 06, 2020 4:49 pm
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by David_Challenge »

Hello Leigh

Your latest update reveals what is happening to me.

In an earlier message I said that the X and Y coordinates were continually changing when the screen was touched. This is I think because if you touch the screen and hold the press the returned values, as shown by the new ReadTouchData component macro, retain their value from the initial press which is the difference from the previous touch. This way as your code keeps applying the same movement the touch coordinate keeps moving even though the touch is static.

If on the other hand the touch moves, even by a slight amount, then the component macro returns a small difference, or no difference, so the coordinates are more steady.

Looking around a bit I see that in Linux touchscreens ought to give an ABS {X, Y} return as opposed to the REL {X, Y} that a mouse returns. Not knowing what lies underneath your code is it possible to get the absolute value otherwise it is going to be extremely difficult to interpret the relative movement into a fixed space of a screen.

David

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times
Contact:

Re: RPi 4B HDMI Component Touchscreen

Post by LeighM »

Here's an update, please try this ...
Attachments
GLCD_RPI.fcpx
(11.24 KiB) Downloaded 128 times

Post Reply