Touch Events

Recurrent H/W and software problems
Post Reply
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Touch Events

Post by AndyGadget »

Annex 1.44.2 using an ILI9341 screen.

Touch.z function returns correct value (0 for no touch, 1 for touch) but a touch release does not create a touch event.
Is this a bug or is it intended operation?
(Be useful if it did flag a touch release :¬)

Code: [Local Link Removed for Guests]

tft.init 1
OnTouch touchme
'timer0 100, touchme
wait

touchme:
touch.read
touched = touch.z
touchx = touch.x
touchy = touch.y

if touched = 1 then
  wlog touched, "Keydown"
else
  wlog touched, "Keyup"
end if
return
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: Touch Events

Post by cicciocb »

Hi Andy,
there is no touch release event associated with the command ONTOUCH.
However, this exists in the GUI [Local Link Removed for Guests]
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Re: Touch Events

Post by AndyGadget »

Thanks Francesco,
I've just found that and am experimenting :D
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Re: Touch Events

Post by AndyGadget »

I'm looking to detect a touch or release event within a group of buttons and then decode which one was pressed within the SETEVENT routine.
I thought I could do this by defining the buttons within a group and the use GUI.TARGET to narrow it down to one key but now think it's not meant to work this way.
Does this mean I have to set up an event handler routine for each individual button?
Is there a neat way of doing this for a large number of buttons?
The application is a musical keyboard / sequencer which will be feeding a VS1053 MIDI module over serial. The MIDI side works fine.

Code: [Local Link Removed for Guests]

tft.init 1
wlog "Running " + Time$
dim BArr(20)
dim BStr$(20) = ".","A","A'","B","C","C'","D","D'","F","F'","G","G'"
gui.init 30, blue

' Draw buttons on screen and give them group value 20
for bcnt = 1 to 11
  BArr(BCnt) = GUI.Button 25 * bcnt,100,20,30,BStr$(bcnt),2,0,0,20,white,black
next bcnt

gui.autorefresh 30,1

' Expect to jump to routine if any of group 20 changes.
gui.setevent 20, CHANGE, keyevent

wait

keyevent:
KeyPressed = GUI.TARGET
wlog "*",KeyPressed
return
User avatar
cicciocb
Site Admin
Posts: 1900
Joined: Mon Feb 03, 2020 1:15 pm
Location: Toulouse
Has thanked: 407 times
Been thanked: 1271 times
Contact:

Re: Touch Events

Post by cicciocb »

[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]Wed Jul 27, 2022 5:40 pm I'm looking to detect a touch or release event within a group of buttons and then decode which one was pressed within the SETEVENT routine.
I thought I could do this by defining the buttons within a group and the use GUI.TARGET to narrow it down to one key but now think it's not meant to work this way.
Does this mean I have to set up an event handler routine for each individual button?
Is there a neat way of doing this for a large number of buttons?
The application is a musical keyboard / sequencer which will be feeding a VS1053 MIDI module over serial. The MIDI side works fine.
Hi Andy,
you could just define the same event for all the group as below

Code: [Local Link Removed for Guests]

tft.init 1
wlog "Running " + Time$
dim BArr(20)
dim BStr$(20) = ".","A","A'","B","C","C'","D","D'","F","F'","G","G'"
gui.init 30, blue

' Draw buttons on screen and give them group value 20
for bcnt = 1 to 11
  BArr(BCnt) = GUI.Button 25 * bcnt,100,20,30,BStr$(bcnt),2,0,0,20,white,black
  gui.setevent BArr(BCnt), CHANGE, keyevent
next bcnt

gui.autorefresh 30,1

' Expect to jump to routine if any of group 20 changes.
'gui.setevent 20, CHANGE, keyevent

wait

keyevent:
KeyPressed = GUI.TARGET
wlog "*",KeyPressed
if KeyPressed = BArr(1) then
  ' do whatever you want
end if
' or use a select case
select case KeyPressed
  case BArr(1)
  ' do whatever you want
  case BArr(2)
  ' do whatever you want
  case BArr(3)
  ' do whatever you want
  '''''''''''
end select

return

AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 120 times
Been thanked: 132 times

Re: Touch Events

Post by AndyGadget »

Why didn't I think of that - Define each event trigger within the setup loop.
Works a treat now :D

Many thanks, Francesco (again).
Post Reply