Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 18:00 18 Apr 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Touch() and Touch(lastx) problem. Bug? Or my fault?

Author Message
Calli
Regular Member

Joined: 20/10/2021
Location: Germany
Posts: 74
Posted: 06:37pm 03 Dec 2021
Copy link to clipboard 
Print this post

I have some problems (very likely with my understanding)


Do
 'While Touched
 Do While Touch(DOWN)
   Print Touch(X),Touch(Y)
   Pause 50
 Loop

 'Last Touched?
 Print "Last: ",Touch(lastx), Touch(lasty)

 Do While Touch(up)
 Loop
Loop


Wile I touch the screen I want to do something, when I release I want the last touched point. Sometimes touch(x) or touch(y) has the last value, and sometimes it has -1. Not sure if that is intended. I mean I can filter that and wait for both being -1.

But touch(lastx) or (lasty) is always -1 which I think is not correct. It should have the last touched point no matter what?

Output:


Saved 189 bytes
Last:   -1      -1
141     120
141     112
Last:   -1      -1
168     55
Last:   -1      -1
168     53
168     55
168     54
167     54
162    -1
Last:   -1      -1
113     110
118     115
118     113
118     116
-1      -1
Last:   -1      -1


Am I wrong minded?
Carsten
Edited 2021-12-04 04:37 by Calli
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1094
Posted: 11:33pm 03 Dec 2021
Copy link to clipboard 
Print this post

Carsten,

I think the problem is a timing issue.

The line
Do While Touch(DOWN)
will return very quickly with a true or false result which determines whether the loop continues or not.
If the touch(DOWN) changes from true to false after the Do While statement completes
but before the Print touch(x),touch(y) line finishes, then one or both of these will return a -1 which in turn will result in lastx and lasty being -1

If you change your Pause line to something like 250 you will see that your program will operate as you want. The longer pause is not really the best solution - it may be better to use the GUI INTERRUPT command and set flags for touch up and down and then test these flags in your main program.

Doug.
... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1984
Posted: 08:07am 04 Dec 2021
Copy link to clipboard 
Print this post

agree.

I always capture touch(x) &y and work on what I had.

This is from my GUI pack and seems fairly bombproof, it returns the touch co-ordinates and set some global variables so not only do I have the current touch, I still have the last point and it doesn't matter if the user lifts the stylus in the meantime, any "lag" is not perceptible in human terms


Sub GetTouch
Xt=Touch(X):Yt=Touch(Y)
End Sub


I then use a function to process the touches.

I prefer the polling method from my touch processor. I go in naively expecting touches and bail if there aren't any


Function ProcessTouch() As Integer
ProcessTouch=-1
GetTouch
If Xt=-1 Then Exit Function
... rest of your touch processing goes here


you can snag the whole code pack at http://www.fruitoftheshed.com/MMBasic.A-Simple-GUI-pack.ashx?HL=gui  and feel free to play. Might give you some pointers
Edited 2021-12-04 18:36 by CaptainBoing
 
Calli
Regular Member

Joined: 20/10/2021
Location: Germany
Posts: 74
Posted: 09:22am 04 Dec 2021
Copy link to clipboard 
Print this post

I was on a journey to do the Gui the old way :)

So I guess I will deal with the data my own way (similar to CaptainBoing) for now.

I still don't get the idea what touch(lastx) is for then :)

All the best,
Carsten
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2285
Posted: 02:00pm 04 Dec 2021
Copy link to clipboard 
Print this post

from the picomite manual on geoff's website:

  Quote  Touch Functions
To detect if and where the screen is touched you can use the following functions in a BASIC program:

TOUCH(X)
Returns the X coordinate of the currently touched location or -1 if the screen is not being touched.

TOUCH(Y)
Returns the Y coordinate of the currently touched location or -1 if the screen is not being touched.

TOUCH(DOWN)
Returns true if the screen is currently being touched (this is much faster than TOUCH(X or Y)).

TOUCH(UP)
Returns true if the screen is currently NOT being touched (also faster than TOUCH(X or Y))

TOUCH(LASTX)
Returns the X coordinate of the last location that was touched.

TOUCH(LASTY)
Returns the Y coordinate of the last location that was touched.

TOUCH(REF)
Returns the reference number of the control that is currently being touched or zero if no control is being
touched.  See the section Advanced Graphics for more details.

TOUCH(LASTREF)
Returns the reference number of the control that was last touched.

this indicates fairly clearly that TOUCH(LASTX) and a TOUCH(LASTY) should latch the last valid value, and not return -1 (unless the touch sensor has not been pressed since startup). perhaps there is a bug whereby 'lastx' and 'lasty' are case sensitive? probably one for peter to comment on.

it would be nice if the syntax of TOUCH and similar functions could be extended to include passing back the coordinates:

TOUCH(DOWN [, X%, Y%])

so that the X and Y locations are passed back in a couple of user-supplied variables. while, strictly speaking, this sort of syntax may be considered bad programming practice, it certainly makes life easier!


cheers,
rob   :-)
Edited 2021-12-05 00:02 by robert.rozee
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 04:06pm 04 Dec 2021
Copy link to clipboard 
Print this post

Lastx and lastly are gui functions and only work within the context of gui interrupts. Think this is the same on MM+ if anyone wants to check. This becomes more obvious if you consider lastref
 
robert.rozee
Guru

Joined: 31/12/2012
Location: New Zealand
Posts: 2285
Posted: 04:41pm 04 Dec 2021
Copy link to clipboard 
Print this post

hi peter,
   geoff's manual (pages 44 and 45) do not make this clear, to the point of suggesting otherwise in his examples. if touch(lastx) and touch(lasty) can return -1, what is the point of even having them? what makes them any different to touch(x) and touch(y)?

is there a technical reason why lastx and lasty return -1? from an implementation perspective, surely they just represent a couple of memory locations that are only updated when a valid touch (down) panel conversion happens.


cheers,
rob   :-)
Edited 2021-12-05 02:42 by robert.rozee
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 05:18pm 04 Dec 2021
Copy link to clipboard 
Print this post

They are designed to be used in the gui touch-up interrupt to let the interrupt know what caused it. At this point touch an y are by definition -1
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 8566
Posted: 08:44pm 04 Dec 2021
Copy link to clipboard 
Print this post

Confirmed: unless OPTION MAXCTRLS is set lastx and lasty don't do anything as GUI functionality is disabled. The PicoMite firmware gives you the option of using touch in MM2 or MM+ mode depending if maxctrls is set. MM2 mode only supports touch(x) and touch(y) (see the mm2 manual).
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024