Created
August 25, 2017 22:32
-
-
Save LightningStalker/84aa4dc0069b9c7cec9de1e7ea2f3797 to your computer and use it in GitHub Desktop.
Resets the USB busses, makes devices reattach without unplugging and plugging back in
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> // requires usblib | |
| #include <usb.h> // compile with #gcc -Wall -o resetusb resetusb.c -lusb | |
| int main(void) | |
| { | |
| struct usb_bus *busses; | |
| usb_init(); | |
| usb_find_busses(); | |
| usb_find_devices(); | |
| busses = usb_get_busses(); | |
| struct usb_bus *bus; | |
| // int c, i, a; | |
| /* ... */ | |
| for (bus = busses; bus; bus = bus->next) { | |
| struct usb_device *dev; | |
| int val; | |
| usb_dev_handle *junk; | |
| for (dev = bus->devices; dev; dev = dev->next) { | |
| char buf[1024]; | |
| junk = usb_open ( dev ); | |
| usb_get_string_simple(junk,2,buf,1023); | |
| if ( junk == NULL ){ | |
| printf("Can't open %p (%s)\n", dev, buf ); | |
| } else { | |
| val = usb_reset(junk); | |
| printf( "reset %p %d (%s)\n", dev, val, buf ); | |
| } | |
| usb_close(junk); | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment