wiiuse
Macros | Functions | Variables
Internal: API for General Internal Use

Macros

#define WIIMOTE_PI   3.14159265f
 
#define OUTF_ERROR   logtarget[0]
 
#define OUTF_WARNING   logtarget[1]
 
#define OUTF_INFO   logtarget[2]
 
#define OUTF_DEBUG   logtarget[3]
 
#define WIIUSE_ERROR(fmt, ...)
 
#define WIIUSE_WARNING(fmt, ...)
 
#define WIIUSE_INFO(fmt, ...)
 
#define WIIUSE_DEBUG(fmt, ...)
 
#define RAD_TO_DEGREE(r)   ((r * 180.0f) / WIIMOTE_PI)
 
#define DEGREE_TO_RAD(d)   (d * (WIIMOTE_PI / 180.0f))
 
#define absf(x)   ((x >= 0) ? (x) : (x * -1.0f))
 
#define diff_f(x, y)   ((x >= y) ? (absf(x - y)) : (absf(y - x)))
 
#define WM_OUTPUT_CHANNEL   0x11
 
#define WM_INPUT_CHANNEL   0x13
 
#define WM_SET_REPORT   0x50
 
#define WM_SET_DATA   0xA0
 
#define WM_CMD_LED   0x11
 
#define WM_CMD_REPORT_TYPE   0x12
 
#define WM_CMD_RUMBLE   0x13
 
#define WM_CMD_IR   0x13
 
#define WM_CMD_CTRL_STATUS   0x15
 
#define WM_CMD_WRITE_DATA   0x16
 
#define WM_CMD_READ_DATA   0x17
 
#define WM_CMD_IR_2   0x1A
 
#define WM_RPT_CTRL_STATUS   0x20
 
#define WM_RPT_READ   0x21
 
#define WM_RPT_WRITE   0x22
 
#define WM_RPT_BTN   0x30
 
#define WM_RPT_BTN_ACC   0x31
 
#define WM_RPT_BTN_EXP_8   0x32
 
#define WM_RPT_BTN_ACC_IR   0x33
 
#define WM_RPT_BTN_EXP   0x34
 
#define WM_RPT_BTN_ACC_EXP   0x35
 
#define WM_RPT_BTN_IR_EXP   0x36
 
#define WM_RPT_BTN_ACC_IR_EXP   0x37
 
#define WM_BT_INPUT   0x01
 
#define WM_BT_OUTPUT   0x02
 
#define WM_DEV_CLASS_0   0x04
 
#define WM_DEV_CLASS_1   0x25
 
#define WM_DEV_CLASS_2   0x00
 
#define WM_PLUS_DEV_CLASS_0   0x08
 
#define WM_PLUS_DEV_CLASS_1   0x05
 
#define WM_PLUS_DEV_CLASS_2   0x00
 
#define WM_VENDOR_ID   0x057E
 
#define WM_PRODUCT_ID   0x0306
 
#define WM_PRODUCT_ID_TR   0x0330
 
#define WM_MAX_BATTERY_CODE   0xC8
 
#define WM_MEM_OFFSET_CALIBRATION   0x16
 
#define WM_EXP_MEM_BASE   0x04A40000
 
#define WM_EXP_ID   0x04A400FA
 
#define WM_EXP_MEM_ENABLE   0x04A40040
 
#define WM_EXP_MEM_ENABLE1   0x04A400F0
 
#define WM_EXP_MEM_ENABLE2   0x04A400FB
 
#define WM_EXP_MEM_CALIBR   0x04A40020
 
#define WM_EXP_MOTION_PLUS_IDENT   0x04A600FA
 
#define WM_EXP_MOTION_PLUS_ENABLE   0x04A600FE
 
#define WM_EXP_MOTION_PLUS_INIT   0x04A600F0
 
#define WM_REG_IR   0x04B00030
 
#define WM_REG_IR_BLOCK1   0x04B00000
 
#define WM_REG_IR_BLOCK2   0x04B0001A
 
#define WM_REG_IR_MODENUM   0x04B00033
 
#define WM_EXP_BBOARD_INIT1   0x04A400F1
 
#define WM_IR_TYPE_BASIC   0x01
 
#define WM_IR_TYPE_EXTENDED   0x03
 
#define WM_CTRL_STATUS_BYTE1_ATTACHMENT   0x02
 
#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED   0x04
 
#define WM_CTRL_STATUS_BYTE1_IR_ENABLED   0x08
 
#define WM_CTRL_STATUS_BYTE1_LED_1   0x10
 
#define WM_CTRL_STATUS_BYTE1_LED_2   0x20
 
#define WM_CTRL_STATUS_BYTE1_LED_3   0x40
 
#define WM_CTRL_STATUS_BYTE1_LED_4   0x80
 
#define WM_ASPECT_16_9_X   660
 
#define WM_ASPECT_16_9_Y   370
 
#define WM_ASPECT_4_3_X   560
 
#define WM_ASPECT_4_3_Y   420
 
#define EXP_ID_CODE_NUNCHUK   0xA4200000
 Expansion stuff.
 
#define EXP_ID_CODE_WII_BOARD   0xA4200402
 
#define EXP_ID_CODE_CLASSIC_CONTROLLER   0xA4200101
 
#define EXP_ID_CODE_GUITAR   0xA4200103
 
#define EXP_ID_CODE_MOTION_PLUS   0xA4200405
 
#define EXP_ID_CODE_MOTION_PLUS_NUNCHUK   0xA4200505 /** Motion Plus ID in Nunchuck passthrough mode */
 
#define EXP_ID_CODE_MOTION_PLUS_CLASSIC   0xA4200705 /** Motion Plus ID in Classic control. passthrough */
 
#define EXP_ID_CODE_TATACON   0xA4200111
 
#define EXP_ID_CODE_INACTIVE_MOTION_PLUS   0xA6200005 /** Inactive Motion Plus ID */
 
#define EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN
 
#define EXP_ID_CODE_NLA_MOTION_PLUS   0xA6200405 /** No longer active Motion Plus ID */
 
#define EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK   0xA6200505 /** No longer active Motion Plus ID in Nunchuck passthrough mode */
 
#define EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC   0xA6200705 /** No longer active Motion Plus ID in Classic control. passthrough */
 
#define EXP_HANDSHAKE_LEN   224
 
#define WIIMOTE_INIT_STATES   (WIIMOTE_STATE_IR_SENS_LVL3)
 
#define WIIMOTE_ENABLE_STATE(wm, s)   (wm->state |= (s))
 
#define WIIMOTE_DISABLE_STATE(wm, s)   (wm->state &= ~(s))
 
#define WIIMOTE_TOGGLE_STATE(wm, s)   ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s))
 
#define WIIMOTE_IS_FLAG_SET(wm, s)   ((wm->flags & (s)) == (s))
 
#define WIIMOTE_ENABLE_FLAG(wm, s)   (wm->flags |= (s))
 
#define WIIMOTE_DISABLE_FLAG(wm, s)   (wm->flags &= ~(s))
 
#define WIIMOTE_TOGGLE_FLAG(wm, s)   ((wm->flags & (s)) ? WIIMOTE_DISABLE_FLAG(wm, s) : WIIMOTE_ENABLE_FLAG(wm, s))
 
#define NUNCHUK_IS_FLAG_SET(wm, s)   ((*(wm->flags) & (s)) == (s))
 
#define MAX_PAYLOAD   32
 
#define WIIUSE_DEFAULT_SMOOTH_ALPHA   0.07f
 
#define SMOOTH_ROLL   0x01
 
#define SMOOTH_PITCH   0x02
 
#define WIIUSE_READ_TIMEOUT   5000
 
#define _STRINGIFY(s)   _STRINGIFY_IMPL(s)
 
#define _STRINGIFY_IMPL(s)   #s
 
#define WIIUSE_VERSION   _STRINGIFY(WIIUSE_MAJOR) "." _STRINGIFY(WIIUSE_MINOR) "." _STRINGIFY(WIIUSE_MICRO)
 
#define INLINE_UTIL   static inline
 
#define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS(_TYPE, _TOBE, _FROMBE)
 
#define WIIUSE_DECLARE_BUFFERING_OPS(_TYPE)
 

Functions

void wiiuse_millisleep (int durationMilliseconds)
 Cross-platform call to sleep for at least the specified number of milliseconds. More...
 
int wiiuse_set_report_type (struct wiimote_t *wm)
 Set the report type based on the current wiimote state. More...
 
void wiiuse_send_next_pending_read_request (struct wiimote_t *wm)
 Send the next pending data read request to the wiimote. More...
 
void wiiuse_send_next_pending_write_request (struct wiimote_t *wm)
 Send the next pending data write request to the wiimote. More...
 
int wiiuse_send (struct wiimote_t *wm, byte report_type, byte *msg, int len)
 Send a packet to the wiimote. More...
 
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). More...
 
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). More...
 
INLINE_UTIL void to_big_endian_uint8_t (byte *buf, uint8_t val)
 
INLINE_UTIL uint8_t from_big_endian_uint8_t (byte *buf)
 

Variables

FILE * logtarget []
 Output FILE stream for each wiiuse_loglevel.
 

Detailed Description

Macro Definition Documentation

◆ EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN

#define EXP_ID_CODE_INACTIVE_MOTION_PLUS_BUILTIN
Value:
0xA4200005

◆ WIIUSE_DECLARE_BUFFERING_OPS

#define WIIUSE_DECLARE_BUFFERING_OPS (   _TYPE)
Value:
INLINE_UTIL void buffer_big_endian_##_TYPE(byte **buf, _TYPE val) \
{ \
to_big_endian_##_TYPE(*buf, val); \
*buf += sizeof(_TYPE); \
} \
INLINE_UTIL _TYPE unbuffer_big_endian_##_TYPE(byte **buf) \
{ \
byte *current = *buf; \
*buf += sizeof(_TYPE); \
return from_big_endian_##_TYPE(current); \
}

◆ WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS

#define WIIUSE_DECLARE_ENDIAN_CONVERSION_OPS (   _TYPE,
  _TOBE,
  _FROMBE 
)
Value:
INLINE_UTIL void to_big_endian_##_TYPE(byte *buf, _TYPE val) \
{ \
_TYPE beVal = _TOBE(val); \
memcpy(buf, &beVal, sizeof(_TYPE)); \
} \
INLINE_UTIL _TYPE from_big_endian_##_TYPE(byte *buf) \
{ \
_TYPE beVal; \
memcpy(&beVal, buf, sizeof(_TYPE)); \
return _FROMBE(beVal); \
}

◆ WIIUSE_ERROR

#define WIIUSE_ERROR (   fmt,
  ... 
)
Value:
do \
{ \
if (OUTF_ERROR) \
fprintf(OUTF_ERROR, "[ERROR] " fmt "\n", ##__VA_ARGS__); \
} while (0)

◆ WIIUSE_INFO

#define WIIUSE_INFO (   fmt,
  ... 
)
Value:
do \
{ \
if (OUTF_INFO) \
fprintf(OUTF_INFO, "[INFO] " fmt "\n", ##__VA_ARGS__); \
} while (0)

◆ WIIUSE_WARNING

#define WIIUSE_WARNING (   fmt,
  ... 
)
Value:
do \
{ \
if (OUTF_WARNING) \
fprintf(OUTF_WARNING, "[WARNING] " fmt "\n", ##__VA_ARGS__); \
} while (0)

Function Documentation

◆ wiiuse_millisleep()

void wiiuse_millisleep ( int  durationMilliseconds)

Cross-platform call to sleep for at least the specified number of milliseconds.

Use instead of Sleep(), usleep(), or similar functions. Defined in util.c

◆ wiiuse_read_data_cb()

int wiiuse_read_data_cb ( struct wiimote_t wm,
wiiuse_read_cb  read_cb,
byte *  buffer,
unsigned int  addr,
uint16_t  len 
)

Read data from the wiimote (callback version).

Parameters
wmPointer to a wiimote_t structure.
read_cbFunction pointer to call when the data arrives from the wiimote.
bufferAn allocated buffer to store the data as it arrives from the wiimote. Must be persistent in memory and large enough to hold the data.
addrThe address of wiimote memory to read from.
lenThe length of the block to be read.

The library can only handle one data read request at a time because it must keep track of the buffer and other events that are specific to that request. So if a request has already been made, subsequent requests will be added to a pending list and be sent out when the previous finishes.

◆ wiiuse_send()

int wiiuse_send ( struct wiimote_t wm,
byte  report_type,
byte *  msg,
int  len 
)

Send a packet to the wiimote.

Parameters
wmPointer to a wiimote_t structure.
report_typeThe report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
msgThe payload. Might be changed by the callee.
lenLength of the payload in bytes.

This function should replace any write()s directly to the wiimote device.

◆ wiiuse_send_next_pending_read_request()

void wiiuse_send_next_pending_read_request ( struct wiimote_t wm)

Send the next pending data read request to the wiimote.

Parameters
wmPointer to a wiimote_t structure.
See also
wiiuse_read_data()

This function is not part of the wiiuse API.

◆ wiiuse_send_next_pending_write_request()

void wiiuse_send_next_pending_write_request ( struct wiimote_t wm)

Send the next pending data write request to the wiimote.

Parameters
wmPointer to a wiimote_t structure.
See also
wiiuse_write_data()

This function is not part of the wiiuse API.

◆ wiiuse_set_report_type()

int wiiuse_set_report_type ( struct wiimote_t wm)

Set the report type based on the current wiimote state.

Parameters
wmPointer to a wiimote_t structure.
Returns
The report type sent.

The wiimote reports formatted packets depending on the report type that was last requested. This function will update the type of report that should be sent based on the current state of the device.

◆ wiiuse_write_data_cb()

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).

Parameters
wmPointer to a wiimote_t structure.
addrThe address to write to.
dataThe data to be written to the memory location.
lenThe length of the block to be written.
cbFunction pointer to call when the data arrives from the wiimote.

The library can only handle one data read request at a time because it must keep track of the buffer and other events that are specific to that request. So if a request has already been made, subsequent requests will be added to a pending list and be sent out when the previous finishes.