Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple Buzz! controler on one Raspberry Pi.
"""
Turn on all the LEDs from each Buzz! controler one after the other.
Work with both kind of wired Buzz! controler.
Require to install hid library, not an easy task.
"""
import hid
import time
from random import randrange
vid = 0x054c # idVendor 0x054c Sony Corp. / Logitech
#pid = 0x1000 # idProduct 0x1000 Wired Buzz!
pid = 0x0002 # idProduct 0x0002 Logitech Trebek(tm) controllerV1
all_off = b'\x00\x00\x00\x00\x00\x00\x00\x00'
all_on = b'\x00\x00\xff\xff\xff\xff\x00\x00'
blink = [
b'\x00\x00\xff\x00\x00\x00\x00\x00',
b'\x00\x00\x00\xff\x00\x00\x00\x00',
b'\x00\x00\x00\x00\xff\x00\x00\x00',
b'\x00\x00\x00\x00\x00\xff\x00\x00',
]
button_release = b'\x00\x00\x00\x00\xf0'
button = [
b'\x00\x00\x01\x00\xf0',
b'\x00\x00 \x00\xf0',
b'\x00\x00\x00\x04\xf0',
b'\x00\x00\x00\x80\xf0',
]
if True:
# First see what's connected that we know about
devices = []
for d in hid.enumerate(0, 0):
print("Adding: ", d)
# if ((d['vendor_id']==vid) & (d['product_id']==pid)):
if (d['vendor_id']==vid):
devices.append(d['path'])
print("All devices:", devices)
while True:
for index, device in enumerate(devices):
try:
h = hid.Device(path=device)
print("Index: ", index, "Device manufacturer: ", h.manufacturer, "Product: ", h.product)
h.write(all_off) # Clear the Buzz Controller LEDs
h.nonblocking=1 # Make sure we are not blocked on read
time.sleep(1)
h.write(all_on) # Clear the Buzz Controller LEDs
time.sleep(1)
except hid.HIDException:
print("Cannot write ... sleep and retry")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment