44 lines
958 B
Python
44 lines
958 B
Python
import digitalio
|
|
from micropython import const
|
|
|
|
|
|
class PinState:
|
|
PRESSED: int = const(0)
|
|
RELEASED: int = const(1)
|
|
|
|
|
|
class PinEvent:
|
|
NO_EVENT: int = const(0)
|
|
PRESSED: int = const(1)
|
|
RELEASED: int = const(2)
|
|
|
|
|
|
class PinStates:
|
|
current: int
|
|
previous: int
|
|
|
|
def __init__(self, current: int, previous: int):
|
|
self.current = current
|
|
self.previous = previous
|
|
|
|
|
|
class Pin:
|
|
index: int
|
|
hw_pin: digitalio.DigitalInOut
|
|
|
|
def __init__(self, index, hw_pin: digitalio.DigitalInOut):
|
|
self.index = index
|
|
self.hw_pin = hw_pin
|
|
self.previous_state = PinState.RELEASED
|
|
|
|
def _consume_next_state(self) -> PinStates:
|
|
states = PinStates(int(self.hw_pin.value), int(self.previous_state))
|
|
self.previous_state = states.current
|
|
return states
|
|
|
|
def read_event(self) -> int:
|
|
raise NotImplementedError()
|
|
|
|
def get_value(self) -> int:
|
|
return self.hw_pin.value
|