
| Revision | 6cb7c7ba52a623d64cb1cfc136d71eba8a9d21ea (tree) |
|---|---|
| Time | 2013-03-24 13:14:14 |
| Author | alucky4416 <alucky4416@user...> |
| Commiter | alucky4416 |
replace usbrh.cpp, usbrh.h (add set led/heater on/off)
| @@ -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,44 @@ 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 | + | |
| 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 | + | |
| 234 | 275 | void usbrh::close() |
| 235 | 276 | { |
| 236 | 277 | int rc = 0; |
| @@ -27,6 +27,8 @@ 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); | |
| 31 | + int set_heater_status(unsigned char heater_onoff); | |
| 30 | 32 | void close(); |
| 31 | 33 | |
| 32 | 34 | }; |