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 9 insertions and 8 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
 
@@ -163,27 +163,28 @@ class LedLoop(EffectLoop):
 
            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()
 
                
 
        return succeed(None)
 
                yield threads.deferToThread(self.serialWrite, board, msg)
 

	
 
    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':
0 comments (0 inline, 0 general)