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:
3
src/io.h
3
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);
|
||||
/** @} */
|
||||
|
||||
11
src/io_nix.c
11
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 */
|
||||
|
||||
12
src/io_win.c
12
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 */
|
||||
|
||||
22
src/wiiuse.c
22
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;
|
||||
|
||||
Reference in New Issue
Block a user