Skip to content

Instantly share code, notes, and snippets.

@bunchc
Created February 11, 2019 21:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bunchc/352b6dca4ef0d9e084633261181aa09d to your computer and use it in GitHub Desktop.
Save bunchc/352b6dca4ef0d9e084633261181aa09d to your computer and use it in GitHub Desktop.
There Are Door Lights - hub_ctrl mods
def send_command(listing, busnum, devnum, hub, port, value, verbose):
""" send_command(self, parameter_list)
Sends the power control command to the USB hub.
"""
if hub == None and busnum == None:
hub = 0 # Default hub = 0
cmd = COMMAND_SET_POWER
hubs = find_hubs(listing, verbose, busnum, devnum, hub)
if len(hubs) == 0:
print("No hubs found.", file=sys.stderr)
exit(1)
if hub == None:
for h in hubs:
if h['busnum'] == busnum and h['devnum'] == devnum:
dev_hub = h['dev']
nports = h['num_ports']
else:
dev_hub = hubs[hub]['dev']
nports = hubs[hub]['num_ports']
uh = dev_hub.open()
if cmd == COMMAND_SET_POWER:
feature = USB_PORT_FEAT_POWER
index = port
if value:
request = usb.REQ_SET_FEATURE
else:
request = usb.REQ_CLEAR_FEATURE
else:
request = usb.REQ_SET_FEATURE
feature = USB_PORT_FEAT_INDICATOR
index = (value << 8) | port
if verbose:
hub_port_status(uh,nports)
print("Sending control message (requestType= %d, REQUEST=%d, FEATURE=%d, INDEX=%d) " % (USB_RT_PORT, request, feature, index))
uh.controlMsg(requestType = USB_RT_PORT, request = request, value = feature, index = index, buffer = None, timeout = 1000)
print("Sent control message (requestType= %d, REQUEST=%d, FEATURE=%d, INDEX=%d) " % (USB_RT_PORT, request, feature, index))
if verbose:
hub_port_status(uh,nports)
del uh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment