Created
April 27, 2025 14:43
-
-
Save MrJake222/3319c098bf4b9c0cda7829077e3c95d0 to your computer and use it in GitHub Desktop.
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> | |
#include <libusb.h> | |
#define MY_VID 0x1209 | |
#define MY_PID 0xb1c0 | |
int main() { | |
libusb_device **devs; | |
libusb_context *ctx = NULL; | |
int r; | |
ssize_t cnt; | |
r = libusb_init(&ctx); | |
if (r < 0) { | |
printf("Init Error %d\n", r); | |
return 1; | |
} | |
cnt = libusb_get_device_list(ctx, &devs); | |
if (cnt < 0) { | |
printf("Get Device List Error\n"); | |
libusb_exit(ctx); | |
return 1; | |
} | |
libusb_device *found = NULL; | |
struct libusb_device_descriptor desc; | |
for (ssize_t i = 0; i < cnt; i++) { | |
libusb_device *device = devs[i]; | |
r = libusb_get_device_descriptor(device, &desc); | |
if (r < 0) { | |
printf("Failed to get device descriptor\n"); | |
continue; | |
} | |
if (desc.idVendor == MY_VID && desc.idProduct == MY_PID) { | |
found = device; | |
break; | |
} | |
} | |
if (!found) { | |
printf("Device not found\n"); | |
goto end; | |
} | |
printf("Device found: VID=0x%04x, PID=0x%04x\n", desc.idVendor, desc.idProduct); | |
libusb_device_handle *handle; | |
r = libusb_open(found, &handle); | |
if (r != 0 || handle == NULL) { | |
printf("Failed to open device: %s\n", libusb_error_name(r)); | |
goto end; | |
} | |
printf("Device opened\n"); | |
printf("Resetting\n"); | |
r = libusb_reset_device(handle); | |
if (r < 0) { | |
printf("Reset Error %d\n", r); | |
goto end; | |
} | |
printf("Done\n"); | |
libusb_close(handle); | |
end: | |
libusb_free_device_list(devs, 1); | |
libusb_exit(ctx); | |
return 0; | |
} |
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
CFLAGS=`pkg-config --cflags --libs libusb-1.0` | |
gcc -o reset reset.c $CFLAGS | |
./reset |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment