Changeset a339960844acef82f06e6c4ba82575fafc4e50ac
- Timestamp:
- 03/08/07 23:02:55 (6 years ago)
- Author:
- dsmith <dsmith@…>
- Children:
- d823757ade41d424c766973b8b4af2e80aa4086a
- Parents:
- 00fb3cb53077938d69d3e05f886c7005b4ada88e
- git-author:
- L. Donnie Smith <donnie.smith@…> (03/08/07 23:02:55)
- git-committer:
- dsmith <dsmith@…> (03/08/07 23:02:55)
- Message:
-
added wiimote_set_err
git-svn-id: http://abstrakraft.org/cwiid/svn/trunk@27 918edb2d-ff29-0410-9de2-eb38e7f22bc7
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r8c3c63a
|
ra339960
|
|
| | 1 | 2007-03-08 L. Donnie Smith <cwiid@abstrakraft.org> |
| | 2 | wiimote |
| | 3 | * created wiimote_err_t function type |
| | 4 | * created wiimote_set_err function |
| | 5 | * added wiimote parameter to wiimote_err calls |
| | 6 | |
| | 7 | wmdemo |
| | 8 | * added implementation of wiimote_err_t, wiimote_set_err |
| | 9 | |
| 1 | 10 | 2007-03-05 L. Donnie Smith <cwiid@abstrakraft.org> |
| 2 | 11 | * Type audit - boolean ints, const strings where appropriate, stdint.h |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote parameter to wiimote_err calls |
| | 20 | * |
| 18 | 21 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 22 | * * Initial ChangeLog |
| … |
… |
|
| 62 | 65 | buf[0] = 0; |
| 63 | 66 | if (send_report(wiimote, 0, RPT_STATUS_REQ, 1, buf)) { |
| 64 | | wiimote_err("Error requesting status"); |
| | 67 | wiimote_err(wiimote, "Error requesting status"); |
| 65 | 68 | ret = -1; |
| 66 | 69 | } |
| … |
… |
|
| 71 | 74 | buf[0]=wiimote->led_rumble_state; |
| 72 | 75 | if (send_report(wiimote, SEND_RPT_NO_RUMBLE, RPT_LED_RUMBLE, 1, buf)) { |
| 73 | | wiimote_err("Error setting LEDs"); |
| | 76 | wiimote_err(wiimote, "Error setting LEDs"); |
| 74 | 77 | ret = -1; |
| 75 | 78 | } |
| … |
… |
|
| 80 | 83 | buf[0]=wiimote->led_rumble_state; |
| 81 | 84 | if (send_report(wiimote, SEND_RPT_NO_RUMBLE, RPT_LED_RUMBLE, 1, buf)) { |
| 82 | | wiimote_err("Error setting rumble"); |
| | 85 | wiimote_err(wiimote, "Error setting rumble"); |
| 83 | 86 | ret = -1; |
| 84 | 87 | } |
| … |
… |
|
| 88 | 91 | break; |
| 89 | 92 | default: |
| 90 | | wiimote_err("Unknown command"); |
| | 93 | wiimote_err(wiimote, "Unknown command"); |
| 91 | 94 | ret = -1; |
| 92 | 95 | break; |
| … |
… |
|
| 106 | 109 | /* Lock wiimote access */ |
| 107 | 110 | if (pthread_mutex_lock(&wiimote->wiimote_mutex)) { |
| 108 | | wiimote_err("Error locking rw_mutex"); |
| | 111 | wiimote_err(wiimote, "Error locking rw_mutex"); |
| 109 | 112 | return -1; |
| 110 | 113 | } |
| … |
… |
|
| 157 | 160 | if ((flags & WIIMOTE_RPT_IR)) { |
| 158 | 161 | if (exec_write_seq(wiimote, seq_len, ir_enable_seq)) { |
| 159 | | wiimote_err("Error on IR enable"); |
| | 162 | wiimote_err(wiimote, "Error on IR enable"); |
| 160 | 163 | if (pthread_mutex_unlock(&wiimote->wiimote_mutex)) { |
| 161 | | wiimote_err("Error unlocking wiimote_mutex: deadlock warning"); |
| | 164 | wiimote_err(wiimote, |
| | 165 | "Error unlocking wiimote_mutex: deadlock warning"); |
| 162 | 166 | } |
| 163 | 167 | return -1; |
| … |
… |
|
| 169 | 173 | if (exec_write_seq(wiimote, SEQ_LEN(ir_disable_seq), |
| 170 | 174 | ir_disable_seq)) { |
| 171 | | wiimote_err("Error on IR enable"); |
| | 175 | wiimote_err(wiimote, "Error on IR enable"); |
| 172 | 176 | if (pthread_mutex_unlock(&wiimote->wiimote_mutex)) { |
| 173 | | wiimote_err("Error unlocking wiimote_mutex: deadlock warning"); |
| | 177 | wiimote_err(wiimote, |
| | 178 | "Error unlocking wiimote_mutex: deadlock warning"); |
| 174 | 179 | } |
| 175 | 180 | return -1; |
| … |
… |
|
| 181 | 186 | buf[1]=rpt_mode; |
| 182 | 187 | if (send_report(wiimote, 0, RPT_RPT_MODE, RPT_MODE_BUF_LEN, buf)) { |
| 183 | | wiimote_err("Error setting report state"); |
| | 188 | wiimote_err(wiimote, "Error setting report state"); |
| 184 | 189 | if (pthread_mutex_unlock(&wiimote->wiimote_mutex)) { |
| 185 | | wiimote_err("Error unlocking wiimote_mutex: deadlock warning"); |
| | 190 | wiimote_err(wiimote, |
| | 191 | "Error unlocking wiimote_mutex: deadlock warning"); |
| 186 | 192 | } |
| 187 | 193 | return -1; |
| … |
… |
|
| 192 | 198 | /* Unlock wiimote_mutex */ |
| 193 | 199 | if (pthread_mutex_unlock(&wiimote->wiimote_mutex)) { |
| 194 | | wiimote_err("Error unlocking wiimote_mutex: deadlock warning"); |
| | 200 | wiimote_err(wiimote, |
| | 201 | "Error unlocking wiimote_mutex: deadlock warning"); |
| 195 | 202 | } |
| 196 | 203 | |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote parameter to wiimote_err calls |
| | 20 | * |
| 18 | 21 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 22 | * * Initial ChangeLog |
| … |
… |
|
| 42 | 45 | /* TODO: clean up error checking and backout code */ |
| 43 | 46 | |
| | 47 | /* TODO: first two wiimote_err calls may pass bad ids due to race |
| | 48 | * conditions. If this is acceptable, at least document it. */ |
| | 49 | |
| 44 | 50 | /* Verify valid wiimote state */ |
| 45 | 51 | if ((wiimote = malloc(sizeof *wiimote)) == NULL) { |
| 46 | | wiimote_err("Error allocate wiimote)"); |
| | 52 | wiimote_err(NULL, "Error allocate wiimote)"); |
| 47 | 53 | return NULL; |
| 48 | 54 | } |
| … |
… |
|
| 50 | 56 | /* Global Lock, Store and Increment wiimote_id */ |
| 51 | 57 | if (pthread_mutex_lock(&global_mutex)) { |
| 52 | | wiimote_err("Error locking global lock"); |
| | 58 | wiimote_err(NULL, "Error locking global lock"); |
| 53 | 59 | free(wiimote); |
| 54 | 60 | return NULL; |
| … |
… |
|
| 56 | 62 | wiimote->id = wiimote_id++; |
| 57 | 63 | if (pthread_mutex_unlock(&global_mutex)) { |
| 58 | | wiimote_err("Error unlocking global lock"); |
| | 64 | wiimote_err(wiimote, "Error unlocking global lock"); |
| 59 | 65 | free(wiimote); |
| 60 | 66 | return NULL; |
| … |
… |
|
| 71 | 77 | if (memcmp(&bdaddr, BDADDR_ANY, sizeof(bdaddr_t)) == 0) { |
| 72 | 78 | if (wiimote_findfirst(&bdaddr)) { |
| | 79 | wiimote_err(wiimote, "Unable to find wiimote"); |
| 73 | 80 | free(wiimote); |
| 74 | | wiimote_err("Unable to find wiimote"); |
| 75 | 81 | return NULL; |
| 76 | 82 | } |
| … |
… |
|
| 95 | 101 | if (connect(wiimote->ctl_socket, (struct sockaddr *)&ctl_remote_addr, |
| 96 | 102 | sizeof(ctl_remote_addr))) { |
| 97 | | free(wiimote); |
| 98 | | wiimote_err("Error establishing control channel connection"); |
| | 103 | wiimote_err(wiimote, |
| | 104 | "Error establishing control channel connection"); |
| | 105 | free(wiimote); |
| 99 | 106 | return NULL; |
| 100 | 107 | } |
| … |
… |
|
| 102 | 109 | sizeof(int_remote_addr))) { |
| 103 | 110 | close(wiimote->ctl_socket); |
| 104 | | free(wiimote); |
| 105 | | wiimote_err("Error establishing interrupt channel connection"); |
| | 111 | wiimote_err(wiimote, |
| | 112 | "Error establishing interrupt channel connection"); |
| | 113 | free(wiimote); |
| 106 | 114 | return NULL; |
| 107 | 115 | } |
| … |
… |
|
| 110 | 118 | close(wiimote->int_socket); |
| 111 | 119 | close(wiimote->ctl_socket); |
| 112 | | free(wiimote); |
| 113 | | wiimote_err("Error creating dispatch queue"); |
| | 120 | wiimote_err(wiimote, "Error creating dispatch queue"); |
| | 121 | free(wiimote); |
| 114 | 122 | } |
| 115 | 123 | |
| … |
… |
|
| 124 | 132 | close(wiimote->ctl_socket); |
| 125 | 133 | queue_free(wiimote->dispatch_queue, (free_func_t *)free_mesg_array); |
| 126 | | free(wiimote); |
| 127 | | wiimote_err("Error initializing synchronization variables"); |
| | 134 | wiimote_err(wiimote, |
| | 135 | "Error initializing synchronization variables"); |
| | 136 | free(wiimote); |
| 128 | 137 | return NULL; |
| 129 | 138 | } |
| … |
… |
|
| 136 | 145 | close(wiimote->ctl_socket); |
| 137 | 146 | queue_free(wiimote->dispatch_queue, (free_func_t *)free_mesg_array); |
| 138 | | free(wiimote); |
| 139 | | wiimote_err("Error creating interrupt channel listener thread"); |
| | 147 | wiimote_err(wiimote, |
| | 148 | "Error creating interrupt channel listener thread"); |
| | 149 | free(wiimote); |
| 140 | 150 | return NULL; |
| 141 | 151 | } |
| … |
… |
|
| 147 | 157 | pthread_join(wiimote->int_listen_thread, NULL); |
| 148 | 158 | queue_free(wiimote->dispatch_queue, (free_func_t *)free_mesg_array); |
| 149 | | free(wiimote); |
| 150 | | wiimote_err("Error creating dispatch thread"); |
| | 159 | wiimote_err(wiimote, "Error creating dispatch thread"); |
| | 160 | free(wiimote); |
| 151 | 161 | return NULL; |
| 152 | 162 | } |
| … |
… |
|
| 169 | 179 | /* Cancel and join int_thread */ |
| 170 | 180 | if (pthread_cancel(wiimote->int_listen_thread)) { |
| 171 | | wiimote_err("Error canceling int_listen_thread"); |
| | 181 | wiimote_err(wiimote, "Error canceling int_listen_thread"); |
| 172 | 182 | } |
| 173 | 183 | else { |
| 174 | 184 | if (pthread_join(wiimote->int_listen_thread, &pthread_ret)) { |
| 175 | | wiimote_err("Error joining int_listen_thread"); |
| | 185 | wiimote_err(wiimote, "Error joining int_listen_thread"); |
| 176 | 186 | } |
| 177 | 187 | else if (pthread_ret != PTHREAD_CANCELED) { |
| 178 | | wiimote_err("Invalid return value from int_listen_thread"); |
| | 188 | wiimote_err(wiimote, |
| | 189 | "Invalid return value from int_listen_thread"); |
| 179 | 190 | } |
| 180 | 191 | } |
| … |
… |
|
| 184 | 195 | * code - specifically, a race condition exists for gtk apps */ |
| 185 | 196 | if (pthread_cancel(wiimote->dispatch_thread)) { |
| 186 | | wiimote_err("Error canceling dispatch_thread"); |
| | 197 | wiimote_err(wiimote, "Error canceling dispatch_thread"); |
| 187 | 198 | } |
| 188 | 199 | if (pthread_detach(wiimote->dispatch_thread)) { |
| 189 | | wiimote_err("Error detaching dispatch_thread"); |
| | 200 | wiimote_err(wiimote, "Error detaching dispatch_thread"); |
| 190 | 201 | } |
| 191 | 202 | |
| 192 | 203 | /* Close sockets */ |
| 193 | 204 | if (close(wiimote->int_socket)) { |
| 194 | | wiimote_err("Error closing interrupt channel"); |
| | 205 | wiimote_err(wiimote, "Error closing interrupt channel"); |
| 195 | 206 | } |
| 196 | 207 | if (close(wiimote->ctl_socket)) { |
| 197 | | wiimote_err("Error closing control channel"); |
| | 208 | wiimote_err(wiimote, "Error closing control channel"); |
| 198 | 209 | } |
| 199 | 210 | |
| 200 | 211 | /* Destroy sync variables */ |
| 201 | 212 | if (pthread_mutex_destroy(&wiimote->wiimote_mutex)) { |
| 202 | | wiimote_err("Error destroying wiimote_mutex"); |
| | 213 | wiimote_err(wiimote, "Error destroying wiimote_mutex"); |
| 203 | 214 | } |
| 204 | 215 | if (pthread_mutex_destroy(&wiimote->rw_mutex)) { |
| 205 | | wiimote_err("Error destroying rw_mutex"); |
| | 216 | wiimote_err(wiimote, "Error destroying rw_mutex"); |
| 206 | 217 | } |
| 207 | 218 | if (pthread_cond_destroy(&wiimote->rw_cond)) { |
| 208 | | wiimote_err("Error destroying rw_cond"); |
| | 219 | wiimote_err(wiimote, "Error destroying rw_cond"); |
| 209 | 220 | } |
| 210 | 221 | if (pthread_mutex_destroy(&wiimote->rw_cond_mutex)) { |
| 211 | | wiimote_err("Error destroying rw_cond_mutex"); |
| | 222 | wiimote_err(wiimote, "Error destroying rw_cond_mutex"); |
| 212 | 223 | } |
| 213 | 224 | |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote parameter to wiimote_err calls |
| | 20 | * |
| 18 | 21 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 22 | * * Initial ChangeLog |
| … |
… |
|
| 95 | 98 | |
| 96 | 99 | if ((mesg = malloc(sizeof *mesg)) == NULL) { |
| 97 | | wiimote_err("Error allocating status mesg"); |
| | 100 | wiimote_err(wiimote, "Error allocating status mesg"); |
| 98 | 101 | } |
| 99 | 102 | mesg->type = WIIMOTE_MESG_STATUS; |
| … |
… |
|
| 126 | 129 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_BTN) { |
| 127 | 130 | if ((mesg = malloc(sizeof *mesg)) == NULL) { |
| 128 | | wiimote_err("Error allocating btn mesg"); |
| | 131 | wiimote_err(wiimote, "Error allocating btn mesg"); |
| 129 | 132 | return -1; |
| 130 | 133 | } |
| … |
… |
|
| 147 | 150 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_ACC) { |
| 148 | 151 | if ((mesg = malloc(sizeof *mesg)) == NULL) { |
| 149 | | wiimote_err("Error allocating acc mesg"); |
| | 152 | wiimote_err(wiimote, "Error allocating acc mesg"); |
| 150 | 153 | return -1; |
| 151 | 154 | } |
| … |
… |
|
| 171 | 174 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_IR) { |
| 172 | 175 | if ((mesg = malloc(sizeof *mesg)) == NULL) { |
| 173 | | wiimote_err("Error allocating ir mesg"); |
| | 176 | wiimote_err(wiimote, "Error allocating ir mesg"); |
| 174 | 177 | return -1; |
| 175 | 178 | } |
| … |
… |
|
| 218 | 221 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_IR) { |
| 219 | 222 | if ((mesg = malloc(sizeof *mesg)) == NULL) { |
| 220 | | wiimote_err("Error allocating ir mesg"); |
| | 223 | wiimote_err(wiimote, "Error allocating ir mesg"); |
| 221 | 224 | return -1; |
| 222 | 225 | } |
| … |
… |
|
| 253 | 256 | switch (wiimote->extension) { |
| 254 | 257 | case WIIMOTE_EXT_NONE: |
| 255 | | wiimote_err("Extension report received with no extension present"); |
| | 258 | wiimote_err(wiimote, |
| | 259 | "Extension report received with no extension present"); |
| 256 | 260 | break; |
| 257 | 261 | case WIIMOTE_EXT_UNKNOWN: |
| … |
… |
|
| 260 | 264 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_NUNCHUK) { |
| 261 | 265 | if ((nunchuk_mesg = malloc(sizeof *nunchuk_mesg)) == NULL) { |
| 262 | | wiimote_err("Error allocating nunchuk mesg"); |
| | 266 | wiimote_err(wiimote, "Error allocating nunchuk mesg"); |
| 263 | 267 | return -1; |
| 264 | 268 | } |
| … |
… |
|
| 280 | 284 | if (wiimote->rpt_mode_flags & WIIMOTE_RPT_CLASSIC) { |
| 281 | 285 | if ((classic_mesg = malloc(sizeof *classic_mesg)) == NULL) { |
| 282 | | wiimote_err("Error allocating classic mesg"); |
| | 286 | wiimote_err(wiimote, "Error allocating classic mesg"); |
| 283 | 287 | return -1; |
| 284 | 288 | } |
| … |
… |
|
| 322 | 326 | /* Read packet */ |
| 323 | 327 | if ((len = read(wiimote->int_socket, buf, READ_BUF_LEN)) == -1) { |
| 324 | | wiimote_err("Interrupt channel read error"); |
| | 328 | wiimote_err(wiimote, "Interrupt channel read error"); |
| 325 | 329 | } |
| 326 | 330 | else { |
| 327 | 331 | /* Verify first byte (DATA/INPUT) */ |
| 328 | 332 | if (buf[0] != (BT_TRANS_DATA | BT_PARAM_INPUT)) { |
| 329 | | wiimote_err("Invalid packet type"); |
| | 333 | wiimote_err(wiimote, "Invalid packet type"); |
| 330 | 334 | } |
| 331 | 335 | |
| … |
… |
|
| 343 | 347 | case RPT_EXT21: |
| 344 | 348 | if ((mesg_array = malloc(sizeof *mesg_array)) == NULL) { |
| 345 | | wiimote_err("Error allocating mesg array"); |
| | 349 | wiimote_err(wiimote, "Error allocating mesg array"); |
| 346 | 350 | break; |
| 347 | 351 | } |
| … |
… |
|
| 417 | 421 | if (queue_queue(wiimote->dispatch_queue, mesg_array)) { |
| 418 | 422 | free_mesg_array(mesg_array); |
| 419 | | wiimote_err("error dispatching mesg array"); |
| | 423 | wiimote_err(wiimote, |
| | 424 | "error dispatching mesg array"); |
| 420 | 425 | } |
| 421 | 426 | } |
| … |
… |
|
| 423 | 428 | case RPT_BTN_ACC_IR36_1: |
| 424 | 429 | case RPT_BTN_ACC_IR36_2: |
| 425 | | wiimote_err("Unsupported report type received " |
| | 430 | wiimote_err(wiimote, "Unsupported report type received " |
| 426 | 431 | "(interleaved data)"); |
| 427 | 432 | break; |
| … |
… |
|
| 437 | 442 | if (((data_len+wiimote->read_received)> |
| 438 | 443 | wiimote->read_len) || error) { |
| 439 | | wiimote_err("Error in read data"); |
| | 444 | wiimote_err(wiimote, "Error in read data"); |
| 440 | 445 | wiimote->rw_status = RW_ERROR; |
| 441 | 446 | } |
| … |
… |
|
| 454 | 459 | * rw_cond_mutex */ |
| 455 | 460 | if (pthread_mutex_lock(&wiimote->rw_cond_mutex)) { |
| 456 | | wiimote_err("Error locking rw_cond_mutex"); |
| | 461 | wiimote_err(wiimote, |
| | 462 | "Error locking rw_cond_mutex"); |
| 457 | 463 | } |
| 458 | 464 | else { |
| 459 | 465 | if (pthread_cond_signal(&wiimote->rw_cond)) { |
| 460 | | wiimote_err("Error signaling rw_cond: " |
| | 466 | wiimote_err(wiimote, |
| | 467 | "Error signaling rw_cond: " |
| 461 | 468 | "deadlock warning"); |
| 462 | 469 | } |
| 463 | 470 | if (pthread_mutex_unlock( |
| 464 | 471 | &wiimote->rw_cond_mutex)) { |
| 465 | | wiimote_err("Error unlocking rw_cond_mutex: " |
| | 472 | wiimote_err(wiimote, |
| | 473 | "Error unlocking rw_cond_mutex: " |
| 466 | 474 | "deadlock warning"); |
| 467 | 475 | } |
| … |
… |
|
| 471 | 479 | } |
| 472 | 480 | else { |
| 473 | | wiimote_err("Extraneous read data received"); |
| | 481 | wiimote_err(wiimote, "Extraneous read data received"); |
| 474 | 482 | } |
| 475 | 483 | break; |
| … |
… |
|
| 480 | 488 | * write_cond_mutex */ |
| 481 | 489 | if (pthread_mutex_lock(&wiimote->rw_cond_mutex)) { |
| 482 | | wiimote_err("Error locking rw_cond_mutex"); |
| | 490 | wiimote_err(wiimote, |
| | 491 | "Error locking rw_cond_mutex"); |
| 483 | 492 | } |
| 484 | 493 | else { |
| 485 | 494 | if (pthread_cond_signal(&wiimote->rw_cond)) { |
| 486 | | wiimote_err("Error signaling rw_cond: " |
| | 495 | wiimote_err(wiimote, |
| | 496 | "Error signaling rw_cond: " |
| 487 | 497 | "deadlock warning"); |
| 488 | 498 | } |
| 489 | 499 | if (pthread_mutex_unlock( |
| 490 | 500 | &wiimote->rw_cond_mutex)) { |
| 491 | | wiimote_err("Error unlocking rw_cond_mutex: " |
| 492 | | "deadlock warning"); |
| | 501 | wiimote_err(wiimote, |
| | 502 | "Error unlocking rw_cond_mutex: " |
| | 503 | "deadlock warning"); |
| 493 | 504 | } |
| 494 | 505 | } |
| 495 | 506 | } |
| 496 | 507 | else { |
| 497 | | wiimote_err("Extraneous write ack received"); |
| | 508 | wiimote_err(wiimote, "Extraneous write ack received"); |
| 498 | 509 | } |
| 499 | 510 | break; |
| 500 | 511 | default: |
| 501 | | wiimote_err("Unknown message type"); |
| | 512 | wiimote_err(wiimote, "Unknown message type"); |
| 502 | 513 | break; |
| 503 | 514 | } |
| … |
… |
|
| 513 | 524 | { |
| 514 | 525 | if (queue_free(queue, (free_func_t *)free_mesg_array)) { |
| 515 | | wiimote_err("Error freeing dispatch queue"); |
| | 526 | /* TODO: return proper wiimote id */ |
| | 527 | wiimote_err(NULL, "Error freeing dispatch queue"); |
| 516 | 528 | } |
| 517 | 529 | } |
| … |
… |
|
| 529 | 541 | do { |
| 530 | 542 | if (queue_wait(dispatch_queue)) { |
| 531 | | wiimote_err("Error waiting on dispatch_queue"); |
| | 543 | wiimote_err(wiimote, "Error waiting on dispatch_queue"); |
| 532 | 544 | return NULL; |
| 533 | 545 | } |
| … |
… |
|
| 538 | 550 | pthread_testcancel(); |
| 539 | 551 | if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate)) { |
| 540 | | wiimote_err("Error disabling cancel state"); |
| | 552 | wiimote_err(wiimote, "Error disabling cancel state"); |
| 541 | 553 | } |
| 542 | 554 | else { |
| … |
… |
|
| 551 | 563 | if (wiimote_write(wiimote, WIIMOTE_RW_REG, 0xA40040, 1, |
| 552 | 564 | &buf)) { |
| 553 | | wiimote_err("Error initializing extension"); |
| | 565 | wiimote_err(wiimote, |
| | 566 | "Error initializing extension"); |
| 554 | 567 | wiimote->extension = WIIMOTE_EXT_UNKNOWN; |
| 555 | 568 | } |
| … |
… |
|
| 557 | 570 | WIIMOTE_RW_REG | WIIMOTE_RW_DECODE, 0xA400FE, |
| 558 | 571 | 1, &buf)) { |
| 559 | | wiimote_err("Error reading extension type"); |
| | 572 | wiimote_err(wiimote, |
| | 573 | "Error reading extension type"); |
| 560 | 574 | wiimote->extension = WIIMOTE_EXT_UNKNOWN; |
| 561 | 575 | } |
| … |
… |
|
| 583 | 597 | |
| 584 | 598 | if (update_rpt_mode(wiimote, -1)) { |
| 585 | | wiimote_err("Error reseting report mode"); |
| | 599 | wiimote_err(wiimote, "Error reseting report mode"); |
| 586 | 600 | } |
| 587 | 601 | |
| … |
… |
|
| 602 | 616 | } |
| 603 | 617 | if (pthread_setcancelstate(cancelstate, &cancelstate)) { |
| 604 | | wiimote_err("Error enabling cancel state"); |
| | 618 | wiimote_err(wiimote, "Error enabling cancel state"); |
| 605 | 619 | } |
| 606 | 620 | } |
| … |
… |
|
| 610 | 624 | |
| 611 | 625 | /* This code should never execute */ |
| 612 | | wiimote_err("Exiting dispatch thread"); |
| | 626 | wiimote_err(wiimote, "Exiting dispatch thread"); |
| 613 | 627 | |
| 614 | 628 | pthread_cleanup_pop(1); |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote parameter to wiimote_err calls |
| | 20 | * |
| 18 | 21 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 22 | * * Initial ChangeLog |
| … |
… |
|
| 55 | 58 | /* Lock wiimote rw access */ |
| 56 | 59 | if (pthread_mutex_lock(&wiimote->rw_mutex)) { |
| 57 | | wiimote_err("Error locking rw_mutex"); |
| | 60 | wiimote_err(wiimote, "Error locking rw_mutex"); |
| 58 | 61 | return -1; |
| 59 | 62 | } |
| … |
… |
|
| 77 | 80 | /* Send read request packet */ |
| 78 | 81 | if (send_report(wiimote, 0, RPT_READ_REQ, RPT_READ_REQ_LEN, buf)) { |
| 79 | | wiimote_err("Error sending read request"); |
| | 82 | wiimote_err(wiimote, "Error sending read request"); |
| 80 | 83 | ret = -1; |
| 81 | 84 | } |
| 82 | 85 | /* Lock rw_cond_mutex */ |
| 83 | 86 | else if (pthread_mutex_lock(&wiimote->rw_cond_mutex)) { |
| 84 | | wiimote_err("Error locking rw_cond_mutex"); |
| | 87 | wiimote_err(wiimote, "Error locking rw_cond_mutex"); |
| 85 | 88 | ret = -1; |
| 86 | 89 | } |
| … |
… |
|
| 90 | 93 | if (pthread_cond_wait(&wiimote->rw_cond, |
| 91 | 94 | &wiimote->rw_cond_mutex)) { |
| 92 | | wiimote_err("Error waiting on rw_cond"); |
| | 95 | wiimote_err(wiimote, "Error waiting on rw_cond"); |
| 93 | 96 | ret = -1; |
| 94 | 97 | } |
| … |
… |
|
| 96 | 99 | /* Unlock rw_cond_mutex */ |
| 97 | 100 | if (pthread_mutex_unlock(&wiimote->rw_cond_mutex)) { |
| 98 | | wiimote_err("Error unlocking rw_cond_mutex: deadlock warning"); |
| | 101 | wiimote_err(wiimote, |
| | 102 | "Error unlocking rw_cond_mutex: deadlock warning"); |
| 99 | 103 | } |
| 100 | 104 | |
| … |
… |
|
| 113 | 117 | /* Unlock rw_mutex */ |
| 114 | 118 | if (pthread_mutex_unlock(&wiimote->rw_mutex)) { |
| 115 | | wiimote_err("Error unlocking rw_mutex: deadlock warning"); |
| | 119 | wiimote_err(wiimote, "Error unlocking rw_mutex: deadlock warning"); |
| 116 | 120 | } |
| 117 | 121 | |
| … |
… |
|
| 135 | 139 | /* Lock wiimote rw access */ |
| 136 | 140 | if (pthread_mutex_lock(&wiimote->rw_mutex)) { |
| 137 | | wiimote_err("Error locking rw_mutex"); |
| | 141 | wiimote_err(wiimote, "Error locking rw_mutex"); |
| 138 | 142 | return -1; |
| 139 | 143 | } |
| … |
… |
|
| 156 | 160 | wiimote->rw_status = RW_PENDING; |
| 157 | 161 | if (send_report(wiimote, 0, RPT_WRITE, RPT_WRITE_LEN, buf)) { |
| 158 | | wiimote_err("Error sending write"); |
| | 162 | wiimote_err(wiimote, "Error sending write"); |
| 159 | 163 | ret = -1; |
| 160 | 164 | } |
| 161 | 165 | /* Lock rw_cond_mutex */ |
| 162 | 166 | else if (pthread_mutex_lock(&wiimote->rw_cond_mutex)) { |
| 163 | | wiimote_err("Error locking rw_cond_mutex"); |
| | 167 | wiimote_err(wiimote, "Error locking rw_cond_mutex"); |
| 164 | 168 | ret = -1; |
| 165 | 169 | } |
| … |
… |
|
| 169 | 173 | if (pthread_cond_wait(&wiimote->rw_cond, |
| 170 | 174 | &wiimote->rw_cond_mutex)) { |
| 171 | | wiimote_err("Error waiting on rw_cond"); |
| | 175 | wiimote_err(wiimote, "Error waiting on rw_cond"); |
| 172 | 176 | ret = -1; |
| 173 | 177 | } |
| … |
… |
|
| 175 | 179 | /* Unlock rw_cond_mutex */ |
| 176 | 180 | if (pthread_mutex_unlock(&wiimote->rw_cond_mutex)) { |
| 177 | | wiimote_err("Error unlocking rw_cond_mutex: deadlock warning"); |
| | 181 | wiimote_err(wiimote, |
| | 182 | "Error unlocking rw_cond_mutex: deadlock warning"); |
| 178 | 183 | } |
| 179 | 184 | |
| … |
… |
|
| 194 | 199 | /* Unlock rw_mutex */ |
| 195 | 200 | if (pthread_mutex_unlock(&wiimote->rw_mutex)) { |
| 196 | | wiimote_err("Error unlocking rw_mutex: deadlock warning"); |
| | 201 | wiimote_err(wiimote, "Error unlocking rw_mutex: deadlock warning"); |
| 197 | 202 | } |
| 198 | 203 | |
| … |
… |
|
| 217 | 222 | if (exec_write_seq(wiimote, SEQ_LEN(speaker_enable_seq), |
| 218 | 223 | speaker_enable_seq)) { |
| 219 | | wiimote_err("Error on speaker enable"); |
| | 224 | wiimote_err(wiimote, "Error on speaker enable"); |
| 220 | 225 | ret = -1; |
| 221 | 226 | } |
| … |
… |
|
| 229 | 234 | if (send_report(wiimote, 0, RPT_SPEAKER_DATA, SOUND_BUF_LEN, buf)) { |
| 230 | 235 | printf("%d\n", i); |
| 231 | | wiimote_err("Error on speaker data"); |
| | 236 | wiimote_err(wiimote, "Error on speaker data"); |
| 232 | 237 | ret = -1; |
| 233 | 238 | break; |
| … |
… |
|
| 242 | 247 | if (exec_write_seq(wiimote, SEQ_LEN(speaker_disable_seq), |
| 243 | 248 | speaker_disable_seq)) { |
| 244 | | wiimote_err("Error on speaker disable"); |
| | 249 | wiimote_err(wiimote, "Error on speaker disable"); |
| 245 | 250 | ret = -1; |
| 246 | 251 | } |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * created wiimote_err_func variable |
| | 20 | * * created wiimote_err_default |
| | 21 | * * added wiimote parameter to wiimote_err definition and calls |
| | 22 | * |
| 18 | 23 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 24 | * * Initial ChangeLog |
| … |
… |
|
| 32 | 37 | #include "wiimote_internal.h" |
| 33 | 38 | |
| 34 | | void wiimote_err(const char *str, ...) |
| | 39 | static wiimote_err_t wiimote_err_default; |
| | 40 | |
| | 41 | static wiimote_err_t *wiimote_err_func = &wiimote_err_default; |
| | 42 | |
| | 43 | int wiimote_set_err(wiimote_err_t *err) |
| | 44 | { |
| | 45 | /* TODO: assuming pointer assignment is atomic operation */ |
| | 46 | /* if it is, and the user doesn't care about race conditions, we don't |
| | 47 | * either */ |
| | 48 | wiimote_err_func = err; |
| | 49 | return 0; |
| | 50 | } |
| | 51 | |
| | 52 | static void wiimote_err_default(int id, const char *str, ...) |
| 35 | 53 | { |
| 36 | 54 | va_list ap; |
| … |
… |
|
| 42 | 60 | } |
| 43 | 61 | |
| | 62 | void wiimote_err(struct wiimote *wiimote, const char *str, ...) |
| | 63 | { |
| | 64 | va_list ap; |
| | 65 | |
| | 66 | if (wiimote_err_func) { |
| | 67 | va_start(ap, str); |
| | 68 | if (wiimote) { |
| | 69 | (*wiimote_err_func)(wiimote->id, str, ap); |
| | 70 | } |
| | 71 | else { |
| | 72 | (*wiimote_err_func)(-1, str, ap); |
| | 73 | } |
| | 74 | va_end(ap); |
| | 75 | } |
| | 76 | } |
| | 77 | |
| 44 | 78 | int verify_handshake(struct wiimote *wiimote) |
| 45 | 79 | { |
| 46 | 80 | unsigned char handshake; |
| 47 | 81 | if (read(wiimote->ctl_socket, &handshake, 1) != 1) { |
| 48 | | wiimote_err("Error on read handshake"); |
| | 82 | wiimote_err(wiimote, "Error on read handshake"); |
| 49 | 83 | return -1; |
| 50 | 84 | } |
| 51 | 85 | else if ((handshake & BT_TRANS_MASK) != BT_TRANS_HANDSHAKE) { |
| 52 | | wiimote_err("Handshake expected, non-handshake received"); |
| | 86 | wiimote_err(wiimote, "Handshake expected, non-handshake received"); |
| 53 | 87 | return -1; |
| 54 | 88 | } |
| 55 | 89 | else if ((handshake & BT_PARAM_MASK) != BT_PARAM_SUCCESSFUL) { |
| 56 | | wiimote_err("Non-successful handshake"); |
| | 90 | wiimote_err(wiimote, "Non-successful handshake"); |
| 57 | 91 | return -1; |
| 58 | 92 | } |
| … |
… |
|
| 139 | 173 | /* Get the first available Bluetooth device */ |
| 140 | 174 | if ((dev_id = hci_get_route(NULL)) == -1) { |
| 141 | | wiimote_err("No Bluetooth device found"); |
| | 175 | wiimote_err(NULL, "No Bluetooth device found"); |
| 142 | 176 | return -1; |
| 143 | 177 | } |
| 144 | 178 | if ((sock = hci_open_dev(dev_id)) == -1) { |
| 145 | | wiimote_err("Error opening Bluetooth device"); |
| | 179 | wiimote_err(NULL, "Error opening Bluetooth device"); |
| 146 | 180 | return -1; |
| 147 | 181 | } |
| … |
… |
|
| 150 | 184 | if ((dev_count = hci_inquiry(dev_id, 2, MAX_RSP, NULL, &dev_list, |
| 151 | 185 | IREQ_CACHE_FLUSH)) == -1) { |
| 152 | | wiimote_err("Error on device inquiry"); |
| | 186 | wiimote_err(NULL, "Error on device inquiry"); |
| 153 | 187 | hci_close_dev(sock); |
| 154 | 188 | return -1; |
| … |
… |
|
| 162 | 196 | if (hci_remote_name(sock, &dev_list[i].bdaddr, WIIMOTE_CMP_LEN, |
| 163 | 197 | dev_name, 5000)) { |
| 164 | | wiimote_err("Error reading device name"); |
| | 198 | wiimote_err(NULL, "Error reading device name"); |
| 165 | 199 | } |
| 166 | 200 | else if (strncmp(dev_name, WIIMOTE_NAME, WIIMOTE_CMP_LEN) == 0) { |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote_err_t definition |
| | 20 | * * added wiimote_set_err prototype |
| | 21 | * |
| 18 | 22 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 23 | * * Initial ChangeLog |
| … |
… |
|
| 189 | 193 | |
| 190 | 194 | typedef void wiimote_mesg_callback_t(int, int, union wiimote_mesg* []); |
| | 195 | typedef void wiimote_err_t(int, const char *, ...); |
| 191 | 196 | |
| 192 | 197 | #ifdef __cplusplus |
| … |
… |
|
| 194 | 199 | #endif |
| 195 | 200 | |
| | 201 | int wiimote_set_err(wiimote_err_t *err); |
| 196 | 202 | wiimote_t *wiimote_connect(bdaddr_t bdaddr, |
| 197 | 203 | wiimote_mesg_callback_t *mesg_callback, |
-
|
rc033b7a
|
ra339960
|
|
| 16 | 16 | * |
| 17 | 17 | * ChangeLog: |
| | 18 | * 03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| | 19 | * * added wiimote parameter to wiimote_err prototype |
| | 20 | * |
| 18 | 21 | * 03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> |
| 19 | 22 | * * Initial ChangeLog |
| … |
… |
|
| 164 | 167 | int update_rpt_mode(struct wiimote *wiimote, int8_t flags); |
| 165 | 168 | |
| 166 | | void wiimote_err(const char *str, ...); |
| | 169 | void wiimote_err(struct wiimote *wiimote, const char *str, ...); |
| 167 | 170 | int verify_handshake(struct wiimote *wiimote); |
| 168 | 171 | int send_report(struct wiimote *wiimote, uint8_t flags, uint8_t report, |
-
|
r15d141c
|
ra339960
|
|
| | 1 | #include <stdarg.h> |
| 1 | 2 | #include <stdio.h> |
| 2 | 3 | |
| … |
… |
|
| 8 | 9 | * parts easily. For examples of read and write code, see wmgui. Speaker |
| 9 | 10 | * support is "experimental" (read: bad) enough to be disabled. The beginnings |
| 10 | | * of a speaker output program are in libwiimote source. */ |
| | 11 | * of a speaker output function are in libwiimote source. */ |
| 11 | 12 | /* Note: accelerometer (including nunchuk) and IR outputs produce a |
| 12 | 13 | * lot of data - the purpose of this program is demonstration, not good |
| … |
… |
|
| 22 | 23 | void set_led_state(wiimote_t *wiimote, unsigned char led_state); |
| 23 | 24 | void set_rpt_mode(wiimote_t *wiimote, unsigned char rpt_mode); |
| | 25 | |
| | 26 | wiimote_err_t err; |
| | 27 | void err(int id, const char *s, ...) |
| | 28 | { |
| | 29 | va_list ap; |
| | 30 | |
| | 31 | va_start(ap, s); |
| | 32 | printf("%d:", id); |
| | 33 | vprintf(s, ap); |
| | 34 | printf("\n"); |
| | 35 | va_end(ap); |
| | 36 | } |
| 24 | 37 | |
| 25 | 38 | int main(int argc, char *argv[]) |
| … |
… |
|
| 33 | 46 | unsigned char rumble = 0; |
| 34 | 47 | int exit = 0; |
| | 48 | |
| | 49 | wiimote_set_err(err); |
| 35 | 50 | |
| 36 | 51 | /* Connect to any wiimote */ |
-
|
rc033b7a
|
ra339960
|
|
| 170 | 170 | #define USAGE "usage:%s [-h] [BDADDR]\n" |
| 171 | 171 | |
| | 172 | wiimote_err_t err; |
| | 173 | |
| | 174 | void err(int id, const char *s, ...) |
| | 175 | { |
| | 176 | message(GTK_MESSAGE_ERROR, s, GTK_WINDOW(winMain)); |
| | 177 | } |
| | 178 | |
| 172 | 179 | int main (int argc, char *argv[]) |
| 173 | 180 | { |
| … |
… |
|
| 183 | 190 | gdk_threads_init(); |
| 184 | 191 | gdk_threads_enter(); |
| | 192 | |
| | 193 | wiimote_set_err(err); |
| 185 | 194 | |
| 186 | 195 | /* Parse Options */ |