• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

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

Commit MetaInfo

Revision6cb7c7ba52a623d64cb1cfc136d71eba8a9d21ea (tree)
Time2013-03-24 13:14:14
Authoralucky4416 <alucky4416@user...>
Commiteralucky4416

Log Message

replace usbrh.cpp, usbrh.h (add set led/heater on/off)

Change Summary

Incremental Difference

--- 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,44 @@ 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+
256+int usbrh::set_heater_status(unsigned char heater_onoff)
257+{
258+ int rc = 0;
259+ char buff[USBRH_BUFFER_SIZE];
260+
261+ if (gDevHandle == (usb_dev_handle *)NULL) return 1;
262+
263+ memset(buff, 0, sizeof(buff));
264+ buff[0] = 1;
265+ buff[1] = heater_onoff << 2; // heater_onoff = 1 is led on
266+ rc = usb_control_msg(gDevHandle, USB_ENDPOINT_OUT + USB_TYPE_CLASS + USB_RECIP_INTERFACE,
267+ 0x09, 0x03<<8, 0, buff, USBRH_BUFFER_SIZE, 5000);
268+ if (rc < 0) {
269+ qDebug() << QString("usb_control_msg error : ") << QString(usb_strerror());
270+ }
271+
272+ return rc;
273+}
274+
234275 void usbrh::close()
235276 {
236277 int rc = 0;
--- a/usbrh.h
+++ b/usbrh.h
@@ -27,6 +27,8 @@ 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);
31+ int set_heater_status(unsigned char heater_onoff);
3032 void close();
3133
3234 };