keymuu
- 23rd February 2011, 00:09
Hi!
there was a thread talking about this but only with two functions, a normal and a long press. Could not found the double-click incorporated there, not in Mel's code or any other place either. So I figured out the following sub-routine based on Mel's code. Bpressed is the byte returned from the´MCP23016 read, where all buttons are attached. the procedure returns in buttoPress what kind of a press it was:
specialButton: 'check if normal button press, double-click or a long press
buttonCnt = 0
gosub getIOexp ' get IOexpander MCP23016
while ((Bpressed && useButton) = useButton) and (buttonCnt < 60) ' check if a long press..
buttonCnt = buttonCnt + 1 : If buttonCnt >= 100 then goto error
pause 25 ' -> 60 x 25ms = 1,5 sec = long press
gosub getIOexp
wend
buttonPress = shortPress ' normal press
if buttonCnt >= 60 then
buttonPress = longPress
return 'it was a LONG PRESS, so no need to check other things
else ' now it can be either a normal press or double-click
buttonCnt = 0
' not pressed at the moment, but wait for a second click
gosub getIOexp ' read the buttons once again, and wait if the user
' clicks/push the button a second time within 1sec
while ((Bpressed && useButton) = 0) and (buttonCnt < 40)
buttonCnt = buttonCnt + 1 : If buttonCnt >= 100 then goto error
pause 25 ' -> 40 x 25ms = 1 sec
if ((Bpressed && useButton) = useButton) then 'pressed/clicked again?
buttonPress = doublePress
return ' it was a DOUBLE-CLICK, so no need to continue
endif
gosub getIOexp
wend ' if not pressed within one second, then it was a single press
' and also the program will not advance within that second, and
' that looks of course like the program would hang for that time.
endif ' buttonCnt >= 60
return ' form specialButton
However, that is not elegant when waiting for a double-click but it was only a single press.:(
The program waits in vain for one second, before it can continue. :mad:
Could somebody please tell if there is some other approach which would not have that one second delay? All ideas are appreciated, thank you.
there was a thread talking about this but only with two functions, a normal and a long press. Could not found the double-click incorporated there, not in Mel's code or any other place either. So I figured out the following sub-routine based on Mel's code. Bpressed is the byte returned from the´MCP23016 read, where all buttons are attached. the procedure returns in buttoPress what kind of a press it was:
specialButton: 'check if normal button press, double-click or a long press
buttonCnt = 0
gosub getIOexp ' get IOexpander MCP23016
while ((Bpressed && useButton) = useButton) and (buttonCnt < 60) ' check if a long press..
buttonCnt = buttonCnt + 1 : If buttonCnt >= 100 then goto error
pause 25 ' -> 60 x 25ms = 1,5 sec = long press
gosub getIOexp
wend
buttonPress = shortPress ' normal press
if buttonCnt >= 60 then
buttonPress = longPress
return 'it was a LONG PRESS, so no need to check other things
else ' now it can be either a normal press or double-click
buttonCnt = 0
' not pressed at the moment, but wait for a second click
gosub getIOexp ' read the buttons once again, and wait if the user
' clicks/push the button a second time within 1sec
while ((Bpressed && useButton) = 0) and (buttonCnt < 40)
buttonCnt = buttonCnt + 1 : If buttonCnt >= 100 then goto error
pause 25 ' -> 40 x 25ms = 1 sec
if ((Bpressed && useButton) = useButton) then 'pressed/clicked again?
buttonPress = doublePress
return ' it was a DOUBLE-CLICK, so no need to continue
endif
gosub getIOexp
wend ' if not pressed within one second, then it was a single press
' and also the program will not advance within that second, and
' that looks of course like the program would hang for that time.
endif ' buttonCnt >= 60
return ' form specialButton
However, that is not elegant when waiting for a double-click but it was only a single press.:(
The program waits in vain for one second, before it can continue. :mad:
Could somebody please tell if there is some other approach which would not have that one second delay? All ideas are appreciated, thank you.