xbmc
Functions
wiiuse.c File Reference

General wiimote operations. More...

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "definitions.h"
#include "wiiuse_internal.h"
#include "events.h"
#include "io.h"
Include dependency graph for wiiuse.c:

Functions

const char * wiiuse_version ()
 Returns the version of the library.
 
void wiiuse_cleanup (struct wiimote_t **wm, int wiimotes)
 Clean up wiimote_t array created by wiiuse_init()
 
struct wiimote_t ** wiiuse_init (int wiimotes)
 Initialize an array of wiimote structures. More...
 
void wiiuse_disconnected (struct wiimote_t *wm)
 The wiimote disconnected. More...
 
void wiiuse_rumble (struct wiimote_t *wm, int status)
 Enable or disable the rumble. More...
 
void wiiuse_toggle_rumble (struct wiimote_t *wm)
 Toggle the state of the rumble. More...
 
void wiiuse_set_leds (struct wiimote_t *wm, int leds)
 Set the enabled LEDs. More...
 
void wiiuse_motion_sensing (struct wiimote_t *wm, int status)
 Set if the wiimote should report motion sensing. More...
 
int wiiuse_set_report_type (struct wiimote_t *wm)
 Set the report type based on the current wiimote state. More...
 
int wiiuse_read_data_cb (struct wiimote_t *wm, wiiuse_read_cb read_cb, byte *buffer, unsigned int addr, unsigned short len)
 Read data from the wiimote (callback version). More...
 
int wiiuse_read_data (struct wiimote_t *wm, byte *buffer, unsigned int addr, unsigned short len)
 Read data from the wiimote (event version). 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_status (struct wiimote_t *wm)
 Request the wiimote controller status. More...
 
struct wiimote_twiiuse_get_by_id (struct wiimote_t **wm, int wiimotes, int unid)
 Find a wiimote_t structure by its unique identifier. More...
 
int wiiuse_write_data (struct wiimote_t *wm, unsigned int addr, byte *data, byte len)
 Write data 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_set_flags (struct wiimote_t *wm, int enable, int disable)
 Set flags for the specified wiimote. More...
 
float wiiuse_set_smooth_alpha (struct wiimote_t *wm, float alpha)
 Set the wiimote smoothing alpha value. More...
 
void wiiuse_set_bluetooth_stack (struct wiimote_t **wm, int wiimotes, enum win_bt_stack_t type)
 Set the bluetooth stack type to use. More...
 
void wiiuse_set_orient_threshold (struct wiimote_t *wm, float threshold)
 Set the orientation event threshold. More...
 
void wiiuse_set_accel_threshold (struct wiimote_t *wm, int threshold)
 Set the accelerometer event threshold. More...
 
void wiiuse_resync (struct wiimote_t *wm)
 Try to resync with the wiimote by starting a new handshake. More...
 
void wiiuse_set_timeout (struct wiimote_t **wm, int wiimotes, byte normal_timeout, byte exp_timeout)
 Set the normal and expansion handshake timeouts. More...
 

Detailed Description

General wiimote operations.

The file includes functions that handle general tasks. Most of these are functions that are part of the API.

Function Documentation

◆ wiiuse_disconnected()

void wiiuse_disconnected ( struct wiimote_t wm)

The wiimote disconnected.

Parameters
wmPointer to a wiimote_t structure.

◆ wiiuse_get_by_id()

struct wiimote_t* wiiuse_get_by_id ( struct wiimote_t **  wm,
int  wiimotes,
int  unid 
)

Find a wiimote_t structure by its unique identifier.

Parameters
wmPointer to a wiimote_t structure.
wiimotesThe number of wiimote_t structures in wm.
unidThe unique identifier to search for.
Returns
Pointer to a wiimote_t structure, or NULL if not found.

◆ wiiuse_init()

struct wiimote_t** wiiuse_init ( int  wiimotes)

Initialize an array of wiimote structures.

Parameters
wiimotesNumber of wiimote_t structures to create.
Returns
An array of initialized wiimote_t structures.
See also
wiiuse_connect()

The array returned by this function can be passed to various functions, including wiiuse_connect().

◆ wiiuse_motion_sensing()

void wiiuse_motion_sensing ( struct wiimote_t wm,
int  status 
)

Set if the wiimote should report motion sensing.

Parameters
wmPointer to a wiimote_t structure.
status1 to enable, 0 to disable.

Since reporting motion sensing sends a lot of data, the wiimote saves power by not transmitting it by default.

◆ wiiuse_read_data()

int wiiuse_read_data ( struct wiimote_t wm,
byte *  buffer,
unsigned int  addr,
unsigned short  len 
)

Read data from the wiimote (event version).

Parameters
wmPointer to a wiimote_t structure.
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_read_data_cb()

int wiiuse_read_data_cb ( struct wiimote_t wm,
wiiuse_read_cb  read_cb,
byte *  buffer,
unsigned int  addr,
unsigned short  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_resync()

void wiiuse_resync ( struct wiimote_t wm)

Try to resync with the wiimote by starting a new handshake.

Parameters
wmPointer to a wiimote_t structure.

◆ wiiuse_rumble()

void wiiuse_rumble ( struct wiimote_t wm,
int  status 
)

Enable or disable the rumble.

Parameters
wmPointer to a wiimote_t structure.
status1 to enable, 0 to disable.

◆ 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.
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_set_accel_threshold()

void wiiuse_set_accel_threshold ( struct wiimote_t wm,
int  threshold 
)

Set the accelerometer event threshold.

Parameters
wmPointer to a wiimote_t structure.
thresholdThe decimal place that should be considered a significant change.

◆ wiiuse_set_bluetooth_stack()

void wiiuse_set_bluetooth_stack ( struct wiimote_t **  wm,
int  wiimotes,
enum win_bt_stack_t  type 
)

Set the bluetooth stack type to use.

Parameters
wmArray of wiimote_t structures.
wiimotesNumber of objects in the wm array.
typeThe type of bluetooth stack to use.

◆ wiiuse_set_flags()

int wiiuse_set_flags ( struct wiimote_t wm,
int  enable,
int  disable 
)

Set flags for the specified wiimote.

Parameters
wmPointer to a wiimote_t structure.
enableFlags to enable.
disableFlags to disable.
Returns
The flags set after 'enable' and 'disable' have been applied.

The values 'enable' and 'disable' may be any flags OR'ed together. Flags are defined in wiiuse.h.

◆ wiiuse_set_leds()

void wiiuse_set_leds ( struct wiimote_t wm,
int  leds 
)

Set the enabled LEDs.

Parameters
wmPointer to a wiimote_t structure.
ledsWhat LEDs to enable.

leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4.

◆ wiiuse_set_orient_threshold()

void wiiuse_set_orient_threshold ( struct wiimote_t wm,
float  threshold 
)

Set the orientation event threshold.

Parameters
wmPointer to a wiimote_t structure.
thresholdThe decimal place that should be considered a significant change.

If threshold is 0.01, and any angle changes by 0.01 then a significant change has occurred and the event callback will be invoked. If threshold is 1 then the angle has to change by a full degree to generate an event.

◆ 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_set_smooth_alpha()

float wiiuse_set_smooth_alpha ( struct wiimote_t wm,
float  alpha 
)

Set the wiimote smoothing alpha value.

Parameters
wmPointer to a wiimote_t structure.
alphaThe alpha value to set. Between 0 and 1.
Returns
Returns the old alpha value.

The alpha value is between 0 and 1 and is used in an exponential smoothing algorithm.

Smoothing is only performed if the WIIMOTE_USE_SMOOTHING is set.

◆ wiiuse_set_timeout()

void wiiuse_set_timeout ( struct wiimote_t **  wm,
int  wiimotes,
byte  normal_timeout,
byte  exp_timeout 
)

Set the normal and expansion handshake timeouts.

Parameters
wmArray of wiimote_t structures.
wiimotesNumber of objects in the wm array.
normal_timeoutThe timeout in milliseconds for a normal read.
exp_timeoutThe timeout in millisecondsd to wait for an expansion handshake.

◆ wiiuse_status()

void wiiuse_status ( struct wiimote_t wm)

Request the wiimote controller status.

Parameters
wmPointer to a wiimote_t structure.

Controller status includes: battery level, LED status, expansions

◆ wiiuse_toggle_rumble()

void wiiuse_toggle_rumble ( struct wiimote_t wm)

Toggle the state of the rumble.

Parameters
wmPointer to a wiimote_t structure.

◆ wiiuse_write_data()

int wiiuse_write_data ( struct wiimote_t wm,
unsigned int  addr,
byte *  data,
byte  len 
)

Write data to the wiimote.

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.