changeset 1549:507581ee458b

modernize the output code for Mini15 Ignore-this: f44087b3bab188a81bb702ad1ffb7854
author Drew Perttula <drewp@bigasterisk.com>
date Fri, 19 May 2017 07:53:36 +0000
parents 5d8009daea51
children cbf4fc71d8d8
files light9/collector/device.py light9/collector/device_test.py
diffstat 2 files changed, 12 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/light9/collector/device.py	Fri May 19 07:49:22 2017 +0000
+++ b/light9/collector/device.py	Fri May 19 07:53:36 2017 +0000
@@ -59,7 +59,8 @@
                 floatVals.append(float(v))
             else:
                 raise TypeError(repr(v))
-            
+
+        # averaging with zeros? not so good
         return Literal(sum(floatVals) / len(floatVals))
     
     return max(values)
@@ -91,8 +92,8 @@
             _8bit(out.cmy_m),
             _8bit(out.cmy_y))
 
-    def fine16Attr(attr):
-        x = floatAttr(attr)
+    def fine16Attr(attr, scale=1.0):
+        x = floatAttr(attr) * scale
         hi = _8bit(x)
         lo = _8bit((x * 255) % 1.0)
         return hi, lo
@@ -108,26 +109,20 @@
     elif deviceType == L9['SimpleDimmer']:
         return {L9['level']: _8bit(floatAttr(L9['brightness']))}
     elif deviceType == L9['Mini15']:
-        inp = deviceAttrSettings
-        rx8 = float(inp.get(L9['rx'], 0)) / 540 * 255
-        ry8 = float(inp.get(L9['ry'], 0)) / 240 * 255
-        r, g, b = hex_to_rgb(inp.get(L9['color'], '#000000'))
-        return {
-            L9['xRotation']: clamp255(int(math.floor(rx8))),
-            # didn't find docs on this, but from tests it looks like 64 fine steps takes you to the next coarse step
-            L9['xFine']: _8bit(1 - (rx8 % 1.0)),
-            L9['yRotation']: clamp255(int(math.floor(ry8))),
-            L9['yFine']: _8bit((ry8 % 1.0) / 4),
+        out = {
             L9['rotationSpeed']: 0, # seems to have no effect
             L9['dimmer']: 255,
-            L9['red']: r,
-            L9['green']: g,
-            L9['blue']: b,
             L9['colorChange']: 0,
             L9['colorSpeed']: 0,
             L9['goboShake']: 0,
             L9['goboChoose']: 0,
         }
+        out[L9['red']], out[L9['green']], out[L9['blue']] = rgbAttr(L9['color'])
+        out[L9['xRotation']], out[L9['xFine']] = fine16Attr(L9['rx'], 1/540)
+        out[L9['yRotation']], out[L9['yFine']] = fine16Attr(L9['ry'], 1/240)
+        # didn't find docs on this, but from tests it looks like 64 fine steps takes you to the next coarse step
+
+        return out
     elif deviceType == L9['ChauvetHex12']:
         out = {}
         out[L9['red']], out[L9['green']], out[L9['blue']] = r, g, b = rgbAttr(L9['color'])
--- a/light9/collector/device_test.py	Fri May 19 07:49:22 2017 +0000
+++ b/light9/collector/device_test.py	Fri May 19 07:53:36 2017 +0000
@@ -35,7 +35,7 @@
         self.assertEqual(42, out[L9['xRotation']])
         self.assertEqual(127, out[L9['xFine']])
         self.assertEqual(47, out[L9['yRotation']])
-        self.assertEqual(51, out[L9['yFine']])
+        self.assertEqual(207, out[L9['yFine']])
         self.assertEqual(0, out[L9['rotationSpeed']])
         
 class TestResolve(unittest.TestCase):