src/events.c File Reference

Handles wiimote events. More...

#include
#include
#include
#include
#include
#include
#include
#include "definitions.h"
#include "io.h"
#include "wiiuse_internal.h"
#include "dynamics.h"
#include "ir.h"
#include "nunchuk.h"
#include "classic.h"
#include "guitar_hero_3.h"
#include "events.h"

Include dependency graph for events.c:


Defines

#define  STATE_CHANGED(a, b)   if (a != b) return 1
#define  CROSS_THRESH(last, now, thresh)
#define  CROSS_THRESH_XYZ(last, now, thresh)

Functions

static void  idle_cycle (struct wiimote_t *wm)
  Called on a cycle where no significant change occurs.
static void  clear_dirty_reads (struct wiimote_t *wm)
  Clear out all old 'dirty' read requests.
static void  propagate_event (struct wiimote_t *wm, byte event, byte *msg)
  Analyze the event that occured on a wiimote.
static void  event_data_read (struct wiimote_t *wm, byte *msg)
  Received a data packet from a read request.
static void  event_status (struct wiimote_t *wm, byte *msg)
  Read the controller status.
static void  handle_expansion (struct wiimote_t *wm, byte *msg)
  Handle data from the expansion.
static void  save_state (struct wiimote_t *wm)
  Save important state data.
static int  state_changed (struct wiimote_t *wm)
  Determine if the current state differs significantly from the previous.
int  wiiuse_poll (struct wiimote_t **wm, int wiimotes)
  Poll the wiimotes for any events.
void  wiiuse_pressed_buttons (struct wiimote_t *wm, byte *msg)
  Find what buttons are pressed.
void  handshake_expansion (struct wiimote_t *wm, byte *data, unsigned short len)
  Handle the handshake data from the expansion device.
void  disable_expansion (struct wiimote_t *wm)
  Disable the expansion device if it was enabled.

Detailed Description

Handles wiimote events.

The file includes functions that handle the events that are sent from the wiimote to us.


Define Documentation

#define CROSS_THRESH ( last,
now,
thresh   ) 

Value:

do {                                                            \
                    if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) {        \
                        if ((diff_f(last.roll, now.roll) >= thresh) ||          \
                            (diff_f(last.pitch, now.pitch) >= thresh) ||        \
                            (diff_f(last.yaw, now.yaw) >= thresh))              \
                        {                                                       \
                            last = now;                                         \
                            return 1;                                           \
                        }                                                       \
                    } else {                                                    \
                        if (last.roll != now.roll)      return 1;               \
                        if (last.pitch != now.pitch)    return 1;               \
                        if (last.yaw != now.yaw)        return 1;               \
                    }                                                           \
                } while (0)

#define CROSS_THRESH_XYZ ( last,
now,
thresh   ) 

Value:

do {                                                            \
                    if (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_ORIENT_THRESH)) {        \
                        if ((diff_f(last.x, now.x) >= thresh) ||                \
                            (diff_f(last.y, now.y) >= thresh) ||                \
                            (diff_f(last.z, now.z) >= thresh))                  \
                        {                                                       \
                            last = now;                                         \
                            return 1;                                           \
                        }                                                       \
                    } else {                                                    \
                        if (last.x != now.x)        return 1;                   \
                        if (last.y != now.y)        return 1;                   \
                        if (last.z != now.z)        return 1;                   \
                    }                                                           \
                } while (0)


Function Documentation

static void clear_dirty_reads ( struct wiimote_t wm  )  [static]

Clear out all old 'dirty' read requests.

Parameters:
wm  Pointer to a wiimote_t structure.

void disable_expansion ( struct wiimote_t wm  ) 

Disable the expansion device if it was enabled.

Parameters:
wm  A pointer to a wiimote_t structure.
data  The data read in from the device.
len  The length of the data block, in bytes.
If the data is NULL then this function will try to start a handshake with the expansion.

static void event_data_read ( struct wiimote_t wm,
byte *  msg  
) [static]

Received a data packet from a read request.

Parameters:
wm  Pointer to a wiimote_t structure.
msg  The message specified in the event packet.
Data from the wiimote comes in packets. If the requested data segment size is bigger than one packet can hold then several packets will be received. These packets are first reassembled into one, then the registered callback function that handles data reads is invoked.

static void event_status ( struct wiimote_t wm,
byte *  msg  
) [static]

Read the controller status.

Parameters:
wm  Pointer to a wiimote_t structure.
msg  The message specified in the event packet.
Read the controller status and execute the registered status callback.

static void handle_expansion ( struct wiimote_t wm,
byte *  msg  
) [static]

Handle data from the expansion.

Parameters:
wm  A pointer to a wiimote_t structure.
msg  The message specified in the event packet for the expansion.

void handshake_expansion ( struct wiimote_t wm,
byte *  data,
unsigned short  len  
)

Handle the handshake data from the expansion device.

Parameters:
wm  A pointer to a wiimote_t structure.
data  The data read in from the device.
len  The length of the data block, in bytes.
Tries to determine what kind of expansion was attached and invoke the correct handshake function.

If the data is NULL then this function will try to start a handshake with the expansion.

static void idle_cycle ( struct wiimote_t wm  )  [static]

Called on a cycle where no significant change occurs.

Parameters:
wm  Pointer to a wiimote_t structure.

static void propagate_event ( struct wiimote_t wm,
byte  event,
byte *  msg  
) [static]

Analyze the event that occured on a wiimote.

Parameters:
wm  An array of pointers to wiimote_t structures.
event  The event that occured.
msg  The message specified in the event packet.
Pass the event to the registered event callback.

static void save_state ( struct wiimote_t wm  )  [static]

Save important state data.

Parameters:
wm  A pointer to a wiimote_t structure.

static int state_changed ( struct wiimote_t wm  )  [static]

Determine if the current state differs significantly from the previous.

Parameters:
wm  A pointer to a wiimote_t structure.
Returns:
1 if a significant change occured, 0 if not.

int wiiuse_poll ( struct wiimote_t **  wm,
int  wiimotes  
)

Poll the wiimotes for any events.

Parameters:
wm  An array of pointers to wiimote_t structures.
wiimotes  The number of wiimote_t structures in the wm array.
Returns:
Returns number of wiimotes that an event has occured on.
It is necessary to poll the wiimote devices for events that occur. If an event occurs on a particular wiimote, the event variable will be set.

void wiiuse_pressed_buttons ( struct wiimote_t wm,
byte *  msg  
)

Find what buttons are pressed.

Parameters:
wm  Pointer to a wiimote_t structure.
msg  The message specified in the event packet.


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