-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathControlPanel.py
More file actions
134 lines (98 loc) · 3.68 KB
/
Copy pathControlPanel.py
File metadata and controls
134 lines (98 loc) · 3.68 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import serial
import socket
# Wanda Setup
PRINT_SENSORS_COMMAND = 0x55000000
ADD_SENSOR_COMMAND = 0xCF000000
wandaSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
wandaSocket.connect(('192.168.1.10', 35912))
except Exception as e:
print(f"Failed to connect: {e}")
exit(1)
# End Wanda Setup
# Serial Setup
PORT_NAME = 'COM3'
FILE_NAME = 'this.txt'
ser = serial.Serial(PORT_NAME, baudrate=115200, write_timeout=1.000)
ser.flushInput()
ser.flushOutput()
# End Serial Setup
def sendToLED():
pass
def sendToWanda(number: int):
number |= 0xBC000000
wandaSocket.sendall(number.to_bytes(length=4, byteorder="little", signed=False))
def bitFlip(instruction: int, bits: int):
return (instruction ^ (1 << bits))
def waitInstruction():
instruction = 0
while True:
instruction_code = ser.readline().decode('UTF-8').strip()
if instruction_code != "":
if instruction_code == "Empty":
continue
elif instruction_code == "Power":
instruction = bitFlip(instruction, 13)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nox Fill":
instruction = bitFlip(instruction, 1)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nox Vent":
instruction = bitFlip(instruction, 2)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nitrogen Fill":
instruction = bitFlip(instruction, 3)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nitrogen Vent":
instruction = bitFlip(instruction, 4)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nitrogen QD":
instruction = bitFlip(instruction, 5)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Nox QD":
instruction = bitFlip(instruction, 6)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Air QD":
instruction = bitFlip(instruction, 7)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Rocket Nox Vent":
instruction = bitFlip(instruction, 8)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Rocket Nitrogen Vent":
instruction = bitFlip(instruction, 9)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Enable Fire":
instruction = bitFlip(instruction, 10)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Fire":
instruction = bitFlip(instruction, 11)
sendToWanda(instruction)
sendToLED()
elif instruction_code == "Abort":
instruction = bitFlip(instruction, 12)
sendToWanda(instruction)
sendToLED()
def sendConfig():
with open('OLED', 'r') as f:
[ser.write(line.encode()) for line in f.readlines()] # Line is stripped in the arduino IDE
f.close()
def main():
while True:
var = ser.readline().decode('UTF-8').strip()
if var == "READY":
break
sendConfig()
waitInstruction()
if __name__ == '__main__':
main()