changeset 1916:070c6d185276

collector takes an explicit dmx message length (again). more collector timing Ignore-this: 6db3f113ad4b209e114c1473543a5341
author Drew Perttula <drewp@bigasterisk.com>
date Sat, 01 Jun 2019 20:06:19 +0000
parents 44016c6caba5
children 713e56e8e2b9
files bin/collector light9/collector/device.py light9/collector/output.py
diffstat 3 files changed, 18 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/bin/collector	Sat Jun 01 20:05:53 2019 +0000
+++ b/bin/collector	Sat Jun 01 20:06:19 2019 +0000
@@ -60,7 +60,7 @@
     try:
         # todo: drive outputs with config files
         outputs = [
-            Udmx(L9['output/dmxA/'], bus=None, address=None),
+            Udmx(L9['output/dmxA/'], bus=None, address=None, lastDmxChannel=221),
             DummyOutput(L9['output/dmxB/']),
         ]
     except Exception:
--- a/light9/collector/device.py	Sat Jun 01 20:05:53 2019 +0000
+++ b/light9/collector/device.py	Sat Jun 01 20:06:19 2019 +0000
@@ -61,7 +61,7 @@
     # incomplete. how-to-resolve should be on the DeviceAttr defs in the graph.
     if deviceAttr in map(
             DeviceAttr,
-        [L9['rx'], L9['ry'], L9['zoom'], L9['focus'], L9['iris']]):
+            [L9['rx'], L9['ry'], L9['zoom'], L9['focus'], L9['iris']]):
         floatVals = []
         for v in values:
             if isinstance(v, Literal):
--- a/light9/collector/output.py	Sat Jun 01 20:05:53 2019 +0000
+++ b/light9/collector/output.py	Sat Jun 01 20:06:19 2019 +0000
@@ -46,7 +46,7 @@
     _writeSucceed = scales.IntStat('write/succeed')
     _writeFail = scales.IntStat('write/fail')
     _writeCall = scales.PmfStat('write/call')
-
+    _writeFps = scales.RecentFpsStat('write/fps')
     def _write(self, buf: bytes) -> None:
         """
         write buffer to output hardware (may be throttled if updates are
@@ -64,7 +64,7 @@
 class BackgroundLoopOutput(Output):
     """Call _write forever at 20hz in background threads"""
 
-    rate = 20  # Hz
+    rate = 30  # Hz
 
     def __init__(self, uri):
         super().__init__(uri)
@@ -91,7 +91,8 @@
 
 class Udmx(BackgroundLoopOutput):
 
-    def __init__(self, uri, bus, address):
+    def __init__(self, uri, bus, address, lastDmxChannel):
+        self.lastDmxChannel = lastDmxChannel
         from pyudmx import pyudmx
         self.dev = pyudmx.uDMXDevice()
         if not self.dev.open(bus=bus, address=address):
@@ -101,17 +102,28 @@
 
     _writeOverflow = scales.IntStat('write/overflow')
 
+    #def update(self, buf:bytes):
+    #    self._write(buf)
+
+    #def _loop(self):
+    #    pass
     def _write(self, buf):
+        self._writeFps.mark()
         with self._writeCall.time():
             try:
                 if not buf:
                     return
 
+                # ok to truncate the last channels if they just went
+                # to 0? No it is not. DMX receivers don't add implicit
+                # zeros there.
+                buf = buf[:self.lastDmxChannel]
+
                 if logAllDmx.isEnabledFor(logging.DEBUG):
                     # for testing fps, smooth fades, etc
                     logAllDmx.debug(
                         '%s: %s' %
-                        (self.shortId(), ' '.join(map(str, buf[:20]))))
+                        (self.shortId(), ' '.join(map(str, buf[:16]))))
 
                 sent = self.dev.send_multi_value(1, buf)
                 if sent != len(buf):