blob: 5fee44db5dd6de671edae504867ada7d8df7b4e5 (
plain)
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
|
import array
import threading
import time
from ola.OlaClient import OlaClient, OLADNotRunningException
class OLAOutput:
name = "OLA"
def set_values(self, values):
send = set()
for c, v in values.items():
univ, addr = c.address
if univ not in self.universes:
self.universes[univ] = array.array('B', (0 for i in range(512)))
uni = self.universes[univ]
if uni[addr] != v:
uni[addr] = v
send.add(univ)
with self._clock:
if self.client is not None:
for univ in send:
self.client.SendDmx(univ, self.universes[univ])
def _setup_client(self):
while True:
try:
self.client = OlaClient()
except OLADNotRunningException:
time.sleep(1)
else:
break
@property
def ok(self):
with self._clock:
return self.client is not None
@property
def status(self):
with self._clock:
if self.client is None:
return "Unable to connect to olad"
else:
return "Everything's good"
def __init__(self):
self.client_thread = None
try:
self.client = OlaClient()
except OLADNotRunningException:
self.client = None
self.client_thread = threading.Thread(target=self._setup_client)
self.client_thread.start()
self.universes = {1: array.array('B', (0 for i in range(512)))}
self._clock = threading.RLock()
|