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 : Thoughts on Double Tap etc
Author | Message | ||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Thinking that having the ability to Tap, Double Tap or Long Press the touch screen for different actions would be useful. Any thoughts on implementing this? Here's what I've tried. Single & Long Press seem to work, Double maybe occasionally. [Code] Dim TouchType as String Dim TouchTime as Integer Do If Touch(x)<>-1 then TouchType="Single Touch" Pause 200 Timer=0 Do While Touch(x)<>-1 TouchTime=Timer If TouchTime < 500 Then TouchType="Double Touch" Elseif TouchTime > 500 Then TouchType="Long Press" Endif Loop ScreenTouched Endif loop Sub ScreenTouched Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print TouchType Pause 1000 Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print "Not Touched" End Sub [/code] Cheers Phil |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
I know simple timing probably won't work reliably; Maybe need to use interrupts, which I haven't gone into yet. Basic Logic sounds simple:= Touch <> -1 Then Touch = -1 Then Touch <> -1 Inside a time of say 300ms Otherwise if your finger is held down & touch < say 500ms a long press is recorded. Could be used for things like Tap to view or Long Press to Edit. Phil. |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
Don't forget that you can set an interrupt on the IRQ signal (ie, touch down) from the touch controller (page 19 of the 5.2B1 manual). That would make it easier as the timing could be wrapped up in the interrupt subroutine and independent of the main program. Geoff Geoff Graham - http://geoffg.net |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Thanks Geoff, I'm not sure exactly how the interrupt behaves. What happens if you are already in the Sub it calls when a 2nd interrupt is generated? Does it behave like an EXIT SUB situation & return to the beginning again? Thanks Phil. |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Think I'm missing something in my basic logic here. Any thoughts? Seems to relatively reliably return Single Touch & Long Press. I do occasionally see it output "Double Touch", but it's a bit random. Wasn't sure how the interrupt behaved once inside the sub it calls so tried disabling it & re-enabling it on END SUB. Don't know if that improved it or made matters worse. Any feedback on the actual sensitivity & responsiveness of the actual panels? I do think mine is way less responsive than say my phone, but then I do expect that given the different technologies. Anyone with a Touch handy like to give it a test on theirs for feedback? Cheers Phil. [Code] Dim TouchType as String Dim TouchTime as Integer SetPin 15, intl, LCDTouch Do 'Empty ATM loop Sub LCDTouch TouchType="Single Touch" SetPin 15, Off Timer=0 Pause 200 'Pause after initial touch Do While Touch(x)<>-1 'Look for 2nd touch or holding belong 200ms & measure time TouchTime=Timer If TouchTime < 350 Then TouchType="Double Touch" Elseif TouchTime > 500 Then TouchType="Long Press" Endif Loop ''''''''''''''''''Endif Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print TouchType Pause 1000 Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print "Not Touched" SetPin 15, intl, LCDTouch End Sub [/code] Edit:- Extra non matched End If in above when I posted. |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Tried adding some timing measurements to the output to assist with debugging. [Code] Dim TouchType as String Dim TouchTime as Integer SetPin 15, intl, LCDTouch Do 'Empty ATM loop Sub LCDTouch TouchType="Single Touch" SetPin 15, Off Timer=0 Do While Touch(x)<>-1 'Measure 1st touch time TouchTime=Timer Loop Pause 100 'Pause after initial touch to wait for 2nd touch, Don't know what's a good value. Do While Touch(x)<>-1 'Look for 2nd touch or holding belong XXXms (set above) & measure time TouchTime=Timer If TouchTime < 400 Then TouchType="Double Touch" Elseif TouchTime > 500 Then TouchType="Long Press" Endif Loop Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print TouchType, "Touch Time =", TouchTime Pause 1000 Print CHR$(27)+"[f"; : Print CHR$(27)+"[2J"; Print "Not Touched" SetPin 15, intl, LCDTouch End Sub [/code] |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
Assuming that you are in the sub because of an interrupt the second interrupt will be ignored until you return from the sub. This is why your time in an interrupt sub must be as short as possible. You might be meaning that you called the sub from somewhere in your program and while you were still in that sub an interrupt occurred to send you recursively into the sub. This will turn your hair grey and cause nightmares. To avoid this never call an interrupt sub from within your program when an interrupt might occur. Geoff Geoff Graham - http://geoffg.net |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
Not quite sure what you are meaning in this statement. Cheers Phil |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9082 |
Think of it like this: Never call an interrupt sub from your main program - ever. Interrupt subs should be specifically dedicated to the interrupts that call them. So if you had an interrupt called SUB MYINT, then NEVER call MYINT as part of your normal code. You COULD call it, but just DON'T! Otherwise you could end up with the hair-pulling example Geoff was talking about, where you have recursion - "If we had an index file, we could look it up in the index file under index file!" - Can anyone name where that quote comes from? Smoke makes things work. When the smoke gets out, it stops! |
||||
Phil23 Guru Joined: 27/03/2016 Location: AustraliaPosts: 1664 |
So if you had an interrupt called SUB MYINT, then NEVER call MYINT as part of your normal code. You COULD call it, but just DON'T! Got it now! What if a 2nd Different interrupt is triggered while in an interrupt sub? Is it ignored? As in all interrupts ignored? OR does it jump out of the first sub. Unlike my first example of the same interrupt while already in the sub that the same interrupt called. Thanks |
||||
CircuitGizmos Guru Joined: 08/09/2011 Location: United StatesPosts: 1421 |
That quote comes from two posts above mine. Which I just quoted in my post by clicking quote. Talk about useless recursion! Micromites and Maximites! - Beginning Maximite |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9082 |
@ Phil - As Geoff said, if you are in an interrupt, and another interrupt is tripped, all other interrupts will be ignored until the first one is returned. So, in other words, if you have a 2nd interrupt instance while still in the first interrupt, that 2nd one will be ignored. This is the primary reason for not hanging around inside an interrupt. Don't even process any code(bar very simple stuff like a few IF/THEN/ELSE type commands) in an interrupt. My preferred method is to simply set a flag, and exit immediately. Then have your main code analyse the flags and take the appropriate action. It IS confusing, until you get your head around how they work, but interrupts are a wonderful thing, and a fantastic feature to have on the MM. @ CG - Clever! Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3167 |
The way the interrupt system works is that MMBasic does not check for interrupts while it is processing an interrupt. This is to prevent uncontrolled recursion which could be a problem due to the way the interpreter and BASIC works. When the program returns from the interrupt sub it will recommence checking for interrupts. For this reason you should make sure that you spend as little time as possible in the interrupt sub. For example, if you are detecting touch down interrupts and only spent 10mS in the interrupt sub you are guaranteed to catch a second touch down interrupt because it would be impossible for someone to tap faster than this. Geoff Geoff Graham - http://geoffg.net |
||||
Print this page |