diff --git a/src/io.h b/src/io.h index 8918a2f..18e3187 100644 --- a/src/io.h +++ b/src/io.h @@ -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); /** @} */ diff --git a/src/io_nix.c b/src/io_nix.c index e2f56f4..4f9d50a 100644 --- a/src/io_nix.c +++ b/src/io_nix.c @@ -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 */ diff --git a/src/io_win.c b/src/io_win.c index 5ed676b..4f6aee0 100644 --- a/src/io_win.c +++ b/src/io_win.c @@ -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 */ diff --git a/src/wiiuse.c b/src/wiiuse.c index 23713b3..604b4ec 100644 --- a/src/wiiuse.c +++ b/src/wiiuse.c @@ -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;