add host software
This commit is contained in:
parent
6dde0414ee
commit
13c8ee7c6c
1
host/requirements.txt
Normal file
1
host/requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
pyusb
|
34
host/setcolor.py
Normal file
34
host/setcolor.py
Normal file
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user