Changeset - b0b9b4616e16
[Not reviewed]
default
0 1 0
Drew Perttula - 11 years ago 2014-06-13 08:04:07
drewp@bigasterisk.com
try serial writing in other thread(s)
Ignore-this: ec59a76e9afcaf530d68aa245991b89a
1 file changed with 7 insertions and 6 deletions:
0 comments (0 inline, 0 general)
light9/effecteval/effectloop.py
Show inline comments
 
from __future__ import division
 
import time, json, logging, traceback
 
import numpy
 
import serial
 
from twisted.internet import reactor
 
from twisted.internet import reactor, threads
 
from twisted.internet.defer import inlineCallbacks, returnValue, succeed, TimeoutError
 
from rdflib import URIRef, Literal
 
import cyclone.httpclient
 
from light9.namespaces import L9, RDF, RDFS
 
from light9.effecteval.effect import EffectNode
 
from light9 import Effects
 
from light9 import networking
 
from light9 import Submaster
 
from light9 import dmxclient
 
log = logging.getLogger('effectloop')
 

	
 
class EffectLoop(object):
 
@@ -158,38 +158,39 @@ class LedLoop(EffectLoop):
 
        combined = {'L': Z, 'R': Z, 'blacklight': 0}
 
        
 
        for out in outputs:
 
            if isinstance(out, Effects.Blacklight):
 
                combined['blacklight'] = max(combined['blacklight'], int(out * 255))
 
            elif isinstance(out, Effects.Strip):
 
                pixels = numpy.array(out.pixels, dtype=numpy.float16)
 
                px255 = (numpy.clip(pixels, 0, 1) * 255).astype(numpy.uint8)
 
                combined[out.which] = numpy.maximum(combined[out.which], px255)
 
                
 
        return combined
 
                
 
    @inlineCallbacks
 
    def sendOutput(self, combined):
 
        for which, px255 in combined.items():
 
            if which == 'blacklight':
 
                if px255 != self.lastSentBacklight:
 
                    self.boards['L'].write('\x60\x01' + chr(px255))
 
                    self.boards['L'].flush()
 
                    yield threads.deferToThread(self.serialWrite, self.boards['L'], '\x60\x01' + chr(px255))
 
                    self.lastSentBacklight = px255
 
            else:
 
                board = self.boards[which]
 
                msg = '\x60\x00' + px255.reshape((-1,)).tostring()
 
                board.write(msg)
 
                board.flush()
 
                yield threads.deferToThread(self.serialWrite, board, msg)
 
                
 
        return succeed(None)
 
    def serialWrite(self, serial, msg):
 
        serial.write(msg)
 
        serial.flush()
 
        
 
    def logMessage(self, out):
 
        return str([(w, p.tolist() if isinstance(p, numpy.ndarray) else p) for w,p in out.items()])
 

	
 
def makeEffectLoop(graph, stats, outputWhere):
 
    if outputWhere == 'dmx':
 
        return EffectLoop(graph, stats)
 
    elif outputWhere == 'leds':
 
        return LedLoop(graph, stats)
 
    else:
 
        raise NotImplementedError
 

	
0 comments (0 inline, 0 general)