move some platform-specific code out of the main wiiuse source

Initializing and cleaning up platform-specific fields in the wiimote
structure is now done in a separate routine.
This commit is contained in:
Ryan Pavlik
2011-09-07 10:26:43 -05:00
parent da52f94619
commit 7e295eb944
4 changed files with 28 additions and 20 deletions

View File

@@ -49,6 +49,9 @@ extern "C" {
/** @{ */
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len);
void wiiuse_init_platform_fields(struct wiimote_t* wm);
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm);
int wiiuse_io_read(struct wiimote_t* wm);
int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len);
/** @} */

View File

@@ -278,6 +278,17 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
return write(wm->out_sock, buf, len);
}
void wiiuse_init_platform_fields(struct wiimote_t* wm) {
memset(&(wm->bdaddr), 0, sizeof(bdaddr_t)); /* = *BDADDR_ANY;*/
wm->out_sock = -1;
wm->in_sock = -1;
}
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) {
wm->out_sock = -1;
wm->in_sock = -1;
}
#endif /* ifdef WIIUSE_BLUEZ */

View File

@@ -253,4 +253,16 @@ int wiiuse_io_write(struct wiimote_t* wm, byte* buf, int len) {
return 0;
}
void wiiuse_init_platform_fields(struct wiimote_t* wm) {
wm->dev_handle = 0;
wm->stack = WIIUSE_STACK_UNKNOWN;
wm->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm->exp_timeout = WIIMOTE_EXP_TIMEOUT;
wm->timeout = wm->normal_timeout;
}
void wiiuse_cleanup_platform_fields(struct wiimote_t* wm) {
wm->dev_handle = 0;
}
#endif /* ifdef WIIUSE_WIN32 */

View File

@@ -138,19 +138,7 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
memset(wm[i], 0, sizeof(struct wiimote_t));
wm[i]->unid = i+1;
#ifdef WIIUSE_BLUEZ
wm[i]->bdaddr = *BDADDR_ANY;
wm[i]->out_sock = -1;
wm[i]->in_sock = -1;
#endif
#ifdef WIIUSE_WIN32
wm[i]->dev_handle = 0;
wm[i]->stack = WIIUSE_STACK_UNKNOWN;
wm[i]->normal_timeout = WIIMOTE_DEFAULT_TIMEOUT;
wm[i]->exp_timeout = WIIMOTE_EXP_TIMEOUT;
wm[i]->timeout = wm[i]->normal_timeout;
#endif
wiiuse_init_platform_fields(wm[i]);
wm[i]->state = WIIMOTE_INIT_STATES;
wm[i]->flags = WIIUSE_INIT_FLAGS;
@@ -186,13 +174,7 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_CONNECTED);
/* reset a bunch of stuff */
#ifdef WIIUSE_BLUEZ
wm->out_sock = -1;
wm->in_sock = -1;
#endif
#ifdef WIIUSE_WIN32
wm->dev_handle = 0;
#endif
wiiuse_cleanup_platform_fields(wm);
wm->leds = 0;
wm->state = WIIMOTE_INIT_STATES;