-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUSB.h
55 lines (39 loc) · 1.15 KB
/
USB.h
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef USBHIDWRITE_USB_H
#define USBHIDWRITE_USB_H
#include <functional>
#include <libusb-1.0/libusb.h>
#include "LOG.h"
typedef void(*CallBack_t)(libusb_transfer*);
class IUSB {
public:
virtual int Init() = 0;
virtual int GetDevice() = 0;
virtual int FindVendor(uint16_t vendorID, uint16_t productID) = 0;
};
class USB : public IUSB {
public:
USB();
~USB();
int Init();
int GetDevice();
int FindVendor(uint16_t vendorID, uint16_t productID);
void ShowDevices();
void ShowInterfaces(ssize_t dev_num);
void SetVidPid(uint16_t vID, uint16_t pID);
int ClaimInterface(int interface_number);
int ReleaseInterface(int interface_number);
int Connect();
int ReadISO( unsigned char endpoint);
int Write(unsigned char endpoint, unsigned char *data, size_t len);
int WriteISO(unsigned char endpoint, unsigned char *data, size_t len);
void SetCallBack(CallBack_t call);
private:
libusb_context *_ctx = NULL;
libusb_device **_devs;
uint16_t vendorID;
uint16_t productID;
libusb_device_handle *dev_handle;
CallBack_t callBackISO;
unsigned char isobuf[65536];
};
#endif