Mercurial > code > home > repos > light9
changeset 1127:b0b9b4616e16
try serial writing in other thread(s)
Ignore-this: ec59a76e9afcaf530d68aa245991b89a
author | Drew Perttula <drewp@bigasterisk.com> |
---|---|
date | Fri, 13 Jun 2014 08:04:07 +0000 |
parents | 63ab21eb7bbf |
children | d2fb69d9722d |
files | light9/effecteval/effectloop.py |
diffstat | 1 files changed, 9 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/light9/effecteval/effectloop.py Fri Jun 13 07:59:05 2014 +0000 +++ b/light9/effecteval/effectloop.py Fri Jun 13 08:04:07 2014 +0000 @@ -2,7 +2,7 @@ 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 @@ 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()])