-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutils.py
53 lines (48 loc) · 1.37 KB
/
utils.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
import sys
import glob
import serial
import serial.tools.list_ports
import socket
import time
from SerialConsole import SerialConsole
def serial_ports():
ports = list(serial.tools.list_ports.comports())
result = {}
for p in ports:
result[p.device] = p.description
return result
def get_computer_name():
return socket.gethostname()
PRESETS = {
"MODE_RAINBOW": "1",
"MODE_RAINBOW_CYCLE": "2",
"MODE_RAINBOW_THEATRE": "3",
"MODE_THEATRE_WHITE": "4",
"MODE_THEATRE_RED": "5",
"MODE_THEATRE_GREEN": "6",
"MODE_THEATRE_BLUE": "7",
"MODE_RED": "8",
"MODE_GREEN": "9",
"MODE_BLUE": "10",
"MODE_WHITE": "CUSTOM#255#255#255",
"MODE_CUSTOM": "11",
"MODE_MOVE": "12",
"CHANGE_WAIT_TIME_1": "WT#1",
"CHANGE_WAIT_TIME_5": "WT#5",
"CHANGE_WAIT_TIME_10": "WT#10",
"CHANGE_WAIT_TIME_20": "WT#20",
"CHANGE_WAIT_TIME_30": "WT#30",
"CHANGE_WAIT_TIME_40": "WT#40",
"CHANGE_WAIT_TIME_50": "WT#50"
}
def handle_change(data):
selected_com = data['selectedPort']
argb_mode = data['argbMode']
argb_value = data['customARGB']
a = serial.Serial(selected_com, 9600, timeout=.1)
time.sleep(5)
instruction = argb_mode if argb_mode != PRESETS['MODE_CUSTOM'] else "CUSTOM#"+argb_value
a.write(bytearray(instruction, 'utf-8'))
a.close()
if __name__ == '__main__':
print(serial_ports())