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
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/en/scanners.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

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.

max_events=64
)

Expand Down Expand Up @@ -68,7 +69,8 @@ class MyKeyboard(KMKKeyboard):
# optional arguments with defaults:
value_when_pressed=False,
pull=True,
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
max_events=64
)
```
Expand All @@ -94,7 +96,8 @@ class MyKeyboard(KMKKeyboard):
# optional arguments with defaults:
value_to_latch=True, # 74HC165: True, CD4021: False
value_when_pressed=False,
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
max_events=64
)
```
Expand Down
12 changes: 9 additions & 3 deletions kmk/scanners/keypad.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def __init__(
column_pins,
*,
columns_to_anodes=DiodeOrientation.COL2ROW,
interval=0.02,
interval=0.01,
debounce_threshold=5,
max_events=64,
):
self.keypad = keypad.KeyMatrix(
Expand All @@ -51,6 +52,7 @@ def __init__(
columns_to_anodes=(columns_to_anodes == DiodeOrientation.COL2ROW),
interval=interval,
max_events=max_events,
debounce_threshold=debounce_threshold,
)
super().__init__()

Expand All @@ -68,14 +70,16 @@ def __init__(
*,
value_when_pressed=False,
pull=True,
interval=0.02,
interval=0.01,
debounce_threshold=5,
max_events=64,
):
self.keypad = keypad.Keys(
pins,
value_when_pressed=value_when_pressed,
pull=pull,
interval=interval,
debounce_threshold=debounce_threshold,
max_events=max_events,
)
super().__init__()
Expand All @@ -91,7 +95,8 @@ def __init__(
value_to_latch=True,
key_count,
value_when_pressed=False,
interval=0.02,
interval=0.01,
debounce_threshold=5,
max_events=64,
):
self.keypad = keypad.ShiftRegisterKeys(
Expand All @@ -102,6 +107,7 @@ def __init__(
key_count=key_count,
value_when_pressed=value_when_pressed,
interval=interval,
debounce_threshold=debounce_threshold,
max_events=max_events,
)
super().__init__()