summaryrefslogtreecommitdiff
path: root/interface/ola.py
diff options
context:
space:
mode:
Diffstat (limited to 'interface/ola.py')
-rw-r--r--interface/ola.py45
1 files changed, 41 insertions, 4 deletions
diff --git a/interface/ola.py b/interface/ola.py
index 445b991..5fee44d 100644
--- a/interface/ola.py
+++ b/interface/ola.py
@@ -1,8 +1,13 @@
import array
-from ola.OlaClient import OlaClient
+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():
@@ -13,10 +18,42 @@ class OLAOutput:
if uni[addr] != v:
uni[addr] = v
send.add(univ)
- for univ in send:
- self.client.SendDmx(univ, self.universes[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 = OlaClient()
+ 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()