1 #ifndef __WIIUSE_H__ 2 #define __WIIUSE_H__ 3 4 #if defined(_WIN32) 5 /* windows */ 6 #include <windows.h> 7 #elif defined(GEKKO) 8 /* wii */ 9 #include <bte/bte.h> 10 #elif defined(__linux__) 11 /* nix */ 12 #include <bluetooth/bluetooth.h> 13 #endif 14 15 #ifdef WIIUSE_INTERNAL_H_INCLUDED 16 #define WCONST 17 #else 18 #define WCONST const 19 #endif 20 21 /* led bit masks */ 22 #define WIIMOTE_LED_NONE 0x00 23 #define WIIMOTE_LED_1 0x10 24 #define WIIMOTE_LED_2 0x20 25 #define WIIMOTE_LED_3 0x40 26 #define WIIMOTE_LED_4 0x80 27 28 /* button codes */ 29 #define WIIMOTE_BUTTON_TWO 0x0001 30 #define WIIMOTE_BUTTON_ONE 0x0002 31 #define WIIMOTE_BUTTON_B 0x0004 32 #define WIIMOTE_BUTTON_A 0x0008 33 #define WIIMOTE_BUTTON_MINUS 0x0010 34 #define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020 35 #define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040 36 #define WIIMOTE_BUTTON_HOME 0x0080 37 #define WIIMOTE_BUTTON_LEFT 0x0100 38 #define WIIMOTE_BUTTON_RIGHT 0x0200 39 #define WIIMOTE_BUTTON_DOWN 0x0400 40 #define WIIMOTE_BUTTON_UP 0x0800 41 #define WIIMOTE_BUTTON_PLUS 0x1000 42 #define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000 43 #define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000 44 #define WIIMOTE_BUTTON_UNKNOWN 0x8000 45 #define WIIMOTE_BUTTON_ALL 0x1F9F 46 47 /* nunchul button codes */ 48 #define NUNCHUK_BUTTON_Z 0x01 49 #define NUNCHUK_BUTTON_C 0x02 50 #define NUNCHUK_BUTTON_ALL 0x03 51 52 /* classic controller button codes */ 53 #define CLASSIC_CTRL_BUTTON_UP 0x0001 54 #define CLASSIC_CTRL_BUTTON_LEFT 0x0002 55 #define CLASSIC_CTRL_BUTTON_ZR 0x0004 56 #define CLASSIC_CTRL_BUTTON_X 0x0008 57 #define CLASSIC_CTRL_BUTTON_A 0x0010 58 #define CLASSIC_CTRL_BUTTON_Y 0x0020 59 #define CLASSIC_CTRL_BUTTON_B 0x0040 60 #define CLASSIC_CTRL_BUTTON_ZL 0x0080 61 #define CLASSIC_CTRL_BUTTON_FULL_R 0x0200 62 #define CLASSIC_CTRL_BUTTON_PLUS 0x0400 63 #define CLASSIC_CTRL_BUTTON_HOME 0x0800 64 #define CLASSIC_CTRL_BUTTON_MINUS 0x1000 65 #define CLASSIC_CTRL_BUTTON_FULL_L 0x2000 66 #define CLASSIC_CTRL_BUTTON_DOWN 0x4000 67 #define CLASSIC_CTRL_BUTTON_RIGHT 0x8000 68 #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF 69 70 /* guitar hero 3 button codes */ 71 #define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001 72 #define GUITAR_HERO_3_BUTTON_YELLOW 0x0008 73 #define GUITAR_HERO_3_BUTTON_GREEN 0x0010 74 #define GUITAR_HERO_3_BUTTON_BLUE 0x0020 75 #define GUITAR_HERO_3_BUTTON_RED 0x0040 76 #define GUITAR_HERO_3_BUTTON_ORANGE 0x0080 77 #define GUITAR_HERO_3_BUTTON_PLUS 0x0400 78 #define GUITAR_HERO_3_BUTTON_MINUS 0x1000 79 #define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000 80 #define GUITAR_HERO_3_BUTTON_ALL 0xFEFF 81 82 /* guitar hero world tour touch bar codes */ 83 #define GUITAR_HERO_3_TOUCH_AVAILABLE 0x1000 84 #define GUITAR_HERO_3_TOUCH_GREEN 0x1001 85 #define GUITAR_HERO_3_TOUCH_RED 0x1002 86 #define GUITAR_HERO_3_TOUCH_YELLOW 0x1004 87 #define GUITAR_HERO_3_TOUCH_BLUE 0x1008 88 #define GUITAR_HERO_3_TOUCH_ORANGE 0x1010 89 90 /* wiimote option flags */ 91 #define WIIUSE_SMOOTHING 0x01 92 #define WIIUSE_CONTINUOUS 0x02 93 #define WIIUSE_ACCEL_THRESH 0x04 94 #define WIIUSE_IR_THRESH 0x08 95 #define WIIUSE_JS_THRESH 0x10 96 #define WIIUSE_INIT_FLAGS WIIUSE_SMOOTHING 97 98 #define WIIUSE_ORIENT_PRECISION 100.0f 99 100 /* expansion codes */ 101 #define EXP_NONE 0 102 #define EXP_NUNCHUK 1 103 #define EXP_CLASSIC 2 104 #define EXP_GUITAR_HERO_3 3 105 #define EXP_WII_BOARD 4 106 #define EXP_MOTION_PLUS 5 107 108 /* IR correction types */ 109 typedef enum ir_position_t { 110 WIIUSE_IR_ABOVE, 111 WIIUSE_IR_BELOW 112 } ir_position_t; 113 114 /** 115 * @brief Check if a button is pressed. 116 * @param dev Pointer to a wiimote_t or expansion structure. 117 * @param button The button you are interested in. 118 * @return 1 if the button is pressed, 0 if not. 119 */ 120 #define IS_PRESSED(dev, button) ((dev->btns & button) == button) 121 122 /** 123 * @brief Check if a button is being held. 124 * @param dev Pointer to a wiimote_t or expansion structure. 125 * @param button The button you are interested in. 126 * @return 1 if the button is held, 0 if not. 127 */ 128 #define IS_HELD(dev, button) ((dev->btns_held & button) == button) 129 130 /** 131 * @brief Check if a button is released on this event. \n\n 132 * This does not mean the button is not pressed, it means \n 133 * this button was just now released. 134 * @param dev Pointer to a wiimote_t or expansion structure. 135 * @param button The button you are interested in. 136 * @return 1 if the button is released, 0 if not. 137 * 138 */ 139 #define IS_RELEASED(dev, button) ((dev->btns_released & button) == button) 140 141 /** 142 * @brief Check if a button has just been pressed this event. 143 * @param dev Pointer to a wiimote_t or expansion structure. 144 * @param button The button you are interested in. 145 * @return 1 if the button is pressed, 0 if not. 146 */ 147 #define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button)) 148 149 /** 150 * @brief Return the IR sensitivity level. 151 * @param wm Pointer to a wiimote_t structure. 152 * @param lvl [out] Pointer to an int that will hold the level setting. 153 * If no level is set 'lvl' will be set to 0. 154 */ 155 #define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \ 156 do { \ 157 if ((wm->state & 0x01000) == 0x01000) *lvl = 1; \ 158 else if ((wm->state & 0x02000) == 0x02000) *lvl = 2; \ 159 else if ((wm->state & 0x04000) == 0x04000) *lvl = 3; \ 160 else if ((wm->state & 0x08000) == 0x08000) *lvl = 4; \ 161 else if ((wm->state & 0x10000) == 0x10000) *lvl = 5; \ 162 else *lvl = 0; \ 163 } while (0) 164 165 #define WIIUSE_USING_ACC(wm) ((wm->state & 0x00100) == 0x00100) 166 #define WIIUSE_USING_EXP(wm) ((wm->state & 0x00200) == 0x00200) 167 #define WIIUSE_USING_IR(wm) ((wm->state & 0x00400) == 0x00400) 168 #define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x00800) == 0x00800) 169 170 #define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num) 171 172 /* 173 * Largest known payload is 21 bytes. 174 * Add 2 for the prefix and round up to a power of 2. 175 */ 176 #define MAX_PAYLOAD 32 177 178 /* 179 * This is left over from an old hack, but it may actually 180 * be a useful feature to keep so it wasn't removed. 181 */ 182 #ifdef WIN32 183 #define WIIMOTE_DEFAULT_TIMEOUT 100 184 #define WIIMOTE_EXP_TIMEOUT 100 185 #endif 186 187 typedef unsigned char ubyte; 188 typedef char sbyte; 189 typedef unsigned short uword; 190 typedef short sword; 191 typedef unsigned int uint; 192 typedef char sint; 193 194 struct wiimote_t; 195 struct vec3b_t; 196 struct orient_t; 197 struct gforce_t; 198 199 #ifdef GEKKO 200 typedef void (*wii_event_cb)(struct wiimote_t*, s32 event); 201 #endif 202 203 /** 204 * @brief Callback that handles a read event. 205 * 206 * @param wm Pointer to a wiimote_t structure. 207 * @param data Pointer to the filled data block. 208 * @param len Length in bytes of the data block. 209 * 210 * @see wiiuse_init() 211 * 212 * A registered function of this type is called automatically by the wiiuse 213 * library when the wiimote has returned the full data requested by a previous 214 * call to wiiuse_read_data(). 215 */ 216 typedef void (*wiiuse_data_cb)(struct wiimote_t* wm, ubyte* data, unsigned short len); 217 218 typedef enum data_req_s 219 { 220 REQ_READY = 0, 221 REQ_SENT, 222 REQ_DONE 223 } data_req_s; 224 225 /** 226 * @struct data_req_t 227 * @brief Data read request structure. 228 */ 229 struct data_req_t { 230 lwp_node node; 231 ubyte data[48]; /**< buffer where read data is written */ 232 unsigned int len; 233 data_req_s state; /**< set to 1 if not using callback and needs to be cleaned up */ 234 wiiuse_data_cb cb; /**< read data callback */ 235 struct data_req_t *next; 236 }; 237 238 typedef void (*cmd_blk_cb)(struct wiimote_t *wm,ubyte *data,uword len); 239 240 typedef enum cmd_blk_s 241 { 242 CMD_READY = 0, 243 CMD_SENT, 244 CMD_DONE 245 } cmd_blk_s; 246 247 struct cmd_blk_t 248 { 249 lwp_node node; 250 251 ubyte data[48]; 252 uint len; 253 254 cmd_blk_s state; 255 cmd_blk_cb cb; 256 257 struct cmd_blk_t *next; 258 }; 259 260 /** 261 * @struct vec2b_t 262 * @brief Unsigned x,y byte vector. 263 */ 264 typedef struct vec2b_t { 265 ubyte x, y; 266 } vec2b_t; 267 268 /** 269 * @struct vec3b_t 270 * @brief Unsigned x,y,z byte vector. 271 */ 272 typedef struct vec3b_t { 273 ubyte x, y, z; 274 } vec3b_t; 275 276 /** 277 * @struct vec3b_t 278 * @brief Unsigned x,y,z byte vector. 279 */ 280 typedef struct vec3w_t { 281 uword x, y, z; 282 } vec3w_t; 283 284 /** 285 * @struct vec3f_t 286 * @brief Signed x,y,z float struct. 287 */ 288 typedef struct vec3f_t { 289 float x, y, z; 290 } vec3f_t; 291 292 /** 293 * @struct orient_t 294 * @brief Orientation struct. 295 * 296 * Yaw, pitch, and roll range from -180 to 180 degrees. 297 */ 298 typedef struct orient_t { 299 float roll; /**< roll, this may be smoothed if enabled */ 300 float pitch; /**< pitch, this may be smoothed if enabled */ 301 float yaw; 302 303 float a_roll; /**< absolute roll, unsmoothed */ 304 float a_pitch; /**< absolute pitch, unsmoothed */ 305 } orient_t; 306 307 /** 308 * @struct gforce_t 309 * @brief Gravity force struct. 310 */ 311 typedef struct gforce_t { 312 float x, y, z; 313 } gforce_t; 314 315 /** 316 * @struct accel_t 317 * @brief Accelerometer struct. For any device with an accelerometer. 318 */ 319 typedef struct accel_t { 320 struct vec3w_t cal_zero; /**< zero calibration */ 321 struct vec3w_t cal_g; /**< 1g difference around 0cal */ 322 323 float st_roll; /**< last smoothed roll value */ 324 float st_pitch; /**< last smoothed roll pitch */ 325 float st_alpha; /**< alpha value for smoothing [0-1] */ 326 } accel_t; 327 328 /** 329 * @struct ir_dot_t 330 * @brief A single IR source. 331 */ 332 typedef struct ir_dot_t { 333 ubyte visible; /**< if the IR source is visible */ 334 335 short rx; /**< raw X coordinate (0-1023) */ 336 short ry; /**< raw Y coordinate (0-767) */ 337 338 ubyte size; /**< size of the IR dot (0-15) */ 339 } ir_dot_t; 340 341 typedef struct fdot_t { 342 float x,y; 343 } fdot_t; 344 345 typedef struct sb_t { 346 fdot_t dots[2]; 347 fdot_t acc_dots[2]; 348 fdot_t rot_dots[2]; 349 float angle; 350 float off_angle; 351 float score; 352 } sb_t; 353 354 /** 355 * @enum aspect_t 356 * @brief Screen aspect ratio. 357 */ 358 typedef enum aspect_t { 359 WIIUSE_ASPECT_4_3, 360 WIIUSE_ASPECT_16_9 361 } aspect_t; 362 363 /** 364 * @struct ir_t 365 * @brief IR struct. Hold all data related to the IR tracking. 366 */ 367 typedef struct ir_t { 368 struct ir_dot_t dot[4]; /**< IR dots */ 369 ubyte num_dots; /**< number of dots at this time */ 370 371 int state; /**< keeps track of the IR state */ 372 373 int raw_valid; /**< is the raw position valid? */ 374 sb_t sensorbar; /**< sensor bar, detected or guessed */ 375 float ax; /**< raw X coordinate */ 376 float ay; /**< raw Y coordinate */ 377 float distance; /**< pixel width of the sensor bar */ 378 float z; /**< calculated distance in meters */ 379 float angle; /**< angle of the wiimote to the sensor bar*/ 380 381 int smooth_valid; /**< is the smoothed position valid? */ 382 float sx; /**< smoothed X coordinate */ 383 float sy; /**< smoothed Y coordinate */ 384 float error_cnt; /**< error count, for smoothing algorithm*/ 385 float glitch_cnt; /**< glitch count, same */ 386 387 int valid; /**< is the bounded position valid? */ 388 float x; /**< bounded X coordinate */ 389 float y; /**< bounded Y coordinate */ 390 enum aspect_t aspect; /**< aspect ratio of the screen */ 391 enum ir_position_t pos; /**< IR sensor bar position */ 392 unsigned int vres[2]; /**< IR virtual screen resolution */ 393 int offset[2]; /**< IR XY correction offset */ 394 395 } ir_t; 396 397 /** 398 * @struct joystick_t 399 * @brief Joystick calibration structure. 400 * 401 * The angle \a ang is relative to the positive y-axis into quadrant I 402 * and ranges from 0 to 360 degrees. So if the joystick is held straight 403 * upwards then angle is 0 degrees. If it is held to the right it is 90, 404 * down is 180, and left is 270. 405 * 406 * The magnitude \a mag is the distance from the center to where the 407 * joystick is being held. The magnitude ranges from 0 to 1. 408 * If the joystick is only slightly tilted from the center the magnitude 409 * will be low, but if it is closer to the outter edge the value will 410 * be higher. 411 */ 412 typedef struct joystick_t { 413 struct vec2b_t max; /**< maximum joystick values */ 414 struct vec2b_t min; /**< minimum joystick values */ 415 struct vec2b_t center; /**< center joystick values */ 416 struct vec2b_t pos; /**< raw position values */ 417 418 float ang; /**< angle the joystick is being held */ 419 float mag; /**< magnitude of the joystick (range 0-1) */ 420 } joystick_t; 421 422 /** 423 * @struct nunchuk_t 424 * @brief Nunchuk expansion device. 425 */ 426 typedef struct nunchuk_t { 427 struct accel_t accel_calib; /**< nunchuk accelerometer calibration */ 428 struct joystick_t js; /**< joystick calibration */ 429 430 int* flags; /**< options flag (points to wiimote_t.flags) */ 431 432 ubyte btns; /**< what buttons have just been pressed */ 433 ubyte btns_last; /**< what buttons have just been pressed */ 434 ubyte btns_held; /**< what buttons are being held down */ 435 ubyte btns_released; /**< what buttons were just released this */ 436 437 struct vec3w_t accel; /**< current raw acceleration data */ 438 struct orient_t orient; /**< current orientation on each axis */ 439 struct gforce_t gforce; /**< current gravity forces on each axis */ 440 } nunchuk_t; 441 442 /** 443 * @struct classic_ctrl_t 444 * @brief Classic controller expansion device. 445 */ 446 typedef struct classic_ctrl_t { 447 short btns; /**< what buttons have just been pressed */ 448 short btns_last; /**< what buttons have just been pressed */ 449 short btns_held; /**< what buttons are being held down */ 450 short btns_released; /**< what buttons were just released this */ 451 452 ubyte rs_raw; 453 ubyte ls_raw; 454 455 float r_shoulder; /**< right shoulder button (range 0-1) */ 456 float l_shoulder; /**< left shoulder button (range 0-1) */ 457 458 struct joystick_t ljs; /**< left joystick calibration */ 459 struct joystick_t rjs; /**< right joystick calibration */ 460 ubyte type; /**< original, pro, wiiu pro */ 461 } classic_ctrl_t; 462 463 /** 464 * @struct guitar_hero_3_t 465 * @brief Guitar Hero 3 expansion device. 466 */ 467 typedef struct guitar_hero_3_t { 468 short btns; /**< what buttons have just been pressed */ 469 short btns_last; /**< what buttons have just been pressed */ 470 short btns_held; /**< what buttons are being held down */ 471 short btns_released; /**< what buttons were just released this */ 472 473 ubyte wb_raw; 474 float whammy_bar; /**< whammy bar (range 0-1) */ 475 476 ubyte tb_raw; 477 int touch_bar; /**< touch bar */ 478 479 struct joystick_t js; /**< joystick calibration */ 480 } guitar_hero_3_t; 481 482 /** 483 * @struct wii_board_t 484 * @brief Wii Balance Board expansion device. 485 */ 486 typedef struct wii_board_t { 487 float tl; /* Interpolated */ 488 float tr; 489 float bl; 490 float br; /* End interp */ 491 short rtl; /* RAW */ 492 short rtr; 493 short rbl; 494 short rbr; /* /RAW */ 495 short ctl[3]; /* Calibration */ 496 short ctr[3]; 497 short cbl[3]; 498 short cbr[3]; /* /Calibration */ 499 float x; 500 float y; 501 } wii_board_t; 502 503 typedef struct motion_plus_t 504 { 505 short rx, ry, rz; 506 ubyte status; 507 ubyte ext; 508 } motion_plus_t; 509 510 /** 511 * @struct expansion_t 512 * @brief Generic expansion device plugged into wiimote. 513 */ 514 typedef struct expansion_t { 515 int type; /**< type of expansion attached */ 516 517 union { 518 struct nunchuk_t nunchuk; 519 struct classic_ctrl_t classic; 520 struct guitar_hero_3_t gh3; 521 struct wii_board_t wb; 522 struct motion_plus_t mp; 523 }; 524 } expansion_t; 525 526 /** 527 * @enum win32_bt_stack_t 528 * @brief Available bluetooth stacks for Windows. 529 */ 530 typedef enum win_bt_stack_t { 531 WIIUSE_STACK_UNKNOWN, 532 WIIUSE_STACK_MS, 533 WIIUSE_STACK_BLUESOLEIL 534 } win_bt_stack_t; 535 536 /** 537 * @struct wiimote_state_t 538 * @brief Significant data from the previous event. 539 */ 540 typedef struct wiimote_state_t { 541 unsigned short btns; 542 543 struct ir_t ir; 544 struct vec3w_t accel; 545 struct expansion_t exp; 546 } wiimote_state_t; 547 548 /** 549 * @enum WIIUSE_EVENT_TYPE 550 * @brief Events that wiiuse can generate from a poll. 551 */ 552 typedef enum WIIUSE_EVENT_TYPE { 553 WIIUSE_NONE = 0, 554 WIIUSE_EVENT, 555 WIIUSE_STATUS, 556 WIIUSE_CONNECT, 557 WIIUSE_DISCONNECT, 558 WIIUSE_UNEXPECTED_DISCONNECT, 559 WIIUSE_READ_DATA, 560 WIIUSE_ACK, 561 WIIUSE_NUNCHUK_INSERTED, 562 WIIUSE_NUNCHUK_REMOVED, 563 WIIUSE_CLASSIC_CTRL_INSERTED, 564 WIIUSE_CLASSIC_CTRL_REMOVED, 565 WIIUSE_GUITAR_HERO_3_CTRL_INSERTED, 566 WIIUSE_GUITAR_HERO_3_CTRL_REMOVED, 567 WIIUSE_WII_BOARD_INSERTED, 568 WIIUSE_WII_BOARD_REMOVED, 569 WIIUSE_MOTION_PLUS_ACTIVATED, 570 WIIUSE_MOTION_PLUS_REMOVED 571 } WIIUSE_EVENT_TYPE; 572 573 /** 574 * @struct wiimote_t 575 * @brief Wiimote structure. 576 */ 577 typedef struct wiimote_t { 578 WCONST int unid; /**< user specified id */ 579 580 #if defined(_WIN32) 581 WCONST HANDLE dev_handle; /**< HID handle */ 582 WCONST OVERLAPPED hid_overlap; /**< overlap handle */ 583 WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */ 584 WCONST int timeout; /**< read timeout */ 585 WCONST ubyte normal_timeout; /**< normal timeout */ 586 WCONST ubyte exp_timeout; /**< timeout for expansion handshake */ 587 #elif defined(GEKKO) 588 WCONST lwp_queue cmdq; 589 WCONST struct bd_addr bdaddr; /**< bt address */ 590 WCONST char bdaddr_str[18]; /**< readable bt address */ 591 WCONST struct bte_pcb *sock; /**< output socket */ 592 WCONST wii_event_cb event_cb; /**< event callback */ 593 #elif defined(unix) 594 WCONST bdaddr_t bdaddr; /**< bt address */ 595 WCONST char bdaddr_str[18]; /**< readable bt address */ 596 WCONST int out_sock; /**< output socket */ 597 WCONST int in_sock; /**< input socket */ 598 #endif 599 600 WCONST int state; /**< various state flags */ 601 WCONST ubyte leds; /**< currently lit leds */ 602 #ifdef GEKKO 603 WCONST ubyte battery_level; /**< battery level */ 604 #else 605 WCONST float battery_level; /**< battery level */ 606 #endif 607 608 WCONST int flags; /**< options flag */ 609 610 WCONST ubyte handshake_state; /**< the state of the connection handshake */ 611 WCONST ubyte expansion_state; /**< the state of the expansion handshake */ 612 613 WCONST struct data_req_t* data_req; /**< list of data read requests */ 614 615 WCONST struct cmd_blk_t *cmd_head; 616 WCONST struct cmd_blk_t *cmd_tail; 617 618 WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */ 619 WCONST struct expansion_t exp; /**< wiimote expansion device */ 620 621 WCONST struct vec3w_t accel; /**< current raw acceleration data */ 622 WCONST struct orient_t orient; /**< current orientation on each axis */ 623 WCONST struct gforce_t gforce; /**< current gravity forces on each axis */ 624 625 WCONST struct ir_t ir; /**< IR data */ 626 627 WCONST unsigned short btns; /**< what buttons are down */ 628 WCONST unsigned short btns_last; /**< what buttons were down before */ 629 WCONST unsigned short btns_held; /**< what buttons are and were held down */ 630 WCONST unsigned short btns_released; /**< what buttons were just released */ 631 632 WCONST struct wiimote_state_t lstate; /**< last saved state */ 633 634 WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */ 635 WCONST ubyte event_buf[MAX_PAYLOAD]; /**< event buffer */ 636 637 WCONST ubyte motion_plus_id[6]; 638 } wiimote; 639 640 #if defined(GEKKO) 641 /** 642 * @struct wiimote_listen_t 643 * @brief Wiimote listen structure. 644 */ 645 typedef struct wiimote_listen_t { 646 WCONST struct bd_addr bdaddr; 647 WCONST struct bte_pcb *sock; 648 WCONST struct wiimote_t *(*assign_cb)(struct bd_addr *bdaddr); 649 WCONST struct wiimote_t *wm; 650 } wiimote_listen; 651 #endif 652 653 /***************************************** 654 * 655 * Include API specific stuff 656 * 657 *****************************************/ 658 659 #ifdef _WIN32 660 #define WIIUSE_EXPORT_DECL __declspec(dllexport) 661 #define WIIUSE_IMPORT_DECL __declspec(dllimport) 662 #else 663 #define WIIUSE_EXPORT_DECL 664 #define WIIUSE_IMPORT_DECL 665 #endif 666 667 #ifdef WIIUSE_COMPILE_LIB 668 #define WIIUSE_EXPORT WIIUSE_EXPORT_DECL 669 #else 670 #define WIIUSE_EXPORT WIIUSE_IMPORT_DECL 671 #endif 672 673 #ifdef __cplusplus 674 extern "C" { 675 #endif 676 677 /* wiiuse.c */ 678 WIIUSE_EXPORT extern const char* wiiuse_version(); 679 680 #ifndef GEKKO 681 WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes); 682 #else 683 WIIUSE_EXPORT extern int wiiuse_register(struct wiimote_listen_t *wml, struct bd_addr *bdaddr, struct wiimote_t *(*assign_cb)(struct bd_addr *bdaddr)); 684 WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes, wii_event_cb event_cb); 685 WIIUSE_EXPORT extern void wiiuse_sensorbar_enable(int enable); 686 #endif 687 688 WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm); 689 WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes); 690 WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status); 691 WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm); 692 WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds,cmd_blk_cb cb); 693 WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status); 694 WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, ubyte* buffer, unsigned int offset, unsigned short len, cmd_blk_cb cb); 695 WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t *wm,unsigned int addr,ubyte *data,ubyte len,cmd_blk_cb cb); 696 WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t *wm,cmd_blk_cb cb); 697 WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid); 698 WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable); 699 WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha); 700 WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type); 701 WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm); 702 WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, ubyte normal_timeout, ubyte exp_timeout); 703 WIIUSE_EXPORT extern int wiiuse_write_streamdata(struct wiimote_t *wm,ubyte *data,ubyte len,cmd_blk_cb cb); 704 705 /* connect.c */ 706 WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout); 707 WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes); 708 WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm); 709 710 /* events.c */ 711 WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes); 712 713 /* ir.c */ 714 WIIUSE_EXPORT extern void wiiuse_set_ir_mode(struct wiimote_t *wm); 715 WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status); 716 WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y); 717 WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos); 718 WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect); 719 WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level); 720 721 /* motion_plus.c */ 722 WIIUSE_EXPORT extern void wiiuse_set_motion_plus(struct wiimote_t *wm, int status); 723 724 /* speaker.c */ 725 WIIUSE_EXPORT extern void wiiuse_set_speaker(struct wiimote_t *wm, int status); 726 727 #ifdef __cplusplus 728 } 729 #endif 730 731 #endif 732