-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusbaspdetector.cpp
More file actions
44 lines (36 loc) · 1.36 KB
/
usbaspdetector.cpp
File metadata and controls
44 lines (36 loc) · 1.36 KB
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
#include "usbaspdetector.h"
#include <QDebug>
USBAspDetector::USBAspDetector(QObject *parent): QObject(parent)
{
listUSBasp = new QProcess(this);
}
bool USBAspDetector::Detect()
{
bool detected;
//listUSBasp->start("sh", QStringList() << "-c" << "system_profiler SPUSBDataType | grep USBasp");
//listUSBasp->waitForFinished();
//QByteArray result = listUSBasp->readAllStandardOutput();
//qDebug() << result;
//listUSBasp->close();
CFMutableDictionaryRef matchingDictionary = NULL;
SInt32 idVendor = 0x16c0; // set vendor id
SInt32 idProduct = 0x05dc; // set product id
io_iterator_t iterator = 0;
io_service_t usbRef;
matchingDictionary = IOServiceMatching(kIOUSBDeviceClassName);
CFDictionaryAddValue(matchingDictionary,CFSTR(kUSBVendorID), CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type, &idVendor));
CFDictionaryAddValue(matchingDictionary,CFSTR(kUSBProductID),CFNumberCreate(kCFAllocatorDefault,kCFNumberSInt32Type, &idProduct));
IOServiceGetMatchingServices(kIOMasterPortDefault,matchingDictionary, &iterator);
usbRef = IOIteratorNext(iterator);
if (usbRef == 0)
{
//qDebug() << "device not found";
detected = false;
}else{
//qDebug() << "device found";
detected = true;
}
IOObjectRelease(iterator);
IOObjectRelease(usbRef);
return detected;
}