# HG changeset patch # User drewp@bigasterisk.com # Date 2015-06-13 06:09:24 # Node ID fccb6ca6516decd54777a6d85e3df20248fda2d2 # Parent b174f95a3b8dd0e0cebcc8dc46559e376179d87a currentSubLevel lets subs drive effects Ignore-this: 13c5c1743c456386b8aca36a189d905b diff --git a/light9/effecteval/effect.py b/light9/effecteval/effect.py --- a/light9/effecteval/effect.py +++ b/light9/effecteval/effect.py @@ -127,6 +127,32 @@ class EffectNode(object): inNames.discard(outName) deps[outName] = inNames self.codes = [codeFromOutput[n] for n in toposort.toposort_flatten(deps)] + + def _currentSubSettingValues(self, sub): + """what KC subSettings are setting levels right now?""" + cs = self.graph.currentState + with cs(tripleFilter=(None, L9['sub'], sub)) as g1: + for subj in g1.subjects(L9['sub'], sub): + with cs(tripleFilter=(subj, None, None)) as g2: + if (subj, RDF.type, L9['SubSetting']) in g2: + v = g2.value(subj, L9['level']).toPython() + yield v + + def currentSubLevel(self, uri): + """what's the max level anyone (probably KC) is + holding this sub to right now?""" + if isinstance(uri, Submaster.Submaster): + # likely the uri was spotted and replaced + uri = uri.uri + if not isinstance(uri, URIRef): + raise TypeError("got %r" % uri) + + foundLevels = list(self._currentSubSettingValues(uri)) + + if not foundLevels: + return 0 + + return max(foundLevels) def eval(self, songTime): ns = {'t': songTime} @@ -134,6 +160,7 @@ class EffectNode(object): ns.update(dict( curve=lambda c, t: c.eval(t), + currentSubLevel=self.currentSubLevel, )) for c in self.codes: diff --git a/light9/effecteval/effectloop.py b/light9/effecteval/effectloop.py --- a/light9/effecteval/effectloop.py +++ b/light9/effecteval/effectloop.py @@ -154,7 +154,7 @@ class EffectLoop(object): now = time.time() if now > self.lastErrorLog + 5: if hasattr(exc, 'expr'): - log.error('in expression %r', exc.expr) + log.exception('in expression %r', exc.expr) log.error("effect %s: %s" % (e.uri, exc)) self.lastErrorLog = now log.debug('eval %s effects, got %s outputs', len(self.currentEffects), len(outputs)) @@ -182,7 +182,7 @@ Z = numpy.zeros((50, 3), dtype=numpy.flo class ControlBoard(object): def __init__(self, dev='/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A7027NYX-if00-port0'): - self._dev = None#serial.Serial(dev, baudrate=115200) + self._dev = serial.Serial(dev, baudrate=115200) def _8bitMessage(self, floatArray): px255 = (numpy.clip(floatArray, 0, 1) * 255).astype(numpy.uint8) @@ -221,7 +221,7 @@ class ControlBoard(object): class LedLoop(EffectLoop): def initOutput(self): self.board = ControlBoard() - self.lastSent = {} + self.lastSent = {} # what's in arduino's memory def combineOutputs(self, outputs): combined = {'L': Z, 'R': Z, @@ -229,6 +229,7 @@ class LedLoop(EffectLoop): 'rgb': numpy.zeros((1, 3), dtype=numpy.float16)} for out in outputs: + log.debug('combine output %r', out) if isinstance(out, Effects.Blacklight): key = 'blacklight%s' % out.which combined[key] = max(combined[key], out) @@ -247,14 +248,17 @@ class LedLoop(EffectLoop): ('setUv', (0,), combined['blacklight0']), ('setUv', (1,), combined['blacklight1']), ('setRgb', (), combined['rgb']), - ]: + ]: key = (meth, selectArgs) - if self.lastSent.get(key) == value: + compValue = value.tolist() if isinstance(value, numpy.ndarray) else value + + if self.lastSent.get(key) == compValue: continue log.debug('value changed: %s(%s %s)', meth, selectArgs, value) + getattr(self.board, meth)(*(selectArgs + (value,))) - self.lastSent[key] = value + self.lastSent[key] = compValue yield succeed(None) # there was an attempt at an async send