12
12
kb_asciimap ,
13
13
)
14
14
15
- Point2D = namedtuple (' Point2D' , ['x' , 'y' ])
16
- Chart = namedtuple (' Chart' , [' value' , ' x_1' , ' x_2' ])
17
- KeyValue = namedtuple (' KeyValue' , [' first' , ' second' ])
15
+ Point2D = namedtuple (" Point2D" , ["x" , "y" ])
16
+ Chart = namedtuple (" Chart" , [" value" , " x_1" , " x_2" ])
17
+ KeyValue = namedtuple (" KeyValue" , [" first" , " second" ])
18
18
19
19
_X_map_chart = (
20
20
Chart (1 , 0 , 1 ),
28
28
29
29
_key_value_map = (
30
30
(
31
- KeyValue (ord ('`' ), ord ('~' )),
32
- KeyValue (ord ('1' ), ord ('!' )),
33
- KeyValue (ord ('2' ), ord ('@' )),
34
- KeyValue (ord ('3' ), ord ('#' )),
35
- KeyValue (ord ('4' ), ord ('$' )),
36
- KeyValue (ord ('5' ), ord ('%' )),
37
- KeyValue (ord ('6' ), ord ('^' )),
38
- KeyValue (ord ('7' ), ord ('&' )),
39
- KeyValue (ord ('8' ), ord ('*' )),
40
- KeyValue (ord ('9' ), ord ('(' )),
41
- KeyValue (ord ('0' ), ord (')' )),
42
- KeyValue (ord ('-' ), ord ('_' )),
43
- KeyValue (ord ('=' ), ord ('+' )),
31
+ KeyValue (ord ("`" ), ord ("~" )),
32
+ KeyValue (ord ("1" ), ord ("!" )),
33
+ KeyValue (ord ("2" ), ord ("@" )),
34
+ KeyValue (ord ("3" ), ord ("#" )),
35
+ KeyValue (ord ("4" ), ord ("$" )),
36
+ KeyValue (ord ("5" ), ord ("%" )),
37
+ KeyValue (ord ("6" ), ord ("^" )),
38
+ KeyValue (ord ("7" ), ord ("&" )),
39
+ KeyValue (ord ("8" ), ord ("*" )),
40
+ KeyValue (ord ("9" ), ord ("(" )),
41
+ KeyValue (ord ("0" ), ord (")" )),
42
+ KeyValue (ord ("-" ), ord ("_" )),
43
+ KeyValue (ord ("=" ), ord ("+" )),
44
44
KeyValue (KEY_BACKSPACE , KEY_BACKSPACE ),
45
45
),
46
46
(
47
47
KeyValue (KEY_TAB , KEY_TAB ),
48
- KeyValue (ord ('q' ), ord ('Q' )),
49
- KeyValue (ord ('w' ), ord ('W' )),
50
- KeyValue (ord ('e' ), ord ('E' )),
51
- KeyValue (ord ('r' ), ord ('R' )),
52
- KeyValue (ord ('t' ), ord ('T' )),
53
- KeyValue (ord ('y' ), ord ('Y' )),
54
- KeyValue (ord ('u' ), ord ('U' )),
55
- KeyValue (ord ('i' ), ord ('I' )),
56
- KeyValue (ord ('o' ), ord ('O' )),
57
- KeyValue (ord ('p' ), ord ('P' )),
58
- KeyValue (ord ('[' ), ord ('{' )),
59
- KeyValue (ord (']' ), ord ('}' )),
60
- KeyValue (ord (' \\ ' ), ord ('|' )),
48
+ KeyValue (ord ("q" ), ord ("Q" )),
49
+ KeyValue (ord ("w" ), ord ("W" )),
50
+ KeyValue (ord ("e" ), ord ("E" )),
51
+ KeyValue (ord ("r" ), ord ("R" )),
52
+ KeyValue (ord ("t" ), ord ("T" )),
53
+ KeyValue (ord ("y" ), ord ("Y" )),
54
+ KeyValue (ord ("u" ), ord ("U" )),
55
+ KeyValue (ord ("i" ), ord ("I" )),
56
+ KeyValue (ord ("o" ), ord ("O" )),
57
+ KeyValue (ord ("p" ), ord ("P" )),
58
+ KeyValue (ord ("[" ), ord ("{" )),
59
+ KeyValue (ord ("]" ), ord ("}" )),
60
+ KeyValue (ord (" \\ " ), ord ("|" )),
61
61
),
62
62
(
63
63
KeyValue (KEY_FN , KEY_FN ),
64
64
KeyValue (KEY_LEFT_SHIFT , KEY_LEFT_SHIFT ),
65
- KeyValue (ord ('a' ), ord ('A' )),
66
- KeyValue (ord ('s' ), ord ('S' )),
67
- KeyValue (ord ('d' ), ord ('D' )),
68
- KeyValue (ord ('f' ), ord ('F' )),
69
- KeyValue (ord ('g' ), ord ('G' )),
70
- KeyValue (ord ('h' ), ord ('H' )),
71
- KeyValue (ord ('j' ), ord ('J' )),
72
- KeyValue (ord ('k' ), ord ('K' )),
73
- KeyValue (ord ('l' ), ord ('L' )),
74
- KeyValue (ord (';' ), ord (':' )),
75
- KeyValue (ord (' \' ' ), ord ('\ " ' )),
65
+ KeyValue (ord ("a" ), ord ("A" )),
66
+ KeyValue (ord ("s" ), ord ("S" )),
67
+ KeyValue (ord ("d" ), ord ("D" )),
68
+ KeyValue (ord ("f" ), ord ("F" )),
69
+ KeyValue (ord ("g" ), ord ("G" )),
70
+ KeyValue (ord ("h" ), ord ("H" )),
71
+ KeyValue (ord ("j" ), ord ("J" )),
72
+ KeyValue (ord ("k" ), ord ("K" )),
73
+ KeyValue (ord ("l" ), ord ("L" )),
74
+ KeyValue (ord (";" ), ord (":" )),
75
+ KeyValue (ord ("'" ), ord ('"' )),
76
76
KeyValue (KEY_ENTER , KEY_ENTER ),
77
77
),
78
78
(
79
79
KeyValue (KEY_LEFT_CTRL , KEY_LEFT_CTRL ),
80
80
KeyValue (KEY_OPT , KEY_OPT ),
81
81
KeyValue (KEY_LEFT_ALT , KEY_LEFT_ALT ),
82
- KeyValue (ord ('z' ), ord ('Z' )),
83
- KeyValue (ord ('x' ), ord ('X' )),
84
- KeyValue (ord ('c' ), ord ('C' )),
85
- KeyValue (ord ('v' ), ord ('V' )),
86
- KeyValue (ord ('b' ), ord ('B' )),
87
- KeyValue (ord ('n' ), ord ('N' )),
88
- KeyValue (ord ('m' ), ord ('M' )),
89
- KeyValue (ord (',' ), ord ('<' )),
90
- KeyValue (ord ('.' ), ord ('>' )),
91
- KeyValue (ord ('/' ), ord ('?' )),
92
- KeyValue (ord (' ' ), ord (' ' )),
82
+ KeyValue (ord ("z" ), ord ("Z" )),
83
+ KeyValue (ord ("x" ), ord ("X" )),
84
+ KeyValue (ord ("c" ), ord ("C" )),
85
+ KeyValue (ord ("v" ), ord ("V" )),
86
+ KeyValue (ord ("b" ), ord ("B" )),
87
+ KeyValue (ord ("n" ), ord ("N" )),
88
+ KeyValue (ord ("m" ), ord ("M" )),
89
+ KeyValue (ord ("," ), ord ("<" )),
90
+ KeyValue (ord ("." ), ord (">" )),
91
+ KeyValue (ord ("/" ), ord ("?" )),
92
+ KeyValue (ord (" " ), ord (" " )),
93
93
),
94
94
)
95
95
96
96
97
97
class KeysState :
98
- tab = False
99
- fn = False
100
- shift = False
101
- ctrl = False
102
- opt = False
103
- alt = False
104
- delete = False
105
- enter = False
106
- space = False
107
- modifiers = 0
98
+ tab = False
99
+ fn = False
100
+ shift = False
101
+ ctrl = False
102
+ opt = False
103
+ alt = False
104
+ delete = False
105
+ enter = False
106
+ space = False
107
+ modifiers = 0
108
108
109
109
def __init__ (self ) -> None :
110
110
self .word = bytearray (0 )
111
111
self .hid_keys = bytearray (0 )
112
112
self .modifier_keys = bytearray (0 )
113
113
114
114
def reset (self ):
115
- self .tab = False
116
- self .fn = False
117
- self .shift = False
118
- self .ctrl = False
119
- self .opt = False
120
- self .alt = False
121
- self .delete = False
122
- self .enter = False
123
- self .space = False
124
- self .modifiers = 0
115
+ self .tab = False
116
+ self .fn = False
117
+ self .shift = False
118
+ self .ctrl = False
119
+ self .opt = False
120
+ self .alt = False
121
+ self .delete = False
122
+ self .enter = False
123
+ self .space = False
124
+ self .modifiers = 0
125
125
self .word = bytearray (0 )
126
126
self .hid_keys = bytearray (0 )
127
127
self .modifier_keys = bytearray (0 )
128
128
129
129
130
130
class Keyboard :
131
-
132
131
def __init__ (self ):
133
- self .output_list = [ Pin (id , Pin .OUT , Pin .PULL_DOWN ) for id in (8 , 9 , 11 ) ]
134
- self .input_list = [ Pin (id , Pin .IN , Pin .PULL_UP ) for id in (13 , 15 , 3 , 4 , 5 , 6 , 7 ) ]
132
+ self .output_list = [Pin (id , Pin .OUT , Pin .PULL_DOWN ) for id in (8 , 9 , 11 )]
133
+ self .input_list = [Pin (id , Pin .IN , Pin .PULL_UP ) for id in (13 , 15 , 3 , 4 , 5 , 6 , 7 )]
135
134
136
135
for pin in self .output_list :
137
136
pin .value (0 )
@@ -148,20 +147,20 @@ def __init__(self):
148
147
149
148
@staticmethod
150
149
def _set_output (pin_list , output ):
151
- output = output & 0B00000111
152
- pin_list [0 ].value (output & 0B00000001 )
153
- pin_list [1 ].value (output & 0B00000010 )
154
- pin_list [2 ].value (output & 0B00000100 )
150
+ output = output & 0b00000111
151
+ pin_list [0 ].value (output & 0b00000001 )
152
+ pin_list [1 ].value (output & 0b00000010 )
153
+ pin_list [2 ].value (output & 0b00000100 )
155
154
156
155
@staticmethod
157
156
def _get_input (pin_list ):
158
- buffer = 0x00
157
+ buffer = 0x00
159
158
pin_value = 0x00
160
159
161
160
for i in range (7 ):
162
161
pin_value = 0x00 if pin_list [i ].value () == 1 else 0x01
163
162
pin_value = pin_value << i
164
- buffer = buffer | pin_value
163
+ buffer = buffer | pin_value
165
164
166
165
return buffer
167
166
@@ -171,11 +170,7 @@ def getKey(self, point: Point2D):
171
170
if point .x < 0 or point .y < 0 :
172
171
return ret
173
172
174
- if (
175
- self ._keys_state_buffer .ctrl
176
- or self ._keys_state_buffer .shift
177
- or self ._is_caps_locked
178
- ):
173
+ if self ._keys_state_buffer .ctrl or self ._keys_state_buffer .shift or self ._is_caps_locked :
179
174
ret = _key_value_map [point .x ][point .y ].second
180
175
else :
181
176
ret = _key_value_map [point .x ][point .y ].first
@@ -272,7 +267,7 @@ def updateKeysState(self):
272
267
self ._key_pos_hid_keys .append (i )
273
268
continue
274
269
275
- if self .getKeyValue (i ).first == ' ' :
270
+ if self .getKeyValue (i ).first == " " :
276
271
self ._keys_state_buffer .space = True
277
272
278
273
self ._key_pos_hid_keys .append (i )
@@ -283,7 +278,7 @@ def updateKeysState(self):
283
278
self ._keys_state_buffer .modifier_keys .append (key )
284
279
285
280
for k in self ._keys_state_buffer .modifier_keys :
286
- self ._keys_state_buffer .modifiers |= ( 1 << (k - 0x80 ) )
281
+ self ._keys_state_buffer .modifiers |= 1 << (k - 0x80 )
287
282
288
283
for i in self ._key_pos_hid_keys :
289
284
k = self .getKeyValue (i ).first
0 commit comments