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

Allow passing debounce_threshold in keypad.py #1044

Merged
merged 18 commits into from
Nov 8, 2024
Merged

Conversation

regicidalplutophage
Copy link
Member

This is needed for proper debouncing

@regicidalplutophage
Copy link
Member Author

I'm testing this on a direct pin keyboard and I've got no complaints. Maybe new defaults are still too conservative even? But then I didn't have any issues with key chatter anyway, so I'm not the target audience for debouncing...

@@ -30,7 +30,8 @@ class MyKeyboard(KMKKeyboard):
row_pins=self.row_pins,
# optional arguments with defaults:
columns_to_anodes=DiodeOrientation.COL2ROW,
interval=0.02, # Debounce time in floating point seconds
interval=0.01, # How often the matrix is sampled
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
interval=0.01, # How often the matrix is sampled
interval=0.01, # Matrix sampling interval in ms

Same for the other parameter lists. ("how often" means frequency btw, which is the inverse).

@@ -30,7 +30,8 @@ class MyKeyboard(KMKKeyboard):
row_pins=self.row_pins,
# optional arguments with defaults:
columns_to_anodes=DiodeOrientation.COL2ROW,
interval=0.02, # Debounce time in floating point seconds
interval=0.01, # How often the matrix is sampled
debounce_threshold=5, # Number of samples needed to change state
Copy link
Collaborator

Choose a reason for hiding this comment

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

I have a strong opinion on keeping the upstream default, even if it's "maybe suboptimal". Make a note in the docs that values around 5 are tested and should work.

Copy link
Member Author

Choose a reason for hiding this comment

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

The way KMK is used we'd need this information in getting started... I'd prefer the minimum viable config to remain within its current scope.

@regicidalplutophage
Copy link
Member Author

Unless you budge on defaults, getting started still needs some rewriting to point to porting guide and scanners. I'm pooped though.

Comment on lines 52 to 65
]
for i in args:
if i is None:
args.pop(i)
kwargs = {
'columns_to_anodes': columns_to_anodes,
'interval': interval,
'debounce_threshold': debounce_threshold,
'max_events': max_events,
}
for key, value in kwargs.items():
if value is None:
kwargs.pop(key)
self.keypad = keypad.Keys(*args, **kwargs)
Copy link
Collaborator

@xs5871 xs5871 Nov 8, 2024

Choose a reason for hiding this comment

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

oh dear. That is much too complicated for my taste. Do we want backwards compatibility with CP8?

  1. No: none if this is necessary
  2. Yes: Since we're not doing any validation nor any abstraction, just use pokemon arguments:
def __init__(self, *args, **kwargs):
    self.keypad = keypad.Keys(*args, **kwargs)

style sidenote: in any case, this screams comprehension:

args = [v for v in args if v is not None]
kwargs = {k:v for k,v in kwargs.items() if v is not None}

Copy link
Member Author

@regicidalplutophage regicidalplutophage Nov 8, 2024

Choose a reason for hiding this comment

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

I didn't go with comprehension because init had explicit arguments. I do like the pokemon arguments though, not sure why it wasn't that in the first place -- referring both to my PR and the main branch.


Right, the too complicated stuff came from the place of wanting to provide non-upstream defaults then have the ability to None-out those defaults if it has to work in earlier versions of circuitpython.

docs/en/scanners.md Show resolved Hide resolved
@regicidalplutophage regicidalplutophage changed the title Expose debounce_threshold in keypad.py Allow passing debounce_threshold in keypad.py Nov 8, 2024
@xs5871 xs5871 merged commit 643afc9 into main Nov 8, 2024
2 checks passed
@xs5871 xs5871 deleted the regicidalplutophage-patch-1 branch November 8, 2024 23:32
@DaVarga
Copy link

DaVarga commented Nov 10, 2024

This line seems to break the main branch
https://github.com/KMKfw/kmk_firmware/pull/1044/files#diff-47931159c3b3d0e39f59c6f47a3d0e133ebffb04b8dafd078d79d5ba0f3bb5f8R52
Right now it throws "TypeError: 'pins' argument required".
Maybe this line should be self.keypad = keypad.KeyMatrix(*args, **kwargs) ?

Same goes for ShiftRegisterKeys

@xs5871 xs5871 mentioned this pull request Nov 10, 2024
@regicidalplutophage
Copy link
Member Author

Well, that's embarassing. The fix is merged now!

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