# HG changeset patch # User Drew Perttula # Date 2014-06-13 08:04:07 # Node ID b0b9b4616e164f40b5879a9e20b8b208b6b0b3b5 # Parent 63ab21eb7bbf87f22b4e6b97087bd5e73576797d try serial writing in other thread(s) Ignore-this: ec59a76e9afcaf530d68aa245991b89a diff --git a/light9/effecteval/effectloop.py b/light9/effecteval/effectloop.py --- a/light9/effecteval/effectloop.py +++ b/light9/effecteval/effectloop.py @@ -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()])