Index: elec/CrO2/software/Makefile
===================================================================
--- elec/CrO2/software/Makefile	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
+++ elec/CrO2/software/Makefile	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
@@ -0,0 +1,45 @@
+# Name: Makefile
+# Project: PowerSwitch
+# Author: Christian Starkjohann
+# Creation Date: 2005-01-16
+# Tabsize: 4
+# Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
+# License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+# This Revision: $Id: Makefile 276 2007-03-20 10:53:04Z cs $
+
+
+# Concigure the following definitions according to your system. The powerSwitch
+# tool has been successfully compiled on Mac OS X, Linux and Windows.
+
+# Use the following 3 lines on Unix (uncomment the framework on Mac OS X):
+USBFLAGS = `libusb-config --cflags`
+USBLIBS = `libusb-config --libs` #-framework CoreFoundation
+EXE_SUFFIX =
+
+# Use the following 3 lines on Windows and comment out the 3 above. You may
+# have to change the include paths to where you installed libusb-win32
+#USBFLAGS = -I/usr/local/include
+#USBLIBS = -L/usr/local/lib -lusb
+#EXE_SUFFIX = .exe
+
+
+CC		= gcc
+CFLAGS	= $(USBFLAGS) -O -Wall -std=c99
+LIBS	= $(USBLIBS)
+
+PROGRAM = powerSwitch$(EXE_SUFFIX)
+
+
+all: $(PROGRAM)
+
+.c.o:
+	$(CC) $(CFLAGS) -c $<
+
+$(PROGRAM): powerSwitch.o
+	$(CC) -o $(PROGRAM) powerSwitch.o $(LIBS)
+
+strip: $(PROGRAM)
+	strip $(PROGRAM)
+
+clean:
+	rm -f *.o $(PROGRAM)
Index: elec/CrO2/software/Makefile.windows
===================================================================
--- elec/CrO2/software/Makefile.windows	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
+++ elec/CrO2/software/Makefile.windows	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
@@ -0,0 +1,18 @@
+# Name: Makefile.windows
+# Project: PowerSwitch
+# Author: Christian Starkjohann
+# Creation Date: 2006-02-20
+# Tabsize: 4
+# Copyright: (c) 2006 by OBJECTIVE DEVELOPMENT Software GmbH
+# License: Proprietary, free under certain conditions. See Documentation.
+# This Revision: $Id$
+
+# You may use this file with
+#   make -f Makefile.windows
+# on Windows with MinGW instead of editing the main Makefile.
+
+include Makefile
+
+USBFLAGS = -I/usr/local/mingw/include
+USBLIBS = -L/usr/local/mingw/lib -lusb
+EXE_SUFFIX = .exe
Index: elec/CrO2/software/powerSwitch.c
===================================================================
--- elec/CrO2/software/powerSwitch.c	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
+++ elec/CrO2/software/powerSwitch.c	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
@@ -0,0 +1,192 @@
+/* Name: powerSwitch.c
+ * Project: PowerSwitch based on AVR USB driver
+ * Author: Christian Starkjohann
+ * Creation Date: 2005-01-16
+ * Tabsize: 4
+ * Copyright: (c) 2005 by OBJECTIVE DEVELOPMENT Software GmbH
+ * License: GNU GPL v2 (see License.txt) or proprietary (CommercialLicense.txt)
+ * This Revision: $Id: powerSwitch.c 472 2008-01-21 18:21:59Z cs $
+ */
+
+/*
+General Description:
+This program controls the PowerSwitch USB device from the command line.
+It must be linked with libusb, a library for accessing the USB bus from
+Linux, FreeBSD, Mac OS X and other Unix operating systems. Libusb can be
+obtained from http://libusb.sourceforge.net/.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <lusb0_usb.h>    /* this is libusb, see http://libusb.sourceforge.net/ */
+
+#define USBDEV_SHARED_VENDOR    0x16C0  /* VOTI */
+#define USBDEV_SHARED_PRODUCT   0x05DC  /* Obdev's free shared PID */
+/* Use obdev's generic shared VID/PID pair and follow the rules outlined
+ * in firmware/usbdrv/USBID-License.txt.
+ */
+
+#define VENDORSTRING "pulkomandy.ath.cx"
+#define PRODUCTSTRING "CrO2"
+
+#define PSCMD_CONFIG  0
+#define PSCMD_GET   1
+#define PSCMD_PUT   2
+/* These are the vendor specific SETUP commands implemented by our USB device */
+
+static void usage(char *name)
+{
+    fprintf(stderr, "usage:\n");
+    fprintf(stderr, "  %s status\n", name);
+    fprintf(stderr, "  %s on <port> [<duration>]\n", name);
+    fprintf(stderr, "  %s off <port> [<duration>]\n", name);
+    fprintf(stderr, "  %s test\n\n", name);
+    fprintf(stderr, "Ports are single digits in the range 0...7\n");
+    fprintf(stderr, "The pulse duration for switching temporarily is given in seconds.\n");
+}
+
+
+static int  usbGetStringAscii(usb_dev_handle *dev, int index, int langid, char *buf, int buflen)
+{
+char    buffer[256];
+int     rval, i;
+
+    if((rval = usb_control_msg(dev, USB_ENDPOINT_IN, USB_REQ_GET_DESCRIPTOR, (USB_DT_STRING << 8) + index, langid, buffer, sizeof(buffer), 1000)) < 0)
+        return rval;
+    if(buffer[1] != USB_DT_STRING)
+        return 0;
+    if((unsigned char)buffer[0] < rval)
+        rval = (unsigned char)buffer[0];
+    rval /= 2;
+    /* lossy conversion to ISO Latin1 */
+    for(i=1;i<rval;i++){
+        if(i > buflen)  /* destination buffer overflow */
+            break;
+        buf[i-1] = buffer[2 * i];
+        if(buffer[2 * i + 1] != 0)  /* outside of ISO Latin1 range */
+            buf[i-1] = '?';
+    }
+    buf[i-1] = 0;
+    return i-1;
+}
+
+
+/* PowerSwitch uses the free shared default VID/PID. If you want to see an
+ * example device lookup where an individually reserved PID is used, see our
+ * RemoteSensor reference implementation.
+ */
+
+#define USB_ERROR_NOTFOUND  1
+#define USB_ERROR_ACCESS    2
+#define USB_ERROR_IO        3
+
+static int usbOpenDevice(usb_dev_handle **device, int vendor, char *vendorName, int product, char *productName)
+{
+struct usb_bus      *bus;
+struct usb_device   *dev;
+usb_dev_handle      *handle = NULL;
+int                 errorCode = USB_ERROR_NOTFOUND;
+static int          didUsbInit = 0;
+
+    if(!didUsbInit){
+        didUsbInit = 1;
+        usb_init();
+    }
+    usb_find_busses();
+    usb_find_devices();
+    for(bus=usb_get_busses(); bus; bus=bus->next){
+        for(dev=bus->devices; dev; dev=dev->next){
+            if(dev->descriptor.idVendor == vendor && dev->descriptor.idProduct == product){
+                char    string[256];
+                int     len;
+                handle = usb_open(dev); /* we need to open the device in order to query strings */
+                if(!handle){
+                    errorCode = USB_ERROR_ACCESS;
+                    fprintf(stderr, "Warning: cannot open USB device: %s\n", usb_strerror());
+                    continue;
+                }
+                if(vendorName == NULL && productName == NULL){  /* name does not matter */
+                    break;
+                }
+                /* now check whether the names match: */
+                len = usbGetStringAscii(handle, dev->descriptor.iManufacturer, 0x0409, string, sizeof(string));
+                if(len < 0){
+                    errorCode = USB_ERROR_IO;
+                    fprintf(stderr, "Warning: cannot query manufacturer for device: %s\n", usb_strerror());
+                }else{
+                    errorCode = USB_ERROR_NOTFOUND;
+                    /* fprintf(stderr, "seen device from vendor ->%s<-\n", string); */
+                    if(strcmp(string, vendorName) == 0){
+                        len = usbGetStringAscii(handle, dev->descriptor.iProduct, 0x0409, string, sizeof(string));
+                        if(len < 0){
+                            errorCode = USB_ERROR_IO;
+                            fprintf(stderr, "Warning: cannot query product for device: %s\n", usb_strerror());
+                        }else{
+                            errorCode = USB_ERROR_NOTFOUND;
+                            /* fprintf(stderr, "seen product ->%s<-\n", string); */
+                            if(strcmp(string, productName) == 0)
+                                break;
+                        }
+                    }
+                }
+                usb_close(handle);
+                handle = NULL;
+            }
+        }
+        if(handle)
+            break;
+    }
+    if(handle != NULL){
+        errorCode = 0;
+        *device = handle;
+    }
+    return errorCode;
+}
+
+void hexdump(unsigned char* bytes, int len)
+{
+	for(int i = 0; i <len; i++)
+		printf("%X ",bytes[i]);
+	puts("");
+}
+
+int main(int argc, char **argv)
+{
+usb_dev_handle      *handle = NULL;
+unsigned char       buffer[275];
+int                 nBytes;
+
+    if(argc < 2){
+        usage(argv[0]);
+        exit(1);
+    }
+    usb_init();
+    if(usbOpenDevice(&handle, USBDEV_SHARED_VENDOR, VENDORSTRING, USBDEV_SHARED_PRODUCT, PRODUCTSTRING) != 0){
+        fprintf(stderr, "Could not find USB device \""PRODUCTSTRING"\" with vid=0x%x pid=0x%x\n", USBDEV_SHARED_VENDOR, USBDEV_SHARED_PRODUCT);
+        exit(1);
+    }
+/* We have searched all devices on all busses for our USB device above. Now
+ * try to open it and perform the vendor specific control operations for the
+ * function requested by the user.
+ */
+    if(strcmp(argv[1], "get") == 0){
+		memset(buffer, 0, 275);
+		nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, PSCMD_GET, 0,0, (char*)buffer, 200, 5000);
+		hexdump(buffer, sizeof(buffer));
+    }else if(strcmp(argv[1], "put") == 0){
+		hexdump(buffer, sizeof(buffer));
+		nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, PSCMD_PUT, 0,0, (char*)buffer, 200, 5000);
+    }else{
+		fprintf(stderr,"Unknown command: %s.\n", argv[1]);
+		usage(argv[0]);
+		nBytes = 0;
+		// TODO manage return code
+    }
+
+	if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
+
+    usb_close(handle);
+    return 0;
+}
+
Index: elec/CrO2/software/windows-driver/PowerSwitch.inf
===================================================================
--- elec/CrO2/software/windows-driver/PowerSwitch.inf	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
+++ elec/CrO2/software/windows-driver/PowerSwitch.inf	(revision 0da6f0129599fc63f759527af64518c2da7ffb10)
@@ -0,0 +1,91 @@
+[Version]
+Signature = "$Chicago$"
+provider  = %manufacturer%
+DriverVer = 03/09/2005,0.1.10.1
+CatalogFile = PowerSwitch.cat
+
+Class = LibUsbDevices
+ClassGUID = {EB781AAF-9C70-4523-A5DF-642A87ECA567}
+
+[ClassInstall]
+AddReg=ClassInstall.AddReg
+
+[ClassInstall32]
+AddReg=ClassInstall.AddReg
+
+[ClassInstall.AddReg]
+HKR,,,,"LibUSB-Win32 Devices"
+HKR,,Icon,,"-20"
+
+[Manufacturer]
+%manufacturer%=Devices
+
+;--------------------------------------------------------------------------
+; Files
+;--------------------------------------------------------------------------
+
+[SourceDisksNames]
+1 = "Libusb-Win32 Driver Installation Disk",,
+
+[SourceDisksFiles]
+libusb0.sys = 1,,
+libusb0.dll = 1,,
+
+[DestinationDirs]
+LIBUSB.Files.Sys = 10,System32\Drivers
+LIBUSB.Files.Dll = 10,System32
+
+[LIBUSB.Files.Sys]
+libusb0.sys
+
+[LIBUSB.Files.Dll]
+libusb0.dll
+
+;--------------------------------------------------------------------------
+; Device driver
+;--------------------------------------------------------------------------
+
+[LIBUSB_DEV]
+CopyFiles = LIBUSB.Files.Sys, LIBUSB.Files.Dll
+AddReg    = LIBUSB_DEV.AddReg
+
+[LIBUSB_DEV.NT]
+CopyFiles = LIBUSB.Files.Sys, LIBUSB.Files.Dll
+
+[LIBUSB_DEV.HW]
+DelReg = LIBUSB_DEV.DelReg.HW
+
+[LIBUSB_DEV.NT.HW]
+DelReg = LIBUSB_DEV.DelReg.HW
+
+[LIBUSB_DEV.NT.Services]
+AddService = libusb0, 0x00000002, LIBUSB.AddService
+
+[LIBUSB_DEV.AddReg]
+HKR,,DevLoader,,*ntkern
+HKR,,NTMPDriver,,libusb0.sys
+
+[LIBUSB_DEV.DelReg.HW]
+HKR,,"LowerFilters"
+
+;--------------------------------------------------------------------------
+; Services
+;--------------------------------------------------------------------------
+
+[LIBUSB.AddService]
+DisplayName    = "LibUsb-Win32 - Kernel Driver 03/09/2005, 0.1.10.1"
+ServiceType    = 1
+StartType      = 3
+ErrorControl   = 0
+ServiceBinary  = %12%\libusb0.sys
+
+;--------------------------------------------------------------------------
+; Devices
+;--------------------------------------------------------------------------
+
+[Devices]
+"PowerSwitch"=LIBUSB_DEV, USB\VID_16c0&PID_05dc
+
+[Strings]
+manufacturer = "www.obdev.at"
+
