-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (59 loc) · 1.81 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
print("Starting main.py")
import gc
import traceback
import supervisor
import board
from misc.time import now, time_diff
from misc.switch import switch_pressed
from keyboard.controller import setup_keyboard
from keyboard.layout import setup_layout
# TODO use nrf EVENTS_USBDETECTED register?
ble_mode = True #not supervisor.runtime.usb_connected
# upper right switch
if board.board_id == 'itsybitsy_nrf52840_express':
ble_mode = not switch_pressed(board.D13, board.A0)
elif board.board_id == 'nice_nano':
ble_mode = not switch_pressed(board.P0_09, board.P1_06)
i = 0
last_exception = 0
while i < 5:
print("Setting up keyboard")
keyboard, deinit = setup_keyboard(ble_mode, 'Micro Qwertz BLE')
setup_layout(keyboard)
if __name__ != '__main__':
break
print("Started")
try:
keyboard.go()
if i > 0 and time_diff(now(), last_exception) > 5000:
i = 0
except Exception as e:
last_exception = now()
i += 1
traceback.print_exception(e)
try:
error = traceback.format_exception(e)
with open('/log.txt', 'a') as log:
for l in error:
log.writelines(l)
except Exception as log_e:
traceback.print_exception(log_e)
deinit()
del keyboard
del deinit
gc.collect()
# TODO
# (ZMK hold tap flavors)
# ble powersaving
# ble and usb
# ble multiple connections
# ble report battery level to host
# ble buffer hid reports until connected then replay
# ble explicitely enter pairing mode
# use native keypad scanner
# fix unit tests
# volume/mute keys
# Reset into UF2 bootloader: connect via serial port, start REPL with crtl+D, execute:
# import microcontroller
# microcontroller.on_next_reset(microcontroller.RunMode.UF2)
# microcontroller.reset()