From 13c8ee7c6c449ca49b5c65422153da72def0b156 Mon Sep 17 00:00:00 2001 From: Joachim Lusiardi Date: Mon, 5 Sep 2016 21:37:41 +0200 Subject: [PATCH] add host software --- host/requirements.txt | 1 + host/setcolor.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 host/requirements.txt create mode 100644 host/setcolor.py diff --git a/host/requirements.txt b/host/requirements.txt new file mode 100644 index 0000000..af159f1 --- /dev/null +++ b/host/requirements.txt @@ -0,0 +1 @@ +pyusb \ No newline at end of file diff --git a/host/setcolor.py b/host/setcolor.py new file mode 100644 index 0000000..9161cb5 --- /dev/null +++ b/host/setcolor.py @@ -0,0 +1,34 @@ +import usb.util +import sys + + +def set_color(r, g, b): + """ + Sets the color of the LED. + :param r: the 8 bit red value of the color + :param g: the 8 bit green value of the color + :param b: the 8 bit blue value of the color + :return: True if 3 bytes were transmitted, False otherwise + """ + d = [r, g, b] + result = dev.ctrl_transfer(0x40, 4, 0, 0, d) + return result == 3 + +if len(sys.argv) != 4: + print("must be called with 'color.py red blue green'") + sys.exit(1) + +red = int(sys.argv[1]) +green = int(sys.argv[2]) +blue = int(sys.argv[3]) + +# find our device +dev = usb.core.find(idVendor=0x16c0, idProduct=0x05dc) + +# was it found? +if dev is None: + raise ValueError('Device not found') + + +print(set_color(red, green, blue)) +