pythonify Potentiometer state

This commit is contained in:
BigTuna94
2022-05-04 20:29:28 -04:00
committed by Kyle Brown
parent b97fca7c76
commit a4d6a44a04
2 changed files with 17 additions and 11 deletions

View File

@@ -4,6 +4,12 @@ from supervisor import ticks_ms
from kmk.modules import Module
class PotentiometerState:
def __init__(self, direction: int, position: int):
self.direction = direction
self.position = position
class Potentiometer:
def __init__(self, pin, move_callback, is_inverted=False):
self.is_inverted = is_inverted
@@ -16,11 +22,11 @@ class Potentiometer:
# callback function on events.
self.on_move_do = lambda state: self.cb(state)
def get_state(self):
return {
'direction': self.is_inverted and -self._direction or self._direction,
'position': self.is_inverted and -self._pos or self._pos,
}
def get_state(self) -> PotentiometerState:
return PotentiometerState(
direction=(self.is_inverted and -self._direction or self._direction),
position=(self.is_inverted and -self._pos or self._pos),
)
def get_pos(self):
'''