50 #ifndef WIIUSE_INTERNAL_H_INCLUDED 51 #define WIIUSE_INTERNAL_H_INCLUDED 53 #ifndef WIIUSE_PLATFORM 55 #define WIIUSE_PLATFORM 57 #elif defined(__linux) 58 #define WIIUSE_PLATFORM 60 #elif defined(__APPLE__) 61 #define WIIUSE_PLATFORM 64 #error "Platform not yet supported!" 72 #include <arpa/inet.h> 73 #include <bluetooth/bluetooth.h> 75 #ifdef WIIUSE_BT_EMBEDDED 76 #include <arpa/inet.h> 77 #include <bt-embedded/l2cap.h> 81 #include <CoreFoundation/CoreFoundation.h> 82 #include <IOBluetooth/IOBluetoothUserLib.h> 87 #if defined(_MSC_VER) && _MSC_VER < 1700 92 #include "wiiuse_msvcstdint.h" 106 #define WM_OUTPUT_CHANNEL 0x11 107 #define WM_INPUT_CHANNEL 0x13 109 #define WM_SET_REPORT 0x50 110 #define WM_SET_DATA 0xA0 113 #define WM_CMD_LED 0x11 114 #define WM_CMD_REPORT_TYPE 0x12 115 #define WM_CMD_RUMBLE 0x13 116 #define WM_CMD_IR 0x13 117 #define WM_CMD_CTRL_STATUS 0x15 118 #define WM_CMD_WRITE_DATA 0x16 119 #define WM_CMD_READ_DATA 0x17 120 #define WM_CMD_IR_2 0x1A 123 #define WM_RPT_CTRL_STATUS 0x20 124 #define WM_RPT_READ 0x21 125 #define WM_RPT_WRITE 0x22 126 #define WM_RPT_BTN 0x30 127 #define WM_RPT_BTN_ACC 0x31 128 #define WM_RPT_BTN_EXP_8 0x32 129 #define WM_RPT_BTN_ACC_IR 0x33 130 #define WM_RPT_BTN_EXP 0x34 131 #define WM_RPT_BTN_ACC_EXP 0x35 132 #define WM_RPT_BTN_IR_EXP 0x36 133 #define WM_RPT_BTN_ACC_IR_EXP 0x37 135 #define WM_BT_INPUT 0x01 136 #define WM_BT_OUTPUT 0x02 158 #define WM_DEV_MINOR_CLASS 0x01 // Regular wiimote 159 #define WM_DEV_MAJOR_CLASS 0x05 160 #define WM_DEV_MAJOR_SERVICE 0x01 162 #define WM_PLUS_DEV_MINOR_CLASS 0x02 // For the newer RVL-CNT-01-TR (MotionPlus Inside) 163 #define WM_PLUS_DEV_MAJOR_CLASS 0x05 164 #define WM_PLUS_DEV_MAJOR_SERVICE 0x00 166 #define WM_DEV_CLASS_0 0x04 // Regular wiimote 167 #define WM_DEV_CLASS_1 0x25 168 #define WM_DEV_CLASS_2 0x00 170 #define WM_PLUS_DEV_CLASS_0 0x08 // For the newer RVL-CNT-01-TR (MotionPlus Inside) 171 #define WM_PLUS_DEV_CLASS_1 0x05 172 #define WM_PLUS_DEV_CLASS_2 0x00 174 #define WM_VENDOR_ID 0x057E 175 #define WM_PRODUCT_ID 0x0306 // Regular wiimote 176 #define WM_PRODUCT_ID_TR 0x0330 // RVL-CNT-01-TR Wiimote (with MotionPlus built-in) 179 #define WM_MAX_BATTERY_CODE 0xC8 182 #define WM_MEM_OFFSET_CALIBRATION 0x16 183 #define WM_EXP_MEM_BASE 0x04A40000 184 #define WM_EXP_ID 0x04A400FA 185 #define WM_EXP_MEM_ENABLE 0x04A40040 186 #define WM_EXP_MEM_ENABLE1 0x04A400F0 187 #define WM_EXP_MEM_ENABLE2 0x04A400FB 188 #define WM_EXP_MEM_CALIBR 0x04A40020 189 #define WM_EXP_MOTION_PLUS_IDENT 0x04A600FA 190 #define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE 191 #define WM_EXP_MOTION_PLUS_INIT 0x04A600F0 192 #define WM_REG_IR 0x04B00030 193 #define WM_REG_IR_BLOCK1 0x04B00000 194 #define WM_REG_IR_BLOCK2 0x04B0001A 195 #define WM_REG_IR_MODENUM 0x04B00033 198 #define WM_EXP_BBOARD_INIT1 0x04A400F1 200 #define WM_IR_TYPE_BASIC 0x01 201 #define WM_IR_TYPE_EXTENDED 0x03 205 #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 206 #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04 207 #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08 208 #define WM_CTRL_STATUS_BYTE1_LED_1 0x10 209 #define WM_CTRL_STATUS_BYTE1_LED_2 0x20 210 #define WM_CTRL_STATUS_BYTE1_LED_3 0x40 211 #define WM_CTRL_STATUS_BYTE1_LED_4 0x80 214 #define WM_ASPECT_16_9_X 660 215 #define WM_ASPECT_16_9_Y 370 216 #define WM_ASPECT_4_3_X 560 217 #define WM_ASPECT_4_3_Y 420 224 #define EXP_ID_CODE_NUNCHUK 0xA4200000 225 #define EXP_ID_CODE_WII_BOARD 0xA4200402 226 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0xA4200101 227 #define EXP_ID_CODE_GUITAR 0xA4200103 228 #define EXP_ID_CODE_MOTION_PLUS 0xA4200405 229 #define EXP_ID_CODE_MOTION_PLUS_NUNCHUK 0xA4200505 230 #define EXP_ID_CODE_MOTION_PLUS_CLASSIC 0xA4200705 231 #define EXP_ID_CODE_TATACON 0xA4200111 234 #define EXP_ID_CODE_INACTIVE_MOTION_PLUS 0xA6200005 235 #define EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN 0xA4200005 237 #define EXP_ID_CODE_NLA_MOTION_PLUS 0xA6200405 238 #define EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK 0xA6200505 239 #define EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC 0xA6200705 241 #define EXP_HANDSHAKE_LEN 224 249 #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3) 252 #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) 253 #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) 254 #define WIIMOTE_TOGGLE_STATE(wm, s) \ 255 ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) 257 #define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s)) 258 #define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s)) 259 #define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s)) 260 #define WIIMOTE_TOGGLE_FLAG(wm, s) \ 261 ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s)) 263 #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s)) 269 #define MAX_PAYLOAD 32 277 #define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f 279 #define SMOOTH_ROLL 0x01 280 #define SMOOTH_PITCH 0x02 282 #define WIIUSE_READ_TIMEOUT 5000 288 #define _STRINGIFY(s) _STRINGIFY_IMPL(s) 289 #define _STRINGIFY_IMPL(s) #s 292 #define WIIUSE_VERSION _STRINGIFY(WIIUSE_MAJOR) "." _STRINGIFY(WIIUSE_MINOR) "." _STRINGIFY(WIIUSE_MICRO) 295 #define INLINE_UTIL __inline 297 #define INLINE_UTIL static inline 323 #ifdef WIIUSE_DOXYGEN_PARSING 329 uint8_t from_big_endian_uint8_t(byte *buf);
336 uint16_t from_big_endian_uint16_t(byte *buf);
344 uint32_t from_big_endian_uint32_t(byte *buf);
355 void to_big_endian_uint8_t(byte *buf, uint8_t val);
363 void to_big_endian_uint16_t(byte *buf, uint16_t val);
371 void to_big_endian_uint32_t(byte *buf, uint32_t val);
384 void buffer_big_endian_uint16_t(byte **buf, uint16_t val);
390 uint16_t unbuffer_big_endian_uint16_t(byte **buf);
394 void buffer_big_endian_uint8_t(byte **buf, uint8_t val);
398 uint8_t unbuffer_big_endian_uint8_t(byte **buf);
402 void buffer_big_endian_uint32_t(byte **buf, uint32_t val);
406 uint8_t unbuffer_big_endian_uint32_t(byte **buf)
411 INLINE_UTIL
void to_big_endian_uint8_t(byte *buf, uint8_t val) { memcpy(buf, &val, 1); }
413 INLINE_UTIL uint8_t from_big_endian_uint8_t(byte *buf)
416 memcpy(&beVal, buf, 1);
420 #define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(_TYPE, _TOBE, _FROMBE) \ 421 INLINE_UTIL void to_big_endian_##_TYPE(byte *buf, _TYPE val) \ 423 _TYPE beVal = _TOBE(val); \ 424 memcpy(buf, &beVal, sizeof(_TYPE)); \ 426 INLINE_UTIL _TYPE from_big_endian_##_TYPE(byte *buf) \ 429 memcpy(&beVal, buf, sizeof(_TYPE)); \ 430 return _FROMBE(beVal); \ 433 WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs)
434 WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl)
436 #undef WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS 438 #define WIIUSE_DECLARE_BUFFERING_OPS(_TYPE) \ 439 INLINE_UTIL void buffer_big_endian_##_TYPE(byte **buf, _TYPE val) \ 441 to_big_endian_##_TYPE(*buf, val); \ 442 *buf += sizeof(_TYPE); \ 444 INLINE_UTIL _TYPE unbuffer_big_endian_##_TYPE(byte **buf) \ 446 byte *current = *buf; \ 447 *buf += sizeof(_TYPE); \ 448 return from_big_endian_##_TYPE(current); \ 451 WIIUSE_DECLARE_BUFFERING_OPS(uint8_t)
452 WIIUSE_DECLARE_BUFFERING_OPS(uint16_t)
453 WIIUSE_DECLARE_BUFFERING_OPS(uint32_t)
455 #undef WIIUSE_DECLARE_BUFFERING_OPS Main Wiimote device structure.
Definition: wiiuse.h:793
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb)
Write data to the wiimote (callback version).
Definition: wiiuse.c:654
void wiiuse_send_next_pending_read_request(struct wiimote_t *wm)
Send the next pending data read request to the wiimote.
Definition: wiiuse.c:494
void wiiuse_send_next_pending_write_request(struct wiimote_t *wm)
Send the next pending data write request to the wiimote.
Definition: wiiuse.c:710
int wiiuse_send(struct wiimote_t *wm, byte report_type, byte *msg, int len)
Send a packet to the wiimote.
Definition: wiiuse.c:749
void(* wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len)
Callback that handles a read event.
Definition: wiiuse.h:364
int wiiuse_read_data_cb(struct wiimote_t *wm, wiiuse_read_cb read_cb, byte *buffer, unsigned int offset, uint16_t len)
Read data from the wiimote (callback version).
Definition: wiiuse.c:411
void wiiuse_millisleep(int durationMilliseconds)
Cross-platform call to sleep for at least the specified number of milliseconds.
Definition: util.c:44
void(* wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len)
Callback that handles a write event.
Definition: wiiuse.h:906
int wiiuse_set_report_type(struct wiimote_t *wm)
Set the report type based on the current wiimote state.
Definition: wiiuse.c:325