From 4d684a5571e531311294271bf20212256ae6a347 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:11:33 +0300 Subject: [PATCH 01/18] Expose debounce_threshold in keypad.py This is needed for proper debouncing --- kmk/scanners/keypad.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index c6b007aea..e3611d5ff 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -44,6 +44,7 @@ def __init__( columns_to_anodes=DiodeOrientation.COL2ROW, interval=0.02, max_events=64, + debounce_threshold=1, ): self.keypad = keypad.KeyMatrix( row_pins, @@ -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__() From cd0b0231f5ad1d4fd9343608c19f763438894e93 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:19:00 +0300 Subject: [PATCH 02/18] Update scanners.md --- docs/en/scanners.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index b0122add8..b1f5e5be3 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -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.02, # How often the matrix is sampled + debounce_threshold=1, # Number of samples needed to change state max_events=64 ) From a371c855e901aa1b6a9b4413398b68c03fecf5a1 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:22:30 +0300 Subject: [PATCH 03/18] Expose it in other scanners as well --- kmk/scanners/keypad.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index e3611d5ff..a12f70cc3 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -43,8 +43,8 @@ def __init__( *, columns_to_anodes=DiodeOrientation.COL2ROW, interval=0.02, - max_events=64, debounce_threshold=1, + max_events=64, ): self.keypad = keypad.KeyMatrix( row_pins, @@ -71,6 +71,7 @@ def __init__( value_when_pressed=False, pull=True, interval=0.02, + debounce_threshold=1, max_events=64, ): self.keypad = keypad.Keys( @@ -78,6 +79,7 @@ def __init__( value_when_pressed=value_when_pressed, pull=pull, interval=interval, + debounce_threshold=debounce_threshold, max_events=max_events, ) super().__init__() @@ -94,6 +96,7 @@ def __init__( key_count, value_when_pressed=False, interval=0.02, + debounce_threshold=1, max_events=64, ): self.keypad = keypad.ShiftRegisterKeys( @@ -104,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__() From b7e41f5800b6c812df631e15e378a644b027716f Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:24:21 +0300 Subject: [PATCH 04/18] Update scanners.md --- docs/en/scanners.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index b1f5e5be3..473197317 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -69,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.02, # How often the matrix is sampled + debounce_threshold=1, # Number of samples needed to change state max_events=64 ) ``` @@ -95,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.02, # How often the matrix is sampled + debounce_threshold=1, # Number of samples needed to change state max_events=64 ) ``` From fdd5fdd7c3b8aeccb28248371c5214177fe95c39 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:26:56 +0300 Subject: [PATCH 05/18] Potentially saner defaults? --- kmk/scanners/keypad.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index a12f70cc3..95d9e335e 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -42,8 +42,8 @@ def __init__( column_pins, *, columns_to_anodes=DiodeOrientation.COL2ROW, - interval=0.02, - debounce_threshold=1, + interval=0.01, + debounce_threshold=2, max_events=64, ): self.keypad = keypad.KeyMatrix( @@ -70,8 +70,8 @@ def __init__( *, value_when_pressed=False, pull=True, - interval=0.02, - debounce_threshold=1, + interval=0.01, + debounce_threshold=2, max_events=64, ): self.keypad = keypad.Keys( @@ -95,8 +95,8 @@ def __init__( value_to_latch=True, key_count, value_when_pressed=False, - interval=0.02, - debounce_threshold=1, + interval=0.01, + debounce_threshold=2, max_events=64, ): self.keypad = keypad.ShiftRegisterKeys( From 526934088c2ffe4a3f6e19bdd0fea197f3f646db Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 21:28:01 +0300 Subject: [PATCH 06/18] Update scanners.md --- docs/en/scanners.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index 473197317..f8fd995ef 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -30,8 +30,8 @@ class MyKeyboard(KMKKeyboard): row_pins=self.row_pins, # optional arguments with defaults: columns_to_anodes=DiodeOrientation.COL2ROW, - interval=0.02, # How often the matrix is sampled - debounce_threshold=1, # Number of samples needed to change state + interval=0.01, # How often the matrix is sampled + debounce_threshold=2, # Number of samples needed to change state max_events=64 ) @@ -69,8 +69,8 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_when_pressed=False, pull=True, - interval=0.02, # How often the matrix is sampled - debounce_threshold=1, # Number of samples needed to change state + interval=0.01, # How often the matrix is sampled + debounce_threshold=2, # Number of samples needed to change state max_events=64 ) ``` @@ -96,8 +96,8 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_to_latch=True, # 74HC165: True, CD4021: False value_when_pressed=False, - interval=0.02, # How often the matrix is sampled - debounce_threshold=1, # Number of samples needed to change state + interval=0.01, # How often the matrix is sampled + debounce_threshold=2, # Number of samples needed to change state max_events=64 ) ``` From 458a2f8344c9e9cf6d3e70d554213b944ee1475b Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:26:48 +0300 Subject: [PATCH 07/18] Even saner defaults --- kmk/scanners/keypad.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 95d9e335e..743a69afa 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -43,7 +43,7 @@ def __init__( *, columns_to_anodes=DiodeOrientation.COL2ROW, interval=0.01, - debounce_threshold=2, + debounce_threshold=5, max_events=64, ): self.keypad = keypad.KeyMatrix( @@ -71,7 +71,7 @@ def __init__( value_when_pressed=False, pull=True, interval=0.01, - debounce_threshold=2, + debounce_threshold=5, max_events=64, ): self.keypad = keypad.Keys( @@ -96,7 +96,7 @@ def __init__( key_count, value_when_pressed=False, interval=0.01, - debounce_threshold=2, + debounce_threshold=5, max_events=64, ): self.keypad = keypad.ShiftRegisterKeys( From a39744a71921e4db89890fd27ddebf836827fb83 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 22:27:52 +0300 Subject: [PATCH 08/18] Update scanners.md --- docs/en/scanners.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index f8fd995ef..0f76a87a5 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -31,7 +31,7 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: columns_to_anodes=DiodeOrientation.COL2ROW, interval=0.01, # How often the matrix is sampled - debounce_threshold=2, # Number of samples needed to change state + debounce_threshold=5, # Number of samples needed to change state max_events=64 ) @@ -70,7 +70,7 @@ class MyKeyboard(KMKKeyboard): value_when_pressed=False, pull=True, interval=0.01, # How often the matrix is sampled - debounce_threshold=2, # Number of samples needed to change state + debounce_threshold=5, # Number of samples needed to change state max_events=64 ) ``` @@ -97,7 +97,7 @@ class MyKeyboard(KMKKeyboard): value_to_latch=True, # 74HC165: True, CD4021: False value_when_pressed=False, interval=0.01, # How often the matrix is sampled - debounce_threshold=2, # Number of samples needed to change state + debounce_threshold=5, # Number of samples needed to change state max_events=64 ) ``` From 6a67ec0da9e85b0d28c0015f12d0a1d99452f637 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:05:04 +0300 Subject: [PATCH 09/18] Update scanners.md --- docs/en/scanners.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index 0f76a87a5..5817a6ddd 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -30,7 +30,7 @@ class MyKeyboard(KMKKeyboard): row_pins=self.row_pins, # optional arguments with defaults: columns_to_anodes=DiodeOrientation.COL2ROW, - interval=0.01, # How often the matrix is sampled + interval=0.01, # Matrix sampling interval in ms debounce_threshold=5, # Number of samples needed to change state max_events=64 ) @@ -69,7 +69,7 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_when_pressed=False, pull=True, - interval=0.01, # How often the matrix is sampled + interval=0.01, # Matrix sampling interval in ms debounce_threshold=5, # Number of samples needed to change state max_events=64 ) @@ -96,7 +96,7 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_to_latch=True, # 74HC165: True, CD4021: False value_when_pressed=False, - interval=0.01, # How often the matrix is sampled + interval=0.01, # Matrix sampling interval in ms debounce_threshold=5, # Number of samples needed to change state max_events=64 ) From 914abbf8324f0846e2ab80a0e41be142867d5e0c Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:09:39 +0300 Subject: [PATCH 10/18] Revert to upstream defaults and add backwards compatibility --- kmk/scanners/keypad.py | 90 +++++++++++++++++++++++++++--------------- 1 file changed, 59 insertions(+), 31 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 743a69afa..7c5eaa2c4 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -42,18 +42,27 @@ def __init__( column_pins, *, columns_to_anodes=DiodeOrientation.COL2ROW, - interval=0.01, - debounce_threshold=5, + interval=0.02, + debounce_threshold=None, max_events=64, ): - self.keypad = keypad.KeyMatrix( + args = [ row_pins, column_pins, - columns_to_anodes=(columns_to_anodes == DiodeOrientation.COL2ROW), - interval=interval, - max_events=max_events, - debounce_threshold=debounce_threshold, - ) + ] + 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) super().__init__() @@ -70,18 +79,28 @@ def __init__( *, value_when_pressed=False, pull=True, - interval=0.01, - debounce_threshold=5, + interval=0.02, + debounce_threshold=None, max_events=64, + **kwargs ): - self.keypad = keypad.Keys( + args = [ pins, - value_when_pressed=value_when_pressed, - pull=pull, - interval=interval, - debounce_threshold=debounce_threshold, - max_events=max_events, - ) + ] + for i in args: + if i is None: + args.pop(i) + kwargs = { + 'value_when_pressed':value_when_pressed, + 'pull':pull, + '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) super().__init__() @@ -92,22 +111,31 @@ def __init__( clock, data, latch, - value_to_latch=True, key_count, + value_to_latch=True, value_when_pressed=False, - interval=0.01, - debounce_threshold=5, + interval=0.02, + debounce_threshold=None, 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, - debounce_threshold=debounce_threshold, - max_events=max_events, - ) + args = [ + clock, + data, + latch, + key_count, + ] + for i in args: + if i is None: + args.pop(i) + kwargs = { + 'value_to_latch':value_to_latch, + 'value_when_pressed':value_when_pressed, + '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) super().__init__() From 192bd407c88c4a49ecfe779c95949c92b23374d1 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:13:54 +0300 Subject: [PATCH 11/18] Lint --- kmk/scanners/keypad.py | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 7c5eaa2c4..cc7c29742 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -54,15 +54,15 @@ def __init__( if i is None: args.pop(i) kwargs = { - 'columns_to_anodes':columns_to_anodes, - 'interval':interval, - 'debounce_threshold':debounce_threshold, - 'max_events':max_events, + '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) + self.keypad = keypad.Keys(*args, **kwargs) super().__init__() @@ -82,7 +82,6 @@ def __init__( interval=0.02, debounce_threshold=None, max_events=64, - **kwargs ): args = [ pins, @@ -91,16 +90,16 @@ def __init__( if i is None: args.pop(i) kwargs = { - 'value_when_pressed':value_when_pressed, - 'pull':pull, - 'interval':interval, - 'debounce_threshold':debounce_threshold, - 'max_events':max_events, + 'value_when_pressed': value_when_pressed, + 'pull': pull, + '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) + self.keypad = keypad.Keys(*args, **kwargs) super().__init__() @@ -128,14 +127,14 @@ def __init__( if i is None: args.pop(i) kwargs = { - 'value_to_latch':value_to_latch, - 'value_when_pressed':value_when_pressed, - 'interval':interval, - 'debounce_threshold':debounce_threshold, - 'max_events':max_events, + 'value_to_latch': value_to_latch, + 'value_when_pressed': value_when_pressed, + '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) + self.keypad = keypad.Keys(*args, **kwargs) super().__init__() From e1d1b61532f7a33719deb3f2428ebe6aafb83aa5 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:25:51 +0300 Subject: [PATCH 12/18] Lint II --- kmk/scanners/keypad.py | 56 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index cc7c29742..ee3b9fd3e 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -4,23 +4,23 @@ class KeypadScanner(Scanner): - ''' + """ Translation layer around a CircuitPython 7 keypad scanner. :param pin_map: A sequence of (row, column) tuples for each key. :param kp: An instance of the keypad class. - ''' + """ @property def key_count(self): return self.keypad.key_count def scan_for_changes(self): - ''' + """ Scan for key events and return a key report if an event exists. The key report is a byte array with contents [row, col, True if pressed else False] - ''' + """ ev = self.keypad.events.get() if ev and self.offset: return keypad.Event(ev.key_number + self.offset, ev.pressed) @@ -28,13 +28,13 @@ def scan_for_changes(self): class MatrixScanner(KeypadScanner): - ''' + """ Row/Column matrix using the CircuitPython 7 keypad scanner. :param row_pins: A sequence of pins used for rows. :param col_pins: A sequence of pins used for columns. :param direction: The diode orientation of the matrix. - ''' + """ def __init__( self, @@ -49,16 +49,16 @@ def __init__( args = [ row_pins, column_pins, - ] + ] 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, - } + "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) @@ -67,11 +67,11 @@ def __init__( class KeysScanner(KeypadScanner): - ''' + """ GPIO-per-key 'matrix' using the native CircuitPython 7 keypad scanner. :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, @@ -85,17 +85,17 @@ def __init__( ): args = [ pins, - ] + ] for i in args: if i is None: args.pop(i) kwargs = { - 'value_when_pressed': value_when_pressed, - 'pull': pull, - 'interval': interval, - 'debounce_threshold': debounce_threshold, - 'max_events': max_events, - } + "value_when_pressed": value_when_pressed, + "pull": pull, + "interval": interval, + "debounce_threshold": debounce_threshold, + "max_events": max_events, + } for key, value in kwargs.items(): if value is None: kwargs.pop(key) @@ -122,17 +122,17 @@ def __init__( data, latch, key_count, - ] + ] for i in args: if i is None: args.pop(i) kwargs = { - 'value_to_latch': value_to_latch, - 'value_when_pressed': value_when_pressed, - 'interval': interval, - 'debounce_threshold': debounce_threshold, - 'max_events': max_events, - } + "value_to_latch": value_to_latch, + "value_when_pressed": value_when_pressed, + "interval": interval, + "debounce_threshold": debounce_threshold, + "max_events": max_events, + } for key, value in kwargs.items(): if value is None: kwargs.pop(key) From de212c928b93e88bd519caf528d7011974e3e1ae Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:28:38 +0300 Subject: [PATCH 13/18] Lint III --- kmk/scanners/keypad.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index ee3b9fd3e..8bb03b31f 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -54,10 +54,10 @@ def __init__( if i is None: args.pop(i) kwargs = { - "columns_to_anodes": columns_to_anodes, - "interval": interval, - "debounce_threshold": debounce_threshold, - "max_events": max_events, + '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: @@ -90,11 +90,11 @@ def __init__( if i is None: args.pop(i) kwargs = { - "value_when_pressed": value_when_pressed, - "pull": pull, - "interval": interval, - "debounce_threshold": debounce_threshold, - "max_events": max_events, + 'value_when_pressed': value_when_pressed, + 'pull': pull, + 'interval': interval, + 'debounce_threshold': debounce_threshold, + 'max_events': max_events, } for key, value in kwargs.items(): if value is None: @@ -127,11 +127,11 @@ def __init__( if i is None: args.pop(i) kwargs = { - "value_to_latch": value_to_latch, - "value_when_pressed": value_when_pressed, - "interval": interval, - "debounce_threshold": debounce_threshold, - "max_events": max_events, + 'value_to_latch': value_to_latch, + 'value_when_pressed': value_when_pressed, + 'interval': interval, + 'debounce_threshold': debounce_threshold, + 'max_events': max_events, } for key, value in kwargs.items(): if value is None: From 8ccf24ef83a3407fbf8d126f476dbfb8870c49f4 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:30:05 +0300 Subject: [PATCH 14/18] Lint IV --- kmk/scanners/keypad.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 8bb03b31f..4721e8560 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -4,23 +4,23 @@ class KeypadScanner(Scanner): - """ + ''' Translation layer around a CircuitPython 7 keypad scanner. :param pin_map: A sequence of (row, column) tuples for each key. :param kp: An instance of the keypad class. - """ + ''' @property def key_count(self): return self.keypad.key_count def scan_for_changes(self): - """ + ''' Scan for key events and return a key report if an event exists. The key report is a byte array with contents [row, col, True if pressed else False] - """ + ''' ev = self.keypad.events.get() if ev and self.offset: return keypad.Event(ev.key_number + self.offset, ev.pressed) @@ -28,13 +28,13 @@ def scan_for_changes(self): class MatrixScanner(KeypadScanner): - """ + ''' Row/Column matrix using the CircuitPython 7 keypad scanner. :param row_pins: A sequence of pins used for rows. :param col_pins: A sequence of pins used for columns. :param direction: The diode orientation of the matrix. - """ + ''' def __init__( self, @@ -67,11 +67,11 @@ def __init__( class KeysScanner(KeypadScanner): - """ + ''' GPIO-per-key 'matrix' using the native CircuitPython 7 keypad scanner. :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, From da47bc149924695d1b28253f1e154e6e77afda9b Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:45:44 +0300 Subject: [PATCH 15/18] Update scanners.md --- docs/en/scanners.md | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/en/scanners.md b/docs/en/scanners.md index 5817a6ddd..7576b557a 100644 --- a/docs/en/scanners.md +++ b/docs/en/scanners.md @@ -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 + +You can find out more in the [CircuitPython documentation](https://docs.circuitpython.org/en/latest/shared-bindings/keypad/index.html). ### keypad MatrixScanner @@ -30,8 +34,8 @@ class MyKeyboard(KMKKeyboard): row_pins=self.row_pins, # optional arguments with defaults: columns_to_anodes=DiodeOrientation.COL2ROW, - interval=0.01, # Matrix sampling interval in ms - debounce_threshold=5, # Number of samples needed to change state + 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 ) @@ -69,8 +73,8 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_when_pressed=False, pull=True, - interval=0.01, # Matrix sampling interval in ms - debounce_threshold=5, # Number of samples needed to change state + 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 ) ``` @@ -96,8 +100,8 @@ class MyKeyboard(KMKKeyboard): # optional arguments with defaults: value_to_latch=True, # 74HC165: True, CD4021: False value_when_pressed=False, - interval=0.01, # Matrix sampling interval in ms - debounce_threshold=5, # Number of samples needed to change state + 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 ) ``` From 8035917140fa760154b574151ab6f1bc4150c57d Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 02:50:40 +0300 Subject: [PATCH 16/18] Update aspell.en.pws --- util/aspell.en.pws | 1 + 1 file changed, 1 insertion(+) diff --git a/util/aspell.en.pws b/util/aspell.en.pws index f2ee422b2..379d18ad7 100644 --- a/util/aspell.en.pws +++ b/util/aspell.en.pws @@ -33,6 +33,7 @@ Crkbd Crowboard Ctrl Cygwin +debounce DFU DISCOVERABLE DIY From 3fb4952f91c2ff18ac1c22b3fdb3cdfeb37ef825 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:04:40 +0300 Subject: [PATCH 17/18] Catching all them arguments --- kmk/scanners/keypad.py | 87 ++---------------------------------------- 1 file changed, 3 insertions(+), 84 deletions(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 4721e8560..0be0699c6 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -36,32 +36,7 @@ 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, - debounce_threshold=None, - max_events=64, - ): - args = [ - row_pins, - column_pins, - ] - 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) + def __init__(self, *args, **kwargs): self.keypad = keypad.Keys(*args, **kwargs) super().__init__() @@ -73,68 +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, - debounce_threshold=None, - max_events=64, - ): - args = [ - pins, - ] - for i in args: - if i is None: - args.pop(i) - kwargs = { - 'value_when_pressed': value_when_pressed, - 'pull': pull, - 'interval': interval, - 'debounce_threshold': debounce_threshold, - 'max_events': max_events, - } - for key, value in kwargs.items(): - if value is None: - kwargs.pop(key) + def __init__(self, *args, **kwargs): self.keypad = keypad.Keys(*args, **kwargs) super().__init__() class ShiftRegisterKeys(KeypadScanner): - def __init__( - self, - *, - clock, - data, - latch, - key_count, - value_to_latch=True, - value_when_pressed=False, - interval=0.02, - debounce_threshold=None, - max_events=64, - ): - args = [ - clock, - data, - latch, - key_count, - ] - for i in args: - if i is None: - args.pop(i) - kwargs = { - 'value_to_latch': value_to_latch, - 'value_when_pressed': value_when_pressed, - 'interval': interval, - 'debounce_threshold': debounce_threshold, - 'max_events': max_events, - } - for key, value in kwargs.items(): - if value is None: - kwargs.pop(key) + def __init__(self, *args, **kwargs): self.keypad = keypad.Keys(*args, **kwargs) super().__init__() From cbb14e28614c03289a70f9ba67ba41846f046529 Mon Sep 17 00:00:00 2001 From: "regicidal.plutophage" <36969337+regicidalplutophage@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:14:18 +0300 Subject: [PATCH 18/18] Remove unused import --- kmk/scanners/keypad.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kmk/scanners/keypad.py b/kmk/scanners/keypad.py index 0be0699c6..9979142cd 100644 --- a/kmk/scanners/keypad.py +++ b/kmk/scanners/keypad.py @@ -1,6 +1,6 @@ import keypad -from kmk.scanners import DiodeOrientation, Scanner +from kmk.scanners import Scanner class KeypadScanner(Scanner):