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> 77 #include <CoreFoundation/CoreFoundation.h> 78 #include <IOBluetooth/IOBluetoothUserLib.h> 83 #if defined(_MSC_VER) && _MSC_VER < 1700 88 #include "wiiuse_msvcstdint.h" 102 #define WM_OUTPUT_CHANNEL 0x11 103 #define WM_INPUT_CHANNEL 0x13 105 #define WM_SET_REPORT 0x50 106 #define WM_SET_DATA 0xA0 109 #define WM_CMD_LED 0x11 110 #define WM_CMD_REPORT_TYPE 0x12 111 #define WM_CMD_RUMBLE 0x13 112 #define WM_CMD_IR 0x13 113 #define WM_CMD_CTRL_STATUS 0x15 114 #define WM_CMD_WRITE_DATA 0x16 115 #define WM_CMD_READ_DATA 0x17 116 #define WM_CMD_IR_2 0x1A 119 #define WM_RPT_CTRL_STATUS 0x20 120 #define WM_RPT_READ 0x21 121 #define WM_RPT_WRITE 0x22 122 #define WM_RPT_BTN 0x30 123 #define WM_RPT_BTN_ACC 0x31 124 #define WM_RPT_BTN_EXP_8 0x32 125 #define WM_RPT_BTN_ACC_IR 0x33 126 #define WM_RPT_BTN_EXP 0x34 127 #define WM_RPT_BTN_ACC_EXP 0x35 128 #define WM_RPT_BTN_IR_EXP 0x36 129 #define WM_RPT_BTN_ACC_IR_EXP 0x37 131 #define WM_BT_INPUT 0x01 132 #define WM_BT_OUTPUT 0x02 154 #define WM_DEV_MINOR_CLASS 0x01 // Regular wiimote 155 #define WM_DEV_MAJOR_CLASS 0x05 156 #define WM_DEV_MAJOR_SERVICE 0x01 158 #define WM_PLUS_DEV_MINOR_CLASS 0x02 // For the newer RVL-CNT-01-TR (MotionPlus Inside) 159 #define WM_PLUS_DEV_MAJOR_CLASS 0x05 160 #define WM_PLUS_DEV_MAJOR_SERVICE 0x00 162 #define WM_DEV_CLASS_0 0x04 // Regular wiimote 163 #define WM_DEV_CLASS_1 0x25 164 #define WM_DEV_CLASS_2 0x00 166 #define WM_PLUS_DEV_CLASS_0 0x08 // For the newer RVL-CNT-01-TR (MotionPlus Inside) 167 #define WM_PLUS_DEV_CLASS_1 0x05 168 #define WM_PLUS_DEV_CLASS_2 0x00 170 #define WM_VENDOR_ID 0x057E 171 #define WM_PRODUCT_ID 0x0306 // Regular wiimote 172 #define WM_PRODUCT_ID_TR 0x0330 // RVL-CNT-01-TR Wiimote (with MotionPlus built-in) 175 #define WM_MAX_BATTERY_CODE 0xC8 178 #define WM_MEM_OFFSET_CALIBRATION 0x16 179 #define WM_EXP_MEM_BASE 0x04A40000 180 #define WM_EXP_ID 0x04A400FA 181 #define WM_EXP_MEM_ENABLE 0x04A40040 182 #define WM_EXP_MEM_ENABLE1 0x04A400F0 183 #define WM_EXP_MEM_ENABLE2 0x04A400FB 184 #define WM_EXP_MEM_CALIBR 0x04A40020 185 #define WM_EXP_MOTION_PLUS_IDENT 0x04A600FA 186 #define WM_EXP_MOTION_PLUS_ENABLE 0x04A600FE 187 #define WM_EXP_MOTION_PLUS_INIT 0x04A600F0 188 #define WM_REG_IR 0x04B00030 189 #define WM_REG_IR_BLOCK1 0x04B00000 190 #define WM_REG_IR_BLOCK2 0x04B0001A 191 #define WM_REG_IR_MODENUM 0x04B00033 194 #define WM_EXP_BBOARD_INIT1 0x04A400F1 196 #define WM_IR_TYPE_BASIC 0x01 197 #define WM_IR_TYPE_EXTENDED 0x03 201 #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 202 #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04 203 #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08 204 #define WM_CTRL_STATUS_BYTE1_LED_1 0x10 205 #define WM_CTRL_STATUS_BYTE1_LED_2 0x20 206 #define WM_CTRL_STATUS_BYTE1_LED_3 0x40 207 #define WM_CTRL_STATUS_BYTE1_LED_4 0x80 210 #define WM_ASPECT_16_9_X 660 211 #define WM_ASPECT_16_9_Y 370 212 #define WM_ASPECT_4_3_X 560 213 #define WM_ASPECT_4_3_Y 420 220 #define EXP_ID_CODE_NUNCHUK 0xA4200000 221 #define EXP_ID_CODE_WII_BOARD 0xA4200402 222 #define EXP_ID_CODE_CLASSIC_CONTROLLER 0xA4200101 223 #define EXP_ID_CODE_GUITAR 0xA4200103 224 #define EXP_ID_CODE_MOTION_PLUS 0xA4200405 225 #define EXP_ID_CODE_MOTION_PLUS_NUNCHUK 0xA4200505 226 #define EXP_ID_CODE_MOTION_PLUS_CLASSIC 0xA4200705 227 #define EXP_ID_CODE_TATACON 0xA4200111 230 #define EXP_ID_CODE_INACTIVE_MOTION_PLUS 0xA6200005 231 #define EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN 0xA4200005 233 #define EXP_ID_CODE_NLA_MOTION_PLUS 0xA6200405 234 #define EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK 0xA6200505 235 #define EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC 0xA6200705 237 #define EXP_HANDSHAKE_LEN 224 245 #define WIIMOTE_INIT_STATES (WIIMOTE_STATE_IR_SENS_LVL3) 248 #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) 249 #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) 250 #define WIIMOTE_TOGGLE_STATE(wm, s) \ 251 ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) 253 #define WIIMOTE_IS_FLAG_SET(wm, s) ((wm->flags & (s)) == (s)) 254 #define WIIMOTE_ENABLE_FLAG(wm, s) (wm->flags |= (s)) 255 #define WIIMOTE_DISABLE_FLAG(wm, s) (wm->flags &= ~(s)) 256 #define WIIMOTE_TOGGLE_FLAG(wm, s) \ 257 ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s)) 259 #define NUNCHUK_IS_FLAG_SET(wm, s) ((*(wm->flags) & (s)) == (s)) 265 #define MAX_PAYLOAD 32 273 #define WIIUSE_DEFAULT_SMOOTH_ALPHA 0.07f 275 #define SMOOTH_ROLL 0x01 276 #define SMOOTH_PITCH 0x02 278 #define WIIUSE_READ_TIMEOUT 5000 284 #define _STRINGIFY(s) _STRINGIFY_IMPL(s) 285 #define _STRINGIFY_IMPL(s) #s 288 #define WIIUSE_VERSION _STRINGIFY(WIIUSE_MAJOR) "." _STRINGIFY(WIIUSE_MINOR) "." _STRINGIFY(WIIUSE_MICRO) 291 #define INLINE_UTIL __inline 293 #define INLINE_UTIL static inline 319 #ifdef WIIUSE_DOXYGEN_PARSING 325 uint8_t from_big_endian_uint8_t(byte *buf);
332 uint16_t from_big_endian_uint16_t(byte *buf);
340 uint32_t from_big_endian_uint32_t(byte *buf);
351 void to_big_endian_uint8_t(byte *buf, uint8_t val);
359 void to_big_endian_uint16_t(byte *buf, uint16_t val);
367 void to_big_endian_uint32_t(byte *buf, uint32_t val);
380 void buffer_big_endian_uint16_t(byte **buf, uint16_t val);
386 uint16_t unbuffer_big_endian_uint16_t(byte **buf);
390 void buffer_big_endian_uint8_t(byte **buf, uint8_t val);
394 uint8_t unbuffer_big_endian_uint8_t(byte **buf);
398 void buffer_big_endian_uint32_t(byte **buf, uint32_t val);
402 uint8_t unbuffer_big_endian_uint32_t(byte **buf)
407 INLINE_UTIL
void to_big_endian_uint8_t(byte *buf, uint8_t val) { memcpy(buf, &val, 1); }
409 INLINE_UTIL uint8_t from_big_endian_uint8_t(byte *buf)
412 memcpy(&beVal, buf, 1);
416 #define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(_TYPE, _TOBE, _FROMBE) \ 417 INLINE_UTIL void to_big_endian_##_TYPE(byte *buf, _TYPE val) \ 419 _TYPE beVal = _TOBE(val); \ 420 memcpy(buf, &beVal, sizeof(_TYPE)); \ 422 INLINE_UTIL _TYPE from_big_endian_##_TYPE(byte *buf) \ 425 memcpy(&beVal, buf, sizeof(_TYPE)); \ 426 return _FROMBE(beVal); \ 429 WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint16_t, htons, ntohs)
430 WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(uint32_t, htonl, ntohl)
432 #undef WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS 434 #define WIIUSE_DECLARE_BUFFERING_OPS(_TYPE) \ 435 INLINE_UTIL void buffer_big_endian_##_TYPE(byte **buf, _TYPE val) \ 437 to_big_endian_##_TYPE(*buf, val); \ 438 *buf += sizeof(_TYPE); \ 440 INLINE_UTIL _TYPE unbuffer_big_endian_##_TYPE(byte **buf) \ 442 byte *current = *buf; \ 443 *buf += sizeof(_TYPE); \ 444 return from_big_endian_##_TYPE(current); \ 447 WIIUSE_DECLARE_BUFFERING_OPS(uint8_t)
448 WIIUSE_DECLARE_BUFFERING_OPS(uint16_t)
449 WIIUSE_DECLARE_BUFFERING_OPS(uint32_t)
451 #undef WIIUSE_DECLARE_BUFFERING_OPS Main Wiimote device structure.
Definition: wiiuse.h:751
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:649
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:705
int wiiuse_send(struct wiimote_t *wm, byte report_type, byte *msg, int len)
Send a packet to the wiimote.
Definition: wiiuse.c:744
void(* wiiuse_read_cb)(struct wiimote_t *wm, byte *data, uint16_t len)
Callback that handles a read event.
Definition: wiiuse.h:358
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:42
void(* wiiuse_write_cb)(struct wiimote_t *wm, unsigned char *data, unsigned short len)
Callback that handles a write event.
Definition: wiiuse.h:854
int wiiuse_set_report_type(struct wiimote_t *wm)
Set the report type based on the current wiimote state.
Definition: wiiuse.c:325