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: GermanyPosts: 74 |
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: AustraliaPosts: 1094 |
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 KingdomPosts: 1984 |
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: GermanyPosts: 74 |
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 ZealandPosts: 2285 |
from the picomite manual on geoff's website: 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 KingdomPosts: 8566 |
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 ZealandPosts: 2285 |
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 KingdomPosts: 8566 |
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 KingdomPosts: 8566 |
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 |