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

Added extra construction support to Encoder.py to support pullup direction from Code.py #891

Merged
merged 5 commits into from
Oct 18, 2023
Merged
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions kmk/modules/encoder.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ 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
Bob837217 marked this conversation as resolved.
Show resolved Hide resolved
EncoderPin(pin_button, button_type=True) if pin_button is not None else None
)

Expand All @@ -138,9 +139,10 @@ def button_event(self):


class EncoderPin:
def __init__(self, pin, button_type=False):
def __init__(self, pin, button_type=False, pull=digitalio.Pull.UP):
self.pin = pin
self.button_type = button_type
self.pull = pull
self.prepare_pin()

def prepare_pin(self):
Expand All @@ -150,12 +152,14 @@ def prepare_pin(self):
else:
self.io = digitalio.DigitalInOut(self.pin)
self.io.direction = digitalio.Direction.INPUT
self.io.pull = digitalio.Pull.UP
self.io.pull = self.pull
else:
self.io = None

def get_value(self):
return self.io.value
return (
self.io.value if digitalio.Pull.UP == self.io.pull else not self.io.value
)
Bob837217 marked this conversation as resolved.
Show resolved Hide resolved


class I2CEncoder(BaseEncoder):
Expand Down