src/wiiuse.c File Reference

General wiimote operations. More...

#include
#include
#include
#include "definitions.h"
#include "wiiuse_internal.h"
#include "events.h"
#include "io.h"

Include dependency graph for wiiuse.c:


Functions

const char *  wiiuse_version ()
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.
void  wiiuse_disconnected (struct wiimote_t *wm)
  The wiimote disconnected.
void  wiiuse_rumble (struct wiimote_t *wm, int status)
  Enable or disable the rumble.
void  wiiuse_toggle_rumble (struct wiimote_t *wm)
  Toggle the state of the rumble.
void  wiiuse_set_leds (struct wiimote_t *wm, int leds)
  Set the enabled LEDs.
void  wiiuse_motion_sensing (struct wiimote_t *wm, int status)
  Set if the wiimote should report motion sensing.
int  wiiuse_set_report_type (struct wiimote_t *wm)
  Set the report type based on the current wiimote state.
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).
int  wiiuse_read_data (struct wiimote_t *wm, byte *buffer, unsigned int addr, unsigned short len)
  Read data from the wiimote (event version).
void  wiiuse_send_next_pending_read_request (struct wiimote_t *wm)
  Send the next pending data read request to the wiimote.
void  wiiuse_status (struct wiimote_t *wm)
  Request the wiimote controller status.
struct wiimote_t wiiuse_get_by_id (struct wiimote_t **wm, int wiimotes, int unid)
  Find a wiimote_t structure by its unique identifier.
int  wiiuse_write_data (struct wiimote_t *wm, unsigned int addr, byte *data, byte len)
  Write data to the wiimote.
int  wiiuse_send (struct wiimote_t *wm, byte report_type, byte *msg, int len)
  Send a packet to the wiimote.
int  wiiuse_set_flags (struct wiimote_t *wm, int enable, int disable)
  Set flags for the specified wiimote.
float  wiiuse_set_smooth_alpha (struct wiimote_t *wm, float alpha)
  Set the wiimote smoothing alpha value.
void  wiiuse_set_bluetooth_stack (struct wiimote_t **wm, int wiimotes, enum win_bt_stack_t type)
  Set the bluetooth stack type to use.
void  wiiuse_set_orient_threshold (struct wiimote_t *wm, float threshold)
  Set the orientation event threshold.
void  wiiuse_set_accel_threshold (struct wiimote_t *wm, int threshold)
  Set the accelerometer event threshold.
void  wiiuse_resync (struct wiimote_t *wm)
  Try to resync with the wiimote by starting a new handshake.
void  wiiuse_set_timeout (struct wiimote_t **wm, int wiimotes, byte normal_timeout, byte exp_timeout)
  Set the normal and expansion handshake timeouts.

Variables

static int  g_banner = 0

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

void wiiuse_disconnected ( struct wiimote_t wm  ) 

The wiimote disconnected.

Parameters:
wm  Pointer to a wiimote_t structure.

struct wiimote_t* wiiuse_get_by_id ( struct wiimote_t **  wm,
int  wiimotes,
int  unid  
) [read]

Find a wiimote_t structure by its unique identifier.

Parameters:
wm  Pointer to a wiimote_t structure.
wiimotes  The number of wiimote_t structures in wm.
unid  The unique identifier to search for.
Returns:
Pointer to a wiimote_t structure, or NULL if not found.

struct wiimote_t** wiiuse_init ( int  wiimotes  )  [read]

Initialize an array of wiimote structures.

Parameters:
wiimotes  Number 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().

void wiiuse_motion_sensing ( struct wiimote_t wm,
int  status  
)

Set if the wiimote should report motion sensing.

Parameters:
wm  Pointer to a wiimote_t structure.
status  1 to enable, 0 to disable.
Since reporting motion sensing sends a lot of data, the wiimote saves power by not transmitting it by default.

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

Read data from the wiimote (event version).

Parameters:
wm  Pointer to a wiimote_t structure.
buffer  An allocated buffer to store the data as it arrives from the wiimote. Must be persistent in memory and large enough to hold the data.
addr  The address of wiimote memory to read from.
len  The 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.

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:
wm  Pointer to a wiimote_t structure.
read_cb  Function pointer to call when the data arrives from the wiimote.
buffer  An allocated buffer to store the data as it arrives from the wiimote. Must be persistent in memory and large enough to hold the data.
addr  The address of wiimote memory to read from.
len  The 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.

void wiiuse_resync ( struct wiimote_t wm  ) 

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

Parameters:
wm  Pointer to a wiimote_t structure.

void wiiuse_rumble ( struct wiimote_t wm,
int  status  
)

Enable or disable the rumble.

Parameters:
wm  Pointer to a wiimote_t structure.
status  1 to enable, 0 to disable.

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

Send a packet to the wiimote.

Parameters:
wm  Pointer to a wiimote_t structure.
report_type  The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiiuse.h
msg  The payload.
len  Length of the payload in bytes.
This function should replace any write()s directly to the wiimote device.

void wiiuse_send_next_pending_read_request ( struct wiimote_t wm  ) 

Send the next pending data read request to the wiimote.

Parameters:
wm  Pointer to a wiimote_t structure.
See also:
wiiuse_read_data()
This function is not part of the wiiuse API.

void wiiuse_set_accel_threshold ( struct wiimote_t wm,
int  threshold  
)

Set the accelerometer event threshold.

Parameters:
wm  Pointer to a wiimote_t structure.
threshold  The decimal place that should be considered a significant change.

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:
wm  Array of wiimote_t structures.
wiimotes  Number of objects in the wm array.
type  The type of bluetooth stack to use.

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

Set flags for the specified wiimote.

Parameters:
wm  Pointer to a wiimote_t structure.
enable  Flags to enable.
disable  Flags 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.

void wiiuse_set_leds ( struct wiimote_t wm,
int  leds  
)

Set the enabled LEDs.

Parameters:
wm  Pointer to a wiimote_t structure.
leds  What LEDs to enable.
leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, WIIMOTE_LED_3, or WIIMOTE_LED_4.

void wiiuse_set_orient_threshold ( struct wiimote_t wm,
float  threshold  
)

Set the orientation event threshold.

Parameters:
wm  Pointer to a wiimote_t structure.
threshold  The 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 occured 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.

int wiiuse_set_report_type ( struct wiimote_t wm  ) 

Set the report type based on the current wiimote state.

Parameters:
wm  Pointer 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.

float wiiuse_set_smooth_alpha ( struct wiimote_t wm,
float  alpha  
)

Set the wiimote smoothing alpha value.

Parameters:
wm  Pointer to a wiimote_t structure.
alpha  The 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.

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

Set the normal and expansion handshake timeouts.

Parameters:
wm  Array of wiimote_t structures.
wiimotes  Number of objects in the wm array.
normal_timeout  The timeout in milliseconds for a normal read.
exp_timeout  The timeout in millisecondsd to wait for an expansion handshake.

void wiiuse_status ( struct wiimote_t wm  ) 

Request the wiimote controller status.

Parameters:
wm  Pointer to a wiimote_t structure.
Controller status includes: battery level, LED status, expansions

void wiiuse_toggle_rumble ( struct wiimote_t wm  ) 

Toggle the state of the rumble.

Parameters:
wm  Pointer to a wiimote_t structure.

const char* wiiuse_version (  ) 

Returns the version of the library.

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

Write data to the wiimote.

Parameters:
wm  Pointer to a wiimote_t structure.
addr  The address to write to.
data  The data to be written to the memory location.
len  The length of the block to be written.


Generated on Wed Apr 2 19:30:10 2008 for wiiuse by  doxygen 1.5.4