-
Notifications
You must be signed in to change notification settings - Fork 2
/
triad_matrix.py
101 lines (78 loc) · 2.23 KB
/
triad_matrix.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
import socket
import logging
from .matrix_commands import (
setOutputToInput,
setOutputVolume
)
_LOGGER = logging.getLogger(__name__)
def send_tcp_command(command, host, port):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((host, port))
sock.settimeout(300)
sock.setblocking(1)
try:
#_LOGGER.warn("Sending " + command.hex())
sock.sendall(command)
data = sock.recv(1024)
received = str(data)
#_LOGGER.warn("Received: " + str(received))
except socket.timeout:
received = "Timeout occurred during data reception"
_LOGGER.warn(received)
except Exception as e:
received = {e}
_LOGGER.warn("Exception " + str(received))
finally:
sock.close()
return received
class TriadMatrixOutputChannel(object):
# Represents an output channel of an Triad Audio Matrix
def __init__(self, host, port, channel):
self._host = host
self._port = port
self._channel = channel
self._source = 0
self._volume = 0
@property
def host(self):
return self._host
@property
def port(self):
return self._port
@property
def channel(self):
return self._channel
@property
def source(self):
return self._source
@source.setter
def source(self,value):
self._source = value
data = setOutputToInput[:]
data.append(self._channel-1)
if self._source == 0:
# this disconnects the output
# send an 8 for an 8 channel matrix
data.append(16)
else:
data.append(self._source-1)
send_tcp_command(data, self._host, self._port)
return 1
@source.deleter
def source(self):
del self._source
@property
def volume(self):
return self._volume
@volume.setter
def volume(self,value):
self._volume = value
data = setOutputVolume[:]
data.append(self._channel-1)
new_volume = int(float(self._volume) * 160)
data.append(new_volume)
send_tcp_command(data, self._host, self._port)
return 1
@volume.deleter
def volume(self):
del self._volume