blob: 42542b61f8a95da36b38c5fdf1eaa62d689649af (
plain)
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
56
57
58
59
60
61
62
63
64
|
/**
* @file bulkenumerator.cpp
* @author Neale Picket neale@woozle.org
* @date Thu Jun 28 2012
* @brief USB Bulk controller backend
*/
#include <libusb.h>
#include "controllers/bulk/bulkcontroller.h"
#include "controllers/bulk/bulkenumerator.h"
#include "controllers/bulk/bulksupported.h"
BulkEnumerator::BulkEnumerator()
: ControllerEnumerator(),
m_context(NULL) {
libusb_init(&m_context);
}
BulkEnumerator::~BulkEnumerator() {
qDebug() << "Deleting USB Bulk devices...";
while (m_devices.size() > 0) {
delete m_devices.takeLast();
}
libusb_exit(m_context);
}
static bool is_interesting(struct libusb_device_descriptor *desc) {
for (int i = 0; bulk_supported[i].vendor_id; ++i) {
if ((bulk_supported[i].vendor_id == desc->idVendor) &&
(bulk_supported[i].product_id == desc->idProduct)) {
return true;
}
}
return false;
}
QList<Controller*> BulkEnumerator::queryDevices() {
qDebug() << "Scanning USB Bulk devices:";
libusb_device **list;
ssize_t cnt = libusb_get_device_list(m_context, &list);
ssize_t i = 0;
int err = 0;
for (i = 0; i < cnt; i++) {
libusb_device *device = list[i];
struct libusb_device_descriptor desc;
libusb_get_device_descriptor(device, &desc);
if (is_interesting(&desc)) {
struct libusb_device_handle *handle = NULL;
err = libusb_open(device, &handle);
if (err) {
qDebug() << "Error opening a device";
continue;
}
BulkController* currentDevice = new BulkController(m_context, handle, &desc);
m_devices.push_back(currentDevice);
}
}
libusb_free_device_list(list, 1);
return m_devices;
}
|