Changeset 116

Show
Ignore:
Timestamp:
05/16/07 19:40:30 (2 years ago)
Author:
dsmith
Message:

deprecated cwiid_{connect,disconnect,command}, added cwiid_{open,close,request_status,set_led,set_rumble,set_rpt_mode}

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ChangeLog

    r113 r116  
     12007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     2        libcwiid 
     3        * removed error_pipe 
     4        * fixed error message reporting 
     5        * changed cwiid_connect, cwiid_disconnect to cwiid_open, cwiid_close 
     6          (added macros for backward compatibility) 
     7        * split cwiid_command into cwiid_request_status, cwiid_set_led, 
     8          cwiid_set_rumble, cwiid_set_rpt_mode (kept cwiid_command for backward 
     9          compatibility) 
     10 
     11        wmdemo 
     12        * updated for function name changes 
     13 
     14        wmgui 
     15        * updated for function name changes 
     16 
     17        wminput 
     18        * updated for function name changes 
     19 
    1202007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    221        libcwiid 
  • trunk/libcwiid/command.c

    r101 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble, 
     20 *    cwiid_set_rpt_mode 
     21 * 
    1822 *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * rewrite for API overhaul 
     
    4549#include "cwiid_internal.h" 
    4650 
    47 #define CMD_BUF_LEN     21 
    4851int cwiid_command(struct wiimote *wiimote, enum cwiid_command command, 
    4952                  int flags) { 
    50         int ret = 0; 
    51         unsigned char buf[CMD_BUF_LEN]; 
    52  
    53         /* TODO: assumption: char assignments are atomic, no mutex lock needed */ 
     53        int ret; 
     54 
    5455        switch (command) { 
    5556        case CWIID_CMD_STATUS: 
    56                 buf[0] = 0; 
    57                 if (send_report(wiimote, 0, RPT_STATUS_REQ, 1, buf)) { 
    58                         cwiid_err(wiimote, "Status request error"); 
    59                         ret = -1; 
    60                 } 
     57                ret = cwiid_request_status(wiimote); 
    6158                break; 
    6259        case CWIID_CMD_LED: 
    63                 wiimote->state.led = flags & 0x0F; 
    64                 buf[0] = wiimote->state.led<<4 | wiimote->state.rumble; 
    65                 if (send_report(wiimote, SEND_RPT_NO_RUMBLE, RPT_LED_RUMBLE, 1, buf)) { 
    66                         cwiid_err(wiimote, "Report send error (led)"); 
    67                         ret = -1; 
    68                 } 
     60                ret = cwiid_set_led(wiimote, flags); 
    6961                break; 
    7062        case CWIID_CMD_RUMBLE: 
    71                 wiimote->state.rumble = flags ? 1 : 0; 
    72                 buf[0] = wiimote->state.led<<4 | wiimote->state.rumble; 
    73                 if (send_report(wiimote, SEND_RPT_NO_RUMBLE, RPT_LED_RUMBLE, 1, buf)) { 
    74                         cwiid_err(wiimote, "Report send error (rumble)"); 
    75                         ret = -1; 
    76                 } 
     63                ret = cwiid_set_rumble(wiimote, flags); 
    7764                break; 
    7865        case CWIID_CMD_RPT_MODE: 
    79                 update_rpt_mode(wiimote, flags); 
     66                ret = cwiid_set_rpt_mode(wiimote, flags); 
    8067                break; 
    8168        default: 
     
    8572 
    8673        return ret; 
     74} 
     75 
     76int cwiid_request_status(cwiid_wiimote_t *wiimote) 
     77{ 
     78        unsigned char data; 
     79 
     80        data = 0; 
     81        if (send_report(wiimote, 0, RPT_STATUS_REQ, 1, &data)) { 
     82                cwiid_err(wiimote, "Status request error"); 
     83                return -1; 
     84        } 
     85 
     86        return 0; 
     87} 
     88 
     89int cwiid_set_led(cwiid_wiimote_t *wiimote, uint8_t led) 
     90{ 
     91        unsigned char data; 
     92 
     93        /* TODO: assumption: char assignments are atomic, no mutex lock needed */ 
     94        wiimote->state.led = led & 0x0F; 
     95        data = wiimote->state.led << 4; 
     96        if (send_report(wiimote, 0, RPT_LED_RUMBLE, 1, &data)) { 
     97                cwiid_err(wiimote, "Report send error (led)"); 
     98                return -1; 
     99        } 
     100 
     101        return 0; 
     102} 
     103 
     104int cwiid_set_rumble(cwiid_wiimote_t *wiimote, uint8_t rumble) 
     105{ 
     106        unsigned char data; 
     107 
     108        /* TODO: assumption: char assignments are atomic, no mutex lock needed */ 
     109        wiimote->state.rumble = rumble ? 1 : 0; 
     110        data = wiimote->state.led << 4; 
     111        if (send_report(wiimote, 0, RPT_LED_RUMBLE, 1, &data)) { 
     112                cwiid_err(wiimote, "Report send error (led)"); 
     113                return -1; 
     114        } 
     115 
     116        return 0; 
     117} 
     118 
     119int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode) 
     120{ 
     121        return update_rpt_mode(wiimote, rpt_mode); 
    87122} 
    88123 
  • trunk/libcwiid/connect.c

    r115 r116  
    1818 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
    1919 *  * remove error_pipe init and destruct 
     20 *  * renamed connect and disconnect to open and close 
    2021 * 
    2122 *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 
     
    5859static int wiimote_id = 0; 
    5960 
    60 cwiid_wiimote_t *cwiid_connect(bdaddr_t *bdaddr, int flags) 
     61cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags) 
    6162{ 
    6263        struct wiimote *wiimote = NULL; 
     
    194195        memset(&wiimote->state, 0, sizeof wiimote->state); 
    195196        wiimote->mesg_callback = NULL; 
    196         cwiid_command(wiimote, CWIID_CMD_LED, 0); 
    197         cwiid_command(wiimote, CWIID_CMD_STATUS, 0); 
     197        cwiid_set_led(wiimote, 0); 
     198        cwiid_request_status(wiimote); 
    198199 
    199200        return wiimote; 
     
    272273} 
    273274 
    274 int cwiid_disconnect(struct wiimote *wiimote) 
     275int cwiid_close(struct wiimote *wiimote) 
    275276{ 
    276277        void *pthread_ret; 
  • trunk/libcwiid/cwiid.h

    r113 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed cwiid_connect, cwiid_disconnect to cwiid_open, cwiid_close 
     20 *  * added cwiid_request_status, cwiid_set_let, cwiid_set_rumble, 
     21 *    cwiid_set_rpt_mode 
     22 * 
    1823 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1924 *  * added timestamp to message functions 
     
    298303 
    299304/* Connection */ 
    300 cwiid_wiimote_t *cwiid_connect(bdaddr_t *bdaddr, int flags); 
    301 int cwiid_disconnect(cwiid_wiimote_t *wiimote); 
     305#define cwiid_connect cwiid_open 
     306#define cwiid_disconnect cwiid_close 
     307cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags); 
     308int cwiid_close(cwiid_wiimote_t *wiimote); 
    302309 
    303310int cwiid_get_id(cwiid_wiimote_t *wiimote); 
     
    319326int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command, 
    320327                  int flags); 
     328int cwiid_request_status(cwiid_wiimote_t *wiimote); 
     329int cwiid_set_led(cwiid_wiimote_t *wiimote, uint8_t led); 
     330int cwiid_set_rumble(cwiid_wiimote_t *wiimote, uint8_t rumble); 
     331int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode); 
    321332int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset, 
    322333               uint16_t len, void *data); 
  • trunk/wmdemo/wmdemo.c

    r112 r116  
    7575        /* Connect to the wiimote */ 
    7676        printf("Put Wiimote in discoverable mode now (press 1+2)...\n"); 
    77         if (!(wiimote = cwiid_connect(&bdaddr, 0))) { 
     77        if (!(wiimote = cwiid_open(&bdaddr, 0))) { 
    7878                fprintf(stderr, "Unable to connect to wiimote\n"); 
    7979                return -1; 
     
    111111                case '5': 
    112112                        toggle_bit(rumble, 1); 
    113                         if (cwiid_command(wiimote, CWIID_CMD_RUMBLE, rumble)) { 
     113                        if (cwiid_set_rumble(wiimote, rumble)) { 
    114114                                fprintf(stderr, "Error setting rumble\n"); 
    115115                        } 
     
    158158                        break; 
    159159                case 'r': 
    160                         if (cwiid_command(wiimote, CWIID_CMD_STATUS, 0)) { 
     160                        if (cwiid_request_status(wiimote)) { 
    161161                                fprintf(stderr, "Error requesting status message\n"); 
    162162                        } 
     
    182182        } 
    183183 
    184         if (cwiid_disconnect(wiimote)) { 
     184        if (cwiid_close(wiimote)) { 
    185185                fprintf(stderr, "Error on wiimote disconnect\n"); 
    186186                return -1; 
     
    192192void set_led_state(cwiid_wiimote_t *wiimote, unsigned char led_state) 
    193193{ 
    194         if (cwiid_command(wiimote, CWIID_CMD_LED, led_state)) { 
     194        if (cwiid_set_led(wiimote, led_state)) { 
    195195                fprintf(stderr, "Error setting LEDs \n"); 
    196196        } 
     
    199199void set_rpt_mode(cwiid_wiimote_t *wiimote, unsigned char rpt_mode) 
    200200{ 
    201         if (cwiid_command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode)) { 
     201        if (cwiid_set_rpt_mode(wiimote, rpt_mode)) { 
    202202                fprintf(stderr, "Error setting report mode\n"); 
    203203        } 
     
    357357                        break; 
    358358                case CWIID_MESG_ERROR: 
    359                         if (cwiid_disconnect(wiimote)) { 
     359                        if (cwiid_close(wiimote)) { 
    360360                                fprintf(stderr, "Error on wiimote disconnect\n"); 
    361361                                exit(-1); 
     
    369369        } 
    370370} 
    371  
  • trunk/wmgui/main.c

    r113 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed cwiid_{connect,disconnect,command} to 
     20 *    cwiid_{open,close,request_status|set_led|set_rumble|set_rpt_mode} 
     21 * 
    1822 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * added timestamp to message callback 
     
    635639                "Put Wiimote in discoverable mode (press 1+2) and press OK", 
    636640                 GTK_WINDOW(winMain)); 
    637         if ((wiimote = cwiid_connect(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 
     641        if ((wiimote = cwiid_open(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 
    638642                message(GTK_MESSAGE_ERROR, "Unable to connect", GTK_WINDOW(winMain)); 
    639643                status("No connection"); 
     
    642646                message(GTK_MESSAGE_ERROR, "Error setting callback", 
    643647                        GTK_WINDOW(winMain)); 
    644                 if (cwiid_disconnect(wiimote)) { 
     648                if (cwiid_close(wiimote)) { 
    645649                        message(GTK_MESSAGE_ERROR, "Error on disconnect", 
    646650                                GTK_WINDOW(winMain)); 
     
    657661                set_gui_state(); 
    658662                set_report_mode(); 
    659                 cwiid_command(wiimote, CWIID_CMD_STATUS, 0); 
     663                cwiid_request_status(wiimote); 
    660664        } 
    661665 
     
    667671void menuDisconnect_activate(void) 
    668672{ 
    669         if (cwiid_disconnect(wiimote)) { 
     673        if (cwiid_close(wiimote)) { 
    670674                message(GTK_MESSAGE_ERROR, "Error on disconnect", GTK_WINDOW(winMain)); 
    671675        } 
     
    747751                  (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(chkLED4)) 
    748752                    ? CWIID_LED4_ON : 0); 
    749                 if (cwiid_command(wiimote, CWIID_CMD_LED, LED_state)) { 
     753                if (cwiid_set_led(wiimote, LED_state)) { 
    750754                        message(GTK_MESSAGE_ERROR, "error setting LEDs", 
    751755                                GTK_WINDOW(winMain)); 
     
    757761{ 
    758762        if (wiimote) { 
    759                 if (cwiid_command(wiimote, CWIID_CMD_RUMBLE
     763                if (cwiid_set_rumble(wiimote
    760764                  gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(chkRumble)))) { 
    761765                        message(GTK_MESSAGE_ERROR, "error setting rumble", 
     
    9971001                rpt_mode |= CWIID_RPT_EXT; 
    9981002        } 
    999         if (cwiid_command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode)) { 
     1003        if (cwiid_set_rpt_mode(wiimote, rpt_mode)) { 
    10001004                message(GTK_MESSAGE_ERROR, "error setting report mode", 
    10011005                        GTK_WINDOW(winMain)); 
  • trunk/wminput/main.c

    r112 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed cwiid_{connect,disconnect,command} to 
     20 *    cwiid_{open,close,request_status|set_led|set_rumble|set_rpt_mode} 
     21 * 
    1822 *  2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * added timestamp to message callback 
     
    165169                } 
    166170        } 
    167         if ((wiimote = cwiid_connect(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 
     171        if ((wiimote = cwiid_open(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 
    168172                wminput_err("unable to connect"); 
    169173                conf_unload(&conf); 
     
    181185                        wminput_err("error on %s init", conf.plugins[i].name); 
    182186                        conf_unload(&conf); 
    183                         cwiid_disconnect(wiimote); 
     187                        cwiid_close(wiimote); 
    184188                        return -1; 
    185189                } 
     
    188192        if (wminput_set_report_mode()) { 
    189193                conf_unload(&conf); 
    190                 cwiid_disconnect(wiimote); 
     194                cwiid_close(wiimote); 
    191195                return -1; 
    192196        } 
     
    199203                wminput_err("error starting uinput listen thread"); 
    200204                conf_unload(&conf); 
    201                 cwiid_disconnect(wiimote); 
     205                cwiid_close(wiimote); 
    202206                return -1; 
    203207        } 
     
    227231 
    228232        /* disconnect */ 
    229         if (cwiid_disconnect(wiimote)) { 
     233        if (cwiid_close(wiimote)) { 
    230234                wminput_err("error on disconnect"); 
    231235                ret = -1; 
     
    261265        } 
    262266 
    263         if (cwiid_command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode_flags)) { 
     267        if (cwiid_set_rpt_mode(wiimote, rpt_mode_flags)) { 
    264268                wminput_err("error setting report mode"); 
    265269                return -1; 
  • trunk/wminput/plugins/ir_ptr/ir_ptr.c

    r101 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed cwiid_{connect,disconnect,command} to 
     20 *    cwiid_{open,close,request_status|set_led|set_rumble|set_rpt_mode} 
     21 * 
    1822 *  2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * updated for API overhaul 
     
    245249        } 
    246250        if (flags != old_flags) { 
    247                 cwiid_command(wiimote, CWIID_CMD_LED, flags); 
     251                cwiid_set_led(wiimote, flags); 
    248252        } 
    249253        old_flags = flags; 
  • trunk/wminput/uinput.c

    r83 r116  
    1616 * 
    1717 *  ChangeLog: 
     18 *  2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 
     19 *  * changed cwiid_{connect,disconnect,command} to 
     20 *    cwiid_{open,close,request_status|set_led|set_rumble|set_rpt_mode} 
     21 * 
    1822 *  2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 
    1923 *  * updated for libcwiid rename 
     
    259263                                        wminput_err("Error on ff upload begin"); 
    260264                                } 
    261                                 if (cwiid_command(data->wiimote, CWIID_CMD_RUMBLE, 1)) { 
     265                                if (cwiid_set_rumble(data->wiimote, 1)) { 
    262266                                        wminput_err("Error setting rumble"); 
    263267                                } 
     
    271275                                        wminput_err("Error on ff erase begin"); 
    272276                                } 
    273                                 if (cwiid_command(data->wiimote, CWIID_CMD_RUMBLE, 0)) { 
     277                                if (cwiid_set_rumble(data->wiimote, 0)) { 
    274278                                        wminput_err("Error clearing rumble"); 
    275279                                }