qmsk.dmx.web: basic dmx update/output
authorTero Marttila <terom@paivola.fi>
Thu, 01 May 2014 23:44:42 +0300
changeset 84 9ebf1a2cee3a
parent 83 136e210fce82
child 85 ee05d89bde77
qmsk.dmx.web: basic dmx update/output
qmsk/dmx/heads.py
qmsk/dmx/web.py
--- a/qmsk/dmx/heads.py	Thu May 01 23:34:20 2014 +0300
+++ b/qmsk/dmx/heads.py	Thu May 01 23:44:42 2014 +0300
@@ -54,9 +54,6 @@
         for attr in self.channels :
             yield self.attrs.get(attr, 0)
 
-    def __call__ (self, dmx) :
-        dmx[self.channel] = tuple(self)
-
 class Stairville_LEDPar56 (Head) :
     CHANNELS = [
         'control1',
--- a/qmsk/dmx/web.py	Thu May 01 23:34:20 2014 +0300
+++ b/qmsk/dmx/web.py	Thu May 01 23:44:42 2014 +0300
@@ -23,7 +23,7 @@
 
     color[c] = 255
     if value :
-        color[alpha] = value / 255.0
+        color['alpha'] = value / 255.0
 
     return colorize(input(head, c, value), **color)
 
@@ -61,14 +61,18 @@
 
     def process (self) :
         if self.request.method == 'POST' :
-            # XXX
-            r, g, b = tuple((int(x, 16) if x else 0) for x in (
-                    self.request.form.get('r'),
-                    self.request.form.get('g'),
-                    self.request.form.get('b'),
-            ))
+            for name, value in self.request.form.iteritems() :
+                head_name, attr = name.split('-', 1)
+                head = self.app.heads[head_name]
 
-            self.app.dmx_color(r, g, b, 255)
+                if value :
+                    value = int(value)
+                    
+                    # update head
+                    head[attr] = value
+
+            # update dmx
+            self.app.update() 
 
     def render_head (self, name, head) :
         if head.alpha() is None :
@@ -131,3 +135,11 @@
 
         self.dmx = dmx
         self.heads = heads
+
+    def update (self) :
+        if not self.dmx :
+            return
+
+        for head in self.heads.itervalues() :
+            self.dmx[head.channel] = tuple(head)
+