changeset 1448:931d2dafca12

new feature: values can have their range remapped in the device processing Ignore-this: 542047e6307a304f2aa52a69d134ba21
author drewp@bigasterisk.com
date Sat, 11 Jun 2016 22:08:37 +0000
parents 8a9a9b58a4e2
children b76017f0b622
files light9/collector/collector.py light9/collector/device.py show/dance2016/theaterLightConfig.n3
diffstat 3 files changed, 22 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/light9/collector/collector.py	Sat Jun 11 21:40:37 2016 +0000
+++ b/light9/collector/collector.py	Sat Jun 11 22:08:37 2016 +0000
@@ -1,6 +1,7 @@
 from __future__ import division
 import time
 import logging
+from rdflib import Literal
 from light9.namespaces import L9, RDF, DEV
 from light9.collector.output import setListElem
 from light9.collector.device import toOutputAttrs, resolve
@@ -42,10 +43,17 @@
     def rebuildOutputMap(self):
         self.outputMap = outputMap(self.graph, self.outputs) # (device, attr) : (output, index)
         self.deviceType = {} # uri: type that's a subclass of Device
+        self.remapOut = {} # (device, deviceAttr) : (start, end)
         for dc in self.graph.subjects(RDF.type, L9['DeviceClass']):
             for dev in self.graph.subjects(RDF.type, dc):
                 self.deviceType[dev] = dc
 
+                for remap in self.graph.objects(dev, L9['outputAttrRange']):
+                    attr = self.graph.value(remap, L9['outputAttr'])
+                    start = float(self.graph.value(remap, L9['start']))
+                    end = float(self.graph.value(remap, L9['end']))
+                    self.remapOut[(dev, attr)] = start, end
+
     def _forgetStaleClients(self, now):
         staleClients = []
         for c, (_, t, _) in self.lastRequest.iteritems():
@@ -90,7 +98,9 @@
         prevClientSettings.update(self.resolvedSettingsDict(settings))
         self.lastRequest[client] = (clientSession, now, prevClientSettings)
 
-
+        # inputs that are omitted, implying a zero, should be added
+        # back here if they would remap to something nonzero.
+        
         deviceAttrs = {} # device: {deviceAttr: value}
         for _, _, lastSettings in self.lastRequest.itervalues():
             for (device, deviceAttr), value in lastSettings.iteritems():
@@ -98,6 +108,9 @@
                 if deviceAttr in attrs:
                     value = resolve(device, deviceAttr, [attrs[deviceAttr],
                                                          value])
+                if (device, deviceAttr) in self.remapOut:
+                    start, end = self.remapOut[(device, deviceAttr)]
+                    value = Literal(start + float(value) * (end - start))
                 attrs[deviceAttr] = value
 
         outputAttrs = {} # device: {outputAttr: value}
--- a/light9/collector/device.py	Sat Jun 11 21:40:37 2016 +0000
+++ b/light9/collector/device.py	Sat Jun 11 22:08:37 2016 +0000
@@ -58,6 +58,8 @@
     Given device attr settings like {L9['color']: Literal('#ff0000')},
     return a similar dict where the keys are output attrs (like
     L9['red']) and the values are suitable for Collector.setAttr
+
+    :outputAttrRange happens before we get here.
     """
     def floatAttr(attr, default=0):
         out = deviceAttrSettings.get(attr)
--- a/show/dance2016/theaterLightConfig.n3	Sat Jun 11 21:40:37 2016 +0000
+++ b/show/dance2016/theaterLightConfig.n3	Sat Jun 11 22:08:37 2016 +0000
@@ -21,8 +21,14 @@
 dev:cycL a :SimpleDimmer; :dmxUniverse dmxA:; :dmxBase 44 .
 
 dev:q1 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 325 .
+dev:q1 :outputAttrRange dev:q1rx . dev:q1rx :outputAttr :rx; :start 0.143; :end 0.271 .
+dev:q1 :outputAttrRange dev:q1ry . dev:q1ry :outputAttr :ry; :start 0.71; :end 0.821 .
 dev:q2 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 352 .
+dev:q2 :outputAttrRange dev:q2rx . dev:q2rx :outputAttr :rx; :start 0.097; :end 0.227 .
+dev:q2 :outputAttrRange dev:q2ry . dev:q2ry :outputAttr :ry; :start 0.739; :end 0.824 .
 dev:q3 a :MacQuantum; :dmxUniverse udmxB:; :dmxBase 379 .
+dev:q3 :outputAttrRange dev:q3rx . dev:q3rx :outputAttr :rx; :start 0.064; :end 0.198 .
+dev:q3 :outputAttrRange dev:q3ry . dev:q3ry :outputAttr :ry; :start 0.765; :end 0.822 .
 
 dev:aura1 a :MacAura; :dmxUniverse udmxB:; :dmxBase 406 .
 dev:aura2 a :MacAura; :dmxUniverse udmxB:; :dmxBase 420 .