astyle on the library.
This commit is contained in:
@@ -77,9 +77,10 @@ int classic_ctrl_handshake(struct wiimote_t* wm, struct classic_ctrl_t* cc, byte
|
|||||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else {
|
||||||
data += 16;
|
data += 16;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* joystick stuff */
|
/* joystick stuff */
|
||||||
|
|||||||
@@ -77,12 +77,21 @@ void calculate_orientation(struct accel_t* ac, struct vec3b_t* accel, struct ori
|
|||||||
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
z = ((float)accel->z - (float)ac->cal_zero.z) / zg;
|
||||||
|
|
||||||
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
/* make sure x,y,z are between -1 and 1 for the tan functions */
|
||||||
if (x < -1.0f) x = -1.0f;
|
if (x < -1.0f) {
|
||||||
else if (x > 1.0f) x = 1.0f;
|
x = -1.0f;
|
||||||
if (y < -1.0f) y = -1.0f;
|
} else if (x > 1.0f) {
|
||||||
else if (y > 1.0f) y = 1.0f;
|
x = 1.0f;
|
||||||
if (z < -1.0f) z = -1.0f;
|
}
|
||||||
else if (z > 1.0f) z = 1.0f;
|
if (y < -1.0f) {
|
||||||
|
y = -1.0f;
|
||||||
|
} else if (y > 1.0f) {
|
||||||
|
y = 1.0f;
|
||||||
|
}
|
||||||
|
if (z < -1.0f) {
|
||||||
|
z = -1.0f;
|
||||||
|
} else if (z > 1.0f) {
|
||||||
|
z = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
/* if it is over 1g then it is probably accelerating and not reliable */
|
/* if it is over 1g then it is probably accelerating and not reliable */
|
||||||
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
if (abs(accel->x - ac->cal_zero.x) <= ac->cal_g.x) {
|
||||||
@@ -180,11 +189,11 @@ void calc_joystick_state(struct joystick_t* js, float x, float y) {
|
|||||||
|
|
||||||
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
|
void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case SMOOTH_ROLL:
|
case SMOOTH_ROLL: {
|
||||||
{
|
|
||||||
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
|
/* it's possible last iteration was nan or inf, so set it to 0 if that happened */
|
||||||
if (isnan(ac->st_roll) || isinf(ac->st_roll))
|
if (isnan(ac->st_roll) || isinf(ac->st_roll)) {
|
||||||
ac->st_roll = 0.0f;
|
ac->st_roll = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the sign changes (which will happen if going from -180 to 180)
|
* If the sign changes (which will happen if going from -180 to 180)
|
||||||
@@ -200,10 +209,10 @@ void apply_smoothing(struct accel_t* ac, struct orient_t* orient, int type) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
case SMOOTH_PITCH:
|
case SMOOTH_PITCH: {
|
||||||
{
|
if (isnan(ac->st_pitch) || isinf(ac->st_pitch)) {
|
||||||
if (isnan(ac->st_pitch) || isinf(ac->st_pitch))
|
|
||||||
ac->st_pitch = 0.0f;
|
ac->st_pitch = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
if (((ac->st_pitch < 0) && (orient->pitch > 0)) || ((ac->st_pitch > 0) && (orient->pitch < 0))) {
|
||||||
ac->st_pitch = orient->pitch;
|
ac->st_pitch = orient->pitch;
|
||||||
|
|||||||
135
src/events.c
135
src/events.c
@@ -184,14 +184,12 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
save_state(wm);
|
save_state(wm);
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case WM_RPT_BTN:
|
case WM_RPT_BTN: {
|
||||||
{
|
|
||||||
/* button */
|
/* button */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_ACC:
|
case WM_RPT_BTN_ACC: {
|
||||||
{
|
|
||||||
/* button - motion */
|
/* button - motion */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
@@ -199,32 +197,28 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_READ:
|
case WM_RPT_READ: {
|
||||||
{
|
|
||||||
/* data read */
|
/* data read */
|
||||||
event_data_read(wm, msg);
|
event_data_read(wm, msg);
|
||||||
|
|
||||||
/* yeah buttons may be pressed, but this wasn't an "event" */
|
/* yeah buttons may be pressed, but this wasn't an "event" */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case WM_RPT_CTRL_STATUS:
|
case WM_RPT_CTRL_STATUS: {
|
||||||
{
|
|
||||||
/* controller status */
|
/* controller status */
|
||||||
event_status(wm, msg);
|
event_status(wm, msg);
|
||||||
|
|
||||||
/* don't execute the event callback */
|
/* don't execute the event callback */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_EXP:
|
case WM_RPT_BTN_EXP: {
|
||||||
{
|
|
||||||
/* button - expansion */
|
/* button - expansion */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
handle_expansion(wm, msg + 2);
|
handle_expansion(wm, msg + 2);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_ACC_EXP:
|
case WM_RPT_BTN_ACC_EXP: {
|
||||||
{
|
|
||||||
/* button - motion - expansion */
|
/* button - motion - expansion */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
@@ -234,8 +228,7 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_ACC_IR:
|
case WM_RPT_BTN_ACC_IR: {
|
||||||
{
|
|
||||||
/* button - motion - ir */
|
/* button - motion - ir */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
@@ -246,8 +239,7 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_IR_EXP:
|
case WM_RPT_BTN_IR_EXP: {
|
||||||
{
|
|
||||||
/* button - ir - expansion */
|
/* button - ir - expansion */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
handle_expansion(wm, msg + 12);
|
handle_expansion(wm, msg + 12);
|
||||||
@@ -257,8 +249,7 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_BTN_ACC_IR_EXP:
|
case WM_RPT_BTN_ACC_IR_EXP: {
|
||||||
{
|
|
||||||
/* button - motion - ir - expansion */
|
/* button - motion - ir - expansion */
|
||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
@@ -271,22 +262,21 @@ void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WM_RPT_WRITE:
|
case WM_RPT_WRITE: {
|
||||||
{
|
|
||||||
event_data_write(wm, msg);
|
event_data_write(wm, msg);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
|
WIIUSE_WARNING("Unknown event, can not handle it [Code 0x%x].", event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* was there an event? */
|
/* was there an event? */
|
||||||
if (state_changed(wm))
|
if (state_changed(wm)) {
|
||||||
wm->event = WIIUSE_EVENT;
|
wm->event = WIIUSE_EVENT;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,8 +324,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
/* find the next non-dirty request */
|
/* find the next non-dirty request */
|
||||||
while (req && req->dirty)
|
while (req && req->dirty) {
|
||||||
req = req->next;
|
req = req->next;
|
||||||
|
}
|
||||||
|
|
||||||
/* if we don't have a request out then we didn't ask for this packet */
|
/* if we don't have a request out then we didn't ask for this packet */
|
||||||
if (!req) {
|
if (!req) {
|
||||||
@@ -345,12 +336,13 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
|
|
||||||
err = msg[2] & 0x0F;
|
err = msg[2] & 0x0F;
|
||||||
|
|
||||||
if (err == 0x08)
|
if (err == 0x08) {
|
||||||
WIIUSE_WARNING("Unable to read data - address does not exist.");
|
WIIUSE_WARNING("Unable to read data - address does not exist.");
|
||||||
else if (err == 0x07)
|
} else if (err == 0x07) {
|
||||||
WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
|
WIIUSE_WARNING("Unable to read data - address is for write-only registers.");
|
||||||
else if (err)
|
} else if (err) {
|
||||||
WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
|
WIIUSE_WARNING("Unable to read data - unknown error code %x.", err);
|
||||||
|
}
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
/* this request errored out, so skip it and go to the next one */
|
/* this request errored out, so skip it and go to the next one */
|
||||||
@@ -360,8 +352,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
free(req);
|
free(req);
|
||||||
|
|
||||||
/* if another request exists send it to the wiimote */
|
/* if another request exists send it to the wiimote */
|
||||||
if (wm->read_req)
|
if (wm->read_req) {
|
||||||
wiiuse_send_next_pending_read_request(wm);
|
wiiuse_send_next_pending_read_request(wm);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -373,7 +366,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
req->wait -= len;
|
req->wait -= len;
|
||||||
if (req->wait >= req->size)
|
if (req->wait >= req->size)
|
||||||
/* this should never happen */
|
/* this should never happen */
|
||||||
|
{
|
||||||
req->wait = 0;
|
req->wait = 0;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_DEBUG("Received read packet:");
|
WIIUSE_DEBUG("Received read packet:");
|
||||||
WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
|
WIIUSE_DEBUG(" Packet read offset: %i bytes", offset);
|
||||||
@@ -389,8 +384,9 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
printf("Read: ");
|
printf("Read: ");
|
||||||
for (; i < req->size - req->wait; ++i)
|
for (; i < req->size - req->wait; ++i) {
|
||||||
printf("%x ", req->buf[i]);
|
printf("%x ", req->buf[i]);
|
||||||
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -417,14 +413,14 @@ static void event_data_read(struct wiimote_t* wm, byte* msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* if another request exists send it to the wiimote */
|
/* if another request exists send it to the wiimote */
|
||||||
if (wm->read_req)
|
if (wm->read_req) {
|
||||||
wiiuse_send_next_pending_read_request(wm);
|
wiiuse_send_next_pending_read_request(wm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void event_data_write(struct wiimote_t *wm, byte *msg)
|
static void event_data_write(struct wiimote_t *wm, byte *msg) {
|
||||||
{
|
|
||||||
|
|
||||||
struct data_req_t* req = wm->data_req;
|
struct data_req_t* req = wm->data_req;
|
||||||
|
|
||||||
@@ -485,8 +481,9 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
|||||||
struct data_req_t* req = wm->data_req;
|
struct data_req_t* req = wm->data_req;
|
||||||
|
|
||||||
/* initial handshake is not finished yet, ignore this */
|
/* initial handshake is not finished yet, ignore this */
|
||||||
if(WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_HANDSHAKE)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* An event occurred.
|
* An event occurred.
|
||||||
@@ -498,29 +495,39 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
|||||||
wiiuse_pressed_buttons(wm, msg);
|
wiiuse_pressed_buttons(wm, msg);
|
||||||
|
|
||||||
/* find what LEDs are lit */
|
/* find what LEDs are lit */
|
||||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) led[0] = 1;
|
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_1) {
|
||||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) led[1] = 1;
|
led[0] = 1;
|
||||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) led[2] = 1;
|
}
|
||||||
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) led[3] = 1;
|
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_2) {
|
||||||
|
led[1] = 1;
|
||||||
|
}
|
||||||
|
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_3) {
|
||||||
|
led[2] = 1;
|
||||||
|
}
|
||||||
|
if (msg[2] & WM_CTRL_STATUS_BYTE1_LED_4) {
|
||||||
|
led[3] = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* probe for Motion+ */
|
/* probe for Motion+ */
|
||||||
if(!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT))
|
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT)) {
|
||||||
wiiuse_probe_motion_plus(wm);
|
wiiuse_probe_motion_plus(wm);
|
||||||
|
}
|
||||||
|
|
||||||
/* is an attachment connected to the expansion port? */
|
/* is an attachment connected to the expansion port? */
|
||||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT)
|
if ((msg[2] & WM_CTRL_STATUS_BYTE1_ATTACHMENT) == WM_CTRL_STATUS_BYTE1_ATTACHMENT) {
|
||||||
{
|
|
||||||
WIIUSE_DEBUG("Attachment detected!");
|
WIIUSE_DEBUG("Attachment detected!");
|
||||||
attachment = 1;
|
attachment = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* is the speaker enabled? */
|
/* is the speaker enabled? */
|
||||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED)
|
if ((msg[2] & WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) == WM_CTRL_STATUS_BYTE1_SPEAKER_ENABLED) {
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_SPEAKER);
|
||||||
|
}
|
||||||
|
|
||||||
/* is IR sensing enabled? */
|
/* is IR sensing enabled? */
|
||||||
if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED)
|
if ((msg[2] & WM_CTRL_STATUS_BYTE1_IR_ENABLED) == WM_CTRL_STATUS_BYTE1_IR_ENABLED) {
|
||||||
ir = 1;
|
ir = 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* find the battery level and normalize between 0 and 1 */
|
/* find the battery level and normalize between 0 and 1 */
|
||||||
wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
|
wm->battery_level = (msg[5] / (float)WM_MAX_BATTERY_CODE);
|
||||||
@@ -548,8 +555,7 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
|||||||
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
|
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
|
||||||
* reenable other incoming reports.
|
* reenable other incoming reports.
|
||||||
*/
|
*/
|
||||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Since the expansion status changed IR needs to
|
* Since the expansion status changed IR needs to
|
||||||
* be reset for the new IR report mode.
|
* be reset for the new IR report mode.
|
||||||
@@ -562,8 +568,12 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* handling new Tx for changed exp */
|
/* handling new Tx for changed exp */
|
||||||
if(!req) return;
|
if (!req) {
|
||||||
if(!(req->state==REQ_SENT)) return;
|
return;
|
||||||
|
}
|
||||||
|
if (!(req->state == REQ_SENT)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
wm->data_req = req->next;
|
wm->data_req = req->next;
|
||||||
req->state = REQ_DONE;
|
req->state = REQ_DONE;
|
||||||
/* if(req->cb!=NULL) req->cb(wm,msg,6); */
|
/* if(req->cb!=NULL) req->cb(wm,msg,6); */
|
||||||
@@ -648,8 +658,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
|||||||
case 2:
|
case 2:
|
||||||
wm->expansion_state = 3;
|
wm->expansion_state = 3;
|
||||||
/* get the calibration data */
|
/* get the calibration data */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||||
disable_expansion(wm);
|
disable_expansion(wm);
|
||||||
|
}
|
||||||
handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
handshake_buf = malloc(EXP_HANDSHAKE_LEN * sizeof(byte));
|
||||||
/* tell the wiimote to send expansion data */
|
/* tell the wiimote to send expansion data */
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP);
|
||||||
@@ -731,8 +742,9 @@ void handshake_expansion(struct wiimote_t* wm, byte* data, uint16_t len) {
|
|||||||
*/
|
*/
|
||||||
void disable_expansion(struct wiimote_t* wm) {
|
void disable_expansion(struct wiimote_t* wm) {
|
||||||
WIIUSE_DEBUG("Disabling expansion");
|
WIIUSE_DEBUG("Disabling expansion");
|
||||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* tell the associated module the expansion was removed */
|
/* tell the associated module the expansion was removed */
|
||||||
switch (wm->exp.type) {
|
switch (wm->exp.type) {
|
||||||
@@ -819,14 +831,12 @@ static void save_state(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
case EXP_MOTION_PLUS:
|
case EXP_MOTION_PLUS:
|
||||||
case EXP_MOTION_PLUS_CLASSIC:
|
case EXP_MOTION_PLUS_CLASSIC:
|
||||||
case EXP_MOTION_PLUS_NUNCHUK:
|
case EXP_MOTION_PLUS_NUNCHUK: {
|
||||||
{
|
|
||||||
wm->lstate.drx = wm->exp.mp.raw_gyro.pitch;
|
wm->lstate.drx = wm->exp.mp.raw_gyro.pitch;
|
||||||
wm->lstate.dry = wm->exp.mp.raw_gyro.roll;
|
wm->lstate.dry = wm->exp.mp.raw_gyro.roll;
|
||||||
wm->lstate.drz = wm->exp.mp.raw_gyro.yaw;
|
wm->lstate.drz = wm->exp.mp.raw_gyro.yaw;
|
||||||
|
|
||||||
if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC)
|
if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) {
|
||||||
{
|
|
||||||
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
||||||
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
||||||
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
||||||
@@ -910,8 +920,7 @@ static int state_changed(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
/* expansion */
|
/* expansion */
|
||||||
switch (wm->exp.type) {
|
switch (wm->exp.type) {
|
||||||
case EXP_NUNCHUK:
|
case EXP_NUNCHUK: {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.nunchuk.js.ang);
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.nunchuk.js.mag);
|
||||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.nunchuk.btns);
|
||||||
@@ -920,8 +929,7 @@ static int state_changed(struct wiimote_t* wm) {
|
|||||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXP_CLASSIC:
|
case EXP_CLASSIC: {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||||
@@ -931,16 +939,14 @@ static int state_changed(struct wiimote_t* wm) {
|
|||||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXP_GUITAR_HERO_3:
|
case EXP_GUITAR_HERO_3: {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
|
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.gh3.js.ang);
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
|
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.gh3.js.mag);
|
||||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
|
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.gh3.whammy_bar);
|
||||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.gh3.btns);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXP_WII_BOARD:
|
case EXP_WII_BOARD: {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.exp_wb_rtr, wm->exp.wb.tr);
|
STATE_CHANGED(wm->lstate.exp_wb_rtr, wm->exp.wb.tr);
|
||||||
STATE_CHANGED(wm->lstate.exp_wb_rtl, wm->exp.wb.tl);
|
STATE_CHANGED(wm->lstate.exp_wb_rtl, wm->exp.wb.tl);
|
||||||
STATE_CHANGED(wm->lstate.exp_wb_rbr, wm->exp.wb.br);
|
STATE_CHANGED(wm->lstate.exp_wb_rbr, wm->exp.wb.br);
|
||||||
@@ -950,14 +956,12 @@ static int state_changed(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
case EXP_MOTION_PLUS:
|
case EXP_MOTION_PLUS:
|
||||||
case EXP_MOTION_PLUS_CLASSIC:
|
case EXP_MOTION_PLUS_CLASSIC:
|
||||||
case EXP_MOTION_PLUS_NUNCHUK:
|
case EXP_MOTION_PLUS_NUNCHUK: {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.pitch);
|
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.dry, wm->exp.mp.raw_gyro.roll);
|
||||||
STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw);
|
STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.yaw);
|
||||||
|
|
||||||
if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC)
|
if (wm->exp.type == EXP_MOTION_PLUS_CLASSIC) {
|
||||||
{
|
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
STATE_CHANGED(wm->lstate.exp_ljs_ang, wm->exp.classic.ljs.ang);
|
||||||
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
STATE_CHANGED(wm->lstate.exp_ljs_mag, wm->exp.classic.ljs.mag);
|
||||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||||
@@ -976,8 +980,7 @@ static int state_changed(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case EXP_NONE:
|
case EXP_NONE: {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -86,9 +86,10 @@ int guitar_hero_3_handshake(struct wiimote_t* wm, struct guitar_hero_3_t* gh3, b
|
|||||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else {
|
||||||
data += 16;
|
data += 16;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* joystick stuff */
|
/* joystick stuff */
|
||||||
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
|
gh3->js.max.x = GUITAR_HERO_3_JS_MAX_X;
|
||||||
|
|||||||
43
src/io.c
43
src/io.c
@@ -120,10 +120,8 @@ void wiiuse_disconnect(struct wiimote_t* wm) {
|
|||||||
* report from the Wiimote.
|
* report from the Wiimote.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength)
|
void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int bufferLength) {
|
||||||
{
|
for (;;) {
|
||||||
for(;;)
|
|
||||||
{
|
|
||||||
if (wiiuse_os_read(wm, buffer, bufferLength) > 0) {
|
if (wiiuse_os_read(wm, buffer, bufferLength) > 0) {
|
||||||
if (buffer[0] == report) {
|
if (buffer[0] == report) {
|
||||||
break;
|
break;
|
||||||
@@ -147,8 +145,7 @@ void wiiuse_wait_report(struct wiimote_t *wm, int report, byte *buffer, int buff
|
|||||||
* amount of data from the Wiimote.
|
* amount of data from the Wiimote.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data)
|
void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, unsigned short size, byte *data) {
|
||||||
{
|
|
||||||
byte pkt[6];
|
byte pkt[6];
|
||||||
byte buf[MAX_PAYLOAD];
|
byte buf[MAX_PAYLOAD];
|
||||||
unsigned n_full_reports;
|
unsigned n_full_reports;
|
||||||
@@ -176,16 +173,14 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns
|
|||||||
last_report = size % 16;
|
last_report = size % 16;
|
||||||
output = data;
|
output = data;
|
||||||
|
|
||||||
for(i = 0; i < n_full_reports; ++i)
|
for (i = 0; i < n_full_reports; ++i) {
|
||||||
{
|
|
||||||
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
||||||
memmove(output, buf + 6, 16);
|
memmove(output, buf + 6, 16);
|
||||||
output += 16;
|
output += 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the last incomplete packet */
|
/* read the last incomplete packet */
|
||||||
if(last_report)
|
if (last_report) {
|
||||||
{
|
|
||||||
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
wiiuse_wait_report(wm, WM_RPT_READ, buf, MAX_PAYLOAD);
|
||||||
memmove(output, buf + 6, last_report);
|
memmove(output, buf + 6, last_report);
|
||||||
}
|
}
|
||||||
@@ -207,8 +202,7 @@ void wiiuse_read_data_sync(struct wiimote_t *wm, byte memory, unsigned addr, uns
|
|||||||
|
|
||||||
#ifdef WIIUSE_SYNC_HANDSHAKE
|
#ifdef WIIUSE_SYNC_HANDSHAKE
|
||||||
|
|
||||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len)
|
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||||
{
|
|
||||||
/* send request to wiimote for accelerometer calibration */
|
/* send request to wiimote for accelerometer calibration */
|
||||||
byte buf[MAX_PAYLOAD];
|
byte buf[MAX_PAYLOAD];
|
||||||
|
|
||||||
@@ -254,8 +248,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len)
|
|||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||||
|
|
||||||
/* now enable IR if it was set before the handshake completed */
|
/* now enable IR if it was set before the handshake completed */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
{
|
|
||||||
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
WIIUSE_DEBUG("Handshake finished, enabling IR.");
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||||
wiiuse_set_ir(wm, 1);
|
wiiuse_set_ir(wm, 1);
|
||||||
@@ -273,11 +266,12 @@ static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned
|
|||||||
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len);
|
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len);
|
||||||
|
|
||||||
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (wm->handshake_state) {
|
switch (wm->handshake_state) {
|
||||||
case 0:
|
case 0: {
|
||||||
{
|
|
||||||
byte* buf;
|
byte* buf;
|
||||||
|
|
||||||
/* continous reporting off, report to buttons only */
|
/* continous reporting off, report to buttons only */
|
||||||
@@ -301,8 +295,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 1:
|
case 1: {
|
||||||
{
|
|
||||||
struct read_req_t* req = wm->read_req;
|
struct read_req_t* req = wm->read_req;
|
||||||
struct accel_t* accel = &wm->accel_calib;
|
struct accel_t* accel = &wm->accel_calib;
|
||||||
byte val;
|
byte val;
|
||||||
@@ -331,8 +324,7 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case 2:
|
case 2: {
|
||||||
{
|
|
||||||
/* request the status of the wiimote to check for any expansion */
|
/* request the status of the wiimote to check for any expansion */
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE);
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_HANDSHAKE_COMPLETE);
|
||||||
@@ -351,21 +343,18 @@ void wiiuse_handshake(struct wiimote_t* wm, byte* data, uint16_t len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm,byte *data,unsigned short len)
|
static void wiiuse_disable_motion_plus1(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||||
{
|
|
||||||
byte val = 0x00;
|
byte val = 0x00;
|
||||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2);
|
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_disable_motion_plus2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm,byte *data,unsigned short len)
|
static void wiiuse_disable_motion_plus2(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||||
{
|
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||||
wiiuse_set_ir_mode(wm);
|
wiiuse_set_ir_mode(wm);
|
||||||
|
|||||||
131
src/ir.c
131
src/ir.c
@@ -57,15 +57,21 @@ static const byte WM_IR_BLOCK2_LEVEL4[] = "\x35\x03";
|
|||||||
static const byte WM_IR_BLOCK1_LEVEL5[] = "\x07\x00\x00\x71\x01\x00\x72\x00\x20";
|
static const byte WM_IR_BLOCK1_LEVEL5[] = "\x07\x00\x00\x71\x01\x00\x72\x00\x20";
|
||||||
static const byte WM_IR_BLOCK2_LEVEL5[] = "\x1f\x03";
|
static const byte WM_IR_BLOCK2_LEVEL5[] = "\x1f\x03";
|
||||||
|
|
||||||
void wiiuse_set_ir_mode(struct wiimote_t *wm)
|
void wiiuse_set_ir_mode(struct wiimote_t *wm) {
|
||||||
{
|
|
||||||
byte buf = 0x00;
|
byte buf = 0x00;
|
||||||
|
|
||||||
if(!wm) return;
|
if (!wm) {
|
||||||
if(!WIIMOTE_IS_SET(wm,WIIMOTE_STATE_IR)) return;
|
return;
|
||||||
|
}
|
||||||
|
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(WIIMOTE_IS_SET(wm,WIIMOTE_STATE_EXP)) buf = WM_IR_TYPE_BASIC;
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||||
else buf = WM_IR_TYPE_EXTENDED;
|
buf = WM_IR_TYPE_BASIC;
|
||||||
|
} else {
|
||||||
|
buf = WM_IR_TYPE_EXTENDED;
|
||||||
|
}
|
||||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -80,8 +86,9 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
|||||||
const byte* block2 = NULL;
|
const byte* block2 = NULL;
|
||||||
int ir_level;
|
int ir_level;
|
||||||
|
|
||||||
if (!wm)
|
if (!wm) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Wait for the handshake to finish first.
|
* Wait for the handshake to finish first.
|
||||||
@@ -108,13 +115,15 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
|||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
/* if already enabled then stop */
|
/* if already enabled then stop */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||||
} else {
|
} else {
|
||||||
/* if already disabled then stop */
|
/* if already disabled then stop */
|
||||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,10 +150,11 @@ void wiiuse_set_ir(struct wiimote_t* wm, int status) {
|
|||||||
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
wiiuse_write_data(wm, WM_REG_IR_BLOCK2, (byte*)block2, 2);
|
||||||
|
|
||||||
/* set the IR mode */
|
/* set the IR mode */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP)) {
|
||||||
buf = WM_IR_TYPE_BASIC;
|
buf = WM_IR_TYPE_BASIC;
|
||||||
else
|
} else {
|
||||||
buf = WM_IR_TYPE_EXTENDED;
|
buf = WM_IR_TYPE_EXTENDED;
|
||||||
|
}
|
||||||
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
wiiuse_write_data(wm, WM_REG_IR_MODENUM, &buf, 1);
|
||||||
|
|
||||||
wiiuse_millisleep(50);
|
wiiuse_millisleep(50);
|
||||||
@@ -201,7 +211,9 @@ static int get_ir_sens(struct wiimote_t* wm, const byte** block1, const byte** b
|
|||||||
* @param status 1 to enable, 0 to disable.
|
* @param status 1 to enable, 0 to disable.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->ir.vres[0] = (x - 1);
|
wm->ir.vres[0] = (x - 1);
|
||||||
wm->ir.vres[1] = (y - 1);
|
wm->ir.vres[1] = (y - 1);
|
||||||
@@ -214,7 +226,9 @@ void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y) {
|
|||||||
* @param wm Pointer to a wiimote_t structure.
|
* @param wm Pointer to a wiimote_t structure.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->ir.pos = pos;
|
wm->ir.pos = pos;
|
||||||
|
|
||||||
@@ -223,20 +237,22 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
|||||||
case WIIUSE_IR_ABOVE:
|
case WIIUSE_IR_ABOVE:
|
||||||
wm->ir.offset[0] = 0;
|
wm->ir.offset[0] = 0;
|
||||||
|
|
||||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
if (wm->ir.aspect == WIIUSE_ASPECT_16_9) {
|
||||||
wm->ir.offset[1] = WM_ASPECT_16_9_Y / 2 - 70;
|
wm->ir.offset[1] = WM_ASPECT_16_9_Y / 2 - 70;
|
||||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
} else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) {
|
||||||
wm->ir.offset[1] = WM_ASPECT_4_3_Y / 2 - 100;
|
wm->ir.offset[1] = WM_ASPECT_4_3_Y / 2 - 100;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case WIIUSE_IR_BELOW:
|
case WIIUSE_IR_BELOW:
|
||||||
wm->ir.offset[0] = 0;
|
wm->ir.offset[0] = 0;
|
||||||
|
|
||||||
if (wm->ir.aspect == WIIUSE_ASPECT_16_9)
|
if (wm->ir.aspect == WIIUSE_ASPECT_16_9) {
|
||||||
wm->ir.offset[1] = -WM_ASPECT_16_9_Y / 2 + 100;
|
wm->ir.offset[1] = -WM_ASPECT_16_9_Y / 2 + 100;
|
||||||
else if (wm->ir.aspect == WIIUSE_ASPECT_4_3)
|
} else if (wm->ir.aspect == WIIUSE_ASPECT_4_3) {
|
||||||
wm->ir.offset[1] = -WM_ASPECT_4_3_Y / 2 + 70;
|
wm->ir.offset[1] = -WM_ASPECT_4_3_Y / 2 + 70;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -253,7 +269,9 @@ void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos) {
|
|||||||
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
* @param aspect Either WIIUSE_ASPECT_16_9 or WIIUSE_ASPECT_4_3
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->ir.aspect = aspect;
|
wm->ir.aspect = aspect;
|
||||||
|
|
||||||
@@ -283,10 +301,16 @@ void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level) {
|
|||||||
const byte* block1 = NULL;
|
const byte* block1 = NULL;
|
||||||
const byte* block2 = NULL;
|
const byte* block2 = NULL;
|
||||||
|
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (level > 5) level = 5;
|
if (level > 5) {
|
||||||
if (level < 1) level = 1;
|
level = 5;
|
||||||
|
}
|
||||||
|
if (level < 1) {
|
||||||
|
level = 1;
|
||||||
|
}
|
||||||
|
|
||||||
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
WIIMOTE_DISABLE_STATE(wm, (WIIMOTE_STATE_IR_SENS_LVL1 |
|
||||||
WIIMOTE_STATE_IR_SENS_LVL2 |
|
WIIMOTE_STATE_IR_SENS_LVL2 |
|
||||||
@@ -348,9 +372,9 @@ void calculate_basic_ir(struct wiimote_t* wm, byte* data) {
|
|||||||
|
|
||||||
/* set each IR spot to visible if spot is in range */
|
/* set each IR spot to visible if spot is in range */
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
if (dot[i].ry == 1023)
|
if (dot[i].ry == 1023) {
|
||||||
dot[i].visible = 0;
|
dot[i].visible = 0;
|
||||||
else {
|
} else {
|
||||||
dot[i].visible = 1;
|
dot[i].visible = 1;
|
||||||
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
dot[i].size = 0; /* since we don't know the size, set it as 0 */
|
||||||
}
|
}
|
||||||
@@ -377,11 +401,12 @@ void calculate_extended_ir(struct wiimote_t* wm, byte* data) {
|
|||||||
dot[i].size = data[(3 * i) + 2] & 0x0F;
|
dot[i].size = data[(3 * i) + 2] & 0x0F;
|
||||||
|
|
||||||
/* if in range set to visible */
|
/* if in range set to visible */
|
||||||
if (dot[i].ry == 1023)
|
if (dot[i].ry == 1023) {
|
||||||
dot[i].visible = 0;
|
dot[i].visible = 0;
|
||||||
else
|
} else {
|
||||||
dot[i].visible = 1;
|
dot[i].visible = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interpret_ir_data(wm);
|
interpret_ir_data(wm);
|
||||||
}
|
}
|
||||||
@@ -398,24 +423,26 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
float roll = 0.0f;
|
float roll = 0.0f;
|
||||||
int last_num_dots = wm->ir.num_dots;
|
int last_num_dots = wm->ir.num_dots;
|
||||||
|
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC)) {
|
||||||
roll = wm->orient.roll;
|
roll = wm->orient.roll;
|
||||||
|
}
|
||||||
|
|
||||||
/* count visible dots */
|
/* count visible dots */
|
||||||
wm->ir.num_dots = 0;
|
wm->ir.num_dots = 0;
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
if (dot[i].visible)
|
if (dot[i].visible) {
|
||||||
wm->ir.num_dots++;
|
wm->ir.num_dots++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (wm->ir.num_dots) {
|
switch (wm->ir.num_dots) {
|
||||||
case 0:
|
case 0: {
|
||||||
{
|
|
||||||
wm->ir.state = 0;
|
wm->ir.state = 0;
|
||||||
|
|
||||||
/* reset the dot ordering */
|
/* reset the dot ordering */
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i) {
|
||||||
dot[i].order = 0;
|
dot[i].order = 0;
|
||||||
|
}
|
||||||
|
|
||||||
wm->ir.x = 0;
|
wm->ir.x = 0;
|
||||||
wm->ir.y = 0;
|
wm->ir.y = 0;
|
||||||
@@ -423,8 +450,7 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case 1:
|
case 1: {
|
||||||
{
|
|
||||||
fix_rotated_ir_dots(wm->ir.dot, roll);
|
fix_rotated_ir_dots(wm->ir.dot, roll);
|
||||||
|
|
||||||
if (wm->ir.state < 2) {
|
if (wm->ir.state < 2) {
|
||||||
@@ -459,10 +485,13 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
if (dot[i].order == 1)
|
if (dot[i].order == 1)
|
||||||
/* visible is the left dot - estimate where the right is */
|
/* visible is the left dot - estimate where the right is */
|
||||||
|
{
|
||||||
ox = (int32_t)(dot[i].x + wm->ir.distance);
|
ox = (int32_t)(dot[i].x + wm->ir.distance);
|
||||||
else if (dot[i].order == 2)
|
} else if (dot[i].order == 2)
|
||||||
/* visible is the right dot - estimate where the left is */
|
/* visible is the right dot - estimate where the left is */
|
||||||
|
{
|
||||||
ox = (int32_t)(dot[i].x - wm->ir.distance);
|
ox = (int32_t)(dot[i].x - wm->ir.distance);
|
||||||
|
}
|
||||||
|
|
||||||
x = ((signed int)dot[i].x + ox) / 2;
|
x = ((signed int)dot[i].x + ox) / 2;
|
||||||
y = dot[i].y;
|
y = dot[i].y;
|
||||||
@@ -486,8 +515,7 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
}
|
}
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
case 4:
|
case 4: {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Two (or more) dots known and seen.
|
* Two (or more) dots known and seen.
|
||||||
* Average them together to estimate the true location.
|
* Average them together to estimate the true location.
|
||||||
@@ -521,8 +549,7 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default: {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,8 +561,9 @@ static void interpret_ir_data(struct wiimote_t* wm) {
|
|||||||
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
WIIUSE_DEBUG("IR sensitivity: %i", ir_level);
|
||||||
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
WIIUSE_DEBUG("IR visible dots: %i", wm->ir.num_dots);
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i)
|
||||||
if (dot[i].visible)
|
if (dot[i].visible) {
|
||||||
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
WIIUSE_DEBUG("IR[%i][order %i] (%.3i, %.3i) -> (%.3i, %.3i)", i, dot[i].order, dot[i].rx, dot[i].ry, dot[i].x, dot[i].y);
|
||||||
|
}
|
||||||
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
WIIUSE_DEBUG("IR[absolute]: (%i, %i)", wm->ir.x, wm->ir.y);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -579,8 +607,9 @@ static void fix_rotated_ir_dots(struct ir_dot_t* dot, float ang) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
for (i = 0; i < 4; ++i) {
|
for (i = 0; i < 4; ++i) {
|
||||||
if (!dot[i].visible)
|
if (!dot[i].visible) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
x = dot[i].rx - (1024 / 2);
|
x = dot[i].rx - (1024 / 2);
|
||||||
y = dot[i].ry - (768 / 2);
|
y = dot[i].ry - (768 / 2);
|
||||||
@@ -629,20 +658,23 @@ static void reorder_ir_dots(struct ir_dot_t* dot) {
|
|||||||
int i, j, order;
|
int i, j, order;
|
||||||
|
|
||||||
/* reset the dot ordering */
|
/* reset the dot ordering */
|
||||||
for (i = 0; i < 4; ++i)
|
for (i = 0; i < 4; ++i) {
|
||||||
dot[i].order = 0;
|
dot[i].order = 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (order = 1; order < 5; ++order) {
|
for (order = 1; order < 5; ++order) {
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
for (; !dot[i].visible || dot[i].order; ++i)
|
for (; !dot[i].visible || dot[i].order; ++i)
|
||||||
if (i >= 3)
|
if (i >= 3) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (j = 0; j < 4; ++j) {
|
for (j = 0; j < 4; ++j) {
|
||||||
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x))
|
if (dot[j].visible && !dot[j].order && (dot[j].x < dot[i].x)) {
|
||||||
i = j;
|
i = j;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
dot[i].order = order;
|
dot[i].order = order;
|
||||||
}
|
}
|
||||||
@@ -659,16 +691,20 @@ static float ir_distance(struct ir_dot_t* dot) {
|
|||||||
int xd, yd;
|
int xd, yd;
|
||||||
|
|
||||||
for (i1 = 0; i1 < 4; ++i1)
|
for (i1 = 0; i1 < 4; ++i1)
|
||||||
if (dot[i1].visible)
|
if (dot[i1].visible) {
|
||||||
break;
|
break;
|
||||||
if (i1 == 4)
|
}
|
||||||
|
if (i1 == 4) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
for (i2 = i1 + 1; i2 < 4; ++i2)
|
for (i2 = i1 + 1; i2 < 4; ++i2)
|
||||||
if (dot[i2].visible)
|
if (dot[i2].visible) {
|
||||||
break;
|
break;
|
||||||
if (i2 == 4)
|
}
|
||||||
|
if (i2 == 4) {
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
xd = dot[i2].x - dot[i1].x;
|
xd = dot[i2].x - dot[i1].x;
|
||||||
yd = dot[i2].y - dot[i1].y;
|
yd = dot[i2].y - dot[i1].y;
|
||||||
@@ -709,8 +745,7 @@ static int ir_correct_for_bounds(int* x, int* y, enum aspect_t aspect, int offse
|
|||||||
if ((*x >= x0)
|
if ((*x >= x0)
|
||||||
&& (*x <= (x0 + xs))
|
&& (*x <= (x0 + xs))
|
||||||
&& (*y >= y0)
|
&& (*y >= y0)
|
||||||
&& (*y <= (y0 + ys)))
|
&& (*y <= (y0 + ys))) {
|
||||||
{
|
|
||||||
*x -= offset_x;
|
*x -= offset_x;
|
||||||
*y -= offset_y;
|
*y -= offset_y;
|
||||||
|
|
||||||
|
|||||||
@@ -43,16 +43,14 @@ static void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp);
|
|||||||
static void calculate_gyro_rates(struct motion_plus_t* mp);
|
static void calculate_gyro_rates(struct motion_plus_t* mp);
|
||||||
|
|
||||||
|
|
||||||
void wiiuse_probe_motion_plus(struct wiimote_t *wm)
|
void wiiuse_probe_motion_plus(struct wiimote_t *wm) {
|
||||||
{
|
|
||||||
byte buf[MAX_PAYLOAD];
|
byte buf[MAX_PAYLOAD];
|
||||||
unsigned id;
|
unsigned id;
|
||||||
|
|
||||||
wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf);
|
wiiuse_read_data_sync(wm, 0, WM_EXP_MOTION_PLUS_IDENT, 6, buf);
|
||||||
|
|
||||||
/* check error code */
|
/* check error code */
|
||||||
if(buf[4] & 0x0f)
|
if (buf[4] & 0x0f) {
|
||||||
{
|
|
||||||
WIIUSE_DEBUG("No Motion+ available, stopping probe.");
|
WIIUSE_DEBUG("No Motion+ available, stopping probe.");
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
||||||
return;
|
return;
|
||||||
@@ -64,8 +62,7 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm)
|
|||||||
if (id != EXP_ID_CODE_INACTIVE_MOTION_PLUS &&
|
if (id != EXP_ID_CODE_INACTIVE_MOTION_PLUS &&
|
||||||
id != EXP_ID_CODE_NLA_MOTION_PLUS &&
|
id != EXP_ID_CODE_NLA_MOTION_PLUS &&
|
||||||
id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK &&
|
id != EXP_ID_CODE_NLA_MOTION_PLUS_NUNCHUK &&
|
||||||
id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC)
|
id != EXP_ID_CODE_NLA_MOTION_PLUS_CLASSIC) {
|
||||||
{
|
|
||||||
/* we have read something weird */
|
/* we have read something weird */
|
||||||
WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected.");
|
WIIUSE_DEBUG("Motion+ ID doesn't match, probably not connected.");
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_MPLUS_PRESENT);
|
||||||
@@ -105,15 +102,11 @@ void wiiuse_probe_motion_plus(struct wiimote_t *wm)
|
|||||||
wiiuse_set_report_type(wm);
|
wiiuse_set_report_type(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short len)
|
void wiiuse_motion_plus_handshake(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||||
{
|
|
||||||
uint32_t val;
|
uint32_t val;
|
||||||
if(data == NULL)
|
if (data == NULL) {
|
||||||
{
|
|
||||||
wiiuse_read_data_cb(wm, wiiuse_motion_plus_handshake, wm->motion_plus_id, WM_EXP_ID, 6);
|
wiiuse_read_data_cb(wm, wiiuse_motion_plus_handshake, wm->motion_plus_id, WM_EXP_ID, 6);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); /* tell wiimote to include exp. data in reports */
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP); /* tell wiimote to include exp. data in reports */
|
||||||
@@ -122,13 +115,11 @@ void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short
|
|||||||
|
|
||||||
if (val == EXP_ID_CODE_MOTION_PLUS ||
|
if (val == EXP_ID_CODE_MOTION_PLUS ||
|
||||||
val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK ||
|
val == EXP_ID_CODE_MOTION_PLUS_NUNCHUK ||
|
||||||
val == EXP_ID_CODE_MOTION_PLUS_CLASSIC)
|
val == EXP_ID_CODE_MOTION_PLUS_CLASSIC) {
|
||||||
{
|
|
||||||
/* handshake done */
|
/* handshake done */
|
||||||
wm->event = WIIUSE_MOTION_PLUS_ACTIVATED;
|
wm->event = WIIUSE_MOTION_PLUS_ACTIVATED;
|
||||||
|
|
||||||
switch(val)
|
switch (val) {
|
||||||
{
|
|
||||||
case EXP_ID_CODE_MOTION_PLUS:
|
case EXP_ID_CODE_MOTION_PLUS:
|
||||||
wm->exp.type = EXP_MOTION_PLUS;
|
wm->exp.type = EXP_MOTION_PLUS;
|
||||||
break;
|
break;
|
||||||
@@ -171,16 +162,14 @@ void wiiuse_motion_plus_handshake(struct wiimote_t *wm,byte *data,unsigned short
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm,byte *data,unsigned short len)
|
static void wiiuse_set_motion_plus_clear2(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||||
{
|
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_FAILED);
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||||
wiiuse_set_ir_mode(wm);
|
wiiuse_set_ir_mode(wm);
|
||||||
wiiuse_status(wm);
|
wiiuse_status(wm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsigned short len)
|
static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm, byte *data, unsigned short len) {
|
||||||
{
|
|
||||||
byte val = 0x00;
|
byte val = 0x00;
|
||||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear2);
|
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear2);
|
||||||
}
|
}
|
||||||
@@ -192,36 +181,31 @@ static void wiiuse_set_motion_plus_clear1(struct wiimote_t *wm,byte *data,unsign
|
|||||||
* @param status 0 - off, 1 - on, standalone, 2 - nunchuk pass-through
|
* @param status 0 - off, 1 - on, standalone, 2 - nunchuk pass-through
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_motion_plus(struct wiimote_t *wm, int status)
|
void wiiuse_set_motion_plus(struct wiimote_t *wm, int status) {
|
||||||
{
|
|
||||||
byte val;
|
byte val;
|
||||||
|
|
||||||
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) ||
|
if (!WIIMOTE_IS_SET(wm, WIIMOTE_STATE_MPLUS_PRESENT) ||
|
||||||
WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE))
|
WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP_HANDSHAKE)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(status)
|
if (status) {
|
||||||
{
|
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_EXP_HANDSHAKE);
|
||||||
val = (status == 1) ? 0x04 : 0x05;
|
val = (status == 1) ? 0x04 : 0x05;
|
||||||
wiiuse_write_data_cb(wm, WM_EXP_MOTION_PLUS_ENABLE, &val, 1, wiiuse_motion_plus_handshake);
|
wiiuse_write_data_cb(wm, WM_EXP_MOTION_PLUS_ENABLE, &val, 1, wiiuse_motion_plus_handshake);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
disable_expansion(wm);
|
disable_expansion(wm);
|
||||||
val = 0x55;
|
val = 0x55;
|
||||||
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear1);
|
wiiuse_write_data_cb(wm, WM_EXP_MEM_ENABLE1, &val, 1, wiiuse_set_motion_plus_clear1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void motion_plus_disconnected(struct motion_plus_t* mp)
|
void motion_plus_disconnected(struct motion_plus_t* mp) {
|
||||||
{
|
|
||||||
WIIUSE_DEBUG("Motion plus disconnected");
|
WIIUSE_DEBUG("Motion plus disconnected");
|
||||||
memset(mp, 0, sizeof(struct motion_plus_t));
|
memset(mp, 0, sizeof(struct motion_plus_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* Pass-through modes interleave data from the gyro
|
* Pass-through modes interleave data from the gyro
|
||||||
* with the expansion data. This extracts the tag
|
* with the expansion data. This extracts the tag
|
||||||
@@ -230,8 +214,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
|||||||
int isMPFrame = (1 << 1) & msg[5];
|
int isMPFrame = (1 << 1) & msg[5];
|
||||||
mp->ext = msg[4] & 0x1; /* extension attached to pass-through port? */
|
mp->ext = msg[4] & 0x1; /* extension attached to pass-through port? */
|
||||||
|
|
||||||
if (mp->ext == 0 || isMPFrame) /* reading gyro frame */
|
if (mp->ext == 0 || isMPFrame) { /* reading gyro frame */
|
||||||
{
|
|
||||||
/* Check if the gyroscope is in fast or slow mode (0 if rotating fast, 1 if slow or still) */
|
/* 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->acc_mode = ((msg[4] & 0x2) << 1) | ((msg[3] & 0x1) << 1) | ((msg[3] & 0x2) >> 1);
|
||||||
|
|
||||||
@@ -248,8 +231,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
|||||||
(mp->raw_gyro.yaw < 0x3fff) &&
|
(mp->raw_gyro.yaw < 0x3fff) &&
|
||||||
!(mp->cal_gyro.roll) &&
|
!(mp->cal_gyro.roll) &&
|
||||||
!(mp->cal_gyro.pitch) &&
|
!(mp->cal_gyro.pitch) &&
|
||||||
!(mp->cal_gyro.yaw))
|
!(mp->cal_gyro.yaw)) {
|
||||||
{
|
|
||||||
wiiuse_calibrate_motion_plus(mp);
|
wiiuse_calibrate_motion_plus(mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,11 +239,9 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
|||||||
calculate_gyro_rates(mp);
|
calculate_gyro_rates(mp);
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
/* expansion frame */
|
/* expansion frame */
|
||||||
if (exp_type == EXP_MOTION_PLUS_NUNCHUK)
|
if (exp_type == EXP_MOTION_PLUS_NUNCHUK) {
|
||||||
{
|
|
||||||
/* ok, this is nunchuck, re-encode it as regular nunchuck packet */
|
/* ok, this is nunchuck, re-encode it as regular nunchuck packet */
|
||||||
|
|
||||||
/* get button states */
|
/* get button states */
|
||||||
@@ -286,13 +266,11 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (exp_type == EXP_MOTION_PLUS_CLASSIC)
|
else if (exp_type == EXP_MOTION_PLUS_CLASSIC) {
|
||||||
{
|
|
||||||
WIIUSE_ERROR("Classic controller pass-through is not implemented!\n");
|
WIIUSE_ERROR("Classic controller pass-through is not implemented!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
WIIUSE_ERROR("Unsupported mode passed to motion_plus_event() !\n");
|
WIIUSE_ERROR("Unsupported mode passed to motion_plus_event() !\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -306,8 +284,7 @@ void motion_plus_event(struct motion_plus_t* mp, int exp_type, byte* msg)
|
|||||||
* This should be called only after receiving the first values
|
* This should be called only after receiving the first values
|
||||||
* from the Motion Plus.
|
* from the Motion Plus.
|
||||||
*/
|
*/
|
||||||
void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp)
|
void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp) {
|
||||||
{
|
|
||||||
mp->cal_gyro.roll = mp->raw_gyro.roll;
|
mp->cal_gyro.roll = mp->raw_gyro.roll;
|
||||||
mp->cal_gyro.pitch = mp->raw_gyro.pitch;
|
mp->cal_gyro.pitch = mp->raw_gyro.pitch;
|
||||||
mp->cal_gyro.yaw = mp->raw_gyro.yaw;
|
mp->cal_gyro.yaw = mp->raw_gyro.yaw;
|
||||||
@@ -316,8 +293,7 @@ void wiiuse_calibrate_motion_plus(struct motion_plus_t *mp)
|
|||||||
mp->orient.yaw = 0.0;
|
mp->orient.yaw = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void calculate_gyro_rates(struct motion_plus_t* mp)
|
static void calculate_gyro_rates(struct motion_plus_t* mp) {
|
||||||
{
|
|
||||||
short int tmp_r, tmp_p, tmp_y;
|
short int tmp_r, tmp_p, tmp_y;
|
||||||
float tmp_roll, tmp_pitch, tmp_yaw;
|
float tmp_roll, tmp_pitch, tmp_yaw;
|
||||||
|
|
||||||
@@ -327,28 +303,34 @@ static void calculate_gyro_rates(struct motion_plus_t* mp)
|
|||||||
tmp_y = mp->raw_gyro.yaw - mp->cal_gyro.yaw;
|
tmp_y = mp->raw_gyro.yaw - mp->cal_gyro.yaw;
|
||||||
|
|
||||||
/* We convert to degree/sec according to fast/slow mode */
|
/* We convert to degree/sec according to fast/slow mode */
|
||||||
if (mp->acc_mode & 0x04)
|
if (mp->acc_mode & 0x04) {
|
||||||
tmp_roll = (float)tmp_r / 20.0f;
|
tmp_roll = (float)tmp_r / 20.0f;
|
||||||
else
|
} else {
|
||||||
tmp_roll = (float)tmp_r / 4.0f;
|
tmp_roll = (float)tmp_r / 4.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (mp->acc_mode & 0x02)
|
if (mp->acc_mode & 0x02) {
|
||||||
tmp_pitch = (float)tmp_p / 20.0f;
|
tmp_pitch = (float)tmp_p / 20.0f;
|
||||||
else
|
} else {
|
||||||
tmp_pitch = (float)tmp_p / 4.0f;
|
tmp_pitch = (float)tmp_p / 4.0f;
|
||||||
|
}
|
||||||
|
|
||||||
if (mp->acc_mode & 0x01)
|
if (mp->acc_mode & 0x01) {
|
||||||
tmp_yaw = (float)tmp_y / 20.0f;
|
tmp_yaw = (float)tmp_y / 20.0f;
|
||||||
else
|
} else {
|
||||||
tmp_yaw = (float)tmp_y / 4.0f;
|
tmp_yaw = (float)tmp_y / 4.0f;
|
||||||
|
}
|
||||||
|
|
||||||
/* Simple filtering */
|
/* Simple filtering */
|
||||||
if (fabs(tmp_roll) < 0.5f)
|
if (fabs(tmp_roll) < 0.5f) {
|
||||||
tmp_roll = 0.0f;
|
tmp_roll = 0.0f;
|
||||||
if (fabs(tmp_pitch) < 0.5f)
|
}
|
||||||
|
if (fabs(tmp_pitch) < 0.5f) {
|
||||||
tmp_pitch = 0.0f;
|
tmp_pitch = 0.0f;
|
||||||
if (fabs(tmp_yaw) < 0.5f)
|
}
|
||||||
|
if (fabs(tmp_yaw) < 0.5f) {
|
||||||
tmp_yaw = 0.0f;
|
tmp_yaw = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
mp->angle_rate_gyro.roll = tmp_roll;
|
mp->angle_rate_gyro.roll = tmp_roll;
|
||||||
mp->angle_rate_gyro.pitch = tmp_pitch;
|
mp->angle_rate_gyro.pitch = tmp_pitch;
|
||||||
|
|||||||
@@ -77,9 +77,10 @@ int nunchuk_handshake(struct wiimote_t* wm, struct nunchuk_t* nc, byte* data, un
|
|||||||
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
wiiuse_read_data_cb(wm, handshake_expansion, handshake_buf, WM_EXP_MEM_CALIBR, EXP_HANDSHAKE_LEN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else {
|
||||||
data += 16;
|
data += 16;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nc->accel_calib.cal_zero.x = data[0];
|
nc->accel_calib.cal_zero.x = data[0];
|
||||||
nc->accel_calib.cal_zero.y = data[1];
|
nc->accel_calib.cal_zero.y = data[1];
|
||||||
@@ -177,7 +178,9 @@ void nunchuk_pressed_buttons(struct nunchuk_t* nc, byte now) {
|
|||||||
* See wiiuse_set_orient_threshold() for details.
|
* See wiiuse_set_orient_threshold() for details.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->exp.nunchuk.orient_threshold = threshold;
|
wm->exp.nunchuk.orient_threshold = threshold;
|
||||||
}
|
}
|
||||||
@@ -192,7 +195,9 @@ void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold)
|
|||||||
* See wiiuse_set_orient_threshold() for details.
|
* See wiiuse_set_orient_threshold() for details.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->exp.nunchuk.accel_threshold = threshold;
|
wm->exp.nunchuk.accel_threshold = threshold;
|
||||||
}
|
}
|
||||||
|
|||||||
36
src/os_nix.c
36
src/os_nix.c
@@ -100,8 +100,7 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
|||||||
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
for (i = 0; (i < found_devices) && (found_wiimotes < max_wiimotes); ++i) {
|
||||||
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
if ((scan_info[i].dev_class[0] == WM_DEV_CLASS_0) &&
|
||||||
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
(scan_info[i].dev_class[1] == WM_DEV_CLASS_1) &&
|
||||||
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2))
|
(scan_info[i].dev_class[2] == WM_DEV_CLASS_2)) {
|
||||||
{
|
|
||||||
/* found a device */
|
/* found a device */
|
||||||
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
ba2str(&scan_info[i].bdaddr, wm[found_wiimotes]->bdaddr_str);
|
||||||
|
|
||||||
@@ -129,11 +128,14 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) {
|
|||||||
for (; i < wiimotes; ++i) {
|
for (; i < wiimotes; ++i) {
|
||||||
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
if (!WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_DEV_FOUND))
|
||||||
/* if the device address is not set, skip it */
|
/* if the device address is not set, skip it */
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (wiiuse_os_connect_single(wm[i], NULL))
|
if (wiiuse_os_connect_single(wm[i], NULL)) {
|
||||||
++connected;
|
++connected;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
@@ -152,16 +154,17 @@ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) {
|
|||||||
struct sockaddr_l2 addr;
|
struct sockaddr_l2 addr;
|
||||||
memset(&addr, 0, sizeof(addr));
|
memset(&addr, 0, sizeof(addr));
|
||||||
|
|
||||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
addr.l2_family = AF_BLUETOOTH;
|
addr.l2_family = AF_BLUETOOTH;
|
||||||
bdaddr_t *bdaddr = &wm->bdaddr;
|
bdaddr_t *bdaddr = &wm->bdaddr;
|
||||||
if (address)
|
if (address)
|
||||||
/* use provided address */
|
/* use provided address */
|
||||||
str2ba(address, &addr.l2_bdaddr);
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
|
str2ba(address, &addr.l2_bdaddr);
|
||||||
|
} else {
|
||||||
/** @todo this line doesn't make sense
|
/** @todo this line doesn't make sense
|
||||||
bacmp(bdaddr, BDADDR_ANY);*/
|
bacmp(bdaddr, BDADDR_ANY);*/
|
||||||
/* use address of device discovered */
|
/* use address of device discovered */
|
||||||
@@ -173,8 +176,9 @@ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) {
|
|||||||
* OUTPUT CHANNEL
|
* OUTPUT CHANNEL
|
||||||
*/
|
*/
|
||||||
wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
wm->out_sock = socket(AF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP);
|
||||||
if (wm->out_sock == -1)
|
if (wm->out_sock == -1) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
addr.l2_psm = htobs(WM_OUTPUT_CHANNEL);
|
||||||
|
|
||||||
@@ -216,8 +220,9 @@ static int wiiuse_os_connect_single(struct wiimote_t* wm, char* address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
close(wm->out_sock);
|
close(wm->out_sock);
|
||||||
close(wm->in_sock);
|
close(wm->in_sock);
|
||||||
@@ -241,7 +246,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
|||||||
int highest_fd = -1;
|
int highest_fd = -1;
|
||||||
|
|
||||||
evnt = 0;
|
evnt = 0;
|
||||||
if (!wm) return 0;
|
if (!wm) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* block select() for 1/2000th of a second */
|
/* block select() for 1/2000th of a second */
|
||||||
tv.tv_sec = 0;
|
tv.tv_sec = 0;
|
||||||
@@ -255,16 +262,19 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
|||||||
FD_SET(wm[i]->in_sock, &fds);
|
FD_SET(wm[i]->in_sock, &fds);
|
||||||
|
|
||||||
/* find the highest fd of the connected wiimotes */
|
/* find the highest fd of the connected wiimotes */
|
||||||
if (wm[i]->in_sock > highest_fd)
|
if (wm[i]->in_sock > highest_fd) {
|
||||||
highest_fd = wm[i]->in_sock;
|
highest_fd = wm[i]->in_sock;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wm[i]->event = WIIUSE_NONE;
|
wm[i]->event = WIIUSE_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highest_fd == -1)
|
if (highest_fd == -1)
|
||||||
/* nothing to poll */
|
/* nothing to poll */
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
|
if (select(highest_fd + 1, &fds, NULL, NULL, &tv) == -1) {
|
||||||
WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
|
WIIUSE_ERROR("Unable to select() the wiimote interrupt socket(s).");
|
||||||
@@ -275,8 +285,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
|||||||
/* check each socket for an event */
|
/* check each socket for an event */
|
||||||
for (i = 0; i < wiimotes; ++i) {
|
for (i = 0; i < wiimotes; ++i) {
|
||||||
/* if this wiimote is not connected, skip it */
|
/* if this wiimote is not connected, skip it */
|
||||||
if (!WIIMOTE_IS_CONNECTED(wm[i]))
|
if (!WIIMOTE_IS_CONNECTED(wm[i])) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
if (FD_ISSET(wm[i]->in_sock, &fds)) {
|
||||||
/* clear out the event buffer */
|
/* clear out the event buffer */
|
||||||
@@ -352,8 +363,9 @@ int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len)
|
|||||||
memcpy(write_buffer + 2, buf, len);
|
memcpy(write_buffer + 2, buf, len);
|
||||||
rc = write(wm->out_sock, write_buffer, len + 2);
|
rc = write(wm->out_sock, write_buffer, len + 2);
|
||||||
|
|
||||||
if(rc < 0)
|
if (rc < 0) {
|
||||||
wiiuse_disconnected(wm);
|
wiiuse_disconnected(wm);
|
||||||
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|||||||
43
src/os_win.c
43
src/os_win.c
@@ -84,8 +84,9 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* query the next hid device info */
|
/* query the next hid device info */
|
||||||
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data))
|
if (!SetupDiEnumDeviceInterfaces(device_info, NULL, &device_id, index, &device_data)) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* get the size of the data block required */
|
/* get the size of the data block required */
|
||||||
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
i = SetupDiGetDeviceInterfaceDetail(device_info, &device_data, NULL, 0, &len, NULL);
|
||||||
@@ -93,16 +94,18 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
|||||||
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
detail_data->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||||
|
|
||||||
/* query the data for this device */
|
/* query the data for this device */
|
||||||
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL))
|
if (!SetupDiGetDeviceInterfaceDetail(device_info, &device_data, detail_data, len, NULL, NULL)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* open the device */
|
/* open the device */
|
||||||
dev = CreateFile(detail_data->DevicePath,
|
dev = CreateFile(detail_data->DevicePath,
|
||||||
(GENERIC_READ | GENERIC_WRITE),
|
(GENERIC_READ | GENERIC_WRITE),
|
||||||
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
(FILE_SHARE_READ | FILE_SHARE_WRITE),
|
||||||
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||||
if (dev == INVALID_HANDLE_VALUE)
|
if (dev == INVALID_HANDLE_VALUE) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
/* get device attributes */
|
/* get device attributes */
|
||||||
attr.Size = sizeof(attr);
|
attr.Size = sizeof(attr);
|
||||||
@@ -131,16 +134,18 @@ int wiiuse_os_find(struct wiimote_t** wm, int max_wiimotes, int timeout) {
|
|||||||
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
WIIUSE_INFO("Connected to wiimote [id %i].", wm[found]->unid);
|
||||||
|
|
||||||
++found;
|
++found;
|
||||||
if (found >= max_wiimotes)
|
if (found >= max_wiimotes) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
/* not a wiimote */
|
/* not a wiimote */
|
||||||
CloseHandle(dev);
|
CloseHandle(dev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (detail_data)
|
if (detail_data) {
|
||||||
free(detail_data);
|
free(detail_data);
|
||||||
|
}
|
||||||
|
|
||||||
SetupDiDestroyDeviceInfoList(device_info);
|
SetupDiDestroyDeviceInfoList(device_info);
|
||||||
|
|
||||||
@@ -153,19 +158,22 @@ int wiiuse_os_connect(struct wiimote_t** wm, int wiimotes) {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
for (; i < wiimotes; ++i) {
|
for (; i < wiimotes; ++i) {
|
||||||
if (!wm[i])
|
if (!wm[i]) {
|
||||||
continue;
|
continue;
|
||||||
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED))
|
}
|
||||||
|
if (WIIMOTE_IS_SET(wm[i], WIIMOTE_STATE_CONNECTED)) {
|
||||||
++connected;
|
++connected;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return connected;
|
return connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
void wiiuse_os_disconnect(struct wiimote_t* wm) {
|
||||||
if (!wm || WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
CloseHandle(wm->dev_handle);
|
CloseHandle(wm->dev_handle);
|
||||||
wm->dev_handle = 0;
|
wm->dev_handle = 0;
|
||||||
@@ -184,7 +192,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
|||||||
byte read_buffer[MAX_PAYLOAD];
|
byte read_buffer[MAX_PAYLOAD];
|
||||||
int evnt = 0;
|
int evnt = 0;
|
||||||
|
|
||||||
if (!wm) return 0;
|
if (!wm) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < wiimotes; ++i) {
|
for (i = 0; i < wiimotes; ++i) {
|
||||||
wm[i]->event = WIIUSE_NONE;
|
wm[i]->event = WIIUSE_NONE;
|
||||||
@@ -209,8 +219,9 @@ int wiiuse_os_poll(struct wiimote_t** wm, int wiimotes) {
|
|||||||
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
||||||
DWORD b, r;
|
DWORD b, r;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ReadFile(wm->dev_handle, buf, len, &b, &wm->hid_overlap)) {
|
if (!ReadFile(wm->dev_handle, buf, len, &b, &wm->hid_overlap)) {
|
||||||
/* partial read */
|
/* partial read */
|
||||||
@@ -226,8 +237,9 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
|||||||
if (r == WAIT_TIMEOUT) {
|
if (r == WAIT_TIMEOUT) {
|
||||||
/* timeout - cancel and continue */
|
/* timeout - cancel and continue */
|
||||||
|
|
||||||
if (*buf)
|
if (*buf) {
|
||||||
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
|
WIIUSE_WARNING("Packet ignored. This may indicate a problem (timeout is %i ms).", wm->timeout);
|
||||||
|
}
|
||||||
|
|
||||||
CancelIo(wm->dev_handle);
|
CancelIo(wm->dev_handle);
|
||||||
ResetEvent(wm->hid_overlap.hEvent);
|
ResetEvent(wm->hid_overlap.hEvent);
|
||||||
@@ -237,8 +249,9 @@ int wiiuse_os_read(struct wiimote_t* wm, byte* buf, int len) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0))
|
if (!GetOverlappedResult(wm->dev_handle, &wm->hid_overlap, &b, 0)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* log the received data */
|
/* log the received data */
|
||||||
#ifdef WITH_WIIUSE_DEBUG
|
#ifdef WITH_WIIUSE_DEBUG
|
||||||
@@ -263,15 +276,15 @@ int wiiuse_os_write(struct wiimote_t* wm, byte report_type, byte* buf, int len)
|
|||||||
int i;
|
int i;
|
||||||
byte write_buffer[MAX_PAYLOAD];
|
byte write_buffer[MAX_PAYLOAD];
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
write_buffer[0] = report_type;
|
write_buffer[0] = report_type;
|
||||||
memcpy(write_buffer + 1, buf, len);
|
memcpy(write_buffer + 1, buf, len);
|
||||||
|
|
||||||
switch (wm->stack) {
|
switch (wm->stack) {
|
||||||
case WIIUSE_STACK_UNKNOWN:
|
case WIIUSE_STACK_UNKNOWN: {
|
||||||
{
|
|
||||||
/* try to auto-detect the stack type */
|
/* try to auto-detect the stack type */
|
||||||
if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) {
|
if (i = WriteFile(wm->dev_handle, write_buffer, 22, &bytes, &wm->hid_overlap)) {
|
||||||
/* bluesoleil will always return 1 here, even if it's not connected */
|
/* bluesoleil will always return 1 here, even if it's not connected */
|
||||||
|
|||||||
@@ -53,12 +53,11 @@ int wii_board_handshake(struct wiimote_t* wm, struct wii_board_t* wb, byte* data
|
|||||||
#ifdef WITH_WIIUSE_DEBUG
|
#ifdef WITH_WIIUSE_DEBUG
|
||||||
int i;
|
int i;
|
||||||
printf("DECRYPTED DATA WIIBOARD\n");
|
printf("DECRYPTED DATA WIIBOARD\n");
|
||||||
for (i = 0; i < len; ++i)
|
for (i = 0; i < len; ++i) {
|
||||||
{
|
if (i % 16 == 0) {
|
||||||
if(i%16==0)
|
if (i != 0) {
|
||||||
{
|
|
||||||
if(i!=0)
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
printf("%X: ", 0x4a40000 + 32 + i);
|
printf("%X: ", 0x4a40000 + 32 + i);
|
||||||
}
|
}
|
||||||
@@ -143,6 +142,5 @@ void wii_board_event(struct wii_board_t* wb, byte* msg) {
|
|||||||
/**
|
/**
|
||||||
@todo not implemented!
|
@todo not implemented!
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_wii_board_calib(struct wiimote_t *wm)
|
void wiiuse_set_wii_board_calib(struct wiimote_t *wm) {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|||||||
186
src/wiiuse.c
186
src/wiiuse.c
@@ -67,8 +67,7 @@ FILE* logtarget[4];
|
|||||||
*
|
*
|
||||||
* The default <code>FILE*</code> for all loglevels is <code>stderr</code>
|
* The default <code>FILE*</code> for all loglevels is <code>stderr</code>
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile)
|
void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile) {
|
||||||
{
|
|
||||||
logtarget[(int)loglevel] = logfile;
|
logtarget[(int)loglevel] = logfile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,8 +77,9 @@ void wiiuse_set_output(enum wiiuse_loglevel loglevel, FILE *logfile)
|
|||||||
void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
|
void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if (!wm)
|
if (!wm) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_INFO("wiiuse clean up...");
|
WIIUSE_INFO("wiiuse clean up...");
|
||||||
|
|
||||||
@@ -131,8 +131,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
|||||||
logtarget[2] = stderr;
|
logtarget[2] = stderr;
|
||||||
logtarget[3] = stderr;
|
logtarget[3] = stderr;
|
||||||
|
|
||||||
if (!wiimotes)
|
if (!wiimotes) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
|
wm = malloc(sizeof(struct wiimote_t*) * wiimotes);
|
||||||
|
|
||||||
@@ -170,7 +171,9 @@ struct wiimote_t** wiiuse_init(int wiimotes) {
|
|||||||
* @param wm Pointer to a wiimote_t structure.
|
* @param wm Pointer to a wiimote_t structure.
|
||||||
*/
|
*/
|
||||||
void wiiuse_disconnected(struct wiimote_t* wm) {
|
void wiiuse_disconnected(struct wiimote_t* wm) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
|
WIIUSE_INFO("Wiimote disconnected [id %i].", wm->unid);
|
||||||
|
|
||||||
@@ -201,8 +204,9 @@ void wiiuse_disconnected(struct wiimote_t* wm) {
|
|||||||
void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
||||||
byte buf;
|
byte buf;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* make sure to keep the current lit leds */
|
/* make sure to keep the current lit leds */
|
||||||
buf = wm->leds;
|
buf = wm->leds;
|
||||||
@@ -218,8 +222,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* preserve IR state */
|
/* preserve IR state */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||||
buf |= 0x04;
|
buf |= 0x04;
|
||||||
|
}
|
||||||
|
|
||||||
wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
|
wiiuse_send(wm, WM_CMD_RUMBLE, &buf, 1);
|
||||||
}
|
}
|
||||||
@@ -231,7 +236,9 @@ void wiiuse_rumble(struct wiimote_t* wm, int status) {
|
|||||||
* @param wm Pointer to a wiimote_t structure.
|
* @param wm Pointer to a wiimote_t structure.
|
||||||
*/
|
*/
|
||||||
void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
|
wiiuse_rumble(wm, !WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE));
|
||||||
}
|
}
|
||||||
@@ -248,15 +255,17 @@ void wiiuse_toggle_rumble(struct wiimote_t* wm) {
|
|||||||
void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
||||||
byte buf;
|
byte buf;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* remove the lower 4 bits because they control rumble */
|
/* remove the lower 4 bits because they control rumble */
|
||||||
wm->leds = (leds & 0xF0);
|
wm->leds = (leds & 0xF0);
|
||||||
|
|
||||||
/* make sure if the rumble is on that we keep it on */
|
/* make sure if the rumble is on that we keep it on */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||||
wm->leds |= 0x01;
|
wm->leds |= 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
buf = wm->leds;
|
buf = wm->leds;
|
||||||
|
|
||||||
@@ -275,10 +284,11 @@ void wiiuse_set_leds(struct wiimote_t* wm, int leds) {
|
|||||||
* by default.
|
* by default.
|
||||||
*/
|
*/
|
||||||
void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
|
void wiiuse_motion_sensing(struct wiimote_t* wm, int status) {
|
||||||
if (status)
|
if (status) {
|
||||||
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
WIIMOTE_ENABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||||
else
|
} else {
|
||||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_ACC);
|
||||||
|
}
|
||||||
|
|
||||||
wiiuse_set_report_type(wm);
|
wiiuse_set_report_type(wm);
|
||||||
}
|
}
|
||||||
@@ -300,34 +310,46 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
|
|||||||
byte buf[2];
|
byte buf[2];
|
||||||
int motion, exp, ir;
|
int motion, exp, ir;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
|
buf[0] = (WIIMOTE_IS_FLAG_SET(wm, WIIUSE_CONTINUOUS) ? 0x04 : 0x00); /* set to 0x04 for continuous reporting */
|
||||||
buf[1] = 0x00;
|
buf[1] = 0x00;
|
||||||
|
|
||||||
/* if rumble is enabled, make sure we keep it */
|
/* if rumble is enabled, make sure we keep it */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||||
buf[0] |= 0x01;
|
buf[0] |= 0x01;
|
||||||
|
}
|
||||||
|
|
||||||
motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
|
motion = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_ACC);
|
||||||
exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
|
exp = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_EXP);
|
||||||
ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
|
ir = WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR);
|
||||||
|
|
||||||
if (motion && ir && exp) buf[1] = WM_RPT_BTN_ACC_IR_EXP;
|
if (motion && ir && exp) {
|
||||||
else if (motion && exp) buf[1] = WM_RPT_BTN_ACC_EXP;
|
buf[1] = WM_RPT_BTN_ACC_IR_EXP;
|
||||||
else if (motion && ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
} else if (motion && exp) {
|
||||||
else if (ir && exp) buf[1] = WM_RPT_BTN_IR_EXP;
|
buf[1] = WM_RPT_BTN_ACC_EXP;
|
||||||
else if (ir) buf[1] = WM_RPT_BTN_ACC_IR;
|
} else if (motion && ir) {
|
||||||
else if (exp) buf[1] = WM_RPT_BTN_EXP;
|
buf[1] = WM_RPT_BTN_ACC_IR;
|
||||||
else if (motion) buf[1] = WM_RPT_BTN_ACC;
|
} else if (ir && exp) {
|
||||||
else buf[1] = WM_RPT_BTN;
|
buf[1] = WM_RPT_BTN_IR_EXP;
|
||||||
|
} else if (ir) {
|
||||||
|
buf[1] = WM_RPT_BTN_ACC_IR;
|
||||||
|
} else if (exp) {
|
||||||
|
buf[1] = WM_RPT_BTN_EXP;
|
||||||
|
} else if (motion) {
|
||||||
|
buf[1] = WM_RPT_BTN_ACC;
|
||||||
|
} else {
|
||||||
|
buf[1] = WM_RPT_BTN;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
|
WIIUSE_DEBUG("Setting report type: 0x%x", buf[1]);
|
||||||
|
|
||||||
exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
|
exp = wiiuse_send(wm, WM_CMD_REPORT_TYPE, buf, 2);
|
||||||
if (exp <= 0)
|
if (exp <= 0) {
|
||||||
return exp;
|
return exp;
|
||||||
|
}
|
||||||
|
|
||||||
return buf[1];
|
return buf[1];
|
||||||
}
|
}
|
||||||
@@ -353,15 +375,18 @@ int wiiuse_set_report_type(struct wiimote_t* wm) {
|
|||||||
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, uint16_t len) {
|
int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buffer, unsigned int addr, uint16_t len) {
|
||||||
struct read_req_t* req;
|
struct read_req_t* req;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
if (!buffer || !len)
|
}
|
||||||
|
if (!buffer || !len) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* make this request structure */
|
/* make this request structure */
|
||||||
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
req = (struct read_req_t*)malloc(sizeof(struct read_req_t));
|
||||||
if (req == NULL)
|
if (req == NULL) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
req->cb = read_cb;
|
req->cb = read_cb;
|
||||||
req->buf = buffer;
|
req->buf = buffer;
|
||||||
req->addr = addr;
|
req->addr = addr;
|
||||||
@@ -381,7 +406,9 @@ int wiiuse_read_data_cb(struct wiimote_t* wm, wiiuse_read_cb read_cb, byte* buff
|
|||||||
wiiuse_send_next_pending_read_request(wm);
|
wiiuse_send_next_pending_read_request(wm);
|
||||||
} else {
|
} else {
|
||||||
struct read_req_t* nptr = wm->read_req;
|
struct read_req_t* nptr = wm->read_req;
|
||||||
for (; nptr->next; nptr = nptr->next);
|
for (; nptr->next; nptr = nptr->next) {
|
||||||
|
;
|
||||||
|
}
|
||||||
nptr->next = req;
|
nptr->next = req;
|
||||||
|
|
||||||
WIIUSE_DEBUG("Added pending data read request.");
|
WIIUSE_DEBUG("Added pending data read request.");
|
||||||
@@ -425,16 +452,21 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
|||||||
byte buf[6];
|
byte buf[6];
|
||||||
struct read_req_t* req;
|
struct read_req_t* req;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
if (!wm->read_req) return;
|
}
|
||||||
|
if (!wm->read_req) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* skip over dirty ones since they have already been read */
|
/* skip over dirty ones since they have already been read */
|
||||||
req = wm->read_req;
|
req = wm->read_req;
|
||||||
while (req && req->dirty)
|
while (req && req->dirty) {
|
||||||
req = req->next;
|
req = req->next;
|
||||||
if (!req)
|
}
|
||||||
|
if (!req) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* the offset is in big endian */
|
/* the offset is in big endian */
|
||||||
to_big_endian_uint32_t(buf, req->addr);
|
to_big_endian_uint32_t(buf, req->addr);
|
||||||
@@ -457,8 +489,9 @@ void wiiuse_send_next_pending_read_request(struct wiimote_t* wm) {
|
|||||||
void wiiuse_status(struct wiimote_t* wm) {
|
void wiiuse_status(struct wiimote_t* wm) {
|
||||||
byte buf = 0;
|
byte buf = 0;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_DEBUG("Requested wiimote status.");
|
WIIUSE_DEBUG("Requested wiimote status.");
|
||||||
|
|
||||||
@@ -477,15 +510,18 @@ void wiiuse_status(struct wiimote_t* wm) {
|
|||||||
*/
|
*/
|
||||||
struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
|
struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid) {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (!wm)
|
if (!wm) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
for (; i < wiimotes; ++i) {
|
for (; i < wiimotes; ++i) {
|
||||||
if (!wm[i])
|
if (!wm[i]) {
|
||||||
continue;
|
continue;
|
||||||
if (wm[i]->unid == unid)
|
}
|
||||||
|
if (wm[i]->unid == unid) {
|
||||||
return wm[i];
|
return wm[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -503,10 +539,12 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data,
|
|||||||
byte buf[21] = {0}; /* the payload is always 23 */
|
byte buf[21] = {0}; /* the payload is always 23 */
|
||||||
|
|
||||||
byte * bufPtr = buf;
|
byte * bufPtr = buf;
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return 0;
|
return 0;
|
||||||
if (!data || !len)
|
}
|
||||||
|
if (!data || !len) {
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
|
WIIUSE_DEBUG("Writing %i bytes to memory location 0x%x...", len, addr);
|
||||||
|
|
||||||
@@ -514,8 +552,9 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data,
|
|||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
printf("Write data is: ");
|
printf("Write data is: ");
|
||||||
for (; i < len; ++i)
|
for (; i < len; ++i) {
|
||||||
printf("%x ", data[i]);
|
printf("%x ", data[i]);
|
||||||
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -549,12 +588,15 @@ int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, const byte* data,
|
|||||||
* to a pending list and be sent out when the previous
|
* to a pending list and be sent out when the previous
|
||||||
* finishes.
|
* finishes.
|
||||||
*/
|
*/
|
||||||
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb)
|
int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, byte len, wiiuse_write_cb write_cb) {
|
||||||
{
|
|
||||||
struct data_req_t* req;
|
struct data_req_t* req;
|
||||||
|
|
||||||
if(!wm || !WIIMOTE_IS_CONNECTED(wm)) return 0;
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
if( !data || !len ) return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
if (!data || !len) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
req = (struct data_req_t*)malloc(sizeof(struct data_req_t));
|
req = (struct data_req_t*)malloc(sizeof(struct data_req_t));
|
||||||
req->cb = write_cb;
|
req->cb = write_cb;
|
||||||
@@ -575,7 +617,9 @@ int wiiuse_write_data_cb(struct wiimote_t *wm, unsigned int addr, byte *data, by
|
|||||||
} else {
|
} else {
|
||||||
struct data_req_t* nptr = wm->data_req;
|
struct data_req_t* nptr = wm->data_req;
|
||||||
WIIUSE_DEBUG("chaud2fois");
|
WIIUSE_DEBUG("chaud2fois");
|
||||||
for (; nptr->next; nptr = nptr->next);
|
for (; nptr->next; nptr = nptr->next) {
|
||||||
|
;
|
||||||
|
}
|
||||||
nptr->next = req;
|
nptr->next = req;
|
||||||
|
|
||||||
WIIUSE_DEBUG("Added pending data write request.");
|
WIIUSE_DEBUG("Added pending data write request.");
|
||||||
@@ -596,14 +640,19 @@ WIIUSE_DEBUG("chaud2fois");
|
|||||||
void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) {
|
void wiiuse_send_next_pending_write_request(struct wiimote_t* wm) {
|
||||||
struct data_req_t* req;
|
struct data_req_t* req;
|
||||||
|
|
||||||
if (!wm || !WIIMOTE_IS_CONNECTED(wm))
|
if (!wm || !WIIMOTE_IS_CONNECTED(wm)) {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
req = wm->data_req;
|
req = wm->data_req;
|
||||||
if (!req)
|
if (!req) {
|
||||||
return;
|
return;
|
||||||
if (!req->data || !req->len)
|
}
|
||||||
|
if (!req->data || !req->len) {
|
||||||
return;
|
return;
|
||||||
if(req->state!=REQ_READY) return;
|
}
|
||||||
|
if (req->state != REQ_READY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wiiuse_write_data(wm, req->addr, req->data, req->len);
|
wiiuse_write_data(wm, req->addr, req->data, req->len);
|
||||||
|
|
||||||
@@ -625,11 +674,11 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
|||||||
switch (report_type) {
|
switch (report_type) {
|
||||||
case WM_CMD_LED:
|
case WM_CMD_LED:
|
||||||
case WM_CMD_RUMBLE:
|
case WM_CMD_RUMBLE:
|
||||||
case WM_CMD_CTRL_STATUS:
|
case WM_CMD_CTRL_STATUS: {
|
||||||
{
|
|
||||||
/* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
|
/* Rumble flag for: 0x11, 0x13, 0x14, 0x15, 0x19 or 0x1a */
|
||||||
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE))
|
if (WIIMOTE_IS_SET(wm, WIIMOTE_STATE_RUMBLE)) {
|
||||||
msg[0] |= 0x01;
|
msg[0] |= 0x01;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
@@ -640,8 +689,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
|||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
printf("[DEBUG] (id %i) SEND: (%.2x) %.2x ", wm->unid, report_type, msg[0]);
|
printf("[DEBUG] (id %i) SEND: (%.2x) %.2x ", wm->unid, report_type, msg[0]);
|
||||||
for (x = 1; x < len; ++x)
|
for (x = 1; x < len; ++x) {
|
||||||
printf("%.2x ", msg[x]);
|
printf("%.2x ", msg[x]);
|
||||||
|
}
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -663,7 +713,9 @@ int wiiuse_send(struct wiimote_t* wm, byte report_type, byte* msg, int len) {
|
|||||||
* Flags are defined in wiiuse.h.
|
* Flags are defined in wiiuse.h.
|
||||||
*/
|
*/
|
||||||
int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
||||||
if (!wm) return 0;
|
if (!wm) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* remove mutually exclusive flags */
|
/* remove mutually exclusive flags */
|
||||||
enable &= ~disable;
|
enable &= ~disable;
|
||||||
@@ -692,15 +744,18 @@ int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable) {
|
|||||||
float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
|
float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha) {
|
||||||
float old;
|
float old;
|
||||||
|
|
||||||
if (!wm) return 0.0f;
|
if (!wm) {
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
old = wm->accel_calib.st_alpha;
|
old = wm->accel_calib.st_alpha;
|
||||||
|
|
||||||
wm->accel_calib.st_alpha = alpha;
|
wm->accel_calib.st_alpha = alpha;
|
||||||
|
|
||||||
/* if there is a nunchuk set that too */
|
/* if there is a nunchuk set that too */
|
||||||
if (wm->exp.type == EXP_NUNCHUK)
|
if (wm->exp.type == EXP_NUNCHUK) {
|
||||||
wm->exp.nunchuk.accel_calib.st_alpha = alpha;
|
wm->exp.nunchuk.accel_calib.st_alpha = alpha;
|
||||||
|
}
|
||||||
|
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
@@ -717,10 +772,13 @@ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt
|
|||||||
#ifdef WIIUSE_WIN32
|
#ifdef WIIUSE_WIN32
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < wiimotes; ++i)
|
for (i = 0; i < wiimotes; ++i) {
|
||||||
wm[i]->stack = type;
|
wm[i]->stack = type;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -736,7 +794,9 @@ void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt
|
|||||||
* the angle has to change by a full degree to generate an event.
|
* the angle has to change by a full degree to generate an event.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->orient_threshold = threshold;
|
wm->orient_threshold = threshold;
|
||||||
}
|
}
|
||||||
@@ -749,7 +809,9 @@ void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold) {
|
|||||||
* @param threshold The decimal place that should be considered a significant change.
|
* @param threshold The decimal place that should be considered a significant change.
|
||||||
*/
|
*/
|
||||||
void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
wm->accel_threshold = threshold;
|
wm->accel_threshold = threshold;
|
||||||
}
|
}
|
||||||
@@ -761,7 +823,9 @@ void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold) {
|
|||||||
* @param wm Pointer to a wiimote_t structure.
|
* @param wm Pointer to a wiimote_t structure.
|
||||||
*/
|
*/
|
||||||
void wiiuse_resync(struct wiimote_t* wm) {
|
void wiiuse_resync(struct wiimote_t* wm) {
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef WIIUSE_SYNC_HANDSHAKE
|
#ifndef WIIUSE_SYNC_HANDSHAKE
|
||||||
wm->handshake_state = 0;
|
wm->handshake_state = 0;
|
||||||
@@ -782,7 +846,9 @@ void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout
|
|||||||
#ifdef WIIUSE_WIN32
|
#ifdef WIIUSE_WIN32
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!wm) return;
|
if (!wm) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < wiimotes; ++i) {
|
for (i = 0; i < wiimotes; ++i) {
|
||||||
wm[i]->normal_timeout = normal_timeout;
|
wm[i]->normal_timeout = normal_timeout;
|
||||||
|
|||||||
@@ -566,8 +566,7 @@ typedef struct guitar_hero_3_t {
|
|||||||
/**
|
/**
|
||||||
* @brief Motion Plus expansion device
|
* @brief Motion Plus expansion device
|
||||||
*/
|
*/
|
||||||
typedef struct motion_plus_t
|
typedef struct motion_plus_t {
|
||||||
{
|
|
||||||
byte ext; /**< is there a device on the pass-through port? */
|
byte ext; /**< is there a device on the pass-through port? */
|
||||||
|
|
||||||
struct ang3s_t raw_gyro; /**< current raw gyroscope data */
|
struct ang3s_t raw_gyro; /**< current raw gyroscope data */
|
||||||
@@ -817,8 +816,7 @@ typedef void (*wiiuse_update_cb)(struct wiimote_callback_data_t* wm);
|
|||||||
*/
|
*/
|
||||||
typedef void (*wiiuse_write_cb)(struct wiimote_t* wm, unsigned char* data, unsigned short len);
|
typedef void (*wiiuse_write_cb)(struct wiimote_t* wm, unsigned char* data, unsigned short len);
|
||||||
|
|
||||||
typedef enum data_req_s
|
typedef enum data_req_s {
|
||||||
{
|
|
||||||
REQ_READY = 0,
|
REQ_READY = 0,
|
||||||
REQ_SENT,
|
REQ_SENT,
|
||||||
REQ_DONE
|
REQ_DONE
|
||||||
|
|||||||
Reference in New Issue
Block a user