• 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

Revisão0b77ce5353acfa1cbc770e7377b420d14a5d6732 (tree)
Hora2013-03-23 11:17:08
Autorarakaki <alucky4416@user...>
Commiterarakaki

Mensagem de Log

feature: add set led on/off.

Mudança Sumário

Diff

--- a/mainwindow.cpp
+++ b/mainwindow.cpp
@@ -76,3 +76,15 @@ void MainWindow::TimeoutDone()
7676
7777 }
7878
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+}
--- a/mainwindow.h
+++ b/mainwindow.h
@@ -21,6 +21,10 @@ public:
2121 private slots:
2222 void TimeoutDone();
2323
24+ void on_checkBox_LED_0_stateChanged(int arg1);
25+
26+ void on_checkBox_LED_1_stateChanged(int arg1);
27+
2428 private:
2529 Ui::MainWindow *ui;
2630
--- a/mainwindow.ui
+++ b/mainwindow.ui
@@ -6,8 +6,8 @@
66 <rect>
77 <x>0</x>
88 <y>0</y>
9- <width>330</width>
10- <height>165</height>
9+ <width>378</width>
10+ <height>219</height>
1111 </rect>
1212 </property>
1313 <property name="font">
@@ -158,14 +158,40 @@
158158 <string>QtUSBRH Thermometer</string>
159159 </property>
160160 </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>
161187 </widget>
162188 <widget class="QMenuBar" name="menuBar">
163189 <property name="geometry">
164190 <rect>
165191 <x>0</x>
166192 <y>0</y>
167- <width>330</width>
168- <height>20</height>
193+ <width>378</width>
194+ <height>21</height>
169195 </rect>
170196 </property>
171197 </widget>
--- a/usbrh.cpp
+++ b/usbrh.cpp
@@ -6,6 +6,7 @@
66 *
77 * Special Thanks: USBRH on *BSD http://www.nk-home.net/~aoyama/usbrh/
88 * 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
910 *
1011 * This program is FREESOFTWARE, by the GPLv2.
1112 */
@@ -19,6 +20,8 @@
1920 #define USBRH_VENDOR 0x1774
2021 #define USBRH_PRODUCT 0x1001
2122
23+#define USBRH_BUFFER_SIZE 7
24+
2225 // parameter
2326 // http://www.sensirion.com/en/pdf/product_information/Data_Sheet_humidity_sensor_SHT1x_SHT7x_E.pdf
2427 // http://www.syscom-inc.co.jp/pdf/sht_datasheet_j.pdf
@@ -195,7 +198,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid)
195198 {
196199 int rc = 0;
197200 int iTemperature, iHumidity;
198- char buff[512];
201+ char buff[USBRH_BUFFER_SIZE];
199202
200203 if (gDevHandle == (usb_dev_handle *)NULL) return 1;
201204
@@ -203,7 +206,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid)
203206 // http://www.ghz.cc/~clepple/libHID/doc/html/libusb_8c-source.html
204207 memset(buff, 0, sizeof(buff));
205208 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);
207210 if (rc < 0) {
208211 qDebug() << QString("usb_control_msg error : ") << QString(usb_strerror());
209212 }
@@ -215,7 +218,7 @@ int usbrh::get_tempr_humid(double *tempr, double *humid)
215218 #ifdef __LIBUSB_WIN32__
216219 dev_endpoint = 0x81;
217220 #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);
219222 if (rc < 0) {
220223 qDebug() << QString("usb_bulk_read error : ") << QString(usb_strerror());
221224 iTemperature = -99.0;
@@ -231,6 +234,25 @@ int usbrh::get_tempr_humid(double *tempr, double *humid)
231234 return rc;
232235 }
233236
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+
234256 void usbrh::close()
235257 {
236258 int rc = 0;
--- a/usbrh.h
+++ b/usbrh.h
@@ -27,6 +27,7 @@ public:
2727 int open();
2828 int config();
2929 int get_tempr_humid(double *tempr, double *humid);
30+ int set_led_status(unsigned char led_index, unsigned char led_onoff);
3031 void close();
3132
3233 };