Merged stuff from fWiine, Wiiuse master and local Motion+ modifs, not working yet
Dos2unix and unexpanded, then selectively committed by rpavlik
This commit is contained in:
140
src/events.c
140
src/events.c
@@ -60,6 +60,7 @@ static void idle_cycle(struct wiimote_t* wm);
|
||||
static void clear_dirty_reads(struct wiimote_t* wm);
|
||||
static void propagate_event(struct wiimote_t* wm, byte event, byte* msg);
|
||||
static void event_data_read(struct wiimote_t* wm, byte* msg);
|
||||
static void event_data_write(struct wiimote_t *wm, byte *msg);
|
||||
static void event_status(struct wiimote_t* wm, byte* msg);
|
||||
static void handle_expansion(struct wiimote_t* wm, byte* msg);
|
||||
|
||||
@@ -396,7 +397,7 @@ static void propagate_event(struct wiimote_t* wm, byte event, byte* msg) {
|
||||
}
|
||||
case WM_RPT_WRITE:
|
||||
{
|
||||
/* write feedback - safe to skip */
|
||||
event_data_write(wm,msg);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -546,6 +547,52 @@ static void event_data_read(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;
|
||||
|
||||
wiiuse_pressed_buttons(wm,msg);
|
||||
|
||||
/* if we don't have a request out then we didn't ask for this packet */
|
||||
if (!req) {
|
||||
WIIUSE_WARNING("Transmitting data packet when no request was made.");
|
||||
return;
|
||||
}
|
||||
if(!(req->state==REQ_SENT)) {
|
||||
WIIUSE_WARNING("Transmission is not necessary");
|
||||
/* delete this request */
|
||||
wm->data_req = req->next;
|
||||
free(req);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
req->state = REQ_DONE;
|
||||
|
||||
if(req->cb) {
|
||||
/* this was a callback, so invoke it now */
|
||||
req->cb(wm,NULL,0);
|
||||
/* delete this request */
|
||||
wm->data_req = req->next;
|
||||
free(req);
|
||||
} else {
|
||||
/*
|
||||
* This should generate an event.
|
||||
* We need to leave the event in the array so the client
|
||||
* can access it still. We'll flag is as being 'REQ_DONE'
|
||||
* and give the client one cycle to use it. Next event
|
||||
* we will remove it from the list.
|
||||
*/
|
||||
wm->event = WIIUSE_WRITE_DATA;
|
||||
|
||||
}
|
||||
/* if another request exists send it to the wiimote */
|
||||
if (wm->data_req) {
|
||||
wiiuse_send_next_pending_write_request(wm);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Read the controller status.
|
||||
*
|
||||
@@ -559,6 +606,7 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
int attachment = 0;
|
||||
int ir = 0;
|
||||
int exp_changed = 0;
|
||||
struct data_req_t* req = wm->data_req;
|
||||
|
||||
/*
|
||||
* An event occured.
|
||||
@@ -613,13 +661,33 @@ static void event_status(struct wiimote_t* wm, byte* msg) {
|
||||
* We need to send a WIIMOTE_CMD_REPORT_TYPE packet to
|
||||
* reenable other incoming reports.
|
||||
*/
|
||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR)) {
|
||||
/*
|
||||
* Since the expansion status changed IR needs to
|
||||
* be reset for the new IR report mode.
|
||||
*/
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
if (exp_changed)
|
||||
{
|
||||
if (exp_changed && WIIMOTE_IS_SET(wm, WIIMOTE_STATE_IR))
|
||||
{
|
||||
/*
|
||||
* Since the expansion status changed IR needs to
|
||||
* be reset for the new IR report mode.
|
||||
*/
|
||||
WIIMOTE_DISABLE_STATE(wm, WIIMOTE_STATE_IR);
|
||||
wiiuse_set_ir(wm, 1);
|
||||
} else {
|
||||
wiiuse_set_report_type(wm);
|
||||
return;
|
||||
}
|
||||
|
||||
/* handling new Tx for changed exp */
|
||||
if(!req) return;
|
||||
if(!(req->state==REQ_SENT)) return;
|
||||
|
||||
wm->data_req = req->next;
|
||||
|
||||
req->state = REQ_DONE;
|
||||
/* if(req->cb!=NULL) req->cb(wm,msg,6); */
|
||||
|
||||
free(req);
|
||||
wiiuse_send_next_pending_write_request(wm);
|
||||
|
||||
} else
|
||||
wiiuse_set_report_type(wm);
|
||||
}
|
||||
@@ -822,6 +890,33 @@ static void save_state(struct wiimote_t* wm) {
|
||||
wm->lstate.exp_wb_rbl = wm->exp.wb.rbl;
|
||||
break;
|
||||
|
||||
case EXP_MOTION_PLUS:
|
||||
case EXP_MOTION_PLUS_CLASSIC:
|
||||
case EXP_MOTION_PLUS_NUNCHUK:
|
||||
{
|
||||
wm->lstate.drx = wm->exp.mp.raw_gyro.p;
|
||||
wm->lstate.dry = wm->exp.mp.raw_gyro.r;
|
||||
wm->lstate.drz = wm->exp.mp.raw_gyro.y;
|
||||
|
||||
if(wm->exp.type == EXP_MOTION_PLUS_CLASSIC)
|
||||
{
|
||||
wm->lstate.exp_ljs_ang = wm->exp.classic.ljs.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.classic.ljs.mag;
|
||||
wm->lstate.exp_rjs_ang = wm->exp.classic.rjs.ang;
|
||||
wm->lstate.exp_rjs_mag = wm->exp.classic.rjs.mag;
|
||||
wm->lstate.exp_r_shoulder = wm->exp.classic.r_shoulder;
|
||||
wm->lstate.exp_l_shoulder = wm->exp.classic.l_shoulder;
|
||||
wm->lstate.exp_btns = wm->exp.classic.btns;
|
||||
} else {
|
||||
wm->lstate.exp_ljs_ang = wm->exp.nunchuk.js.ang;
|
||||
wm->lstate.exp_ljs_mag = wm->exp.nunchuk.js.mag;
|
||||
wm->lstate.exp_btns = wm->exp.nunchuk.btns;
|
||||
wm->lstate.exp_accel = wm->exp.nunchuk.accel;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case EXP_NONE:
|
||||
break;
|
||||
}
|
||||
@@ -925,6 +1020,35 @@ static int state_changed(struct wiimote_t* wm) {
|
||||
STATE_CHANGED(wm->lstate.exp_wb_rbl,wm->exp.wb.bl);
|
||||
break;
|
||||
}
|
||||
|
||||
case EXP_MOTION_PLUS:
|
||||
case EXP_MOTION_PLUS_CLASSIC:
|
||||
case EXP_MOTION_PLUS_NUNCHUK:
|
||||
{
|
||||
STATE_CHANGED(wm->lstate.drx, wm->exp.mp.raw_gyro.p);
|
||||
STATE_CHANGED(wm->lstate.dry, wm->exp.mp.raw_gyro.r);
|
||||
STATE_CHANGED(wm->lstate.drz, wm->exp.mp.raw_gyro.y);
|
||||
|
||||
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_mag, wm->exp.classic.ljs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_ang, wm->exp.classic.rjs.ang);
|
||||
STATE_CHANGED(wm->lstate.exp_rjs_mag, wm->exp.classic.rjs.mag);
|
||||
STATE_CHANGED(wm->lstate.exp_r_shoulder, wm->exp.classic.r_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_l_shoulder, wm->exp.classic.l_shoulder);
|
||||
STATE_CHANGED(wm->lstate.exp_btns, wm->exp.classic.btns);
|
||||
} else {
|
||||
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_btns, wm->exp.nunchuk.btns);
|
||||
|
||||
CROSS_THRESH(wm->lstate.exp_orient, wm->exp.nunchuk.orient, wm->exp.nunchuk.orient_threshold);
|
||||
CROSS_THRESH_XYZ(wm->lstate.exp_accel, wm->exp.nunchuk.accel, wm->exp.nunchuk.accel_threshold);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case EXP_NONE:
|
||||
{
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user