diff --git a/input/wiimote.c b/input/wiimote.c index 8198501a16..68bf8a2fe7 100644 --- a/input/wiimote.c +++ b/input/wiimote.c @@ -66,13 +66,12 @@ void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg); /* TODO - Get rid of Apple-specific functions. */ void apple_pad_send_control(void *data, uint8_t* data_buf, size_t size); -/** - * @brief Request the wiimote controller status. +/* + * Request the wiimote controller status. * - * @param wm Pointer to a wiimote_t structure. - * - * Controller status includes: battery level, LED status, expansions + * Controller status includes: battery level, LED status, expansions. */ + void wiimote_status(struct wiimote_t* wm) { byte buf = 0; @@ -95,20 +94,22 @@ void wiimote_data_report(struct wiimote_t* wm, byte type) return; buf[1] = type; - //CUIDADO es un &buf? + + /* CUIDADO es un &buf? */ wiimote_send(wm, WM_CMD_REPORT_TYPE, buf, 2); } -/** - * @brief Set the enabled LEDs. +/* + * Set the enabled LEDs. * - * @param wm Pointer to a wiimote_t structure. - * @param leds What LEDs to enable. - * - * \a leds is a bitwise or of WIIMOTE_LED_1, WIIMOTE_LED_2, - * WIIMOTE_LED_3, or WIIMOTE_LED_4. + * leds is a bitwise OR of: + * - WIIMOTE_LED_1 + * - WIIMOTE_LED_2 + * - WIIMOTE_LED_3 + * - WIIMOTE_LED_4 */ + void wiimote_set_leds(struct wiimote_t* wm, int leds) { byte buf; @@ -116,7 +117,7 @@ void wiimote_set_leds(struct wiimote_t* wm, int leds) if (!wm || !WIIMOTE_IS_CONNECTED(wm)) return; - /* remove the lower 4 bits because they control rumble */ + /* Remove the lower 4 bits because they control rumble. */ wm->leds = (leds & 0xF0); buf = wm->leds; @@ -124,29 +125,23 @@ void wiimote_set_leds(struct wiimote_t* wm, int leds) wiimote_send(wm, WM_CMD_LED, &buf, 1); } -/** - * @brief Find what buttons are pressed. - * - * @param wm Pointer to a wiimote_t structure. - * @param msg The message specified in the event packet. +/* + * Find what buttons are pressed. */ + void wiimote_pressed_buttons(struct wiimote_t* wm, byte* msg) { - short now; + /* Convert to big endian. */ + short now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL; - /* convert to big endian */ - now = BIG_ENDIAN_SHORT(*(short*)msg) & WIIMOTE_BUTTON_ALL; - - /* buttons pressed now */ + /* buttons pressed now. */ wm->btns = now; } -/** - * @brief Handle data from the expansion. - * - * @param wm A pointer to a wiimote_t structure. - * @param msg The message specified in the event packet for the expansion. +/* + * Handle data from the expansion. */ + void wiimote_handle_expansion(struct wiimote_t* wm, byte* msg) { switch (wm->exp.type) @@ -159,46 +154,40 @@ void wiimote_handle_expansion(struct wiimote_t* wm, byte* msg) } } -/** -* @brief Get initialization data from the wiimote. -* -* @param wm Pointer to a wiimote_t structure. -* @param data unused -* @param len unused -* -* When first called for a wiimote_t structure, a request -* is sent to the wiimote for initialization information. -* This includes factory set accelerometer data. -* The handshake will be concluded when the wiimote responds -* with this data. -*/ +/* + * Get initialization data from the Wiimote. + * + * When first called for a wiimote_t structure, a request + * is sent to the wiimote for initialization information. + * This includes factory set accelerometer data. + * The handshake will be concluded when the wiimote responds + * with this data. + */ + int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned short len) { - if (!wm) return 0; + if (!wm) + return 0; - while(1) + do { -#ifdef WIIMOTE_DBG - printf("Handshake %d\n",wm->handshake_state); -#endif switch (wm->handshake_state) { case 0: - { - /* no ha habido nunca handshake, debemos forzar un - * mensaje de staus para ver que pasa. */ + /* no ha habido nunca handshake, debemos forzar un + * mensaje de staus para ver que pasa. */ - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - wiimote_set_leds(wm, WIIMOTE_LED_NONE); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + wiimote_set_leds(wm, WIIMOTE_LED_NONE); - /* request the status of the wiimote to see if there is an expansion */ - wiimote_status(wm); + /* Request the status of the Wiimote to + * see if there is an expansion */ + wiimote_status(wm); - wm->handshake_state=1; - return 0; - } + wm->handshake_state=1; + return 0; case 1: { /* estamos haciendo handshake o bien se necesita iniciar un @@ -208,7 +197,8 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, if(event != WM_RPT_CTRL_STATUS) return 0; - /* is an attachment connected to the expansion port? */ + /* Is an attachment connected to + * the expansion port? */ if ((data[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) attachment = 1; @@ -218,21 +208,18 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)); #endif - /* expansion port */ if (attachment && !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { + /* Expansion port */ + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); - /* send the initialization code for the attachment */ -#ifdef WIIMOTE_DBG - printf("haciendo el handshake de la expansion\n"); -#endif + /* Send the initialization code for the attachment */ if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_HANDSHAKE_COMPLETE)) { -#ifdef WIIMOTE_DBG - printf("rehandshake\n"); -#endif + /* Rehandshake. */ + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); /* forzamos un handshake por si venimos * de un hanshake completo. */ @@ -240,6 +227,7 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, } byte buf; + /*Old way. initialize the extension was by writing the * single encryption byte 0x00 to 0x(4)A40040. */ #if 0 @@ -264,11 +252,10 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, wm->handshake_state = 4; return 0; - } else if (!attachment && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) { - /* attachment removed */ + /* Attachment removed */ WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); wm->exp.type = EXP_NONE; @@ -293,98 +280,82 @@ int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, return 0; } case 2: - { - /* find handshake no expansion. */ + /* Find handshake no expansion. */ #ifdef WIIMOTE_DBG - printf("Finalizado HANDSHAKE SIN EXPANSION\n"); + printf("Finalizado HANDSHAKE SIN EXPANSION\n"); #endif - wiimote_data_report(wm,WM_RPT_BTN); - wm->handshake_state = 6; - continue; - } + wiimote_data_report(wm,WM_RPT_BTN); + wm->handshake_state = 6; + continue; case 3: - { - /* Find handshake expansion. */ + /* Find handshake expansion. */ #ifdef WIIMOTE_DBG - printf("Finalizado HANDSHAKE CON EXPANSION\n"); + printf("Finalizado HANDSHAKE CON EXPANSION\n"); #endif - wiimote_data_report(wm,WM_RPT_BTN_EXP); - wm->handshake_state = 6; - continue; - } + wiimote_data_report(wm,WM_RPT_BTN_EXP); + wm->handshake_state = 6; + continue; case 4: - { - if(event != WM_RPT_READ) - return 0; + if(event != WM_RPT_READ) + return 0; - int id = BIG_ENDIAN_LONG(*(int*)(data)); + int id = BIG_ENDIAN_LONG(*(int*)(data)); #ifdef WIIMOTE_DBG - printf("Expansion id=0x%04x\n",id); + printf("Expansion id=0x%04x\n",id); #endif - /*EXP_ID_CODE_CLASSIC_CONTROLLER*/ - if(id != 0xa4200101) - { - wm->handshake_state = 2; + /* EXP_ID_CODE_CLASSIC_CONTROLLER */ + + if(id != 0xa4200101) + { + wm->handshake_state = 2; #if 0 - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP); #endif - continue; - } - else - { - usleep(100000); - /* pedimos datos de calibracion del JOY! */ - wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16); - wm->handshake_state = 5; - } - - return 0; - } - case 5: - { - if(event != WM_RPT_READ) - return 0; - - classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len); - wm->handshake_state = 3; continue; + } + else + { + usleep(100000); + /* pedimos datos de calibracion del JOY! */ + wiimote_read_data(wm, WM_EXP_MEM_CALIBR, 16); + wm->handshake_state = 5; + } - } + return 0; + case 5: + if(event != WM_RPT_READ) + return 0; + + classic_ctrl_handshake(wm, &wm->exp.cc.classic, data,len); + wm->handshake_state = 3; + continue; case 6: - { - WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); - WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); - wm->handshake_state = 1; - if(wm->unid==0) - wiimote_set_leds(wm, WIIMOTE_LED_1); - else if(wm->unid==1) - wiimote_set_leds(wm, WIIMOTE_LED_2); - else if(wm->unid==2) - wiimote_set_leds(wm, WIIMOTE_LED_3); - else if(wm->unid==3) - wiimote_set_leds(wm, WIIMOTE_LED_4); - return 1; - } + WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE); + WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE); + wm->handshake_state = 1; + if(wm->unid==0) + wiimote_set_leds(wm, WIIMOTE_LED_1); + else if(wm->unid==1) + wiimote_set_leds(wm, WIIMOTE_LED_2); + else if(wm->unid==2) + wiimote_set_leds(wm, WIIMOTE_LED_3); + else if(wm->unid==3) + wiimote_set_leds(wm, WIIMOTE_LED_4); + return 1; default: - { - break; - } + break; } - } + } while(1); } -/** - * @brief Send a packet to the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param report_type The report type to send (WIIMOTE_CMD_LED, WIIMOTE_CMD_RUMBLE, etc). Found in wiimote.h - * @param msg The payload. - * @param len Length of the payload in bytes. +/* + * Send a packet to the wiimote. * * This function should replace any write()s directly to the wiimote device. */ + int wiimote_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) { byte buf[32]; @@ -406,12 +377,8 @@ int wiimote_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) return 1; } -/** - * @brief Read data from the wiimote (event version). - * - * @param wm Pointer to a wiimote_t structure. - * @param addr The address of wiimote memory to read from. - * @param len The length of the block to be read. +/* + * Read data from the wiimote (event version). * * The library can only handle one data read request at a time * because it must keep track of the buffer and other @@ -420,17 +387,16 @@ int wiimote_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) * to a pending list and be sent out when the previous * finishes. */ + int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, unsigned short len) { + byte buf[6]; + /* No puden ser mas de 16 lo leido o vendra en trozos! */ - if (!wm || !WIIMOTE_IS_CONNECTED(wm)) + if (!wm || !WIIMOTE_IS_CONNECTED(wm) || !len) return 0; - if (!len) - return 0; - - byte buf[6]; /* the offset is in big endian */ *(int*)(buf) = BIG_ENDIAN_LONG(addr); @@ -446,13 +412,8 @@ int wiimote_read_data(struct wiimote_t* wm, unsigned int addr, return 1; } -/** - * @brief Write data to the wiimote. - * - * @param wm Pointer to a wiimote_t structure. - * @param addr The address to write to. - * @param data The data to be written to the memory location. - * @param len The length of the block to be written. +/* + * Write data to the wiimote. */ int wiimote_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len) @@ -510,8 +471,10 @@ static void process_axis(struct axis_t* axis, byte raw) axis->max = raw + 2; } - if (raw < axis->min) axis->min = raw; - if (raw > axis->max) axis->max = raw; + if (raw < axis->min) + axis->min = raw; + if (raw > axis->max) + axis->max = raw; axis->raw_value = raw; if (raw < axis->center) @@ -527,7 +490,7 @@ static void process_axis(struct axis_t* axis, byte raw) void classic_ctrl_event(struct classic_ctrl_t* cc, byte* msg) { cc->btns = ~BIG_ENDIAN_SHORT(*(short*)(msg + 4)) & CLASSIC_CTRL_BUTTON_ALL; - process_axis(&cc->ljs.x, (msg[0] & 0x3F)); + process_axis(&cc->ljs.x, (msg[0] & 0x3F)); process_axis(&cc->ljs.y, (msg[1] & 0x3F)); process_axis(&cc->rjs.x, ((msg[0] & 0xC0) >> 3) | ((msg[1] & 0xC0) >> 5) | ((msg[2] & 0x80) >> 7)); diff --git a/input/wiimote.h b/input/wiimote.h index 129e0cdc22..98120f98de 100644 --- a/input/wiimote.h +++ b/input/wiimote.h @@ -45,157 +45,165 @@ extern "C" { #endif - typedef unsigned char byte; - typedef char sbyte; +typedef unsigned char byte; +typedef char sbyte; - /* Convert to big endian */ - #define BIG_ENDIAN_LONG(i) (htonl(i)) - #define BIG_ENDIAN_SHORT(i) (htons(i)) +/* Convert to big endian */ +#define BIG_ENDIAN_LONG(i) (htonl(i)) +#define BIG_ENDIAN_SHORT(i) (htons(i)) - #define absf(x) ((x >= 0) ? (x) : (x * -1.0f)) - #define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x))) +#define absf(x) ((x >= 0) ? (x) : (x * -1.0f)) +#define diff_f(x, y) ((x >= y) ? (absf(x - y)) : (absf(y - x))) - /* wiimote state flags*/ - #define WIIMOTE_STATE_DEV_FOUND 0x0001 - #define WIIMOTE_STATE_HANDSHAKE 0x0002 /* actual connection exists but no handshake yet */ - #define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 - #define WIIMOTE_STATE_CONNECTED 0x0008 - #define WIIMOTE_STATE_EXP 0x0040 +/* wiimote state flags*/ +#define WIIMOTE_STATE_DEV_FOUND 0x0001 +#define WIIMOTE_STATE_HANDSHAKE 0x0002 /* Actual connection exists but no handshake yet */ +#define WIIMOTE_STATE_HANDSHAKE_COMPLETE 0x0004 +#define WIIMOTE_STATE_CONNECTED 0x0008 +#define WIIMOTE_STATE_EXP 0x0040 - /* Communication channels */ +/* Communication channels */ - #define WM_SET_REPORT 0x50 +#define WM_SET_REPORT 0x50 - /* commands */ - #define WM_CMD_LED 0x11 - #define WM_CMD_REPORT_TYPE 0x12 - #define WM_CMD_RUMBLE 0x13 - #define WM_CMD_IR 0x13 - #define WM_CMD_CTRL_STATUS 0x15 - #define WM_CMD_WRITE_DATA 0x16 - #define WM_CMD_READ_DATA 0x17 - #define WM_CMD_IR_2 0x1A +/* Commands */ +#define WM_CMD_LED 0x11 +#define WM_CMD_REPORT_TYPE 0x12 +#define WM_CMD_RUMBLE 0x13 +#define WM_CMD_IR 0x13 +#define WM_CMD_CTRL_STATUS 0x15 +#define WM_CMD_WRITE_DATA 0x16 +#define WM_CMD_READ_DATA 0x17 +#define WM_CMD_IR_2 0x1A - /* input report ids */ - #define WM_RPT_CTRL_STATUS 0x20 - #define WM_RPT_READ 0x21 - #define WM_RPT_WRITE 0x22 - #define WM_RPT_BTN 0x30 - #define WM_RPT_BTN_ACC 0x31 - #define WM_RPT_BTN_ACC_IR 0x33 - #define WM_RPT_BTN_EXP 0x34 - #define WM_RPT_BTN_ACC_EXP 0x35 - #define WM_RPT_BTN_IR_EXP 0x36 - #define WM_RPT_BTN_ACC_IR_EXP 0x37 +/* Input report IDs */ +#define WM_RPT_CTRL_STATUS 0x20 +#define WM_RPT_READ 0x21 +#define WM_RPT_WRITE 0x22 +#define WM_RPT_BTN 0x30 +#define WM_RPT_BTN_ACC 0x31 +#define WM_RPT_BTN_ACC_IR 0x33 +#define WM_RPT_BTN_EXP 0x34 +#define WM_RPT_BTN_ACC_EXP 0x35 +#define WM_RPT_BTN_IR_EXP 0x36 +#define WM_RPT_BTN_ACC_IR_EXP 0x37 - #define WM_BT_INPUT 0x01 - #define WM_BT_OUTPUT 0x02 +#define WM_BT_INPUT 0x01 +#define WM_BT_OUTPUT 0x02 - /* controller status stuff */ - #define WM_MAX_BATTERY_CODE 0xC8 +/* controller status stuff */ +#define WM_MAX_BATTERY_CODE 0xC8 - #define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD +#define EXP_ID_CODE_CLASSIC_CONTROLLER 0x9A1EFDFD - /* offsets in wiimote memory */ - #define WM_MEM_OFFSET_CALIBRATION 0x16 - #define WM_EXP_MEM_BASE 0x04A40000 - #define WM_EXP_MEM_ENABLE 0x04A40040 - #define WM_EXP_MEM_CALIBR 0x04A40020 +/* offsets in wiimote memory */ +#define WM_MEM_OFFSET_CALIBRATION 0x16 +#define WM_EXP_MEM_BASE 0x04A40000 +#define WM_EXP_MEM_ENABLE 0x04A40040 +#define WM_EXP_MEM_CALIBR 0x04A40020 - #define EXP_HANDSHAKE_LEN 224 +#define EXP_HANDSHAKE_LEN 224 - /* controller status flags for the first message byte */ - /* bit 1 is unknown */ - #define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 - #define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04 - #define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08 - #define WM_CTRL_STATUS_BYTE1_LED_1 0x10 - #define WM_CTRL_STATUS_BYTE1_LED_2 0x20 - #define WM_CTRL_STATUS_BYTE1_LED_3 0x40 - #define WM_CTRL_STATUS_BYTE1_LED_4 0x80 +/* controller status flags for the first message byte */ +/* bit 1 is unknown */ +#define WM_CTRL_STATUS_BYTE1_ATTACHMENT 0x02 +#define WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED 0x04 +#define WM_CTRL_STATUS_BYTE1_IR_ENABLED 0x08 +#define WM_CTRL_STATUS_BYTE1_LED_1 0x10 +#define WM_CTRL_STATUS_BYTE1_LED_2 0x20 +#define WM_CTRL_STATUS_BYTE1_LED_3 0x40 +#define WM_CTRL_STATUS_BYTE1_LED_4 0x80 - /* led bit masks */ - #define WIIMOTE_LED_NONE 0x00 - #define WIIMOTE_LED_1 0x10 - #define WIIMOTE_LED_2 0x20 - #define WIIMOTE_LED_3 0x40 - #define WIIMOTE_LED_4 0x80 +/* LED bit masks */ +#define WIIMOTE_LED_NONE 0x00 +#define WIIMOTE_LED_1 0x10 +#define WIIMOTE_LED_2 0x20 +#define WIIMOTE_LED_3 0x40 +#define WIIMOTE_LED_4 0x80 - /* button masks */ - #define WIIMOTE_BUTTON_ALL 0x1F9F - #define CLASSIC_CTRL_BUTTON_ALL 0xFEFF +/* button masks */ +#define WIIMOTE_BUTTON_ALL 0x1F9F +#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF - /* expansion codes */ - #define EXP_NONE 0 - #define EXP_CLASSIC 2 +/* expansion codes */ +#define EXP_NONE 0 +#define EXP_CLASSIC 2 - typedef struct axis_t { - bool has_center; +typedef struct axis_t +{ + bool has_center; - byte min; - byte center; - byte max; - byte raw_value; - float value; - } axis_t; + byte min; + byte center; + byte max; + byte raw_value; + float value; +} axis_t; - typedef struct joystick_t { - axis_t x; - axis_t y; - } joystick_t; +typedef struct joystick_t +{ + axis_t x; + axis_t y; +} joystick_t; - typedef struct classic_ctrl_t { - short btns; - struct joystick_t ljs; - struct joystick_t rjs; - } classic_ctrl_t; +typedef struct classic_ctrl_t +{ + short btns; + struct joystick_t ljs; + struct joystick_t rjs; +} classic_ctrl_t; - /** - * @struct expansion_t - * @brief Generic expansion device plugged into wiimote. - */ - typedef struct expansion_t { - int type; /**< type of expansion attached */ +/* + * Generic expansion device plugged into wiimote. + */ +typedef struct expansion_t +{ + /* Type of expansion attached. */ + int type; - union { - struct classic_ctrl_t classic; - } cc; - } expansion_t; + union { + struct classic_ctrl_t classic; + } cc; +} expansion_t; - /** - * @struct wiimote_t - * @brief Wiimote structure. - */ - typedef struct wiimote_t { - int unid; /**< user specified id */ +/* Wiimote structure. */ +typedef struct wiimote_t +{ + /* User specified ID. */ + int unid; + /* TODO/FIXME - refactor */ + struct apple_pad_connection* connection; + /* Various state flags. */ + int state; + /* Currently lit LEDs. */ + byte leds; + /* Battery level. */ + float battery_level; + /* The state of the connection handshake. */ + byte handshake_state; + /* Wiimote expansion device. */ + struct expansion_t exp; + /* What buttons have just been pressed. */ + unsigned short btns; +} wiimote; - struct apple_pad_connection* connection; - int state; /**< various state flags */ - byte leds; /**< currently lit leds */ - float battery_level; /**< battery level */ - - byte handshake_state; /**< the state of the connection handshake */ - - struct expansion_t exp; /**< wiimote expansion device */ - - unsigned short btns; /**< what buttons have just been pressed */ - } wiimote; - - /* macro to manage states */ - #define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) - #define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) - #define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) - #define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) - #define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) +/* Macro to manage states */ +#define WIIMOTE_IS_SET(wm, s) ((wm->state & (s)) == (s)) +#define WIIMOTE_ENABLE_STATE(wm, s) (wm->state |= (s)) +#define WIIMOTE_DISABLE_STATE(wm, s) (wm->state &= ~(s)) +#define WIIMOTE_TOGGLE_STATE(wm, s) ((wm->state & (s)) ? WIIMOTE_DISABLE_STATE(wm, s) : WIIMOTE_ENABLE_STATE(wm, s)) +#define WIIMOTE_IS_CONNECTED(wm) (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_CONNECTED)) int wiimote_handshake(struct wiimote_t* wm, byte event, byte* data, unsigned short len); void wiimote_status(struct wiimote_t* wm); -void wiimote_data_report(struct wiimote_t* wm, byte type); -void wiimote_pressed_buttons(struct wiimote_t* wm, byte* msg); -void wiimote_handle_expansion(struct wiimote_t* wm, byte* msg); +void wiimote_data_report(struct wiimote_t* wm, byte type); + +void wiimote_pressed_buttons(struct wiimote_t* wm, byte* msg); + +void wiimote_handle_expansion(struct wiimote_t* wm, byte* msg); #if defined(__cplusplus) }