-
Notifications
You must be signed in to change notification settings - Fork 0
/
caveControl.py
145 lines (122 loc) · 4.48 KB
/
caveControl.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
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
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/env python
#GUI
import wx
from data.layout import maingui
#transmissions
from threading import Thread, active_count
import socket #for christie
import telnetlib #for marantz
class Transmit():
def __init__(self):
self.callback = None
#projectors
self.ips = ["172.22.1." + str(i) for i in range(101,111)]
#audio
self.audioIP = "172.22.1.50"
#dispatch to all projectors
def allProjectors(self, command):
for i in range(len(self.ips)):
thr = Thread(target=self._transmitThread, args=(i, command))
thr.start()
#dispatch to 1 projector
def projector(self, id, command):
thr = Thread(target=self._transmitThread, args=(id, command))
thr.start()
def _transmitThread(self, id, command):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(5.0)
ip = self.ips[int(id) - 1]
try:
s.connect((ip, 3002))
s.send(("(#" + command + ")").encode())
response = str(s.recv(1024).decode())
self.callback.gridUpdate(id, response)
except socket.timeout:
self.callback.gridUpdate(id, "Timeout")
s.close()
def audio(self, command):
thr = Thread(target=self._transmitAudio, args=(command,))
thr.start()
def _transmitAudio(self, command):
#is the connection still open?
try:
self.tn.sock_avail()
except:
self.tn = telnetlib.Telnet()
try:
self.tn.open(self.audioIP, 23, 3)
except:
return
try:
self.tn.write((command + "\r").encode())
#print(self.tn.read_eager().decode())
#print(response)
self.callback.gridUpdate(10, command)
except:
self.callback.gridUpdate(10, "Message error.")
class gui(maingui):
def __init__(self,parent):
#initialize widgets
maingui.__init__(self,parent)
#initialize grid statuses
transmit.callback = self
transmit.allProjectors("PWR?")
transmit.audio("PW?")
def togglePower(self, event):
if event.IsChecked():
event.GetEventObject().SetLabel("ON")
transmit.allProjectors("PWR1")
else:
#confirm power off, because the cooldown takes uninterruptible minutes
dlg = wx.MessageDialog(None, "Are you sure you want to shut down the projectors?",'Confirm', wx.YES_NO | wx.ICON_QUESTION)
result = dlg.ShowModal()
if result == wx.ID_YES:
event.GetEventObject().SetLabel("OFF")
transmit.allProjectors("PWR0")
else:
event.GetEventObject().SetValue(True)
def toggleShutters(self, event):
if event.IsChecked():
event.GetEventObject().SetLabel("OPEN")
transmit.allProjectors("SHU0")
else:
event.GetEventObject().SetLabel("CLOSED")
transmit.allProjectors("SHU1")
def toggleFloor(self, event):
if event.IsChecked():
event.GetEventObject().SetLabel("ON")
transmit.projector(9, "PWR1")
transmit.projector(10, "PWR1")
else:
event.GetEventObject().SetLabel("OFF")
transmit.projector(9, "PWR0")
transmit.projector(10, "PWR0")
def toggleStereo(self, event):
if event.IsChecked():
event.GetEventObject().SetLabel("ON")
transmit.allProjectors("TDM+MAIN5")
else:
event.GetEventObject().SetLabel("OFF")
transmit.allProjectors("TDM+MAIN0")
def toggleAudio(self, event):
if event.IsChecked():
event.GetEventObject().SetLabel("ON")
transmit.audio("PWON")
else:
event.GetEventObject().SetLabel("OFF")
transmit.audio("PWSTANDBY")
def updateVolume(self, event):
volume = "MV" + str(event.GetEventObject().GetValue()).zfill(2)
transmit.audio(volume)
#the threads call this when they're done
def gridUpdate(self, id, message):
self.grid.SetCellValue(row=id, col=0, s=message)
def quit(self, event):
transmit.tn.close()
wx.Exit()
if __name__ == '__main__':
app = wx.App(False)
transmit = Transmit()
frame = gui(None)
frame.Show()
app.MainLoop()