Changeset 116 for trunk/libcwiid
- Timestamp:
- 05/16/07 19:40:30 (2 years ago)
- Files:
-
- trunk/libcwiid/command.c (modified) (3 diffs)
- trunk/libcwiid/connect.c (modified) (4 diffs)
- trunk/libcwiid/cwiid.h (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
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);
