Skip to content

Commit

Permalink
style: code format
Browse files Browse the repository at this point in the history
Signed-off-by: lbuque <[email protected]>
  • Loading branch information
lbuque committed Feb 4, 2024
1 parent 4bd264d commit bacf8fe
Show file tree
Hide file tree
Showing 25 changed files with 895 additions and 713 deletions.
169 changes: 82 additions & 87 deletions m5stack/libs/hardware/keyboard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
kb_asciimap,
)

Point2D = namedtuple('Point2D', ['x', 'y'])
Chart = namedtuple('Chart', ['value', 'x_1', 'x_2'])
KeyValue = namedtuple('KeyValue', ['first', 'second'])
Point2D = namedtuple("Point2D", ["x", "y"])
Chart = namedtuple("Chart", ["value", "x_1", "x_2"])
KeyValue = namedtuple("KeyValue", ["first", "second"])

_X_map_chart = (
Chart(1, 0, 1),
Expand All @@ -28,110 +28,109 @@

_key_value_map = (
(
KeyValue(ord('`'), ord('~')),
KeyValue(ord('1'), ord('!')),
KeyValue(ord('2'), ord('@')),
KeyValue(ord('3'), ord('#')),
KeyValue(ord('4'), ord('$')),
KeyValue(ord('5'), ord('%')),
KeyValue(ord('6'), ord('^')),
KeyValue(ord('7'), ord('&')),
KeyValue(ord('8'), ord('*')),
KeyValue(ord('9'), ord('(')),
KeyValue(ord('0'), ord(')')),
KeyValue(ord('-'), ord('_')),
KeyValue(ord('='), ord('+')),
KeyValue(ord("`"), ord("~")),
KeyValue(ord("1"), ord("!")),
KeyValue(ord("2"), ord("@")),
KeyValue(ord("3"), ord("#")),
KeyValue(ord("4"), ord("$")),
KeyValue(ord("5"), ord("%")),
KeyValue(ord("6"), ord("^")),
KeyValue(ord("7"), ord("&")),
KeyValue(ord("8"), ord("*")),
KeyValue(ord("9"), ord("(")),
KeyValue(ord("0"), ord(")")),
KeyValue(ord("-"), ord("_")),
KeyValue(ord("="), ord("+")),
KeyValue(KEY_BACKSPACE, KEY_BACKSPACE),
),
(
KeyValue(KEY_TAB, KEY_TAB),
KeyValue(ord('q'), ord('Q')),
KeyValue(ord('w'), ord('W')),
KeyValue(ord('e'), ord('E')),
KeyValue(ord('r'), ord('R')),
KeyValue(ord('t'), ord('T')),
KeyValue(ord('y'), ord('Y')),
KeyValue(ord('u'), ord('U')),
KeyValue(ord('i'), ord('I')),
KeyValue(ord('o'), ord('O')),
KeyValue(ord('p'), ord('P')),
KeyValue(ord('['), ord('{')),
KeyValue(ord(']'), ord('}')),
KeyValue(ord('\\'), ord('|')),
KeyValue(ord("q"), ord("Q")),
KeyValue(ord("w"), ord("W")),
KeyValue(ord("e"), ord("E")),
KeyValue(ord("r"), ord("R")),
KeyValue(ord("t"), ord("T")),
KeyValue(ord("y"), ord("Y")),
KeyValue(ord("u"), ord("U")),
KeyValue(ord("i"), ord("I")),
KeyValue(ord("o"), ord("O")),
KeyValue(ord("p"), ord("P")),
KeyValue(ord("["), ord("{")),
KeyValue(ord("]"), ord("}")),
KeyValue(ord("\\"), ord("|")),
),
(
KeyValue(KEY_FN, KEY_FN),
KeyValue(KEY_LEFT_SHIFT, KEY_LEFT_SHIFT),
KeyValue(ord('a'), ord('A')),
KeyValue(ord('s'), ord('S')),
KeyValue(ord('d'), ord('D')),
KeyValue(ord('f'), ord('F')),
KeyValue(ord('g'), ord('G')),
KeyValue(ord('h'), ord('H')),
KeyValue(ord('j'), ord('J')),
KeyValue(ord('k'), ord('K')),
KeyValue(ord('l'), ord('L')),
KeyValue(ord(';'), ord(':')),
KeyValue(ord('\''), ord('\"')),
KeyValue(ord("a"), ord("A")),
KeyValue(ord("s"), ord("S")),
KeyValue(ord("d"), ord("D")),
KeyValue(ord("f"), ord("F")),
KeyValue(ord("g"), ord("G")),
KeyValue(ord("h"), ord("H")),
KeyValue(ord("j"), ord("J")),
KeyValue(ord("k"), ord("K")),
KeyValue(ord("l"), ord("L")),
KeyValue(ord(";"), ord(":")),
KeyValue(ord("'"), ord('"')),
KeyValue(KEY_ENTER, KEY_ENTER),
),
(
KeyValue(KEY_LEFT_CTRL, KEY_LEFT_CTRL),
KeyValue(KEY_OPT, KEY_OPT),
KeyValue(KEY_LEFT_ALT, KEY_LEFT_ALT),
KeyValue(ord('z'), ord('Z')),
KeyValue(ord('x'), ord('X')),
KeyValue(ord('c'), ord('C')),
KeyValue(ord('v'), ord('V')),
KeyValue(ord('b'), ord('B')),
KeyValue(ord('n'), ord('N')),
KeyValue(ord('m'), ord('M')),
KeyValue(ord(','), ord('<')),
KeyValue(ord('.'), ord('>')),
KeyValue(ord('/'), ord('?')),
KeyValue(ord(' '), ord(' ')),
KeyValue(ord("z"), ord("Z")),
KeyValue(ord("x"), ord("X")),
KeyValue(ord("c"), ord("C")),
KeyValue(ord("v"), ord("V")),
KeyValue(ord("b"), ord("B")),
KeyValue(ord("n"), ord("N")),
KeyValue(ord("m"), ord("M")),
KeyValue(ord(","), ord("<")),
KeyValue(ord("."), ord(">")),
KeyValue(ord("/"), ord("?")),
KeyValue(ord(" "), ord(" ")),
),
)


class KeysState:
tab = False
fn = False
shift = False
ctrl = False
opt = False
alt = False
delete = False
enter = False
space = False
modifiers = 0
tab = False
fn = False
shift = False
ctrl = False
opt = False
alt = False
delete = False
enter = False
space = False
modifiers = 0

def __init__(self) -> None:
self.word = bytearray(0)
self.hid_keys = bytearray(0)
self.modifier_keys = bytearray(0)

def reset(self):
self.tab = False
self.fn = False
self.shift = False
self.ctrl = False
self.opt = False
self.alt = False
self.delete = False
self.enter = False
self.space = False
self.modifiers = 0
self.tab = False
self.fn = False
self.shift = False
self.ctrl = False
self.opt = False
self.alt = False
self.delete = False
self.enter = False
self.space = False
self.modifiers = 0
self.word = bytearray(0)
self.hid_keys = bytearray(0)
self.modifier_keys = bytearray(0)


class Keyboard:

def __init__(self):
self.output_list = [ Pin(id, Pin.OUT, Pin.PULL_DOWN) for id in (8, 9, 11) ]
self.input_list = [ Pin(id, Pin.IN, Pin.PULL_UP) for id in (13, 15, 3, 4, 5, 6, 7) ]
self.output_list = [Pin(id, Pin.OUT, Pin.PULL_DOWN) for id in (8, 9, 11)]
self.input_list = [Pin(id, Pin.IN, Pin.PULL_UP) for id in (13, 15, 3, 4, 5, 6, 7)]

for pin in self.output_list:
pin.value(0)
Expand All @@ -148,20 +147,20 @@ def __init__(self):

@staticmethod
def _set_output(pin_list, output):
output = output & 0B00000111
pin_list[0].value(output & 0B00000001)
pin_list[1].value(output & 0B00000010)
pin_list[2].value(output & 0B00000100)
output = output & 0b00000111
pin_list[0].value(output & 0b00000001)
pin_list[1].value(output & 0b00000010)
pin_list[2].value(output & 0b00000100)

@staticmethod
def _get_input(pin_list):
buffer = 0x00
buffer = 0x00
pin_value = 0x00

for i in range(7):
pin_value = 0x00 if pin_list[i].value() == 1 else 0x01
pin_value = pin_value << i
buffer = buffer | pin_value
buffer = buffer | pin_value

return buffer

Expand All @@ -171,11 +170,7 @@ def getKey(self, point: Point2D):
if point.x < 0 or point.y < 0:
return ret

if (
self._keys_state_buffer.ctrl
or self._keys_state_buffer.shift
or self._is_caps_locked
):
if self._keys_state_buffer.ctrl or self._keys_state_buffer.shift or self._is_caps_locked:
ret = _key_value_map[point.x][point.y].second
else:
ret = _key_value_map[point.x][point.y].first
Expand Down Expand Up @@ -272,7 +267,7 @@ def updateKeysState(self):
self._key_pos_hid_keys.append(i)
continue

if self.getKeyValue(i).first == ' ':
if self.getKeyValue(i).first == " ":
self._keys_state_buffer.space = True

self._key_pos_hid_keys.append(i)
Expand All @@ -283,7 +278,7 @@ def updateKeysState(self):
self._keys_state_buffer.modifier_keys.append(key)

for k in self._keys_state_buffer.modifier_keys:
self._keys_state_buffer.modifiers |= (1 << (k - 0x80))
self._keys_state_buffer.modifiers |= 1 << (k - 0x80)

for i in self._key_pos_hid_keys:
k = self.getKeyValue(i).first
Expand Down
33 changes: 16 additions & 17 deletions m5stack/libs/hardware/keyboard/asciimap.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@


SHIFT = 0x80

KEY_LEFT_CTRL = 0x80
KEY_LEFT_CTRL = 0x80
KEY_LEFT_SHIFT = 0x81
KEY_LEFT_ALT = 0x82
KEY_LEFT_ALT = 0x82

KEY_FN = 0xff
KEY_FN = 0xFF
KEY_OPT = 0x00

KEY_BACKSPACE = 0x2a
KEY_TAB = 0x2b
KEY_ENTER = 0x28
KEY_BACKSPACE = 0x2A
KEY_TAB = 0x2B
KEY_ENTER = 0x28

# +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
# | NUL | SOH | STX | ETX | EOT | ENQ | ACK | BEL | BS | TAB | LF | VT | FF | CR | SO | SI |
Expand Down Expand Up @@ -46,12 +44,13 @@
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
# | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
# +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
kb_asciimap = \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x2a\x2b\x28\x00\x00\x00\x00\x00' \
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
b'\x2c\x9e\xb4\xa0\xa1\xa2\xa4\x34\xa6\xa7\xa5\xae\x36\x2d\x37\x38' \
b'\x27\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\xb3\x33\xb6\x2e\xb7\xb8' \
b'\x9f\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92' \
b'\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x2f\x31\x30\xa3\xad' \
b'\x35\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12' \
b'\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\xaf\xb1\xb0\xb5\x00'
kb_asciimap = (
b"\x00\x00\x00\x00\x00\x00\x00\x00\x2a\x2b\x28\x00\x00\x00\x00\x00"
b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
b"\x2c\x9e\xb4\xa0\xa1\xa2\xa4\x34\xa6\xa7\xa5\xae\x36\x2d\x37\x38"
b"\x27\x1e\x1f\x20\x21\x22\x23\x24\x25\x26\xb3\x33\xb6\x2e\xb7\xb8"
b"\x9f\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92"
b"\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x2f\x31\x30\xa3\xad"
b"\x35\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12"
b"\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\xaf\xb1\xb0\xb5\x00"
)
1 change: 1 addition & 0 deletions m5stack/libs/hardware/matrix_keyboard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .keyboard import Keyboard
from micropython import schedule


class MatrixKeyboard(Keyboard):
def __init__(self) -> None:
super().__init__()
Expand Down
1 change: 1 addition & 0 deletions m5stack/libs/image_plus/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from M5 import Widgets

try:
import urequests as requests
except ImportError:
Expand Down
1 change: 1 addition & 0 deletions m5stack/libs/label_plus.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from M5 import Widgets

try:
import urequests as requests
except ImportError:
Expand Down
1 change: 0 additions & 1 deletion m5stack/libs/m5camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
_visible = True



def init(
x, y, width, height, pixformat=RGB565, framesize=FRAME_QVGA, fb_count=2, fb_location=IN_PSRAM
) -> None:
Expand Down
2 changes: 1 addition & 1 deletion m5stack/libs/module/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
_attrs = {
"DualKmeterModule": "dual_kmeter",
"Relay4Module": "relay_4",
"Encoder4MotorModule": "encoder4_motor"
"Encoder4MotorModule": "encoder4_motor",
}

# Lazy loader, effectively does:
Expand Down
Loading

0 comments on commit bacf8fe

Please sign in to comment.