-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateConfiguration.py
executable file
·56 lines (49 loc) · 1.95 KB
/
StateConfiguration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from State import State
from KeyOptions import KeyOptions
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
import microcontroller
import time
class StateConfiguration(State):
def __init__(self, keyboard):
self.keyboard = keyboard
self.keyboard_layout = KeyboardLayoutUS(self.keyboard)
def start(self):
self.pixel.fill((0, 0, 255))
self.current = microcontroller.nvm[0]
if self.current >= len(KeyOptions.OPTIONS):
self.current = 0
self.make_keystrokes("Start Configuration")
self.make_keystrokes(Keycode.ENTER)
self.make_keystrokes(Keycode.ENTER)
self.make_keystrokes("Current Configuration ")
self.make_keystrokes(Keycode.ENTER)
self.make_keystrokes(KeyOptions.OPTIONS[self.current]["description"])
self.make_keystrokes(Keycode.ENTER)
self.make_keystrokes(Keycode.ENTER)
def end(self):
microcontroller.nvm[0] = self.current
pass
def onButtonPress(self):
self.current += 1
if self.current >= len(KeyOptions.OPTIONS):
self.current = 0
self.make_keystrokes(""+KeyOptions.OPTIONS[self.current]["description"])
self.make_keystrokes(Keycode.ENTER)
def doKeyStrokes(self, key_output):
if isinstance(self.key_output, (list, tuple)) and isinstance(self.key_output[0], dict):
for k in self.key_output:
self.make_keystrokes(k['keys'], k['delay'])
else:
self.make_keystrokes(self.key_output, delay=0)
pass
def make_keystrokes(self, keys):
if isinstance(keys, str):
self.keyboard_layout.write(keys)
elif isinstance(keys, int):
self.keyboard.press(keys)
self.keyboard.release_all()
elif isinstance(keys, (list, tuple)):
self.keyboard.press(*keys)
self.keyboard.release_all()
time.sleep(0.1)