Skip to content

Conversation

@EGJ-Moorington
Copy link
Contributor

Added CircuitPython_Button_Handler, a helper library that handles different types of button presses such as short presses, long presses, double presses and holding actions.

@dastels
Copy link
Collaborator

dastels commented Aug 5, 2024

I suggest using the adafruit_debouncer module rather than using sleep to implement a debounce.

@dastels
Copy link
Collaborator

dastels commented Aug 5, 2024

Actually, it might be even better to add functionality to adafruit_debouncer.Button.

@dhalbert
Copy link
Contributor

dhalbert commented Aug 5, 2024

keypad can also be used as the basis of this on boards that support it (most do): it provides timestamped button up/down events without any Python-based polling or delays. https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython

@EGJ-Moorington
Copy link
Contributor Author

EGJ-Moorington commented Aug 5, 2024

keypad can also be used as the basis of this on boards that support it (most do): it provides timestamped button up/down events without any Python-based polling or delays. https://learn.adafruit.com/key-pad-matrix-scanning-in-circuitpython

Thanks for the feedback! Now I'm left wondering if I should make the version based on keypad a separate library (so that non-compatible boards can still use the library) or just make it Button_Handler 2.0.0.
It could also be possible to add functionality that doesn't use keypad via a

try:
  import keypad
except ImportError:
  # Implementation for non-compatible boards
else:
  # Implementation for compatible boards

, correct?

@dhalbert
Copy link
Contributor

dhalbert commented Aug 5, 2024

Boards without keypad are tight on space, so importing a dual-compatible version might bring in unused code which would use up RAM. Or you can refactor it so there are two different files to import. But the semantics may be different, because keypad can be used in a non-blocking way.

@EGJ-Moorington
Copy link
Contributor Author

EGJ-Moorington commented Aug 5, 2024

Based on that, could

try:
  import keypad
except ImportError:
  import non_keypad_using_lib_ver as lib
else:
  import lib_ver_using_keypad as lib

work, or would the same issues arise? Also, I'm struggling to understand the last sentence on your response:

But the semantics may be different, because keypad can be used in a non-blocking way.

I'd appreciate it if you could explain that to me.

@EGJ-Moorington
Copy link
Contributor Author

Hello again! Just released version 2.0.0, which uses keypad as the base of the library.

@tannewt tannewt requested a review from dhalbert August 19, 2024 19:59
Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I did not see this earlier. Libraries don't need to be reviewed before they're added to the bundle. I looked at the API briefly: the only thing I'd suggest is that instead of using strings to different button inputs, use some enum-like construct, like a set of integers, or maybe different objects. So for instance

ButtonInput(ButtonInput.DOUBLE_PRESS, callback=double_press),

or maybe

DoublePressInput(callback.double_press)

@EGJ-Moorington
Copy link
Contributor Author

EGJ-Moorington commented Sep 2, 2024

Thanks for the feedback, @dhalbert! I added the changes in version 3.0.0.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this, and thanks for your patience during the review.

@dhalbert dhalbert merged commit 994fb4e into adafruit:main Sep 3, 2024
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.

3 participants