From 3c9cfdf656506a6bb80618bcc71b92203b46ec16 Mon Sep 17 00:00:00 2001 From: Jan Ciger Date: Thu, 15 Sep 2011 01:29:43 +0200 Subject: [PATCH] Renamed variables to something more descriptive, removed unused code --- src/events.c | 86 ++++------------------------------------------- src/motion_plus.c | 48 +++++++++++++------------- src/wiiuse.h | 14 ++++---- 3 files changed, 37 insertions(+), 111 deletions(-) diff --git a/src/events.c b/src/events.c index 9e287df..61b1605 100644 --- a/src/events.c +++ b/src/events.c @@ -740,7 +740,6 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { byte buf = 0x00; byte* handshake_buf; -#ifndef OLD_EXP_HANDSHAKE switch(wm->expansion_state) { /* These two initialization writes disable the encryption */ case 0: @@ -807,79 +806,6 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) { wiiuse_status(wm); break; } - -#else - if (!data) { - byte* handshake_buf; - byte buf = 0x00; - - if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) - disable_expansion(wm); - - /* increase the timeout until the handshake completes */ - #ifdef WIIUSE_WIN32 - WIIUSE_DEBUG("Setting timeout to expansion %i ms.", wm->exp_timeout); - wm->timeout = wm->exp_timeout; - #endif - - wiiuse_write_data(wm, WM_EXP_MEM_ENABLE, &buf, 1); - - /* get the calibration data */ - handshake_buf = (byte *)malloc(EXP_HANDSHAKE_LEN * sizeof(byte)); - wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN); - - /* tell the wiimote to send expansion data */ - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); - - return; - } - - id = from_big_endian_uint32_t(data + 220); - - /* call the corresponding handshake function for this expansion */ - switch (id) { - case EXP_ID_CODE_NUNCHUK: - { - if (nunchuk_handshake(wm, &wm->exp.nunchuk, data, len)) - wm->event = WIIUSE_NUNCHUK_INSERTED; - break; - } - case EXP_ID_CODE_CLASSIC_CONTROLLER: - { - if (classic_ctrl_handshake(wm, &wm->exp.classic, data, len)) - wm->event = WIIUSE_CLASSIC_CTRL_INSERTED; - break; - } - case EXP_ID_CODE_GUITAR: - { - if (guitar_hero_3_handshake(wm, &wm->exp.gh3, data, len)) - wm->event = WIIUSE_GUITAR_HERO_3_CTRL_INSERTED; - break; - } - case EXP_ID_CODE_WII_BOARD: - { - if (wii_board_handshake(wm, &wm->exp.wb, data, len)) - wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED; - break; - } - - case EXP_ID_CODE_MOTION_PLUS: - case EXP_ID_CODE_MOTION_PLUS_CLASSIC: - case EXP_ID_CODE_MOTION_PLUS_NUNCHUK: - /* wiiuse_motion_plus_handshake(wm, data, len); */ - wm->event = WIIUSE_MOTION_PLUS_ACTIVATED; - break; - - - default: - { - WIIUSE_WARNING("Unknown expansion type. Code: 0x%x", id); - break; - } - } - - free(data); -#endif } @@ -984,9 +910,9 @@ static void save_state(struct wiimote_t* wm) { case EXP_MOTION_PLUS_CLASSIC: case EXP_MOTION_PLUS_NUNCHUK: { - wm->lstate.drx = wm->exp.mp.raw_gyro.p; - wm->lstate.dry = wm->exp.mp.raw_gyro.r; - wm->lstate.drz = wm->exp.mp.raw_gyro.y; + wm->lstate.drx = wm->exp.mp.raw_gyro.pitch; + wm->lstate.dry = wm->exp.mp.raw_gyro.roll; + wm->lstate.drz = wm->exp.mp.raw_gyro.yaw; if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC) { @@ -1115,9 +1041,9 @@ static int state_changed(struct wiimote_t* wm) { case EXP_MOTION_PLUS_CLASSIC: case EXP_MOTION_PLUS_NUNCHUK: { - STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.p); - STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.r); - STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.y); + STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch); + STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.roll); + STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw); if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC) { diff --git a/src/motion_plus.c b/src/motion_plus.c index 25b3ca7..d06ef75 100644 --- a/src/motion_plus.c +++ b/src/motion_plus.c @@ -88,9 +88,9 @@ void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short WIIUSE_DEBUG("Motion plus connected"); /* Init gyroscopes */ - wm->exp.mp.cal_gyro.r = 0; - wm->exp.mp.cal_gyro.p = 0; - wm->exp.mp.cal_gyro.y = 0; + wm->exp.mp.cal_gyro.roll = 0; + wm->exp.mp.cal_gyro.pitch = 0; + wm->exp.mp.cal_gyro.yaw = 0; wm->exp.mp.orient.roll = 0.0; wm->exp.mp.orient.pitch = 0.0; wm->exp.mp.orient.yaw = 0.0; @@ -162,20 +162,20 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) /* Check if the gyroscope is in fast or slow mode (0 if rotating fast, 1 if slow or still) */ mp->acc_mode = ((msg[4] & 0x2) << 1) | ((msg[3] & 0x1) << 1) | ((msg[3] & 0x2) >> 1); - mp->raw_gyro.r = ((msg[4] & 0xFC) << 6) | msg[1]; - mp->raw_gyro.p = ((msg[5] & 0xFC) << 6) | msg[2]; - mp->raw_gyro.y = ((msg[3] & 0xFC) << 6) | msg[0]; + mp->raw_gyro.roll = ((msg[4] & 0xFC) << 6) | msg[1]; + mp->raw_gyro.pitch = ((msg[5] & 0xFC) << 6) | msg[2]; + mp->raw_gyro.yaw = ((msg[3] & 0xFC) << 6) | msg[0]; /* First calibration */ - if ((mp->raw_gyro.r > 5000) && - (mp->raw_gyro.p > 5000) && - (mp->raw_gyro.y > 5000) && - (mp->raw_gyro.r < 0x3fff) && - (mp->raw_gyro.p < 0x3fff) && - (mp->raw_gyro.y < 0x3fff) && - !(mp->cal_gyro.r) && - !(mp->cal_gyro.p) && - !(mp->cal_gyro.y)) + if ((mp->raw_gyro.roll > 5000) && + (mp->raw_gyro.pitch > 5000) && + (mp->raw_gyro.yaw > 5000) && + (mp->raw_gyro.roll < 0x3fff) && + (mp->raw_gyro.pitch < 0x3fff) && + (mp->raw_gyro.yaw < 0x3fff) && + !(mp->cal_gyro.roll) && + !(mp->cal_gyro.pitch) && + !(mp->cal_gyro.yaw)) { wiiuse_calibrate_motion_plus(mp); } @@ -235,9 +235,9 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) */ void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) { - mp->cal_gyro.r = mp->raw_gyro.r; - mp->cal_gyro.p = mp->raw_gyro.p; - mp->cal_gyro.y = mp->raw_gyro.y; + mp->cal_gyro.roll = mp->raw_gyro.roll; + mp->cal_gyro.pitch = mp->raw_gyro.pitch; + mp->cal_gyro.yaw = mp->raw_gyro.yaw; mp->orient.roll = 0.0; mp->orient.pitch = 0.0; mp->orient.yaw = 0.0; @@ -249,9 +249,9 @@ static void calculate_gyro_rates(struct motion_plus_t* mp) float tmp_roll, tmp_pitch, tmp_yaw; /* We consider calibration data */ - tmp_r = mp->raw_gyro.r - mp->cal_gyro.r; - tmp_p = mp->raw_gyro.p - mp->cal_gyro.p; - tmp_y = mp->raw_gyro.y - mp->cal_gyro.y; + tmp_r = mp->raw_gyro.roll - mp->cal_gyro.roll; + tmp_p = mp->raw_gyro.pitch - mp->cal_gyro.pitch; + tmp_y = mp->raw_gyro.yaw - mp->cal_gyro.yaw; /* We convert to degree/sec according to fast/slow mode */ if (mp->acc_mode & 0x04) @@ -277,7 +277,7 @@ static void calculate_gyro_rates(struct motion_plus_t* mp) if (fabs(tmp_yaw) < 0.5) tmp_yaw = 0.0; - mp->angle_rate_gyro.r = tmp_roll; - mp->angle_rate_gyro.p = tmp_pitch; - mp->angle_rate_gyro.y = tmp_yaw; + mp->angle_rate_gyro.roll = tmp_roll; + mp->angle_rate_gyro.pitch = tmp_pitch; + mp->angle_rate_gyro.yaw = tmp_yaw; } diff --git a/src/wiiuse.h b/src/wiiuse.h index 87de021..93c1f75 100644 --- a/src/wiiuse.h +++ b/src/wiiuse.h @@ -326,18 +326,18 @@ struct read_req_t { /** * @struct ang3s_t - * @brief RPY short angles. + * @brief Roll/Pitch/Yaw short angles. */ typedef struct ang3s_t { - short r, p, y; + int16_t roll, pitch, yaw; } ang3s_t; /** * @struct ang3f_t - * @brief RPY float angles. + * @brief Roll/Pitch/Yaw float angles. */ typedef struct ang3f_t { - float r, p, y; + float roll, pitch, yaw; } ang3f_t; /** @@ -534,8 +534,8 @@ typedef struct guitar_hero_3_t { */ typedef struct motion_plus_t { - int ext_initialized; /* is the pass-through device initialized? */ - unsigned char ext; + int ext_initialized; /**< is the pass-through device initialized? */ + byte ext; /**< is there a device on the pass-through port? */ struct ang3s_t raw_gyro; /**< current raw gyroscope data */ struct ang3s_t cal_gyro; /**< calibration raw gyroscope data */ @@ -544,7 +544,7 @@ typedef struct motion_plus_t byte acc_mode; /**< Fast/slow rotation mode for roll, pitch and yaw (0 if rotating fast, 1 if slow or still) */ int raw_gyro_threshold; /**< threshold for gyroscopes to generate an event */ - struct nunchuk_t *nc; /* pointers to nunchuk & classic in pass-through-mode */ + struct nunchuk_t *nc; /**< pointers to nunchuk & classic in pass-through-mode */ struct classic_ctrl_t *classic; } motion_plus_t;