Commits

wump  committed b885aa8

initial commit

  • Participants

Comments (0)

Files changed (9)

+(.*)\.pyc$
+Author: Wladimir van der Laan <laanwj@gmail.com>
+                Python port
+
+Author: Martijn de Boer <combustd@sexybiggetje.nl>
+		Lead developer for libcombustd and the combustd application.
+		
+Author: Gert-Jan de Boer <google@nosco-ict.nl>
+		Developer
+
+== Installation ==
+
+1)
+Add this to udev rules to allow a user to control the device via libusb, create a new file
+in /etc/udev/rules.d/, for example 71-ambx.rules:
+
+SUBSYSTEM=="usb", ATTR{idVendor}=="0471", ATTR{idProduct}=="083f", GROUP="video", MODE="0664"
+
+2)
+# udevadm control --reload-rules
+
+3) replug the device. Have fun!
+Copyright (c) 2010, Martijn de Boer, Gert-Jan de Boer, Wladimir van der Laan
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+- Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

File py/drivers/__init__.py

+

File py/drivers/ambx.py

+# -*- coding: utf-8 -*-
+'''
+Python interface to Philips AMBX hardware.
+Based on combusd (http://code.google.com/p/combustd/) by Martijn de Boer / Gert-Jan de Boer.
+'''
+import usb
+import logging
+from support.ByteArray import B,Bhex
+
+logger = logging.getLogger("AMBX")
+
+# Usb identification
+VENDOR  = 0x0471
+PRODUCT = 0x083f
+
+# Endpoints
+EP_IN = 0x81
+EP_OUT = 0x02
+EP_PNP = 0x83
+
+# Packet start
+PKT_HEADER = 0xA1
+
+# -- Commands --
+
+
+# Set a single color, for a specific light
+# Params 0xRR 0xGG 0xBB
+# 0xRR = Red color
+# 0xGG = Green color
+# 0xBB = Blue color
+SET_LIGHT_COLOR = 0x03
+
+# Set a color sequence using delays
+# Params 0xMM 0xMM then a repeated sequence of 0xRR 0xGG 0xBB
+# 0xMM = milliseconds
+# 0xMM = milliseconds
+# 0xRR = Red color
+# 0xGG = Green color
+# 0xBB = Blue color
+SET_TIMED_COLOR_SEQUENCE = 0x72
+
+# -- Lights --
+# Definitions so we do not need to remember the hex values for the lights
+class Lights:
+    # LEFT/RIGHT lights. Normally placed adjecent to your screen.
+    LEFT = 0x0B
+    RIGHT = 0x1B
+  
+    # Wallwasher lights. Normally placed behind your screen.
+    WWLEFT = 0x2B
+    WWCENTER = 0x3B
+    WWRIGHT = 0x4B
+                              
+# Timeouts
+TIMEOUT_LIBUSBC = 2500
+TIMEOUT_LIBUSBR = 2500
+TIMEOUT_LIBUSBW = 2500
+
+class AMBX(object):
+    def __init__(self, dev=0):
+        self._log = logging.getLogger("AMBX.%i" % dev)
+        devs = self._enumerate_devices()
+        self._devptr = devs[dev]
+        self.num = dev
+        self._init_hw()
+        
+    @classmethod
+    def _enumerate_devices(self):
+        '''
+        Enumerate all USB devices with the right vendor
+        and product ID
+        '''
+        devs = []
+        logger.debug("Enumerating devices")
+        for bus in usb.busses():
+            for device in bus.devices:
+                if device.idVendor==VENDOR and device.idProduct==PRODUCT:
+                    logger.debug("Found device %i on %s:%s", len(devs), bus.dirname, device.filename)
+                    devs.append(device)
+        return devs
+        
+    def _init_hw(self):
+        self._log.debug("Opening device")
+        self._dev = self._devptr.open()
+        self._log.debug("Claiming interface 0")
+        self._dev.claimInterface(0)
+        self._log.debug("Initialisation succesful")
+
+    def write(self, data, timeout=TIMEOUT_LIBUSBW):
+        '''Write command data to device'''
+        return self._dev.interruptWrite(EP_OUT, data, timeout)
+
+    def set_color_rgb8(self, light, color):
+        '''Set light color'''
+        self.write(B([PKT_HEADER, light, SET_LIGHT_COLOR, color[0], color[1], color[2]]))
+

File py/setcolor.py

+#!/usr/bin/env python
+'''
+Test light generation using Philips AMBX.
+
+Command line arguments:
+  setcolor.py (left|right|wwleft|wwcenter|wwright) <rr> <gg> <bb>
+
+Where rr, gg and bb are integers 0-255.
+'''
+import logging,sys
+from drivers.ambx import AMBX
+from drivers.ambx import PKT_HEADER,Lights,SET_LIGHT_COLOR
+from support.ByteArray import B,Bhex
+import time
+
+logging.basicConfig(level=logging.DEBUG,
+            datefmt='%a, %d %b %Y %H:%M:%S',
+            format='%(asctime)s %(levelname)-8s %(name)-8s %(message)s',
+            stream=sys.stdout)
+
+logger = logging.getLogger("test")
+
+light_names = {
+"left": Lights.LEFT,
+"right": Lights.RIGHT,
+"wwleft": Lights.WWLEFT,
+"wwcenter": Lights.WWCENTER,
+"wwright": Lights.WWRIGHT,
+}
+
+dev = AMBX(0)
+
+light = light_names[sys.argv[1]]
+rr = int(sys.argv[2])
+gg = int(sys.argv[3])
+bb = int(sys.argv[4])
+
+dev.set_color_rgb8(light, [rr, gg, bb])

File py/support/ByteArray.py

+# -*- coding: utf-8 -*-
+# Part of "terra", (C) W.J. van der Laan 2009
+"""Simple byte array handling (pre python 3.0)"""
+from array import array
+
+def B(x):
+    return array("B",x)
+
+def Bhex(d):
+    return " ".join(["%02x" % x for x in d])
+
+def hex_dump(d, width=16):
+    addr = 0
+    s = ""
+    while addr < len(d):
+        s += "%04x: " % addr
+        s += " ".join(["%02x" % x for x in d[addr:addr+width]])
+        addr += width
+        s += "\n"
+    return s
+
+def pad(d, size, value=0):
+    if len(d) < size:
+        return d + B([value]*(size-len(d)))
+    else:
+        return d

File py/support/__init__.py

Empty file added.