
ストロベリー・リナックスUSB温度計USBRHを使った温度計 by Qt
| Revision | 5b1379c54f22dca4e8adfc6066350b5b6a6b05cd (tree) |
|---|---|
| Time | 2013-03-24 12:35:06 |
| Author | alucky4416 <alucky4416@user...> |
| Commiter | arakaki |
feature: add set heater on/off.
| @@ -88,3 +88,10 @@ void MainWindow::on_checkBox_LED_1_stateChanged(int arg1) | ||
| 88 | 88 | rc = rhdev->set_led_status(1, (unsigned char)arg1); |
| 89 | 89 | |
| 90 | 90 | } |
| 91 | + | |
| 92 | +void MainWindow::on_checkBox_HEATER_stateChanged(int arg1) | |
| 93 | +{ | |
| 94 | + int rc; | |
| 95 | + rc = rhdev->set_heater_status((unsigned char)arg1); | |
| 96 | + | |
| 97 | +} |
| @@ -25,6 +25,8 @@ private slots: | ||
| 25 | 25 | |
| 26 | 26 | void on_checkBox_LED_1_stateChanged(int arg1); |
| 27 | 27 | |
| 28 | + void on_checkBox_HEATER_stateChanged(int arg1); | |
| 29 | + | |
| 28 | 30 | private: |
| 29 | 31 | Ui::MainWindow *ui; |
| 30 | 32 |
| @@ -174,7 +174,7 @@ | ||
| 174 | 174 | <widget class="QCheckBox" name="checkBox_LED_1"> |
| 175 | 175 | <property name="geometry"> |
| 176 | 176 | <rect> |
| 177 | - <x>210</x> | |
| 177 | + <x>140</x> | |
| 178 | 178 | <y>120</y> |
| 179 | 179 | <width>80</width> |
| 180 | 180 | <height>20</height> |
| @@ -184,6 +184,19 @@ | ||
| 184 | 184 | <string>LED 1</string> |
| 185 | 185 | </property> |
| 186 | 186 | </widget> |
| 187 | + <widget class="QCheckBox" name="checkBox_HEATER"> | |
| 188 | + <property name="geometry"> | |
| 189 | + <rect> | |
| 190 | + <x>270</x> | |
| 191 | + <y>120</y> | |
| 192 | + <width>80</width> | |
| 193 | + <height>20</height> | |
| 194 | + </rect> | |
| 195 | + </property> | |
| 196 | + <property name="text"> | |
| 197 | + <string>Heater</string> | |
| 198 | + </property> | |
| 199 | + </widget> | |
| 187 | 200 | </widget> |
| 188 | 201 | <widget class="QMenuBar" name="menuBar"> |
| 189 | 202 | <property name="geometry"> |
| @@ -253,6 +253,25 @@ int usbrh::set_led_status(unsigned char led_index, unsigned char led_onoff) | ||
| 253 | 253 | return rc; |
| 254 | 254 | } |
| 255 | 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 | + | |
| 256 | 275 | void usbrh::close() |
| 257 | 276 | { |
| 258 | 277 | int rc = 0; |
| @@ -28,6 +28,7 @@ public: | ||
| 28 | 28 | int config(); |
| 29 | 29 | int get_tempr_humid(double *tempr, double *humid); |
| 30 | 30 | int set_led_status(unsigned char led_index, unsigned char led_onoff); |
| 31 | + int set_heater_status(unsigned char heater_onoff); | |
| 31 | 32 | void close(); |
| 32 | 33 | |
| 33 | 34 | }; |