try using endianness conversion functions instead of icky macros

This commit is contained in:
Ryan Pavlik
2011-09-02 16:14:27 -05:00
parent 8216db96f6
commit 44612529a7
7 changed files with 73 additions and 39 deletions

View File

@@ -48,7 +48,6 @@
*/
int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data, uint16_t len) {
uint16_t *handshake_short;
/* decrypt data */
#ifdef WITH_WIIUSE_DEBUG
@@ -68,22 +67,21 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data
printf("\n");
#endif
handshake_short = (uint16_t*)data;
byte * bufptr = data + 4;
wb->ctr[0] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbr[0] = unbuffer_big_endian_uint16_t(&bufptr);
wb->ctl[0] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbl[0] = unbuffer_big_endian_uint16_t(&bufptr);
wb->ctr[0] = FROM_BIG_ENDIAN_SHORT(handshake_short[2]);
wb->cbr[0] = FROM_BIG_ENDIAN_SHORT(handshake_short[3]);
wb->ctl[0] = FROM_BIG_ENDIAN_SHORT(handshake_short[4]);
wb->cbl[0] = FROM_BIG_ENDIAN_SHORT(handshake_short[5]);
wb->ctr[1] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbr[1] = unbuffer_big_endian_uint16_t(&bufptr);
wb->ctl[1] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbl[1] = unbuffer_big_endian_uint16_t(&bufptr);
wb->ctr[1] = FROM_BIG_ENDIAN_SHORT(handshake_short[6]);
wb->cbr[1] = FROM_BIG_ENDIAN_SHORT(handshake_short[7]);
wb->ctl[1] = FROM_BIG_ENDIAN_SHORT(handshake_short[8]);
wb->cbl[1] = FROM_BIG_ENDIAN_SHORT(handshake_short[9]);
wb->ctr[2] = FROM_BIG_ENDIAN_SHORT(handshake_short[10]);
wb->cbr[2] = FROM_BIG_ENDIAN_SHORT(handshake_short[11]);
wb->ctl[2] = FROM_BIG_ENDIAN_SHORT(handshake_short[12]);
wb->cbl[2] = FROM_BIG_ENDIAN_SHORT(handshake_short[13]);
wb->ctr[2] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbr[2] = unbuffer_big_endian_uint16_t(&bufptr);
wb->ctl[2] = unbuffer_big_endian_uint16_t(&bufptr);
wb->cbl[2] = unbuffer_big_endian_uint16_t(&bufptr);
/* handshake done */
wm->event = WIIUSE_WII_BOARD_CTRL_INSERTED;
@@ -126,11 +124,11 @@ static float do_interpolate(uint16_t raw, uint16_t cal[3]) {
* @param msg The message specified in the event packet.
*/
void wii_board_event(struct wii_board_t* wb, byte* msg) {
uint16_t *shmsg = (uint16_t*)(msg);
wb->rtr = FROM_BIG_ENDIAN_SHORT(shmsg[0]);
wb->rbr = FROM_BIG_ENDIAN_SHORT(shmsg[1]);
wb->rtl = FROM_BIG_ENDIAN_SHORT(shmsg[2]);
wb->rbl = FROM_BIG_ENDIAN_SHORT(shmsg[3]);
byte * bufPtr = msg;
wb->rtr = unbuffer_big_endian_uint16_t(&bufPtr);
wb->rbr = unbuffer_big_endian_uint16_t(&bufPtr);
wb->rtl = unbuffer_big_endian_uint16_t(&bufPtr);
wb->rbl = unbuffer_big_endian_uint16_t(&bufPtr);
/*
Interpolate values