Changeset 116
- Timestamp:
- 05/16/07 19:40:30 (2 years ago)
- Files:
-
- trunk/ChangeLog (modified) (1 diff)
- trunk/libcwiid/command.c (modified) (3 diffs)
- trunk/libcwiid/connect.c (modified) (4 diffs)
- trunk/libcwiid/cwiid.h (modified) (3 diffs)
- trunk/wmdemo/wmdemo.c (modified) (8 diffs)
- trunk/wmgui/main.c (modified) (8 diffs)
- trunk/wminput/main.c (modified) (7 diffs)
- trunk/wminput/plugins/ir_ptr/ir_ptr.c (modified) (2 diffs)
- trunk/wminput/uinput.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ChangeLog
r113 r116 1 2007-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 1 20 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 2 21 libcwiid trunk/libcwiid/command.c
r101 r116 16 16 * 17 17 * 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 * 18 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * rewrite for API overhaul … … 45 49 #include "cwiid_internal.h" 46 50 47 #define CMD_BUF_LEN 2148 51 int cwiid_command(struct wiimote *wiimote, enum cwiid_command command, 49 52 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 54 55 switch (command) { 55 56 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); 61 58 break; 62 59 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); 69 61 break; 70 62 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); 77 64 break; 78 65 case CWIID_CMD_RPT_MODE: 79 update_rpt_mode(wiimote, flags);66 ret = cwiid_set_rpt_mode(wiimote, flags); 80 67 break; 81 68 default: … … 85 72 86 73 return ret; 74 } 75 76 int 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 89 int 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 104 int 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 119 int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode) 120 { 121 return update_rpt_mode(wiimote, rpt_mode); 87 122 } 88 123 trunk/libcwiid/connect.c
r115 r116 18 18 * 2007-05-16 L. Donnie Smith <cwiid@abstrakraft.org> 19 19 * * remove error_pipe init and destruct 20 * * renamed connect and disconnect to open and close 20 21 * 21 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> … … 58 59 static int wiimote_id = 0; 59 60 60 cwiid_wiimote_t *cwiid_ connect(bdaddr_t *bdaddr, int flags)61 cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags) 61 62 { 62 63 struct wiimote *wiimote = NULL; … … 194 195 memset(&wiimote->state, 0, sizeof wiimote->state); 195 196 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); 198 199 199 200 return wiimote; … … 272 273 } 273 274 274 int cwiid_ disconnect(struct wiimote *wiimote)275 int cwiid_close(struct wiimote *wiimote) 275 276 { 276 277 void *pthread_ret; trunk/libcwiid/cwiid.h
r113 r116 16 16 * 17 17 * 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 * 18 23 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 24 * * added timestamp to message functions … … 298 303 299 304 /* 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 307 cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags); 308 int cwiid_close(cwiid_wiimote_t *wiimote); 302 309 303 310 int cwiid_get_id(cwiid_wiimote_t *wiimote); … … 319 326 int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command, 320 327 int flags); 328 int cwiid_request_status(cwiid_wiimote_t *wiimote); 329 int cwiid_set_led(cwiid_wiimote_t *wiimote, uint8_t led); 330 int cwiid_set_rumble(cwiid_wiimote_t *wiimote, uint8_t rumble); 331 int cwiid_set_rpt_mode(cwiid_wiimote_t *wiimote, uint8_t rpt_mode); 321 332 int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset, 322 333 uint16_t len, void *data); trunk/wmdemo/wmdemo.c
r112 r116 75 75 /* Connect to the wiimote */ 76 76 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))) { 78 78 fprintf(stderr, "Unable to connect to wiimote\n"); 79 79 return -1; … … 111 111 case '5': 112 112 toggle_bit(rumble, 1); 113 if (cwiid_ command(wiimote, CWIID_CMD_RUMBLE, rumble)) {113 if (cwiid_set_rumble(wiimote, rumble)) { 114 114 fprintf(stderr, "Error setting rumble\n"); 115 115 } … … 158 158 break; 159 159 case 'r': 160 if (cwiid_ command(wiimote, CWIID_CMD_STATUS, 0)) {160 if (cwiid_request_status(wiimote)) { 161 161 fprintf(stderr, "Error requesting status message\n"); 162 162 } … … 182 182 } 183 183 184 if (cwiid_ disconnect(wiimote)) {184 if (cwiid_close(wiimote)) { 185 185 fprintf(stderr, "Error on wiimote disconnect\n"); 186 186 return -1; … … 192 192 void set_led_state(cwiid_wiimote_t *wiimote, unsigned char led_state) 193 193 { 194 if (cwiid_ command(wiimote, CWIID_CMD_LED, led_state)) {194 if (cwiid_set_led(wiimote, led_state)) { 195 195 fprintf(stderr, "Error setting LEDs \n"); 196 196 } … … 199 199 void set_rpt_mode(cwiid_wiimote_t *wiimote, unsigned char rpt_mode) 200 200 { 201 if (cwiid_ command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode)) {201 if (cwiid_set_rpt_mode(wiimote, rpt_mode)) { 202 202 fprintf(stderr, "Error setting report mode\n"); 203 203 } … … 357 357 break; 358 358 case CWIID_MESG_ERROR: 359 if (cwiid_ disconnect(wiimote)) {359 if (cwiid_close(wiimote)) { 360 360 fprintf(stderr, "Error on wiimote disconnect\n"); 361 361 exit(-1); … … 369 369 } 370 370 } 371 trunk/wmgui/main.c
r113 r116 16 16 * 17 17 * 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 * 18 22 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * added timestamp to message callback … … 635 639 "Put Wiimote in discoverable mode (press 1+2) and press OK", 636 640 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) { 638 642 message(GTK_MESSAGE_ERROR, "Unable to connect", GTK_WINDOW(winMain)); 639 643 status("No connection"); … … 642 646 message(GTK_MESSAGE_ERROR, "Error setting callback", 643 647 GTK_WINDOW(winMain)); 644 if (cwiid_ disconnect(wiimote)) {648 if (cwiid_close(wiimote)) { 645 649 message(GTK_MESSAGE_ERROR, "Error on disconnect", 646 650 GTK_WINDOW(winMain)); … … 657 661 set_gui_state(); 658 662 set_report_mode(); 659 cwiid_ command(wiimote, CWIID_CMD_STATUS, 0);663 cwiid_request_status(wiimote); 660 664 } 661 665 … … 667 671 void menuDisconnect_activate(void) 668 672 { 669 if (cwiid_ disconnect(wiimote)) {673 if (cwiid_close(wiimote)) { 670 674 message(GTK_MESSAGE_ERROR, "Error on disconnect", GTK_WINDOW(winMain)); 671 675 } … … 747 751 (gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(chkLED4)) 748 752 ? CWIID_LED4_ON : 0); 749 if (cwiid_ command(wiimote, CWIID_CMD_LED, LED_state)) {753 if (cwiid_set_led(wiimote, LED_state)) { 750 754 message(GTK_MESSAGE_ERROR, "error setting LEDs", 751 755 GTK_WINDOW(winMain)); … … 757 761 { 758 762 if (wiimote) { 759 if (cwiid_ command(wiimote, CWIID_CMD_RUMBLE,763 if (cwiid_set_rumble(wiimote, 760 764 gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(chkRumble)))) { 761 765 message(GTK_MESSAGE_ERROR, "error setting rumble", … … 997 1001 rpt_mode |= CWIID_RPT_EXT; 998 1002 } 999 if (cwiid_ command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode)) {1003 if (cwiid_set_rpt_mode(wiimote, rpt_mode)) { 1000 1004 message(GTK_MESSAGE_ERROR, "error setting report mode", 1001 1005 GTK_WINDOW(winMain)); trunk/wminput/main.c
r112 r116 16 16 * 17 17 * 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 * 18 22 * 2007-05-14 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * added timestamp to message callback … … 165 169 } 166 170 } 167 if ((wiimote = cwiid_ connect(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) {171 if ((wiimote = cwiid_open(&bdaddr, CWIID_FLAG_MESG_IFC)) == NULL) { 168 172 wminput_err("unable to connect"); 169 173 conf_unload(&conf); … … 181 185 wminput_err("error on %s init", conf.plugins[i].name); 182 186 conf_unload(&conf); 183 cwiid_ disconnect(wiimote);187 cwiid_close(wiimote); 184 188 return -1; 185 189 } … … 188 192 if (wminput_set_report_mode()) { 189 193 conf_unload(&conf); 190 cwiid_ disconnect(wiimote);194 cwiid_close(wiimote); 191 195 return -1; 192 196 } … … 199 203 wminput_err("error starting uinput listen thread"); 200 204 conf_unload(&conf); 201 cwiid_ disconnect(wiimote);205 cwiid_close(wiimote); 202 206 return -1; 203 207 } … … 227 231 228 232 /* disconnect */ 229 if (cwiid_ disconnect(wiimote)) {233 if (cwiid_close(wiimote)) { 230 234 wminput_err("error on disconnect"); 231 235 ret = -1; … … 261 265 } 262 266 263 if (cwiid_ command(wiimote, CWIID_CMD_RPT_MODE, rpt_mode_flags)) {267 if (cwiid_set_rpt_mode(wiimote, rpt_mode_flags)) { 264 268 wminput_err("error setting report mode"); 265 269 return -1; trunk/wminput/plugins/ir_ptr/ir_ptr.c
r101 r116 16 16 * 17 17 * 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 * 18 22 * 2007-04-24 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * updated for API overhaul … … 245 249 } 246 250 if (flags != old_flags) { 247 cwiid_ command(wiimote, CWIID_CMD_LED, flags);251 cwiid_set_led(wiimote, flags); 248 252 } 249 253 old_flags = flags; trunk/wminput/uinput.c
r83 r116 16 16 * 17 17 * 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 * 18 22 * 2007-04-09 L. Donnie Smith <cwiid@abstrakraft.org> 19 23 * * updated for libcwiid rename … … 259 263 wminput_err("Error on ff upload begin"); 260 264 } 261 if (cwiid_ command(data->wiimote, CWIID_CMD_RUMBLE, 1)) {265 if (cwiid_set_rumble(data->wiimote, 1)) { 262 266 wminput_err("Error setting rumble"); 263 267 } … … 271 275 wminput_err("Error on ff erase begin"); 272 276 } 273 if (cwiid_ command(data->wiimote, CWIID_CMD_RUMBLE, 0)) {277 if (cwiid_set_rumble(data->wiimote, 0)) { 274 278 wminput_err("Error clearing rumble"); 275 279 }
