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
 
@@ -2,7 +2,7 @@ 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
 
@@ -166,21 +166,22 @@ class LedLoop(EffectLoop):
 
                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()])
0 comments (0 inline, 0 general)