Skip to content

Commit

Permalink
Implemented the reviewer suggestion for the GPIO constructor to take …
Browse files Browse the repository at this point in the history
…in an additional optional argument defaulting to Pull.UP instead of overloading the argument with a tuple. This is tested, and documented in English
  • Loading branch information
Gordon Jamieson committed Oct 13, 2023
1 parent 5d4e9b5 commit 9f0c772
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/en/encoder.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ encoder_handler = EncoderHandler()
keyboard.modules = [layers, holdtap, encoder_handler]
```

2. Define the pins for each encoder: `pin_a`, `pin_b` for rotations, `pin_button` for the switch in the encoder. Set switch to `None` if the encoder's button is handled differently (as a part of matrix for example) or not at all. If you want to invert the direction of the encoder, set the 4th (optional) parameter `is_inverted` to `True`. 5th parameter is [encoder divisor](#encoder-resolution) (optional), it can be either `2` or `4`.
2. Define the pins for each encoder: `pin_a`, `pin_b` for rotations, `pin_button` for the switch in the encoder. Set switch to `None` if the encoder's button is handled differently (as a part of matrix for example) or not at all. If you want to invert the direction of the encoder, set the 4th (optional) parameter `is_inverted` to `True`. 5th parameter is [encoder divisor](#encoder-resolution) (optional), it can be either `2` or `4`. If your encoder button pull direction is not the default of `digitalio.Pull.UP`, you may specify the 6th (optional) parameter `button_pull` as `digitalio.Pull.DOWN`.

```python
# Regular GPIO Encoder
encoder_handler.pins = (
Expand Down
10 changes: 5 additions & 5 deletions kmk/modules/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def vel_report(self):


class GPIOEncoder(BaseEncoder):
def __init__(self, pin_a, pin_b, pin_button=None, is_inverted=False, divisor=None):
def __init__(self, pin_a, pin_b, pin_button=None, is_inverted=False, divisor=None, button_pull=digitalio.Pull.UP):
super().__init__(is_inverted)

# Divisor can be 4 or 2 depending on whether the detent
Expand All @@ -121,10 +121,10 @@ def __init__(self, pin_a, pin_b, pin_button=None, is_inverted=False, divisor=Non

self.pin_a = EncoderPin(pin_a)
self.pin_b = EncoderPin(pin_b)
self.pin_button = (
EncoderPin(*pin_button) if isinstance(pin_button, tuple) else
EncoderPin(pin_button, button_type=True) if pin_button is not None else None
)
if pin_button:
self.pin_button = EncoderPin(pin_button, button_type=True, pull=button_pull)
else:
self.pin_button = None

self._state = (self.pin_a.get_value(), self.pin_b.get_value())
self._start_state = self._state
Expand Down

0 comments on commit 9f0c772

Please sign in to comment.