Add modifications from bhartsho (for easier python binding)
This commit is contained in:
@@ -15,7 +15,7 @@ http://sourceforge.net/projects/wiiuse/
|
|||||||
v0.15 -- ???
|
v0.15 -- ???
|
||||||
---------------------------
|
---------------------------
|
||||||
Added:
|
Added:
|
||||||
-
|
- Callback API with constant-size WiimoteState_t. Thanks to bhartsho.
|
||||||
Fixed:
|
Fixed:
|
||||||
-
|
-
|
||||||
Changed:
|
Changed:
|
||||||
|
|||||||
36
src/events.c
36
src/events.c
@@ -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.
|
* @brief Called on a cycle where no significant change occurs.
|
||||||
*
|
*
|
||||||
|
|||||||
23
src/wiiuse.h
23
src/wiiuse.h
@@ -773,6 +773,29 @@ WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* w
|
|||||||
/* this function not currently implemented... */
|
/* this function not currently implemented... */
|
||||||
WIIUSE_EXPORT extern void wiiuse_set_wii_board_calib(struct wiimote_t *wm);
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user