diff options
author | Ben Connors <benconnors@outlook.com> | 2019-11-08 23:36:02 -0500 |
---|---|---|
committer | Ben Connors <benconnors@outlook.com> | 2019-11-08 23:37:06 -0500 |
commit | 19bc10f5df5fa88a7ec8fac70dd5e070a639d730 (patch) | |
tree | f83e50012db59c6b7955375fbaf104edefd672d8 /interface | |
parent | e7a0cc042c298682799ed4a47c8ee4639fc44517 (diff) |
Fix some output stuff
- Can now defer output load, retry if it fails
- New command for showing (currently) output status
Diffstat (limited to 'interface')
-rw-r--r-- | interface/interface.py | 14 | ||||
-rw-r--r-- | interface/ola.py | 45 |
2 files changed, 55 insertions, 4 deletions
diff --git a/interface/interface.py b/interface/interface.py index 7528653..08fd17d 100644 --- a/interface/interface.py +++ b/interface/interface.py @@ -90,6 +90,10 @@ class Interface: todisp.append("Authored by %s, last modified at %s" % (self.w.author, self.w.modified.strftime("%Y-%m-%d %H:%M:%S"))) self.pager.display_many(todisp) + + if not self.output.ok: + self.pager.display_many(("WARNING: Output is not OK!",), True) + self.input.main(self._resize) def handle_show(self, f): @@ -587,6 +591,12 @@ class Interface: return "Step index out of range" self.renderer.advance((n, (p-1) if p is not None else p)) + def current_status(self): + self.pager.display_many(( + "CURRENT STATUS", + "Output is %sOK: %s" % ("" if self.output.ok else "NOT ", self.output.status), + ), True) + def __init__(self, path, output): ## Have to do most of the actual initialization in the main method, as curses isn't ## ready yet. @@ -635,6 +645,8 @@ class Interface: ("list chasers", lambda: self.list_functions(CHASER)), ("list audio", lambda: self.list_functions(AUDIO)), + ("currentstatus", lambda: self.current_status()), + ("pager page", self.page), ("pager clear", self.page_clear), ("quit", self.base_quit), @@ -752,6 +764,8 @@ class Interface: ("advance $num", lambda n: self.run_jump(n, None, False)), ("advance", lambda: self.run_jump(0, None, True)), ("badvance", lambda: self.run_jump(1, None, True)), + + ("currentstatus", self.current_status), )) self.output = output 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() |