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

Alternative ButtonBoard #628

Closed
bennuttall opened this issue Mar 21, 2018 · 2 comments
Closed

Alternative ButtonBoard #628

bennuttall opened this issue Mar 21, 2018 · 2 comments
Projects

Comments

@bennuttall
Copy link
Member

Currently the ButtonBoard class has an n-tuple value:

>>> bb = ButtonBoard(2, 3, 4, 5)
>>> tuple(bb.value)
(0, 0, 0, 0)

and if one button is pressed, the activated callback is fired:

>>> bb.when_pressed = lambda: print("Pressed")
>>> bb.all[0].pin.drive_low()
Pressed
>>> tuple(bb.value)
(1, 0, 0, 0)

I wondered if we could introduce a threshold, so you could specify how many active buttons were required for the event to fire, e.g:

>>> bb = ButtonBoard(2, 3, 4, 5, threshold=4)

i.e. all four buttons must be pressed for the event to fire.

@waveform80 suggested that this should be a separate class - similar to the differentiation between LEDBoard and LEDBarGraph where the new class would have a single 0-1 value rather than an n-tuple. So perhaps ButtonGroup?

This would only allow either one-button activations (with ButtonBoard) or all-button activations (with ButtonGroup) but nothing in-between (unless this can be solved with nesting mentioned in #607) - not a huge problem as I don't expect this to be too common (and can be achieved using other methods).

@lurch
Copy link
Contributor

lurch commented Mar 22, 2018

What's the imagined use-case for having a ButtonBoard that only fires it's when_pressed event when e.g. any 3 out of a possible 5 buttons are pressed? (if I'm understanding your threshold suggestion correctly)

Or are you specifically only asking for an event that fires when all buttons are pressed. Would adding an when_all_pressed event to the existing ButtonBoard class solve your requirement?

@bennuttall bennuttall added this to Triage in Triage Feb 8, 2019
@bennuttall bennuttall moved this from Triage to Pending suggestions in Triage Feb 9, 2019
@bennuttall
Copy link
Member Author

Closing this in favour of #522 - moving this discussion there

Triage automation moved this from Pending suggestions to Done Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Triage
  
Done
Development

No branches or pull requests

2 participants