-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·55 lines (45 loc) · 1.49 KB
/
manage.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
#!/usr/bin/env python3
# use this script to manage the passwords on the device
import sys
from getpass import getpass
from serial import Serial
from serial.tools.list_ports import comports
def usage():
print("Usage:")
print(" ", sys.argv[0], "rm")
print(" ", sys.argv[0], "add")
print(" ", sys.argv[0], "reset")
exit(1)
def get_port():
for port in comports():
if port.product == "Arduino Micro":
return port[0]
raise FileNotFoundError("Auto detection failed (searched for Arduino Micro)")
encoding = "latin-1"
baud_rate = 9600
if __name__ == "__main__":
try:
if len(sys.argv) < 2:
usage()
if sys.argv[1] == "add":
name = input("Account: ")
password = getpass("Password: ")
msg = name + "\x1F" + password + "\n"
with Serial(get_port(), baud_rate) as ser:
ser.write(msg.encode("utf8"))
elif sys.argv[1] == "rm":
name = input("Account: ")
msg = "\x08" + name + "\n"
with Serial(get_port(), baud_rate) as ser:
ser.write(msg.encode(encoding))
elif sys.argv[1] == "reset":
with Serial(get_port(), baud_rate) as ser:
ser.write("\x7F\n".encode(encoding))
elif sys.argv[1] == "find":
print("Found board on port", get_port())
else:
usage()
except FileNotFoundError as err:
print(err)
except KeyboardInterrupt:
print()