brilliantlabsAR / frame-codebase

The complete codebase for Frame
https://www.brilliant.xyz
Other
146 stars 30 forks source link

tap_callback behavior #220

Open kjjohnsen opened 2 weeks ago

kjjohnsen commented 2 weeks ago

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.