Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting callback function for joystick #2

Open
simonbyrne opened this issue Apr 18, 2017 · 3 comments
Open

Setting callback function for joystick #2

simonbyrne opened this issue Apr 18, 2017 · 3 comments

Comments

@simonbyrne
Copy link
Member

Currently, the recommended way to define a callback is via:

@schedule for e in sticktask()
    foo(e)
end
  1. Should we define a function to make this easier? e.g. setcallback(foo).
  2. If so, how should it behave when invoked multiple times? We could keep a global array of functions, but I worry about the performance overhead.

cc: @aviks

@aviks
Copy link
Member

aviks commented Apr 18, 2017

The way python does this is sense.stick.direction_up = my_move_up_fn, in that the framework does the work of despatching on event types. This is the kind of API pioneered in Ben's GPIOZero, which allows writing code like button.when_pressed = led.on which I find very easy to reason about.

@simonbyrne
Copy link
Member Author

That is nice, we should be able to do something like that. Let me think about it a bit.

@aviks
Copy link
Member

aviks commented Apr 18, 2017

Cool. As I said elsewhere, this kind of thing probably leads to spaghetti code eventually, but it's good for teaching.

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

No branches or pull requests

2 participants