Note

This is a work in progress. Most, but not all, functions in libcwiid are documented, and there may be small errors. When in doubt, refer to cwiid.h.

If you are developing with old versions, see the (somewhat dated) documentation for the old libwiimote.

API

cwiid_open

Synopsis

cwiid_wiimote_t *cwiid_open(bdaddr_t *bdaddr, int flags);

Parameters

bdaddr
pointer to bluetooth device address of the wiimote
flags
option flags to be enabled

Description

Establish a connection with a wiimote.

Pass the address of a bdaddr set to *BDADDR_ANY to connect to any (one) available wiimote. In this case, the bdaddr will be filled with the address of the connected wiimote. Due to the bizarre way in which BlueZ implements BDADDR_ANY, it is recommended that BDADDR_ANY not be passed directly to wiimote_connect, as this may change the value of BDADDR_ANY. See  this page for a description of the bdaddr_t type, and cwiid_enable for option flags and descriptions.

Return Value

cwiid_wiimote handle, or NULL on error


cwiid_close

Synopsis

int cwiid_close(cwiid_wiimote_t *wiimote);

Parameters

wiimote
cwiid_wiimote handle

Description

Disconnect from wiimote.

Return Value

zero on success or nonzero on error


cwiid_get_id

Synopsis

int cwiid_get_id(cwiid_wiimote_t *wiimote);

Parameters

wiimote
cwiid_wiimote handle

Description

Accessor function for the wiimote id, which is guaranteed to be unique among all wiimotes in a single process.

Return Value

id


cwiid_set_data

Synopsis

int cwiid_set_data(cwiid_wiimote_t *wiimote, const void *data);

Parameters

wiimote
cwiid_wiimote handle
data
pointer to user data

Description

Modifier function for the user data field.

Return Value

zero on success or nonzero on error


cwiid_get_data

Synopsis

const void *cwiid_get_data(cwiid_wiimote_t *wiimote);

Parameters

wiimote
cwiid_wiimote handle

Description

Accessor function for the user data field.

Return Value

Pointer to user data as set by cwiid_set_data.


cwiid_enable

Synopsis

int cwiid_enable(cwiid_wiimote_t *wiimote, int flags);

Parameters

wiimote
cwiid_wiimote handle
flags
option flags to be enabled

Description

Option flags can be enabled by cwiid_connect, or subsequently with cwiid_enable. Option flags and their meanings are as follows:

  • CWIID_FLAG_MESG_IFC: Enable the message based interfaces (message callback and cwiid_get_mesg).
  • CWIID_FLAG_CONTINUOUS: Enable continuous wiimote reports
  • CWIID_FLAG_REPEAT_BTN: Deliver a button message for each button value received, even if it hasn't changed.
  • CWIID_FLAG_NONBLOCK: Causes cwiid_get_mesg to fail instead of block if no messages are ready.

Return Value

zero on success or nonzero on error


cwiid_disable

Synopsis

int cwiid_disable(cwiid_wiimote_t *wiimote, int flags);

Parameters

wiimote
cwiid_wiimote handle
flags
option flags to be disabled

Description

Disables option flags enabled by cwiid_connect or cwiid_enable.

Return Value

zero on success or nonzero on error


cwiid_set_mesg_callback

Synopsis

typedef void cwiid_mesg_callback_t(cwiid_wiimote_t *, int, union cwiid_mesg []);
int cwiid_set_mesg_callback(cwiid_wiimote_t *wiimote, cwiid_mesg_callback_t *callback);

Parameters

wiimote
cwiid_wiimote handle
callback
pointer to cwiid message callback function

Description

Sets the message callback function, which is called when a set of messages are received from the wiimote (each message in a set was generated from the same packet and therefore arrived simultaneously). Note that option flag CWIID_FLAG_MESG_IFC must be enabled for the callback to be called. Passing NULL for the callback cancels the current callback, if there is one.

Return Value

zero on success or nonzero on error


cwiid_get_mesg

Synopsis

int cwiid_get_mesg(cwiid_wiimote_t *wiimote, int *mesg_count, union cwiid_mesg *mesg[]);

Parameters

wiimote
cwiid_wiimote handle
mesg_count
pointer to mesg_count
mesg
pointer to array of messages

Description

Retrieve the oldest undelivered message set. Messages are delivered either through a callback, or cwiid_get_mesg.

Return Value

zero on success or nonzero on error


cwiid_get_state

Synopsis

int cwiid_get_state(cwiid_wiimote_t *wiimote, struct cwiid_state *state);

Parameters

wiimote
cwiid_wiimote handle
state
pointer to wiimote state structure

Description

Retrieve the current state of the wiimote.

Return Value

zero on success or nonzero on error


cwiid_command

Synopsis

int cwiid_command(cwiid_wiimote_t *wiimote, enum cwiid_command command, int flags);

Parameters

wiimote
cwiid_wiimote handle
command
command to be executed
flags
command-specific flags

Description

Issue command to wiimote. Available commands and their associated flags are as follows:

CWIID_CMD_STATUS
Request a status message (delivered to the message callback) (flags ignored)
CWIID_CMD_LED
Set the LED state. The following flags may be bitwise ORed:

  • CWIID_LED1_ON
  • CWIID_LED2_ON
  • CWIID_LED3_ON
  • CWIID_LED4_ON
CWIID_CMD_RUMBLE
Set the Rumble state. Set flags to 0 for off, anything else for on.
CWIID_CMD_RPT_MODE
Set the reporting mode of the wiimote, which determines what wiimote peripherals are enabled, and what data is received by the host. The following flags may be bitwise ORed (Note that it may not be assumed that each flag is a single bit - specifically, CWIID_RPT_EXT = CWIID_RPT_NUNCHUK | CWIID_RPT_CLASSIC):
  • CWIID_RPT_STATUS
  • CWIID_RPT_BTN
  • CWIID_RPT_ACC
  • CWIID_RPT_IR
  • CWIID_RPT_NUNCHUK
  • CWIID_RPT_CLASSIC
  • CWIID_RPT_EXT

Return Value

zero on success or nonzero on error


cwiid_read

Synopsis

int cwiid_read(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset, uint16_t len, void *data);

Parameters

wiimote
cwiid_wiimote handle
flags
read flags
offset
start address
len
number of bytes to read
data
destination buffer

Description

Read data from the Wiimote. Mutually exclusive flags CWIID_RW_EEPROM and CWIID_RW_REG select the address space (EEPROM/flash or register, respectively). The CWIID_RW_DECODE flag performs any necessary decoding algorithms to data read from the register address space.

Return Value

zero on success or nonzero on error


cwiid_write

Synopsis

int cwiid_write(cwiid_wiimote_t *wiimote, uint8_t flags, uint32_t offset, uint16_t len, const void *data);

Parameters

wiimote
cwiid_wiimote handle
flags
write flags
offset
start address
len
number of bytes to write
data
source buffer

Description

Write data to the Wiimote. Mutually exclusive flags CWIID_RW_EEPROM and CWIID_RW_REG select the address space (EEPROM/flash or register, respectively). The CWIID_RW_DECODE flag is ignored.

Return Value

zero on success or nonzero on error


TODO: Bluetooth functions

cwiid_get_bdinfo_array

cwiid_find_wiimote