• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

ストロベリー・リナックスUSB温度計USBRHを使った温度計 by Qt


Commit MetaInfo

Revisionb92ea415455a38727c28865eeba3c4bfab3b7aed (tree)
Zeit2012-05-24 23:10:06
Autorarakaki <alucky4416@user...>
Commiterarakaki

Log Message

ADD: mainwindow.ui. libusb_win32 support

Ändern Zusammenfassung

Diff

--- a/QtUSBRH.pro
+++ b/QtUSBRH.pro
@@ -9,6 +9,7 @@ QT += core gui
99 TARGET = QtUSBRH
1010 TEMPLATE = app
1111
12+win32: DEFINES += __LIBUSB_WIN32__
1213
1314 SOURCES += main.cpp\
1415 mainwindow.cpp \
@@ -22,6 +23,5 @@ FORMS += mainwindow.ui
2223 unix:INCLUDEPATH += /usr/include/
2324 unix:LIBS += -lusb
2425
25-win32:INCLUDES += D:\SugarSync\QtWork\QtUSBRH
26-
27-
26+win32:HEADERS += lusb0_usb.h
27+win32:LIBS += $$PWD/libusb.a
Binary files /dev/null and b/libusb.a differ
--- /dev/null
+++ b/lusb0_usb.h
@@ -0,0 +1,427 @@
1+#ifndef __USB_H__
2+#define __USB_H__
3+
4+#include <stdlib.h>
5+#include <windows.h>
6+
7+/*
8+ * 'interface' is defined somewhere in the Windows header files. This macro
9+ * is deleted here to avoid conflicts and compile errors.
10+ */
11+
12+#ifdef interface
13+#undef interface
14+#endif
15+
16+/*
17+ * PATH_MAX from limits.h can't be used on Windows if the dll and
18+ * import libraries are build/used by different compilers
19+ */
20+
21+#define LIBUSB_PATH_MAX 512
22+
23+
24+/*
25+ * USB spec information
26+ *
27+ * This is all stuff grabbed from various USB specs and is pretty much
28+ * not subject to change
29+ */
30+
31+/*
32+ * Device and/or Interface Class codes
33+ */
34+#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
35+#define USB_CLASS_AUDIO 1
36+#define USB_CLASS_COMM 2
37+#define USB_CLASS_HID 3
38+#define USB_CLASS_PRINTER 7
39+#define USB_CLASS_MASS_STORAGE 8
40+#define USB_CLASS_HUB 9
41+#define USB_CLASS_DATA 10
42+#define USB_CLASS_VENDOR_SPEC 0xff
43+
44+/*
45+ * Descriptor types
46+ */
47+#define USB_DT_DEVICE 0x01
48+#define USB_DT_CONFIG 0x02
49+#define USB_DT_STRING 0x03
50+#define USB_DT_INTERFACE 0x04
51+#define USB_DT_ENDPOINT 0x05
52+
53+#define USB_DT_HID 0x21
54+#define USB_DT_REPORT 0x22
55+#define USB_DT_PHYSICAL 0x23
56+#define USB_DT_HUB 0x29
57+
58+/*
59+ * Descriptor sizes per descriptor type
60+ */
61+#define USB_DT_DEVICE_SIZE 18
62+#define USB_DT_CONFIG_SIZE 9
63+#define USB_DT_INTERFACE_SIZE 9
64+#define USB_DT_ENDPOINT_SIZE 7
65+#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
66+#define USB_DT_HUB_NONVAR_SIZE 7
67+
68+
69+/* ensure byte-packed structures */
70+#include <pshpack1.h>
71+
72+
73+/* All standard descriptors have these 2 fields in common */
74+struct usb_descriptor_header
75+{
76+ unsigned char bLength;
77+ unsigned char bDescriptorType;
78+};
79+
80+/* String descriptor */
81+struct usb_string_descriptor
82+{
83+ unsigned char bLength;
84+ unsigned char bDescriptorType;
85+ unsigned short wData[1];
86+};
87+
88+/* HID descriptor */
89+struct usb_hid_descriptor
90+{
91+ unsigned char bLength;
92+ unsigned char bDescriptorType;
93+ unsigned short bcdHID;
94+ unsigned char bCountryCode;
95+ unsigned char bNumDescriptors;
96+};
97+
98+/* Endpoint descriptor */
99+#define USB_MAXENDPOINTS 32
100+struct usb_endpoint_descriptor
101+{
102+ unsigned char bLength;
103+ unsigned char bDescriptorType;
104+ unsigned char bEndpointAddress;
105+ unsigned char bmAttributes;
106+ unsigned short wMaxPacketSize;
107+ unsigned char bInterval;
108+ unsigned char bRefresh;
109+ unsigned char bSynchAddress;
110+
111+ unsigned char *extra; /* Extra descriptors */
112+ int extralen;
113+};
114+
115+#define USB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
116+#define USB_ENDPOINT_DIR_MASK 0x80
117+
118+#define USB_ENDPOINT_TYPE_MASK 0x03 /* in bmAttributes */
119+#define USB_ENDPOINT_TYPE_CONTROL 0
120+#define USB_ENDPOINT_TYPE_ISOCHRONOUS 1
121+#define USB_ENDPOINT_TYPE_BULK 2
122+#define USB_ENDPOINT_TYPE_INTERRUPT 3
123+
124+/* Interface descriptor */
125+#define USB_MAXINTERFACES 32
126+struct usb_interface_descriptor
127+{
128+ unsigned char bLength;
129+ unsigned char bDescriptorType;
130+ unsigned char bInterfaceNumber;
131+ unsigned char bAlternateSetting;
132+ unsigned char bNumEndpoints;
133+ unsigned char bInterfaceClass;
134+ unsigned char bInterfaceSubClass;
135+ unsigned char bInterfaceProtocol;
136+ unsigned char iInterface;
137+
138+ struct usb_endpoint_descriptor *endpoint;
139+
140+ unsigned char *extra; /* Extra descriptors */
141+ int extralen;
142+};
143+
144+#define USB_MAXALTSETTING 128 /* Hard limit */
145+
146+struct usb_interface
147+{
148+ struct usb_interface_descriptor *altsetting;
149+
150+ int num_altsetting;
151+};
152+
153+/* Configuration descriptor information.. */
154+#define USB_MAXCONFIG 8
155+struct usb_config_descriptor
156+{
157+ unsigned char bLength;
158+ unsigned char bDescriptorType;
159+ unsigned short wTotalLength;
160+ unsigned char bNumInterfaces;
161+ unsigned char bConfigurationValue;
162+ unsigned char iConfiguration;
163+ unsigned char bmAttributes;
164+ unsigned char MaxPower;
165+
166+ struct usb_interface *interface;
167+
168+ unsigned char *extra; /* Extra descriptors */
169+ int extralen;
170+};
171+
172+/* Device descriptor */
173+struct usb_device_descriptor
174+{
175+ unsigned char bLength;
176+ unsigned char bDescriptorType;
177+ unsigned short bcdUSB;
178+ unsigned char bDeviceClass;
179+ unsigned char bDeviceSubClass;
180+ unsigned char bDeviceProtocol;
181+ unsigned char bMaxPacketSize0;
182+ unsigned short idVendor;
183+ unsigned short idProduct;
184+ unsigned short bcdDevice;
185+ unsigned char iManufacturer;
186+ unsigned char iProduct;
187+ unsigned char iSerialNumber;
188+ unsigned char bNumConfigurations;
189+};
190+
191+struct usb_ctrl_setup
192+{
193+ unsigned char bRequestType;
194+ unsigned char bRequest;
195+ unsigned short wValue;
196+ unsigned short wIndex;
197+ unsigned short wLength;
198+};
199+
200+/*
201+ * Standard requests
202+ */
203+#define USB_REQ_GET_STATUS 0x00
204+#define USB_REQ_CLEAR_FEATURE 0x01
205+/* 0x02 is reserved */
206+#define USB_REQ_SET_FEATURE 0x03
207+/* 0x04 is reserved */
208+#define USB_REQ_SET_ADDRESS 0x05
209+#define USB_REQ_GET_DESCRIPTOR 0x06
210+#define USB_REQ_SET_DESCRIPTOR 0x07
211+#define USB_REQ_GET_CONFIGURATION 0x08
212+#define USB_REQ_SET_CONFIGURATION 0x09
213+#define USB_REQ_GET_INTERFACE 0x0A
214+#define USB_REQ_SET_INTERFACE 0x0B
215+#define USB_REQ_SYNCH_FRAME 0x0C
216+
217+#define USB_TYPE_STANDARD (0x00 << 5)
218+#define USB_TYPE_CLASS (0x01 << 5)
219+#define USB_TYPE_VENDOR (0x02 << 5)
220+#define USB_TYPE_RESERVED (0x03 << 5)
221+
222+#define USB_RECIP_DEVICE 0x00
223+#define USB_RECIP_INTERFACE 0x01
224+#define USB_RECIP_ENDPOINT 0x02
225+#define USB_RECIP_OTHER 0x03
226+
227+/*
228+ * Various libusb API related stuff
229+ */
230+
231+#define USB_ENDPOINT_IN 0x80
232+#define USB_ENDPOINT_OUT 0x00
233+
234+/* Error codes */
235+#define USB_ERROR_BEGIN 500000
236+
237+/*
238+ * This is supposed to look weird. This file is generated from autoconf
239+ * and I didn't want to make this too complicated.
240+ */
241+#define USB_LE16_TO_CPU(x)
242+
243+/*
244+ * Device reset types for usb_reset_ex.
245+ * http://msdn.microsoft.com/en-us/library/ff537269%28VS.85%29.aspx
246+ * http://msdn.microsoft.com/en-us/library/ff537243%28v=vs.85%29.aspx
247+ */
248+#define USB_RESET_TYPE_RESET_PORT (1 << 0)
249+#define USB_RESET_TYPE_CYCLE_PORT (1 << 1)
250+#define USB_RESET_TYPE_FULL_RESET (USB_RESET_TYPE_CYCLE_PORT | USB_RESET_TYPE_RESET_PORT)
251+
252+
253+/* Data types */
254+/* struct usb_device; */
255+/* struct usb_bus; */
256+
257+struct usb_device
258+{
259+ struct usb_device *next, *prev;
260+
261+ char filename[LIBUSB_PATH_MAX];
262+
263+ struct usb_bus *bus;
264+
265+ struct usb_device_descriptor descriptor;
266+ struct usb_config_descriptor *config;
267+
268+ void *dev; /* Darwin support */
269+
270+ unsigned char devnum;
271+
272+ unsigned char num_children;
273+ struct usb_device **children;
274+};
275+
276+struct usb_bus
277+{
278+ struct usb_bus *next, *prev;
279+
280+ char dirname[LIBUSB_PATH_MAX];
281+
282+ struct usb_device *devices;
283+ unsigned long location;
284+
285+ struct usb_device *root_dev;
286+};
287+
288+/* Version information, Windows specific */
289+struct usb_version
290+{
291+ struct
292+ {
293+ int major;
294+ int minor;
295+ int micro;
296+ int nano;
297+ } dll;
298+ struct
299+ {
300+ int major;
301+ int minor;
302+ int micro;
303+ int nano;
304+ } driver;
305+};
306+
307+
308+struct usb_dev_handle;
309+typedef struct usb_dev_handle usb_dev_handle;
310+
311+/* Variables */
312+#ifndef __USB_C__
313+#define usb_busses usb_get_busses()
314+#endif
315+
316+
317+
318+#include <poppack.h>
319+
320+
321+#ifdef __cplusplus
322+extern "C"
323+{
324+#endif
325+
326+ /* Function prototypes */
327+
328+ /* usb.c */
329+ usb_dev_handle *usb_open(struct usb_device *dev);
330+ int usb_close(usb_dev_handle *dev);
331+ int usb_get_string(usb_dev_handle *dev, int index, int langid, char *buf,
332+ size_t buflen);
333+ int usb_get_string_simple(usb_dev_handle *dev, int index, char *buf,
334+ size_t buflen);
335+
336+ /* descriptors.c */
337+ int usb_get_descriptor_by_endpoint(usb_dev_handle *udev, int ep,
338+ unsigned char type, unsigned char index,
339+ void *buf, int size);
340+ int usb_get_descriptor(usb_dev_handle *udev, unsigned char type,
341+ unsigned char index, void *buf, int size);
342+
343+ /* <arch>.c */
344+ int usb_bulk_write(usb_dev_handle *dev, int ep, char *bytes, int size,
345+ int timeout);
346+ int usb_bulk_read(usb_dev_handle *dev, int ep, char *bytes, int size,
347+ int timeout);
348+ int usb_interrupt_write(usb_dev_handle *dev, int ep, char *bytes, int size,
349+ int timeout);
350+ int usb_interrupt_read(usb_dev_handle *dev, int ep, char *bytes, int size,
351+ int timeout);
352+ int usb_control_msg(usb_dev_handle *dev, int requesttype, int request,
353+ int value, int index, char *bytes, int size,
354+ int timeout);
355+ int usb_set_configuration(usb_dev_handle *dev, int configuration);
356+ int usb_claim_interface(usb_dev_handle *dev, int interface);
357+ int usb_release_interface(usb_dev_handle *dev, int interface);
358+ int usb_set_altinterface(usb_dev_handle *dev, int alternate);
359+ int usb_resetep(usb_dev_handle *dev, unsigned int ep);
360+ int usb_clear_halt(usb_dev_handle *dev, unsigned int ep);
361+ int usb_reset(usb_dev_handle *dev);
362+ int usb_reset_ex(usb_dev_handle *dev, unsigned int reset_type);
363+
364+ char *usb_strerror(void);
365+
366+ void usb_init(void);
367+ void usb_set_debug(int level);
368+ int usb_find_busses(void);
369+ int usb_find_devices(void);
370+ struct usb_device *usb_device(usb_dev_handle *dev);
371+ struct usb_bus *usb_get_busses(void);
372+
373+
374+ /* Windows specific functions */
375+
376+#define LIBUSB_HAS_INSTALL_SERVICE_NP 1
377+ int usb_install_service_np(void);
378+ void CALLBACK usb_install_service_np_rundll(HWND wnd, HINSTANCE instance,
379+ LPSTR cmd_line, int cmd_show);
380+
381+#define LIBUSB_HAS_UNINSTALL_SERVICE_NP 1
382+ int usb_uninstall_service_np(void);
383+ void CALLBACK usb_uninstall_service_np_rundll(HWND wnd, HINSTANCE instance,
384+ LPSTR cmd_line, int cmd_show);
385+
386+#define LIBUSB_HAS_INSTALL_DRIVER_NP 1
387+ int usb_install_driver_np(const char *inf_file);
388+ void CALLBACK usb_install_driver_np_rundll(HWND wnd, HINSTANCE instance,
389+ LPSTR cmd_line, int cmd_show);
390+
391+#define LIBUSB_HAS_TOUCH_INF_FILE_NP 1
392+ int usb_touch_inf_file_np(const char *inf_file);
393+ void CALLBACK usb_touch_inf_file_np_rundll(HWND wnd, HINSTANCE instance,
394+ LPSTR cmd_line, int cmd_show);
395+
396+#define LIBUSB_HAS_INSTALL_NEEDS_RESTART_NP 1
397+ int usb_install_needs_restart_np(void);
398+
399+#define LIBUSB_HAS_INSTALL_NP 1
400+ int usb_install_npW(HWND hwnd, HINSTANCE instance, LPCWSTR cmd_line, int starg_arg);
401+ int usb_install_npA(HWND hwnd, HINSTANCE instance, LPCSTR cmd_line, int starg_arg);
402+ #define usb_install_np usb_install_npA
403+ void CALLBACK usb_install_np_rundll(HWND wnd, HINSTANCE instance,
404+ LPSTR cmd_line, int cmd_show);
405+
406+ const struct usb_version *usb_get_version(void);
407+
408+ int usb_isochronous_setup_async(usb_dev_handle *dev, void **context,
409+ unsigned char ep, int pktsize);
410+ int usb_bulk_setup_async(usb_dev_handle *dev, void **context,
411+ unsigned char ep);
412+ int usb_interrupt_setup_async(usb_dev_handle *dev, void **context,
413+ unsigned char ep);
414+
415+ int usb_submit_async(void *context, char *bytes, int size);
416+ int usb_reap_async(void *context, int timeout);
417+ int usb_reap_async_nocancel(void *context, int timeout);
418+ int usb_cancel_async(void *context);
419+ int usb_free_async(void **context);
420+
421+
422+#ifdef __cplusplus
423+}
424+#endif
425+
426+#endif /* __USB_H__ */
427+
--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -13,6 +13,7 @@
1313 #include "mainwindow.h"
1414 #include "ui_mainwindow.h"
1515
16+#include <QMessageBox>
1617 #include <QDebug>
1718
1819 MainWindow::MainWindow(QWidget *parent) :
@@ -23,11 +24,20 @@ MainWindow::MainWindow(QWidget *parent) :
2324
2425 ui->lcdNum_Tempr->display(0.0);
2526 ui->lcdNum_Humid->display(0.0);
26-
27+ IntvlTimer = NULL;
2728 int rc;
29+
2830 rhdev = new usbrh();
2931 rc = rhdev->open();
32+ if (rc) {
33+ QMessageBox::warning(this, tr("QtUSBRH"), tr("USBRH Device Not Found."));
34+ return;
35+ }
3036 rc = rhdev->config();
37+ if (rc) {
38+ QMessageBox::warning(this, tr("QtUSBRH"), tr("USBRH Device Failure Config."));
39+ return;
40+ }
3141
3242 IntvlTimer = new QTimer(this);
3343 connect(IntvlTimer, SIGNAL(timeout()), this, SLOT(TimeoutDone()));
@@ -38,8 +48,10 @@ MainWindow::MainWindow(QWidget *parent) :
3848
3949 MainWindow::~MainWindow()
4050 {
41- IntvlTimer->stop();
42- delete IntvlTimer;
51+ if(IntvlTimer) {
52+ IntvlTimer->stop();
53+ delete IntvlTimer;
54+ }
4355
4456 rhdev->close();
4557 delete rhdev;
@@ -55,8 +67,12 @@ void MainWindow::TimeoutDone()
5567 rc = rhdev->get_tempr_humid(&Tempr, &Humid);
5668 // qDebug() << QString("Tempr = %1, Humid = %2").arg(Tempr).arg(Humid);
5769
58- ui->lcdNum_Tempr->display(Tempr);
59- ui->lcdNum_Humid->display(Humid);
70+ if (rc < 0) {
71+ ;
72+ } else {
73+ ui->lcdNum_Tempr->display(Tempr);
74+ ui->lcdNum_Humid->display(Humid);
75+ }
6076
6177 }
6278
--- /dev/null
+++ b/mainwindow.ui
@@ -0,0 +1,185 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<ui version="4.0">
3+ <class>MainWindow</class>
4+ <widget class="QMainWindow" name="MainWindow">
5+ <property name="geometry">
6+ <rect>
7+ <x>0</x>
8+ <y>0</y>
9+ <width>330</width>
10+ <height>165</height>
11+ </rect>
12+ </property>
13+ <property name="font">
14+ <font>
15+ <pointsize>9</pointsize>
16+ </font>
17+ </property>
18+ <property name="windowTitle">
19+ <string>QtUSBRH</string>
20+ </property>
21+ <widget class="QWidget" name="centralWidget">
22+ <widget class="QLCDNumber" name="lcdNum_Tempr">
23+ <property name="geometry">
24+ <rect>
25+ <x>60</x>
26+ <y>50</y>
27+ <width>81</width>
28+ <height>31</height>
29+ </rect>
30+ </property>
31+ <property name="font">
32+ <font>
33+ <pointsize>12</pointsize>
34+ <weight>50</weight>
35+ <bold>false</bold>
36+ </font>
37+ </property>
38+ <property name="smallDecimalPoint">
39+ <bool>true</bool>
40+ </property>
41+ </widget>
42+ <widget class="QLCDNumber" name="lcdNum_Humid">
43+ <property name="geometry">
44+ <rect>
45+ <x>200</x>
46+ <y>50</y>
47+ <width>81</width>
48+ <height>31</height>
49+ </rect>
50+ </property>
51+ <property name="font">
52+ <font>
53+ <pointsize>12</pointsize>
54+ <weight>50</weight>
55+ <bold>false</bold>
56+ </font>
57+ </property>
58+ <property name="smallDecimalPoint">
59+ <bool>true</bool>
60+ </property>
61+ </widget>
62+ <widget class="QLabel" name="label">
63+ <property name="geometry">
64+ <rect>
65+ <x>60</x>
66+ <y>30</y>
67+ <width>91</width>
68+ <height>21</height>
69+ </rect>
70+ </property>
71+ <property name="font">
72+ <font>
73+ <pointsize>12</pointsize>
74+ <weight>75</weight>
75+ <bold>true</bold>
76+ </font>
77+ </property>
78+ <property name="text">
79+ <string>Temperature</string>
80+ </property>
81+ </widget>
82+ <widget class="QLabel" name="label_2">
83+ <property name="geometry">
84+ <rect>
85+ <x>200</x>
86+ <y>30</y>
87+ <width>91</width>
88+ <height>21</height>
89+ </rect>
90+ </property>
91+ <property name="font">
92+ <font>
93+ <pointsize>12</pointsize>
94+ <weight>75</weight>
95+ <bold>true</bold>
96+ </font>
97+ </property>
98+ <property name="text">
99+ <string>Humidity</string>
100+ </property>
101+ </widget>
102+ <widget class="QLabel" name="label_3">
103+ <property name="geometry">
104+ <rect>
105+ <x>150</x>
106+ <y>50</y>
107+ <width>20</width>
108+ <height>31</height>
109+ </rect>
110+ </property>
111+ <property name="font">
112+ <font>
113+ <pointsize>18</pointsize>
114+ </font>
115+ </property>
116+ <property name="text">
117+ <string>'C</string>
118+ </property>
119+ </widget>
120+ <widget class="QLabel" name="label_4">
121+ <property name="geometry">
122+ <rect>
123+ <x>290</x>
124+ <y>50</y>
125+ <width>20</width>
126+ <height>31</height>
127+ </rect>
128+ </property>
129+ <property name="font">
130+ <font>
131+ <pointsize>18</pointsize>
132+ <weight>75</weight>
133+ <bold>true</bold>
134+ </font>
135+ </property>
136+ <property name="text">
137+ <string>%</string>
138+ </property>
139+ </widget>
140+ <widget class="QLabel" name="label_5">
141+ <property name="geometry">
142+ <rect>
143+ <x>30</x>
144+ <y>10</y>
145+ <width>181</width>
146+ <height>16</height>
147+ </rect>
148+ </property>
149+ <property name="font">
150+ <font>
151+ <pointsize>12</pointsize>
152+ <weight>75</weight>
153+ <italic>true</italic>
154+ <bold>true</bold>
155+ </font>
156+ </property>
157+ <property name="text">
158+ <string>QtUSBRH Thermometer</string>
159+ </property>
160+ </widget>
161+ </widget>
162+ <widget class="QMenuBar" name="menuBar">
163+ <property name="geometry">
164+ <rect>
165+ <x>0</x>
166+ <y>0</y>
167+ <width>330</width>
168+ <height>20</height>
169+ </rect>
170+ </property>
171+ </widget>
172+ <widget class="QToolBar" name="mainToolBar">
173+ <attribute name="toolBarArea">
174+ <enum>TopToolBarArea</enum>
175+ </attribute>
176+ <attribute name="toolBarBreak">
177+ <bool>false</bool>
178+ </attribute>
179+ </widget>
180+ <widget class="QStatusBar" name="statusBar"/>
181+ </widget>
182+ <layoutdefault spacing="6" margin="11"/>
183+ <resources/>
184+ <connections/>
185+</ui>
--- a/usbrh.cpp
+++ b/usbrh.cpp
@@ -10,7 +10,10 @@
1010 * This program is FREESOFTWARE, by the GPLv2.
1111 */
1212
13-#include <string.h>
13+#include <QString>
14+#include <QDebug>
15+
16+//#include <string.h>
1417 #include "usbrh.h"
1518
1619 // ---------------------------------------------------------------------------------------
@@ -41,10 +44,11 @@ struct usb_device* usbrh::searchdevice(unsigned int vendor, unsigned int product
4144
4245 count = 0;
4346
47+// qDebug() << QString("vendor = 0x%1, product = 0x%2").arg(vendor, 4, 16, QChar('0')).arg(product, 4, 16, QChar('0'));
4448 for (bus = usb_get_busses(); bus; bus = bus->next) {
4549 for (dev = bus->devices; dev; dev = dev->next) {
46- if (dev->descriptor.idVendor == vendor &&
47- dev->descriptor.idProduct == product) {
50+// qDebug() << QString("vendor = 0x%1, product = 0x%2").arg(dev->descriptor.idVendor, 4, 16, QChar('0')).arg(dev->descriptor.idProduct, 4, 16, QChar('0'));
51+ if ((dev->descriptor.idVendor == (unsigned short)vendor) && (dev->descriptor.idProduct == (unsigned short)product)) {
4852 count++;
4953 if (count==num) {
5054 return (dev);
@@ -128,6 +132,7 @@ int usbrh::config()
128132 if (gDevice == (struct usb_device *)NULL) return 1;
129133
130134 if ((rc = usb_set_configuration(gDevHandle, gDevice->config->bConfigurationValue)) < 0) {
135+#ifndef __LIBUSB_WIN32__
131136 if ((rc = usb_detach_kernel_driver_np(gDevHandle, gDevice->config->interface->altsetting->bInterfaceNumber)) < 0) {
132137 // puts("usb_detach_kernel_driver_np error");
133138 this->close(); // usb_close(dh);
@@ -135,17 +140,21 @@ int usbrh::config()
135140 return rc;
136141 } else {
137142 if((rc =usb_set_configuration(gDevHandle, gDevice->config->bConfigurationValue)) < 0) {
143+#endif
138144 //printf("usb_set_configuration error: %s\n", usb_strerror());
139145 usb_close(gDevHandle);
140146 gDevHandle = NULL;
141147 rc = 3;// exit(3);
142148 return rc;
149+#ifndef __LIBUSB_WIN32__
143150 }
144151 }
152+#endif
145153 }
146154
147155 if ((rc =usb_claim_interface(gDevHandle, gDevice->config->interface->altsetting->bInterfaceNumber)) < 0) {
148156 //puts("usb_claim_interface error");
157+#ifndef __LIBUSB_WIN32__
149158 if ((rc = usb_detach_kernel_driver_np(gDevHandle, gDevice->config->interface->altsetting->bInterfaceNumber)) <0) {
150159 // puts("usb_detach_kernel_driver_np error");
151160 usb_close(gDevHandle);
@@ -153,13 +162,16 @@ int usbrh::config()
153162 rc = 4; // exit(4);
154163 } else {
155164 if((rc =usb_claim_interface(gDevHandle, gDevice->config->interface->altsetting->bInterfaceNumber)) < 0){
165+#endif
156166 //puts("usb_claim_interface error");
157167 usb_close(gDevHandle);
158168 gDevHandle = NULL;
159169 rc = 4; // exit(4);
160170 return rc;
171+#ifndef __LIBUSB_WIN32__
161172 }
162173 }
174+#endif
163175 }
164176
165177 return rc;
@@ -175,16 +187,29 @@ int usbrh::get_tempr_humid(double *tempr, double *humid)
175187
176188 // SET_REPORT
177189 // http://www.ghz.cc/~clepple/libHID/doc/html/libusb_8c-source.html
190+ memset(buff, 0, sizeof(buff));
178191 rc = usb_control_msg(gDevHandle, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
179- 0x09, 0x02<<8, 0, buff, 7, 5000);
192+ 0x09, 0x02<<8, 0, buff, 7, 5000);
193+ if (rc < 0) {
194+ qDebug() << QString("usb_control_msg error : ") << QString(usb_strerror());
195+ }
180196 //sleep(1);
181197
182198 // Read data from device
183199 memset(buff, 0, sizeof(buff));
184- rc = usb_bulk_read(gDevHandle, 1, buff, 7, 5000);
185-
186- iTemperature = buff[2] << 8 | (buff[3] & 0xff);
187- iHumidity = buff[0] << 8 | (buff[1] & 0xff);
200+ int dev_endpoint = 0x01; // device EndPoint
201+#ifdef __LIBUSB_WIN32__
202+ dev_endpoint = 0x81;
203+#endif
204+ rc = usb_bulk_read(gDevHandle, dev_endpoint, buff, 7, 5000);
205+ if (rc < 0) {
206+ qDebug() << QString("usb_bulk_read error : ") << QString(usb_strerror());
207+ iTemperature = -99.0;
208+ iHumidity = -99.0;
209+ } else {
210+ iTemperature = buff[2] << 8 | (buff[3] & 0xff);
211+ iHumidity = buff[0] << 8 | (buff[1] & 0xff);
212+ }
188213
189214 *tempr = convert_temp(iTemperature);
190215 *humid = convert_humidity(iHumidity);
--- a/usbrh.h
+++ b/usbrh.h
@@ -2,7 +2,11 @@
22 #ifndef __USBRH_H__
33 #define __USBRH_H__
44
5+#if __LIBUSB_WIN32__
6+#include "lusb0_usb.h"
7+#else
58 #include <usb.h>
9+#endif
610
711 #define USBRH_VENDOR 0x1774
812 #define USBRH_PRODUCT 0x1001