Commits

wump  committed 6f1afa2

implement timed sequence

  • Participants
  • Parent commits 41f7f44

Comments (0)

Files changed (2)

File py/ambx/ambx.py

 '''
 import usb
 import logging
+
 from support.ByteArray import B,Bhex
 from support.usbutil import devices_by_vendor_product
 
 TIMEOUT_LIBUSBR = 2500
 TIMEOUT_LIBUSBW = 2500
 
+def float_to_rgb8(color):
+    return [min(max(int(x*256.0),0),255) for x in color]
+
 class AMBX(object):
     def __init__(self, dev=0, usbdev=None):
         self._log = logging.getLogger("AMBX.%i" % dev)
         self.write(B([PKT_HEADER, light, SET_LIGHT_COLOR, color[0], color[1], color[2]]))
         
     def set_color_float(self, light, color):
-        color8 = [min(max(int(x*256.0),0),255) for x in color]
-        self.set_color_rgb8(light, color8)
+        self.set_color_rgb8(light, float_to_rgb8(color))
 
+    def set_sequence_rgb8(self, light, millis, colors):
+        '''Set light color sequence'''
+        assert(millis >= 0 and millis <= 0xffff)
+        if not colors:
+            return
+        pkt = [PKT_HEADER, light, SET_TIMED_COLOR_SEQUENCE, millis >> 8, millis & 255]
+        for color in colors:
+            assert(len(color) == 3)
+            pkt.extend(color)
+        self.write(B(pkt))
+        
+    def set_sequence_float(self, light, millis, colors):
+        self.set_sequence_rgb8(light, millis, [float_to_rgb8(color) for color in colors])
+
+#!/usr/bin/env python
 '''
 Qt4-based color selection UI for AMBX.
 (C) W.J. van der Laan 2011