-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
41 lines (31 loc) · 792 Bytes
/
main.cpp
File metadata and controls
41 lines (31 loc) · 792 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
#include <errno.h>
static int reset_by_vid_pid(int vid, int pid);
int main(int argc, char **argv)
{
if(argc < 2) return 11;
int vid = strtol(argv[1], 0, 16);
int pid = strtol(argv[2], 0, 16);
reset_by_vid_pid(vid, pid);
return 0;
}
static int reset_by_vid_pid(int vid, int pid)
{
int rc = 0;
struct libusb_device_handle *handle;
libusb_init(NULL);
handle = libusb_open_device_with_vid_pid(NULL, vid, pid);
if(!handle){
return 1;
}
if(libusb_reset_device(handle)){
printf("Reset failed, you may need to replug your device.\n");
rc = 1;
}
libusb_attach_kernel_driver(handle, 0);
libusb_close(handle);
libusb_exit(NULL);
return rc;
}