i3detroit/i3Twitterbot

Interruptable countdown

Opened this issue · 4 comments

If the switch is toggled back to closed during a camera countdown, stop the countdown and take no picture.

It appears to be difficult to do this within the PyBBIO interrupt framework, as it queues interrupts and waits for the callback function to complete before calling it again.

Well, ideally you wouldn't do any real work in the interrupt handler - they should be as short as possible. I haven't read through the current code, so feel free to ignore me, but I would:
In the open button handler just a var that says what time to take the picture/send tweet.
In the close button hander set the countdown var to -1 or something.

Then in the main loop you update the screen and track the time vs the destination time. When you hit the time, then you trigger your functions for sending the tweet. If the dest time is -1, you go back to your normal, non-countdown, state.

This would require much rewriting, but is certainly the correct approach.

I aim to... make life much more difficult... 😄