Changeset - 070c6d185276
[Not reviewed]
default
0 3 0
Drew Perttula - 6 years ago 2019-06-01 20:06:19
drewp@bigasterisk.com
collector takes an explicit dmx message length (again). more collector timing
Ignore-this: 6db3f113ad4b209e114c1473543a5341
3 files changed with 18 insertions and 6 deletions:
0 comments (0 inline, 0 general)
bin/collector
Show inline comments
 
@@ -57,13 +57,13 @@ class Attrs(PrettyErrorHandler, cyclone.
 

	
 

	
 
def launch(graph, doLoadTest=False):
 
    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:
 
        log.error("setting up outputs:")
 
        traceback.print_exc()
 
        raise
light9/collector/device.py
Show inline comments
 
@@ -58,13 +58,13 @@ def resolve(
 
    if deviceAttr == DeviceAttr(L9['color']):
 
        rgbs = [hex_to_rgb(v) for v in values]
 
        return rgb_to_hex([max(*component) for component in zip(*rgbs)])
 
    # 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):
 
                floatVals.append(float(v.toPython()))
 
            elif isinstance(v, (int, float)):
 
                floatVals.append(float(v))
light9/collector/output.py
Show inline comments
 
@@ -43,13 +43,13 @@ class Output(object):
 
            log.debug(msg)
 
            self._lastLoggedMsg = msg
 

	
 
    _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
 
        too fast, or repeated if they are too slow)
 
        """
 
        pass
 
@@ -61,13 +61,13 @@ class DummyOutput(Output):
 
        super().__init__(uri)
 

	
 

	
 
class BackgroundLoopOutput(Output):
 
    """Call _write forever at 20hz in background threads"""
 

	
 
    rate = 20  # Hz
 
    rate = 30  # Hz
 

	
 
    def __init__(self, uri):
 
        super().__init__(uri)
 
        self._currentBuffer = b''
 

	
 
        self._loop()
 
@@ -88,33 +88,45 @@ class BackgroundLoopOutput(Output):
 
        d = threads.deferToThread(self._write, sendingBuffer)
 
        d.addCallbacks(done, err)
 

	
 

	
 
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):
 
            raise ValueError("dmx open failed")
 

	
 
        super().__init__(uri)
 

	
 
    _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):
 
                    raise ValueError("incomplete send")
 

	
 
            except usb.core.USBError as e:
0 comments (0 inline, 0 general)