ストロベリー・リナックスUSB温度計USBRHを使った温度計 by Qt
Revisão | 0b77ce5353acfa1cbc770e7377b420d14a5d6732 (tree) |
---|---|
Hora | 2013-03-23 11:17:08 |
Autor | arakaki <alucky4416@user...> |
Commiter | arakaki |
feature: add set led on/off.
@@ -76,3 +76,15 @@ void MainWindow::TimeoutDone() | ||
76 | 76 | |
77 | 77 | } |
78 | 78 | |
79 | +void MainWindow::on_checkBox_LED_0_stateChanged(int arg1) | |
80 | +{ | |
81 | + int rc; | |
82 | + rc = rhdev->set_led_status(0, (unsigned char)arg1); | |
83 | +} | |
84 | + | |
85 | +void MainWindow::on_checkBox_LED_1_stateChanged(int arg1) | |
86 | +{ | |
87 | + int rc; | |
88 | + rc = rhdev->set_led_status(1, (unsigned char)arg1); | |
89 | + | |
90 | +} |
@@ -21,6 +21,10 @@ public: | ||
21 | 21 | private slots: |
22 | 22 | void TimeoutDone(); |
23 | 23 | |
24 | + void on_checkBox_LED_0_stateChanged(int arg1); | |
25 | + | |
26 | + void on_checkBox_LED_1_stateChanged(int arg1); | |
27 | + | |
24 | 28 | private: |
25 | 29 | Ui::MainWindow *ui; |
26 | 30 |
@@ -6,8 +6,8 @@ | ||
6 | 6 | <rect> |
7 | 7 | <x>0</x> |
8 | 8 | <y>0</y> |
9 | - <width>330</width> | |
10 | - <height>165</height> | |
9 | + <width>378</width> | |
10 | + <height>219</height> | |
11 | 11 | </rect> |
12 | 12 | </property> |
13 | 13 | <property name="font"> |
@@ -158,14 +158,40 @@ | ||
158 | 158 | <string>QtUSBRH Thermometer</string> |
159 | 159 | </property> |
160 | 160 | </widget> |
161 | + <widget class="QCheckBox" name="checkBox_LED_0"> | |
162 | + <property name="geometry"> | |
163 | + <rect> | |
164 | + <x>80</x> | |
165 | + <y>120</y> | |
166 | + <width>80</width> | |
167 | + <height>20</height> | |
168 | + </rect> | |
169 | + </property> | |
170 | + <property name="text"> | |
171 | + <string>LED 0</string> | |
172 | + </property> | |
173 | + </widget> | |
174 | + <widget class="QCheckBox" name="checkBox_LED_1"> | |
175 | + <property name="geometry"> | |
176 | + <rect> | |
177 | + <x>210</x> | |
178 | + <y>120</y> | |
179 | + <width>80</width> | |
180 | + <height>20</height> | |
181 | + </rect> | |
182 | + </property> | |
183 | + <property name="text"> | |
184 | + <string>LED 1</string> | |
185 | + </property> | |
186 | + </widget> | |
161 | 187 | </widget> |
162 | 188 | <widget class="QMenuBar" name="menuBar"> |
163 | 189 | <property name="geometry"> |
164 | 190 | <rect> |
165 | 191 | <x>0</x> |
166 | 192 | <y>0</y> |
167 | - <width>330</width> | |
168 | - <height>20</height> | |
193 | + <width>378</width> | |
194 | + <height>21</height> | |
169 | 195 | </rect> |
170 | 196 | </property> |
171 | 197 | </widget> |
@@ -6,6 +6,7 @@ | ||
6 | 6 | * |
7 | 7 | * Special Thanks: USBRH on *BSD http://www.nk-home.net/~aoyama/usbrh/ |
8 | 8 | * USBRH on Linux/libusb Mar.14 2007 http://d.hatena.ne.jp/Briareos/ |
9 | + * USBRH driver for Linux http://green-rabbit.sakura.ne.jp/usbrh/#id13 | |
9 | 10 | * |
10 | 11 | * This program is FREESOFTWARE, by the GPLv2. |
11 | 12 | */ |
@@ -19,6 +20,8 @@ | ||
19 | 20 | #define USBRH_VENDOR 0x1774 |
20 | 21 | #define USBRH_PRODUCT 0x1001 |
21 | 22 | |
23 | +#define USBRH_BUFFER_SIZE 7 | |
24 | + | |
22 | 25 | // parameter |
23 | 26 | // http://www.sensirion.com/en/pdf/product_information/Data_Sheet_humidity_sensor_SHT1x_SHT7x_E.pdf |
24 | 27 | // http://www.syscom-inc.co.jp/pdf/sht_datasheet_j.pdf |
@@ -195,7 +198,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid) | ||
195 | 198 | { |
196 | 199 | int rc = 0; |
197 | 200 | int iTemperature, iHumidity; |
198 | - char buff[512]; | |
201 | + char buff[USBRH_BUFFER_SIZE]; | |
199 | 202 | |
200 | 203 | if (gDevHandle == (usb_dev_handle *)NULL) return 1; |
201 | 204 |
@@ -203,7 +206,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid) | ||
203 | 206 | // http://www.ghz.cc/~clepple/libHID/doc/html/libusb_8c-source.html |
204 | 207 | memset(buff, 0, sizeof(buff)); |
205 | 208 | rc = usb_control_msg(gDevHandle, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, |
206 | - 0x09, 0x02<<8, 0, buff, 7, 5000); | |
209 | + 0x09, 0x02<<8, 0, buff, USBRH_BUFFER_SIZE, 5000); | |
207 | 210 | if (rc < 0) { |
208 | 211 | qDebug() << QString("usb_control_msg error : ") << QString(usb_strerror()); |
209 | 212 | } |
@@ -215,7 +218,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid) | ||
215 | 218 | #ifdef __LIBUSB_WIN32__ |
216 | 219 | dev_endpoint = 0x81; |
217 | 220 | #endif |
218 | - rc = usb_bulk_read(gDevHandle, dev_endpoint, buff, 7, 5000); | |
221 | + rc = usb_bulk_read(gDevHandle, dev_endpoint, buff, USBRH_BUFFER_SIZE, 5000); | |
219 | 222 | if (rc < 0) { |
220 | 223 | qDebug() << QString("usb_bulk_read error : ") << QString(usb_strerror()); |
221 | 224 | iTemperature = -99.0; |
@@ -231,6 +234,25 @@ int usbrh::get_tempr_humid(double *tempr, double *humid) | ||
231 | 234 | return rc; |
232 | 235 | } |
233 | 236 | |
237 | +int usbrh::set_led_status(unsigned char led_index, unsigned char led_onoff) | |
238 | +{ | |
239 | + int rc = 0; | |
240 | + char buff[USBRH_BUFFER_SIZE]; | |
241 | + | |
242 | + if (gDevHandle == (usb_dev_handle *)NULL) return 1; | |
243 | + | |
244 | + memset(buff, 0, sizeof(buff)); | |
245 | + buff[0] = 3 + led_index; | |
246 | + buff[1] = led_onoff; // led_onoff = 1 is led on | |
247 | + rc = usb_control_msg(gDevHandle, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE, | |
248 | + 0x09, 0x03<<8, 0, buff, USBRH_BUFFER_SIZE, 5000); | |
249 | + if (rc < 0) { | |
250 | + qDebug() << QString("usb_control_msg error : ") << QString(usb_strerror()); | |
251 | + } | |
252 | + | |
253 | + return rc; | |
254 | +} | |
255 | + | |
234 | 256 | void usbrh::close() |
235 | 257 | { |
236 | 258 | int rc = 0; |
@@ -27,6 +27,7 @@ public: | ||
27 | 27 | int open(); |
28 | 28 | int config(); |
29 | 29 | int get_tempr_humid(double *tempr, double *humid); |
30 | + int set_led_status(unsigned char led_index, unsigned char led_onoff); | |
30 | 31 | void close(); |
31 | 32 | |
32 | 33 | }; |