Black formatting for lint test

This commit is contained in:
elric91 2021-09-19 10:48:35 +02:00 committed by Kyle Brown
parent 7993a4e415
commit 484bcc4d22

View File

@ -20,8 +20,10 @@
import board import board
import digitalio import digitalio
from kmk.modules import Module from kmk.modules import Module
# NB : not using rotaryio as it requires the pins to be consecutive # NB : not using rotaryio as it requires the pins to be consecutive
class Encoder: class Encoder:
_debug = False _debug = False
@ -44,7 +46,6 @@ class Encoder:
((True, True), (False, False)): 0, ((True, True), (False, False)): 0,
} }
def __init__(self, pin_a, pin_b, pin_button=None, is_inverted=False): def __init__(self, pin_a, pin_b, pin_button=None, is_inverted=False):
self.pin_a = EncoderPin(pin_a) self.pin_a = EncoderPin(pin_a)
self.pin_b = EncoderPin(pin_b) self.pin_b = EncoderPin(pin_b)
@ -61,26 +62,31 @@ class Encoder:
self.on_move_do = None self.on_move_do = None
self.on_button_do = None self.on_button_do = None
def get_state(self): def get_state(self):
return({'direction':self.is_inverted and -self._actual_direction or self._actual_direction, return {
'direction': self.is_inverted
and -self._actual_direction
or self._actual_direction,
'position': self.is_inverted and -self._actual_pos or self._actual_pos, 'position': self.is_inverted and -self._actual_pos or self._actual_pos,
'is_pressed':not self._actual_button_state}) 'is_pressed': not self._actual_button_state,
}
# to be called in a loop # to be called in a loop
def update_state(self): def update_state(self):
# Rotation events # Rotation events
new_state = (self.pin_a.get_value(), self.pin_b.get_value()) new_state = (self.pin_a.get_value(), self.pin_b.get_value())
if new_state != self._actual_state: if new_state != self._actual_state:
if self._debug : print(" ", new_state) if self._debug:
print(" ", new_state)
self._movement_counter += 1 self._movement_counter += 1
new_direction = self.STATES[(self._actual_state, new_state)] new_direction = self.STATES[(self._actual_state, new_state)]
if new_direction != 0: if new_direction != 0:
self._actual_direction = new_direction self._actual_direction = new_direction
# when the encoder settles on a position # when the encoder settles on a position
if new_state == (True, True) and self._movement_counter > 2 : # if < 2 state changes, it is a misstep if (
new_state == (True, True) and self._movement_counter > 2
): # if < 2 state changes, it is a misstep
self._movement_counter = 0 self._movement_counter = 0
self._actual_pos += self._actual_direction self._actual_pos += self._actual_direction
if self._debug: if self._debug:
@ -99,9 +105,7 @@ class Encoder:
self.on_button_do(self.get_state()) self.on_button_do(self.get_state())
class EncoderPin: class EncoderPin:
def __init__(self, pin, button_type=False): def __init__(self, pin, button_type=False):
self.pin = pin self.pin = pin
self.button_type = button_type self.button_type = button_type
@ -120,7 +124,6 @@ class EncoderPin:
class EncoderHandler(Module): class EncoderHandler(Module):
def __init__(self): def __init__(self):
self.encoders = [] self.encoders = []
self.pins = None self.pins = None
@ -160,7 +163,6 @@ class EncoderHandler(Module):
key = self.map[layer_id][encoder_id][2] key = self.map[layer_id][encoder_id][2]
keyboard.tap_key(key) keyboard.tap_key(key)
def before_matrix_scan(self, keyboard): def before_matrix_scan(self, keyboard):
''' '''
Return value will be injected as an extra matrix update Return value will be injected as an extra matrix update