wasDoubleclicked_event WITHOUT wasClicked_event
-
Hello
I use MicroPython on M5StickCPlus or M5AtomS3.
The goal to use the callbacks to manage Clicks and DoubleClicks :
BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
BtnA.setCallback(type=BtnA.CB_TYPE.WAS_DOUBLECLICKED, cb=btnA_wasDoubleclicked_event)I want the DoubleClick event to be triggerer WITHOUT the Clicked event to be fired (even twice !)
It makes this :
Simple Click : btnA_wasClicked_event
Double Click : btnA_wasClicked_event, btnA_wasClicked_event, btnA_wasDoubleclicked_eventBad :(
I used before managing DoubleClick myself with microtimes... but do not want anymore :)
-
[SOLVED]
Here is my solution, using ONLY wasPressed and wasReleased events :)
from time import ticks_ms ms_down = 0; ms_up = 0; ms_last_up = ticks_ms() click_timer = Timer(0) def btnA_wasPressed_event(state): global ms_down ms_down = ticks_ms() click_timer.init(period=250, mode=Timer.ONE_SHOT, callback=btnA_longclick) def btnA_wasReleased_event(state): global ms_up, ms_last_up click_timer.deinit() ms_up = ticks_ms(); click_length = ms_up - ms_down click_delay = ms_up - ms_last_up; ms_last_up = ms_up if (click_delay < 250): ms_last_up = 0 btnA_doubleclick() elif (click_length < 250): click_timer.init(period=250, mode=Timer.ONE_SHOT, callback=btnA_simpleclick)
With the functions here :
def btnA_simpleclick(timer): pass def btnA_doubleclick(): pass def btnA_longclick(timer): click_timer.init(period=250, mode=Timer.ONE_SHOT, callback=btnA_longclick) pass