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

buttonWasPressed, pinWasPressed #164

Open
pelikhan opened this issue Jun 9, 2016 · 3 comments
Open

buttonWasPressed, pinWasPressed #164

pelikhan opened this issue Jun 9, 2016 · 3 comments
Assignees

Comments

@pelikhan
Copy link

pelikhan commented Jun 9, 2016

It would be great to have the same API as micropython for button presses:

# returns True or False to indicate if the button was pressed since the device
# started or the last time this method was called.
button.was_pressed()
# returns the running total of button presses, and resets this counter to zero
button.get_presses()

It's particularly usefull in a tight loop when button presses are missed/.

http://microbit-micropython.readthedocs.io/en/latest/microbit_micropython_api.html?highlight=was_pressed

@finneyj
Copy link
Contributor

finneyj commented Jun 9, 2016

thanks @pelikhan

Sure, that would be a trivial but useful enhancement. I hate to introduce duplication though: @dpgeorge - would upstreaming this API be a welcome move, assuming we preserve semantics with your API of course?

@dpgeorge
Copy link
Contributor

dpgeorge commented Jun 9, 2016

I thought the point of having the message bus with primitives like BUTTON_EVT_DOWN was so that we could easily implement such semantics ourselves (which is what we do, we listen for EVT_DOWN and use that to update the state about button presses). Adding wasPressed would complicate the button API in the DAL.

@finneyj
Copy link
Contributor

finneyj commented Jun 23, 2016

@dpgeorge @pelikhan

For sure, the aim is to allow folks to use the building blocks here to create the best programming experience possible for higher level languages. It also makes sense to consider sharing best practice round too though, where it make sense to do so to reduce effort and duplication.

For most drivers we support calls for basic synchronous and asynchronous use, and for microBitButton we already have isPressed(), so I'm happy either way on this one.

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

No branches or pull requests

3 participants