Add modifications from bhartsho (for easier python binding)

This commit is contained in:
Ryan Pavlik
2011-06-17 10:34:19 -05:00
parent 71b75efd98
commit ba5ac5e822
3 changed files with 60 additions and 1 deletions

View File

@@ -15,7 +15,7 @@ http://sourceforge.net/projects/wiiuse/
v0.15 -- ???
---------------------------
Added:
-
- Callback API with constant-size WiimoteState_t. Thanks to bhartsho.
Fixed:
-
Changed:

View File

@@ -192,6 +192,42 @@ int wiiuse_poll(struct wiimote_t** wm, int wiimotes) {
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
/* Harts API */
int wiiuse_update(struct wiimote_t** wiimotes, int nwiimotes, wiiuse_update_cb callback) {
if (wiiuse_poll(wiimotes, nwiimotes)) {
static struct WiimoteState_t s;
int i = 0;
for (; i < nwiimotes; ++i) {
switch (wiimotes[i]->event) {
case WIIUSE_NONE:
break;
default:
/* this could be: WIIUSE_EVENT, WIIUSE_STATUS, WIIUSE_CONNECT, etc.. */
s.uid = wiimotes[i]->unid;
s.leds = wiimotes[i]->leds;
s.battery_level = wiimotes[i]->battery_level;
s.accel = wiimotes[i]->accel;
s.orient = wiimotes[i]->orient;
s.gforce = wiimotes[i]->gforce;
s.ir = wiimotes[i]->ir;
s.buttons = wiimotes[i]->btns;
s.buttons_held = wiimotes[i]->btns_held;
s.buttons_released = wiimotes[i]->btns_released;
s.event = wiimotes[i]->event;
s.state = wiimotes[i]->state;
s.expansion = wiimotes[i]->exp;
callback( &s );
break;
}
}
return 1;
}
return 0;
}
/**
* @brief Called on a cycle where no significant change occurs.
*

View File

@@ -773,6 +773,29 @@ WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* w
/* this function not currently implemented... */
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
/* wiiuse.c harts API */
typedef struct WiimoteState_t {
WCONST int uid;
WCONST byte leds;
WCONST float battery_level;
WCONST struct vec3b_t accel;
WCONST struct orient_t orient;
WCONST struct gforce_t gforce;
WCONST struct ir_t ir;
WCONST uint16_t buttons;
WCONST uint16_t buttons_held;
WCONST uint16_t buttons_released;
WCONST WIIUSE_EVENT_TYPE event;
WCONST int state;
WCONST struct expansion_t expansion;
} WiimoteState;
typedef void (*wiiuse_update_cb)(struct WiimoteState_t* wm);
WIIUSE_EXPORT extern int wiiuse_update(struct wiimote_t** wm, int wiimotes, wiiuse_update_cb callback);
/* end harts API */
#ifdef __cplusplus
}
#endif