Changeset a339960844acef82f06e6c4ba82575fafc4e50ac

Show
Ignore:
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:
10 modified

Legend:

Unmodified
Added
Removed
  • ChangeLog

    r8c3c63a ra339960  
     12007-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 
    1102007-03-05 L. Donnie Smith <cwiid@abstrakraft.org> 
    211        * Type audit - boolean ints, const strings where appropriate, stdint.h 
  • wiimote/command.c

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote parameter to wiimote_err calls 
     20 * 
    1821 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * Initial ChangeLog 
     
    6265                buf[0] = 0; 
    6366                if (send_report(wiimote, 0, RPT_STATUS_REQ, 1, buf)) { 
    64                         wiimote_err("Error requesting status"); 
     67                        wiimote_err(wiimote, "Error requesting status"); 
    6568                        ret = -1; 
    6669                } 
     
    7174                buf[0]=wiimote->led_rumble_state; 
    7275                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"); 
    7477                        ret = -1; 
    7578                } 
     
    8083                buf[0]=wiimote->led_rumble_state; 
    8184                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"); 
    8386                        ret = -1; 
    8487                } 
     
    8891                break; 
    8992        default: 
    90                 wiimote_err("Unknown command"); 
     93                wiimote_err(wiimote, "Unknown command"); 
    9194                ret = -1; 
    9295                break; 
     
    106109        /* Lock wiimote access */ 
    107110        if (pthread_mutex_lock(&wiimote->wiimote_mutex)) { 
    108                 wiimote_err("Error locking rw_mutex"); 
     111                wiimote_err(wiimote, "Error locking rw_mutex"); 
    109112                return -1; 
    110113        } 
     
    157160        if ((flags & WIIMOTE_RPT_IR)) { 
    158161                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"); 
    160163                        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"); 
    162166                        } 
    163167                        return -1; 
     
    169173                if (exec_write_seq(wiimote, SEQ_LEN(ir_disable_seq), 
    170174                                   ir_disable_seq)) { 
    171                         wiimote_err("Error on IR enable"); 
     175                        wiimote_err(wiimote, "Error on IR enable"); 
    172176                        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"); 
    174179                        } 
    175180                        return -1; 
     
    181186        buf[1]=rpt_mode; 
    182187        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"); 
    184189                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"); 
    186192                } 
    187193                return -1; 
     
    192198        /* Unlock wiimote_mutex */ 
    193199        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"); 
    195202        } 
    196203 
  • wiimote/connect.c

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote parameter to wiimote_err calls 
     20 * 
    1821 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * Initial ChangeLog 
     
    4245        /* TODO: clean up error checking and backout code */ 
    4346 
     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 
    4450        /* Verify valid wiimote state */ 
    4551        if ((wiimote = malloc(sizeof *wiimote)) == NULL) { 
    46                 wiimote_err("Error allocate wiimote)"); 
     52                wiimote_err(NULL, "Error allocate wiimote)"); 
    4753                return NULL; 
    4854        } 
     
    5056        /* Global Lock, Store and Increment wiimote_id */ 
    5157        if (pthread_mutex_lock(&global_mutex)) { 
    52                 wiimote_err("Error locking global lock"); 
     58                wiimote_err(NULL, "Error locking global lock"); 
    5359                free(wiimote); 
    5460                return NULL; 
     
    5662        wiimote->id = wiimote_id++; 
    5763        if (pthread_mutex_unlock(&global_mutex)) { 
    58                 wiimote_err("Error unlocking global lock"); 
     64                wiimote_err(wiimote, "Error unlocking global lock"); 
    5965                free(wiimote); 
    6066                return NULL; 
     
    7177        if (memcmp(&bdaddr, BDADDR_ANY, sizeof(bdaddr_t)) == 0) { 
    7278                if (wiimote_findfirst(&bdaddr)) { 
     79                        wiimote_err(wiimote, "Unable to find wiimote"); 
    7380                        free(wiimote); 
    74                         wiimote_err("Unable to find wiimote"); 
    7581                        return NULL; 
    7682                } 
     
    95101        if (connect(wiimote->ctl_socket, (struct sockaddr *)&ctl_remote_addr, 
    96102                        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); 
    99106                return NULL; 
    100107        } 
     
    102109                             sizeof(int_remote_addr))) { 
    103110                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); 
    106114                return NULL; 
    107115        } 
     
    110118                close(wiimote->int_socket); 
    111119                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); 
    114122        } 
    115123                 
     
    124132                close(wiimote->ctl_socket); 
    125133                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); 
    128137                return NULL; 
    129138        } 
     
    136145                close(wiimote->ctl_socket); 
    137146                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); 
    140150                return NULL; 
    141151        } 
     
    147157                pthread_join(wiimote->int_listen_thread, NULL); 
    148158                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); 
    151161                return NULL; 
    152162        } 
     
    169179        /* Cancel and join int_thread */ 
    170180        if (pthread_cancel(wiimote->int_listen_thread)) { 
    171                 wiimote_err("Error canceling int_listen_thread"); 
     181                wiimote_err(wiimote, "Error canceling int_listen_thread"); 
    172182        } 
    173183        else { 
    174184                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"); 
    176186                } 
    177187                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"); 
    179190                } 
    180191        } 
     
    184195         * code - specifically, a race condition exists for gtk apps */ 
    185196        if (pthread_cancel(wiimote->dispatch_thread)) { 
    186                 wiimote_err("Error canceling dispatch_thread"); 
     197                wiimote_err(wiimote, "Error canceling dispatch_thread"); 
    187198        } 
    188199        if (pthread_detach(wiimote->dispatch_thread)) { 
    189                 wiimote_err("Error detaching dispatch_thread"); 
     200                wiimote_err(wiimote, "Error detaching dispatch_thread"); 
    190201        } 
    191202 
    192203        /* Close sockets */ 
    193204        if (close(wiimote->int_socket)) { 
    194                 wiimote_err("Error closing interrupt channel"); 
     205                wiimote_err(wiimote, "Error closing interrupt channel"); 
    195206        } 
    196207        if (close(wiimote->ctl_socket)) { 
    197                 wiimote_err("Error closing control channel"); 
     208                wiimote_err(wiimote, "Error closing control channel"); 
    198209        } 
    199210 
    200211        /* Destroy sync variables */ 
    201212        if (pthread_mutex_destroy(&wiimote->wiimote_mutex)) { 
    202                 wiimote_err("Error destroying wiimote_mutex"); 
     213                wiimote_err(wiimote, "Error destroying wiimote_mutex"); 
    203214        } 
    204215        if (pthread_mutex_destroy(&wiimote->rw_mutex)) { 
    205                 wiimote_err("Error destroying rw_mutex"); 
     216                wiimote_err(wiimote, "Error destroying rw_mutex"); 
    206217        } 
    207218        if (pthread_cond_destroy(&wiimote->rw_cond)) { 
    208                 wiimote_err("Error destroying rw_cond"); 
     219                wiimote_err(wiimote, "Error destroying rw_cond"); 
    209220        } 
    210221        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"); 
    212223        } 
    213224 
  • wiimote/event.c

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote parameter to wiimote_err calls 
     20 * 
    1821 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * Initial ChangeLog 
     
    9598 
    9699        if ((mesg = malloc(sizeof *mesg)) == NULL) { 
    97                 wiimote_err("Error allocating status mesg"); 
     100                wiimote_err(wiimote, "Error allocating status mesg"); 
    98101        } 
    99102        mesg->type = WIIMOTE_MESG_STATUS; 
     
    126129                if (wiimote->rpt_mode_flags & WIIMOTE_RPT_BTN) { 
    127130                        if ((mesg = malloc(sizeof *mesg)) == NULL) { 
    128                                 wiimote_err("Error allocating btn mesg"); 
     131                                wiimote_err(wiimote, "Error allocating btn mesg"); 
    129132                                return -1; 
    130133                        } 
     
    147150        if (wiimote->rpt_mode_flags & WIIMOTE_RPT_ACC) { 
    148151                if ((mesg = malloc(sizeof *mesg)) == NULL) { 
    149                         wiimote_err("Error allocating acc mesg"); 
     152                        wiimote_err(wiimote, "Error allocating acc mesg"); 
    150153                        return -1; 
    151154                } 
     
    171174        if (wiimote->rpt_mode_flags & WIIMOTE_RPT_IR) { 
    172175                if ((mesg = malloc(sizeof *mesg)) == NULL) { 
    173                         wiimote_err("Error allocating ir mesg"); 
     176                        wiimote_err(wiimote, "Error allocating ir mesg"); 
    174177                        return -1; 
    175178                } 
     
    218221        if (wiimote->rpt_mode_flags & WIIMOTE_RPT_IR) { 
    219222                if ((mesg = malloc(sizeof *mesg)) == NULL) { 
    220                         wiimote_err("Error allocating ir mesg"); 
     223                        wiimote_err(wiimote, "Error allocating ir mesg"); 
    221224                        return -1; 
    222225                } 
     
    253256        switch (wiimote->extension) { 
    254257        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"); 
    256260                break; 
    257261        case WIIMOTE_EXT_UNKNOWN: 
     
    260264                if (wiimote->rpt_mode_flags & WIIMOTE_RPT_NUNCHUK) { 
    261265                        if ((nunchuk_mesg = malloc(sizeof *nunchuk_mesg)) == NULL) { 
    262                                 wiimote_err("Error allocating nunchuk mesg"); 
     266                                wiimote_err(wiimote, "Error allocating nunchuk mesg"); 
    263267                                return -1; 
    264268                        } 
     
    280284                if (wiimote->rpt_mode_flags & WIIMOTE_RPT_CLASSIC) { 
    281285                        if ((classic_mesg = malloc(sizeof *classic_mesg)) == NULL) { 
    282                                 wiimote_err("Error allocating classic mesg"); 
     286                                wiimote_err(wiimote, "Error allocating classic mesg"); 
    283287                                return -1; 
    284288                        } 
     
    322326                /* Read packet */ 
    323327                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"); 
    325329                } 
    326330                else { 
    327331                        /* Verify first byte (DATA/INPUT) */ 
    328332                        if (buf[0] != (BT_TRANS_DATA | BT_PARAM_INPUT)) { 
    329                                 wiimote_err("Invalid packet type"); 
     333                                wiimote_err(wiimote, "Invalid packet type"); 
    330334                        } 
    331335 
     
    343347                        case RPT_EXT21: 
    344348                                if ((mesg_array = malloc(sizeof *mesg_array)) == NULL) { 
    345                                         wiimote_err("Error allocating mesg array"); 
     349                                        wiimote_err(wiimote, "Error allocating mesg array"); 
    346350                                        break; 
    347351                                } 
     
    417421                                        if (queue_queue(wiimote->dispatch_queue, mesg_array)) { 
    418422                                                free_mesg_array(mesg_array); 
    419                                                 wiimote_err("error dispatching mesg array"); 
     423                                                wiimote_err(wiimote, 
     424                                                            "error dispatching mesg array"); 
    420425                                        } 
    421426                                } 
     
    423428                        case RPT_BTN_ACC_IR36_1: 
    424429                        case RPT_BTN_ACC_IR36_2: 
    425                                 wiimote_err("Unsupported report type received " 
     430                                wiimote_err(wiimote, "Unsupported report type received " 
    426431                                            "(interleaved data)"); 
    427432                                break; 
     
    437442                                        if (((data_len+wiimote->read_received)> 
    438443                                          wiimote->read_len) || error) { 
    439                                                 wiimote_err("Error in read data"); 
     444                                                wiimote_err(wiimote, "Error in read data"); 
    440445                                                wiimote->rw_status = RW_ERROR; 
    441446                                        } 
     
    454459                                                 * rw_cond_mutex */ 
    455460                                                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"); 
    457463                                                } 
    458464                                                else { 
    459465                                                        if (pthread_cond_signal(&wiimote->rw_cond)) { 
    460                                                                 wiimote_err("Error signaling rw_cond: " 
     466                                                                wiimote_err(wiimote, 
     467                                                                            "Error signaling rw_cond: " 
    461468                                                                            "deadlock warning"); 
    462469                                                        } 
    463470                                                        if (pthread_mutex_unlock( 
    464471                                                          &wiimote->rw_cond_mutex)) { 
    465                                                                 wiimote_err("Error unlocking rw_cond_mutex: " 
     472                                                                wiimote_err(wiimote, 
     473                                                                            "Error unlocking rw_cond_mutex: " 
    466474                                                                        "deadlock warning"); 
    467475                                                        } 
     
    471479                                } 
    472480                                else { 
    473                                         wiimote_err("Extraneous read data received"); 
     481                                        wiimote_err(wiimote, "Extraneous read data received"); 
    474482                                } 
    475483                                break; 
     
    480488                                         * write_cond_mutex */ 
    481489                                        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"); 
    483492                                        } 
    484493                                        else { 
    485494                                                if (pthread_cond_signal(&wiimote->rw_cond)) { 
    486                                                         wiimote_err("Error signaling rw_cond: " 
     495                                                        wiimote_err(wiimote, 
     496                                                                    "Error signaling rw_cond: " 
    487497                                                                    "deadlock warning"); 
    488498                                                } 
    489499                                                if (pthread_mutex_unlock( 
    490500                                                  &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"); 
    493504                                                } 
    494505                                        } 
    495506                                } 
    496507                                else { 
    497                                         wiimote_err("Extraneous write ack received"); 
     508                                        wiimote_err(wiimote, "Extraneous write ack received"); 
    498509                                } 
    499510                                break; 
    500511                        default: 
    501                                 wiimote_err("Unknown message type"); 
     512                                wiimote_err(wiimote, "Unknown message type"); 
    502513                                break; 
    503514                        } 
     
    513524{ 
    514525        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"); 
    516528        } 
    517529} 
     
    529541        do { 
    530542                if (queue_wait(dispatch_queue)) { 
    531                         wiimote_err("Error waiting on dispatch_queue"); 
     543                        wiimote_err(wiimote, "Error waiting on dispatch_queue"); 
    532544                        return NULL; 
    533545                } 
     
    538550                        pthread_testcancel(); 
    539551                        if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cancelstate)) { 
    540                                 wiimote_err("Error disabling cancel state"); 
     552                                wiimote_err(wiimote, "Error disabling cancel state"); 
    541553                        } 
    542554                        else { 
     
    551563                                                if (wiimote_write(wiimote, WIIMOTE_RW_REG, 0xA40040, 1, 
    552564                                                                  &buf)) { 
    553                                                         wiimote_err("Error initializing extension"); 
     565                                                        wiimote_err(wiimote, 
     566                                                                    "Error initializing extension"); 
    554567                                                        wiimote->extension = WIIMOTE_EXT_UNKNOWN; 
    555568                                                } 
     
    557570                                                         WIIMOTE_RW_REG | WIIMOTE_RW_DECODE, 0xA400FE, 
    558571                                                             1, &buf)) { 
    559                                                         wiimote_err("Error reading extension type"); 
     572                                                        wiimote_err(wiimote, 
     573                                                                    "Error reading extension type"); 
    560574                                                        wiimote->extension = WIIMOTE_EXT_UNKNOWN; 
    561575                                                } 
     
    583597 
    584598                                        if (update_rpt_mode(wiimote, -1)) { 
    585                                                 wiimote_err("Error reseting report mode"); 
     599                                                wiimote_err(wiimote, "Error reseting report mode"); 
    586600                                        } 
    587601 
     
    602616                                } 
    603617                                if (pthread_setcancelstate(cancelstate, &cancelstate)) { 
    604                                         wiimote_err("Error enabling cancel state"); 
     618                                        wiimote_err(wiimote, "Error enabling cancel state"); 
    605619                                } 
    606620                        } 
     
    610624 
    611625        /* This code should never execute */ 
    612         wiimote_err("Exiting dispatch thread"); 
     626        wiimote_err(wiimote, "Exiting dispatch thread"); 
    613627 
    614628        pthread_cleanup_pop(1); 
  • wiimote/rw.c

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/06/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote parameter to wiimote_err calls 
     20 * 
    1821 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * Initial ChangeLog 
     
    5558        /* Lock wiimote rw access */ 
    5659        if (pthread_mutex_lock(&wiimote->rw_mutex)) { 
    57                 wiimote_err("Error locking rw_mutex"); 
     60                wiimote_err(wiimote, "Error locking rw_mutex"); 
    5861                return -1; 
    5962        } 
     
    7780        /* Send read request packet */ 
    7881        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"); 
    8083                ret = -1; 
    8184        } 
    8285        /* Lock rw_cond_mutex  */ 
    8386        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"); 
    8588                ret = -1; 
    8689        } 
     
    9093                        if (pthread_cond_wait(&wiimote->rw_cond, 
    9194                                              &wiimote->rw_cond_mutex)) { 
    92                                 wiimote_err("Error waiting on rw_cond"); 
     95                                wiimote_err(wiimote, "Error waiting on rw_cond"); 
    9396                                ret = -1; 
    9497                        } 
     
    9699                /* Unlock rw_cond_mutex */ 
    97100                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"); 
    99103                } 
    100104 
     
    113117        /* Unlock rw_mutex */ 
    114118        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"); 
    116120        } 
    117121 
     
    135139        /* Lock wiimote rw access */ 
    136140        if (pthread_mutex_lock(&wiimote->rw_mutex)) { 
    137                 wiimote_err("Error locking rw_mutex"); 
     141                wiimote_err(wiimote, "Error locking rw_mutex"); 
    138142                return -1; 
    139143        } 
     
    156160                wiimote->rw_status = RW_PENDING; 
    157161                if (send_report(wiimote, 0, RPT_WRITE, RPT_WRITE_LEN, buf)) { 
    158                         wiimote_err("Error sending write"); 
     162                        wiimote_err(wiimote, "Error sending write"); 
    159163                        ret = -1; 
    160164                } 
    161165                /* Lock rw_cond_mutex  */ 
    162166                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"); 
    164168                        ret = -1; 
    165169                } 
     
    169173                                if (pthread_cond_wait(&wiimote->rw_cond, 
    170174                                                      &wiimote->rw_cond_mutex)) { 
    171                                         wiimote_err("Error waiting on rw_cond"); 
     175                                        wiimote_err(wiimote, "Error waiting on rw_cond"); 
    172176                                        ret = -1; 
    173177                                } 
     
    175179                        /* Unlock rw_cond_mutex */ 
    176180                        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"); 
    178183                        } 
    179184 
     
    194199        /* Unlock rw_mutex */ 
    195200        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"); 
    197202        } 
    198203 
     
    217222        if (exec_write_seq(wiimote, SEQ_LEN(speaker_enable_seq), 
    218223                           speaker_enable_seq)) { 
    219                 wiimote_err("Error on speaker enable"); 
     224                wiimote_err(wiimote, "Error on speaker enable"); 
    220225                ret = -1; 
    221226        } 
     
    229234                if (send_report(wiimote, 0, RPT_SPEAKER_DATA, SOUND_BUF_LEN, buf)) { 
    230235                        printf("%d\n", i); 
    231                         wiimote_err("Error on speaker data"); 
     236                        wiimote_err(wiimote, "Error on speaker data"); 
    232237                        ret = -1; 
    233238                        break; 
     
    242247        if (exec_write_seq(wiimote, SEQ_LEN(speaker_disable_seq), 
    243248                           speaker_disable_seq)) { 
    244                 wiimote_err("Error on speaker disable"); 
     249                wiimote_err(wiimote, "Error on speaker disable"); 
    245250                ret = -1; 
    246251        } 
  • wiimote/util.c

    rc033b7a ra339960  
    1616 * 
    1717 *  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 * 
    1823 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1924 *  * Initial ChangeLog 
     
    3237#include "wiimote_internal.h" 
    3338 
    34 void wiimote_err(const char *str, ...) 
     39static wiimote_err_t wiimote_err_default; 
     40 
     41static wiimote_err_t *wiimote_err_func = &wiimote_err_default; 
     42 
     43int 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 
     52static void wiimote_err_default(int id, const char *str, ...) 
    3553{ 
    3654        va_list ap; 
     
    4260} 
    4361 
     62void 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 
    4478int verify_handshake(struct wiimote *wiimote) 
    4579{ 
    4680        unsigned char handshake; 
    4781        if (read(wiimote->ctl_socket, &handshake, 1) != 1) { 
    48                 wiimote_err("Error on read handshake"); 
     82                wiimote_err(wiimote, "Error on read handshake"); 
    4983                return -1; 
    5084        } 
    5185        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"); 
    5387                return -1; 
    5488        } 
    5589        else if ((handshake & BT_PARAM_MASK) != BT_PARAM_SUCCESSFUL) { 
    56                 wiimote_err("Non-successful handshake"); 
     90                wiimote_err(wiimote, "Non-successful handshake"); 
    5791                return -1; 
    5892        } 
     
    139173        /* Get the first available Bluetooth device */ 
    140174        if ((dev_id = hci_get_route(NULL)) == -1) { 
    141                 wiimote_err("No Bluetooth device found"); 
     175                wiimote_err(NULL, "No Bluetooth device found"); 
    142176                return -1; 
    143177        } 
    144178        if ((sock = hci_open_dev(dev_id)) == -1) { 
    145                 wiimote_err("Error opening Bluetooth device"); 
     179                wiimote_err(NULL, "Error opening Bluetooth device"); 
    146180                return -1; 
    147181        } 
     
    150184        if ((dev_count = hci_inquiry(dev_id, 2, MAX_RSP, NULL, &dev_list, 
    151185                                     IREQ_CACHE_FLUSH)) == -1) { 
    152                 wiimote_err("Error on device inquiry"); 
     186                wiimote_err(NULL, "Error on device inquiry"); 
    153187                hci_close_dev(sock); 
    154188                return -1; 
     
    162196                        if (hci_remote_name(sock, &dev_list[i].bdaddr, WIIMOTE_CMP_LEN, 
    163197                                            dev_name, 5000)) { 
    164                                 wiimote_err("Error reading device name"); 
     198                                wiimote_err(NULL, "Error reading device name"); 
    165199                        } 
    166200                        else if (strncmp(dev_name, WIIMOTE_NAME, WIIMOTE_CMP_LEN) == 0) { 
  • wiimote/wiimote.h

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote_err_t definition 
     20 *  * added wiimote_set_err prototype 
     21 * 
    1822 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * Initial ChangeLog 
     
    189193 
    190194typedef void wiimote_mesg_callback_t(int, int, union wiimote_mesg* []); 
     195typedef void wiimote_err_t(int, const char *, ...); 
    191196 
    192197#ifdef __cplusplus 
     
    194199#endif 
    195200 
     201int wiimote_set_err(wiimote_err_t *err); 
    196202wiimote_t *wiimote_connect(bdaddr_t bdaddr, 
    197203                           wiimote_mesg_callback_t *mesg_callback, 
  • wiimote/wiimote_internal.h

    rc033b7a ra339960  
    1616 * 
    1717 *  ChangeLog: 
     18 *  03/05/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added wiimote parameter to wiimote_err prototype 
     20 * 
    1821 *  03/01/2007: L. Donnie Smith <cwiid@abstrakraft.org> 
    1922 *  * Initial ChangeLog 
     
    164167int update_rpt_mode(struct wiimote *wiimote, int8_t flags); 
    165168 
    166 void wiimote_err(const char *str, ...); 
     169void wiimote_err(struct wiimote *wiimote, const char *str, ...); 
    167170int verify_handshake(struct wiimote *wiimote); 
    168171int send_report(struct wiimote *wiimote, uint8_t flags, uint8_t report, 
  • wmdemo/main.c

    r15d141c ra339960  
     1#include <stdarg.h> 
    12#include <stdio.h> 
    23 
     
    89 * parts easily.  For examples of read and write code, see wmgui.  Speaker 
    910 * 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. */ 
    1112/* Note: accelerometer (including nunchuk) and IR outputs produce a 
    1213 * lot of data - the purpose of this program is demonstration, not good 
     
    2223void set_led_state(wiimote_t *wiimote, unsigned char led_state); 
    2324void set_rpt_mode(wiimote_t *wiimote, unsigned char rpt_mode); 
     25 
     26wiimote_err_t err; 
     27void 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} 
    2437 
    2538int main(int argc, char *argv[]) 
     
    3346        unsigned char rumble = 0; 
    3447        int exit = 0; 
     48 
     49        wiimote_set_err(err); 
    3550 
    3651        /* Connect to any wiimote */ 
  • wmgui/main.c

    rc033b7a ra339960  
    170170#define USAGE "usage:%s [-h] [BDADDR]\n" 
    171171 
     172wiimote_err_t err; 
     173 
     174void err(int id, const char *s, ...) 
     175{ 
     176        message(GTK_MESSAGE_ERROR, s, GTK_WINDOW(winMain)); 
     177} 
     178 
    172179int main (int argc, char *argv[]) 
    173180{ 
     
    183190        gdk_threads_init(); 
    184191        gdk_threads_enter(); 
     192 
     193        wiimote_set_err(err); 
    185194 
    186195        /* Parse Options */