Currently, the tap callback appears to "queue" one callback while the frame is sleeping.
function handle_tap()
print('got tap')
if can_tap then
can_tap=false
print('allowed tap')
frame.sleep(5)
can_tap=true
end
end
can_tap=true
frame.imu.tap_callback(handle_tap)
When tapping again (anytime during the roughly 5 second period), this code will result in a print of 'got tap', 'allowed tap', 5 second delay, then 'got tap', 'allowed tap' again. It only appears to queue one tap callback, such that tapping 3 times has no additional effect.
[Edit] I believe that this functionality is somewhat normal, but could be better explained. I think what is happening is that frame.sleep() is designed to wake on tap. But, frame.sleep(5) requires at least 5 seconds before waking up. So, it must still listen for tap, still wait the 5 seconds, then give the second tap immediately after wakeup. I was able to "detect" this by checking the time of the tap against the time it last woke up from sleep, but would prefer that you have some way to detect if the tap is waking the frame from sleep or if it's a tap while awake already.
Currently, the tap callback appears to "queue" one callback while the frame is sleeping.
When tapping again (anytime during the roughly 5 second period), this code will result in a print of 'got tap', 'allowed tap', 5 second delay, then 'got tap', 'allowed tap' again. It only appears to queue one tap callback, such that tapping 3 times has no additional effect.
[Edit] I believe that this functionality is somewhat normal, but could be better explained. I think what is happening is that frame.sleep() is designed to wake on tap. But, frame.sleep(5) requires at least 5 seconds before waking up. So, it must still listen for tap, still wait the 5 seconds, then give the second tap immediately after wakeup. I was able to "detect" this by checking the time of the tap against the time it last woke up from sleep, but would prefer that you have some way to detect if the tap is waking the frame from sleep or if it's a tap while awake already.