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 all 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
15 changes: 11 additions & 4 deletions docs/en/scanners.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ need to swap it out with an alternative scanner.
## Keypad Scanners
The scanners in `kmk.scanners.keypad` wrap the `keypad` module that ships with
CircuitPython and support the same configuration and tuning options as their
upstream. You can find out more in the [CircuitPython
upstream.

**Some users may need to tweak debounce parameters**, `interval=0.01,debounce_threshold=5` is a good starting point. `debounce_threshold` is only applicable for CircuitPython >= 9.2.0
xs5871 marked this conversation as resolved.
Show resolved Hide resolved

You can find out more in the [CircuitPython
documentation](https://docs.circuitpython.org/en/latest/shared-bindings/keypad/index.html).

### keypad MatrixScanner
Expand All @@ -30,7 +34,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.02, # Matrix sampling interval in ms
debounce_threshold=None, # Number of samples needed to change state, values greater than 1 enable debouncing. Only applicable for CircuitPython >= 9.2.0
max_events=64
)

Expand Down Expand Up @@ -68,7 +73,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.02, # Matrix sampling interval in ms
debounce_threshold=None, # Number of samples needed to change state, values greater than 1 enable debouncing. Only applicable for CircuitPython >= 9.2.0
max_events=64
)
```
Expand All @@ -94,7 +100,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.02, # Matrix sampling interval in ms
debounce_threshold=None, # Number of samples needed to change state, values greater than 1 enable debouncing. Only applicable for CircuitPython >= 9.2.0
max_events=64
)
```
Expand Down
62 changes: 7 additions & 55 deletions kmk/scanners/keypad.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import keypad

from kmk.scanners import DiodeOrientation, Scanner
from kmk.scanners import Scanner


class KeypadScanner(Scanner):
Expand Down Expand Up @@ -36,22 +36,8 @@ class MatrixScanner(KeypadScanner):
:param direction: The diode orientation of the matrix.
'''

def __init__(
self,
row_pins,
column_pins,
*,
columns_to_anodes=DiodeOrientation.COL2ROW,
interval=0.02,
max_events=64,
):
self.keypad = keypad.KeyMatrix(
row_pins,
column_pins,
columns_to_anodes=(columns_to_anodes == DiodeOrientation.COL2ROW),
interval=interval,
max_events=max_events,
)
def __init__(self, *args, **kwargs):
self.keypad = keypad.Keys(*args, **kwargs)
super().__init__()


Expand All @@ -62,46 +48,12 @@ class KeysScanner(KeypadScanner):
:param pins: An array of arrays of CircuitPython Pin objects, such that pins[r][c] is the pin for row r, column c.
'''

def __init__(
self,
pins,
*,
value_when_pressed=False,
pull=True,
interval=0.02,
max_events=64,
):
self.keypad = keypad.Keys(
pins,
value_when_pressed=value_when_pressed,
pull=pull,
interval=interval,
max_events=max_events,
)
def __init__(self, *args, **kwargs):
self.keypad = keypad.Keys(*args, **kwargs)
super().__init__()


class ShiftRegisterKeys(KeypadScanner):
def __init__(
self,
*,
clock,
data,
latch,
value_to_latch=True,
key_count,
value_when_pressed=False,
interval=0.02,
max_events=64,
):
self.keypad = keypad.ShiftRegisterKeys(
clock=clock,
data=data,
latch=latch,
value_to_latch=value_to_latch,
key_count=key_count,
value_when_pressed=value_when_pressed,
interval=interval,
max_events=max_events,
)
def __init__(self, *args, **kwargs):
self.keypad = keypad.Keys(*args, **kwargs)
super().__init__()
1 change: 1 addition & 0 deletions util/aspell.en.pws
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Crkbd
Crowboard
Ctrl
Cygwin
debounce
DFU
DISCOVERABLE
DIY
Expand Down