Skip to content

Fix race condition when wait_for_event is used at the same time as direction_up etc.#155

Open
aonghusonia wants to merge 2 commits into
astro-pi:masterfrom
aonghusonia:master
Open

Fix race condition when wait_for_event is used at the same time as direction_up etc.#155
aonghusonia wants to merge 2 commits into
astro-pi:masterfrom
aonghusonia:master

Conversation

@aonghusonia
Copy link
Copy Markdown

if you already have a callback assigned to one of the directions ot any and you wait_for_event the first press gets ignored because its read by the callback.

wait_for_event now raises an error if there is a joystick callback assigned. Also added a warning to the documentation

… same time

raise error if using wait_for_event when callbacks are assigned.
Clarify usage restrictions for joystick functions and events.
@aonghusonia
Copy link
Copy Markdown
Author

This code replicates the issue

from sense_hat import SenseHat
from signal import pause

sense = SenseHat()

def callback(event):
    print("direction_up callback: The joystick was {} {}".format(event.action, event.direction))

sense.stick.direction_up = callback

event = sense.stick.wait_for_event()
print("wait_for_event: The joystick was {} {}".format(event.action, event.direction))

pause()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant