summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 20:12:49 +0900
committerSam Spilsbury <Sam@XPS-SUSE.site>2008-11-29 20:12:49 +0900
commit11c94add14eda814490eb82bb73027dfae98bb6d (patch)
tree81dff153645bc12307a771a76cc52d91a0e4aede
parentad4a2000161d801454163789fa4628156ea30da0 (diff)
downloadwiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.gz
wiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.bz2
* Use dynamically allocated memory, options don't work -- yet
-rw-r--r--action.c39
-rw-r--r--callback.c106
-rw-r--r--compiz-wiimote.h9
-rw-r--r--connect.c66
-rw-r--r--gesture.c102
-rw-r--r--report.c65
-rw-r--r--util.c30
7 files changed, 216 insertions, 201 deletions
diff --git a/action.c b/action.c
index 2ad0bfa..0b55a7f 100644
--- a/action.c
+++ b/action.c
@@ -31,6 +31,7 @@ wiimoteToggle (CompDisplay *d,
int nOption)
{
int rc;
+ CompWiimote *wiimote;
WIIMOTE_DISPLAY (d);
@@ -82,16 +83,24 @@ wiimoteToggle (CompDisplay *d,
"display_text");
compLogMessage ("wiimote", CompLogLevelInfo,
"Hold down the 1 and 2 Buttons on your Nintendo Wii Remote now");
- /* Create the second thread. */
- rc = pthread_create(&ad->cWiimote[ad->nWiimote].connectWiimote, &secondThreadAttr, connectWiimote, (void *)d);
+
+ /* Initialize memory to save wii remove data */
- /* Clean up second thread's attribute. */
- pthread_attr_destroy(&secondThreadAttr);
- if (!rc)
+ wiimote = wiimoteAddWiimote (d);
+ if (wiimote)
{
+
+ /* Create the second thread. */
+ rc = pthread_create(&wiimote->connectWiimote, &secondThreadAttr, connectWiimote, (void *)d);
+
+ /* Clean up second thread's attribute. */
+ pthread_attr_destroy(&secondThreadAttr);
+ if (!rc)
+ {
/* So the thread succeeded!
* Start Checking! */
ad->checkingTimeoutHandle = compAddTimeout (10, 10 * 1.2, checkConnected, d);
+ }
}
}
return TRUE;
@@ -106,9 +115,11 @@ wiimoteDisable (CompDisplay *d,
{
int rc;
-
+ CompWiimote *wiimote;
WIIMOTE_DISPLAY (d);
+ for (wiimote = ad->wiimotes; wiimote->next; wiimote = wiimote->next) ;
+
/* nWiimote -1 because we increment nWiimote
* so we need to find the most recent (Which is -1)
*/
@@ -117,12 +128,12 @@ wiimoteDisable (CompDisplay *d,
if (ad->nWiimote < 1)
return FALSE;
- ad->cWiimote[ad->nWiimote - 1].initiated = FALSE;
- ad->cWiimote[ad->nWiimote - 1].connected = FALSE;
+ wiimote->initiated = FALSE;
+ wiimote->connected = FALSE;
/* Wait for the second thread to return control to itself */
- rc = pthread_join(ad->cWiimote[ad->nWiimote -1].connectWiimote, NULL);
+ rc = pthread_join(wiimote->connectWiimote, NULL);
if (rc)
compLogMessage ("wiimote", CompLogLevelError,
"Threading error occurred.\n");
@@ -137,14 +148,14 @@ wiimoteDisable (CompDisplay *d,
/* Remove the lights timeout handle */
- if (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle)
- compRemoveTimeout (ad->cWiimote[ad->nWiimote - 1].lightsTimeoutHandle);
+ if (wiimote->lightsTimeoutHandle)
+ compRemoveTimeout (wiimote->lightsTimeoutHandle);
/* Tell the user that we are closing the connection */
compLogMessage ("wiimote", CompLogLevelInfo,
"Closing connection to most recently connected Wii Remote\n");
- if (cwiid_close(ad->cWiimote[ad->nWiimote - 1].wiimote)) {
+ if (cwiid_close(wiimote->wiimote)) {
compLogMessage ("wiimote", CompLogLevelError,
"Error closing that connection\n");
return -1;
@@ -152,6 +163,8 @@ wiimoteDisable (CompDisplay *d,
/* Decrement Wiimote Iter */
+ wiimoteRemoveWiimote (d, wiimote);
+
ad->nWiimote--;
return TRUE;
@@ -194,7 +207,7 @@ wiimoteSendInfo (CompDisplay *d,
ad->infoTimeoutHandle = compAddTimeout(wiimoteGetPollInterval (s->display) ,
wiimoteGetPollInterval (s->display) * 1.2, sendReports, s);
- ad->gestureTimeoutHandle = compAddTimeout(wiimoteGetGestureTimeout (s->display) ,
+ ad->gestureTimeoutHandle = compAddTimeout(wiimoteGetGestureTimeout (s->display) ,
wiimoteGetGestureTimeout (s->display) * 1.2, wiimoteCheckForGestures, s);
}
return TRUE;
diff --git a/callback.c b/callback.c
index 7d1776d..6cadf49 100644
--- a/callback.c
+++ b/callback.c
@@ -55,24 +55,23 @@ void wiimoteCWiiDCallback(cwiid_wiimote_t *wiimote, int mesg_count,
float totalX = 0.0f, totalY = 0.0f;
int count = 0;
int id = cwiid_get_id (wiimote);
- int wiimoteNumber = 0;
struct cwiid_state state;
+ CompWiimote *cmpwiimote;
cwiid_get_state(wiimote, &state);
//unsigned char led_state = 0;
WIIMOTE_DISPLAY (firstDisplay);
- ad->cWiimote[wiimoteNumber].nunchuck.connected = FALSE;
+ //cmpwiimote->nunchuck.connected = FALSE;
- for (i = 0; i < MAX_WIIMOTES; i++)
+ for (cmpwiimote = ad->wiimotes; cmpwiimote; cmpwiimote = cmpwiimote->next)
{
- if (id == ad->cWiimote[i].id)
- {
- wiimoteNumber = i;
- break;
- }
+ if (cmpwiimote->id == id)
+ break;
}
+ if (wiimote)
+ {
for (i=0; i < mesg_count; i++)
{
switch (mesg[i].type) {
@@ -81,18 +80,18 @@ void wiimoteCWiiDCallback(cwiid_wiimote_t *wiimote, int mesg_count,
case CWIID_EXT_NONE:
break;
case CWIID_EXT_NUNCHUK:
- ad->cWiimote[wiimoteNumber].nunchuck.connected = TRUE;
- ad->cWiimote[wiimoteNumber].nunchuck.initAccX =
+ cmpwiimote->nunchuck.connected = TRUE;
+ cmpwiimote->nunchuck.initAccX =
state.ext.nunchuk.acc[CWIID_X];
- ad->cWiimote[wiimoteNumber].nunchuck.initAccY =
+ cmpwiimote->nunchuck.initAccY =
state.ext.nunchuk.acc[CWIID_Y];
- ad->cWiimote[wiimoteNumber].nunchuck.initAccZ =
+ cmpwiimote->nunchuck.initAccZ =
state.ext.nunchuk.acc[CWIID_Z];
- ad->cWiimote[wiimoteNumber].nunchuck.initStickX =
+ cmpwiimote->nunchuck.initStickX =
state.ext.nunchuk.stick[CWIID_X];
- ad->cWiimote[wiimoteNumber].nunchuck.initStickY =
+ cmpwiimote->nunchuck.initStickY =
state.ext.nunchuk.stick[CWIID_Y];
- wiimoteProcessNunchuckButtons(firstDisplay, wiimoteNumber, (struct cwiid_nunchuk_mesg *) &mesg[i]);
+ wiimoteProcessNunchuckButtons(firstDisplay, cmpwiimote, (struct cwiid_nunchuk_mesg *) &mesg[i]); // Just pass the pointer methinks
break;
case CWIID_EXT_CLASSIC:
break;
@@ -102,45 +101,45 @@ void wiimoteCWiiDCallback(cwiid_wiimote_t *wiimote, int mesg_count,
printf("\n");
break;
case CWIID_MESG_BTN:
- wiimoteProcessButtons(firstDisplay, wiimoteNumber, (struct cwiid_btn_mesg *) &mesg[i]);
+ wiimoteProcessButtons(firstDisplay, cmpwiimote, (struct cwiid_btn_mesg *) &mesg[i]); // Just pass the pointer
break;
case CWIID_MESG_ACC:
- ad->cWiimote[wiimoteNumber].acc.accDX = ((ad->cWiimote[wiimoteNumber].acc.accX) - (ad->cWiimote[wiimoteNumber].acc.initAccX));
- ad->cWiimote[wiimoteNumber].acc.accDY = ((ad->cWiimote[wiimoteNumber].acc.accY) - (ad->cWiimote[wiimoteNumber].acc.initAccY));
- ad->cWiimote[wiimoteNumber].acc.accX = mesg[i].acc_mesg.acc[CWIID_X];
- ad->cWiimote[wiimoteNumber].acc.accY = mesg[i].acc_mesg.acc[CWIID_Y];
- ad->cWiimote[wiimoteNumber].acc.accZ = mesg[i].acc_mesg.acc[CWIID_Z];
+ cmpwiimote->acc.accDX = ((cmpwiimote->acc.accX) - (cmpwiimote->acc.initAccX));
+ cmpwiimote->acc.accDY = ((cmpwiimote->acc.accY) - (cmpwiimote->acc.initAccY));
+ cmpwiimote->acc.accX = mesg[i].acc_mesg.acc[CWIID_X];
+ cmpwiimote->acc.accY = mesg[i].acc_mesg.acc[CWIID_Y];
+ cmpwiimote->acc.accZ = mesg[i].acc_mesg.acc[CWIID_Z];
break;
case CWIID_MESG_IR:
valid_source = 0;
for (j = 0; j < CWIID_IR_SRC_COUNT; j++) {
if (mesg[i].ir_mesg.src[j].valid) {
valid_source = 1;
- ad->cWiimote[wiimoteNumber].ir[j].valid = TRUE;
- ad->cWiimote[wiimoteNumber].ir[j].x = mesg[i].ir_mesg.src[j].pos[CWIID_X];
- ad->cWiimote[wiimoteNumber].ir[j].y = mesg[i].ir_mesg.src[j].pos[CWIID_Y];
- ad->cWiimote[wiimoteNumber].ir[j].size = mesg[i].ir_mesg.src[j].size;
+ cmpwiimote->ir[j].valid = TRUE;
+ cmpwiimote->ir[j].x = mesg[i].ir_mesg.src[j].pos[CWIID_X];
+ cmpwiimote->ir[j].y = mesg[i].ir_mesg.src[j].pos[CWIID_Y];
+ cmpwiimote->ir[j].size = mesg[i].ir_mesg.src[j].size;
totalX += mesg[i].ir_mesg.src[j].pos[CWIID_X];
totalY += mesg[i].ir_mesg.src[j].pos[CWIID_Y];
count++;
}
else
{
- ad->cWiimote[wiimoteNumber].ir[j].valid = FALSE;
+ cmpwiimote->ir[j].valid = FALSE;
}
}
break;
case CWIID_MESG_NUNCHUK:
- ad->cWiimote[wiimoteNumber].nunchuck.connected = TRUE;
- ad->cWiimote[wiimoteNumber].nunchuck.accDX = ((ad->cWiimote[wiimoteNumber].nunchuck.accX) - (ad->cWiimote[wiimoteNumber].nunchuck.initAccX));
- ad->cWiimote[wiimoteNumber].nunchuck.accDY = ((ad->cWiimote[wiimoteNumber].nunchuck.accY) - (ad->cWiimote[wiimoteNumber].nunchuck.initAccY));
- ad->cWiimote[wiimoteNumber].nunchuck.accX = mesg[i].nunchuk_mesg.acc[CWIID_X];
- ad->cWiimote[wiimoteNumber].nunchuck.accY = mesg[i].nunchuk_mesg.acc[CWIID_Y];
- ad->cWiimote[wiimoteNumber].nunchuck.accZ = mesg[i].nunchuk_mesg.acc[CWIID_Z];
- ad->cWiimote[wiimoteNumber].nunchuck.stickDX = ((ad->cWiimote[wiimoteNumber].nunchuck.stickX) - (ad->cWiimote[wiimoteNumber].nunchuck.initStickX));
- ad->cWiimote[wiimoteNumber].nunchuck.stickDY = ((ad->cWiimote[wiimoteNumber].nunchuck.stickY) - (ad->cWiimote[wiimoteNumber].nunchuck.initStickY));
- ad->cWiimote[wiimoteNumber].nunchuck.stickX = mesg[i].nunchuk_mesg.stick[CWIID_X];
- ad->cWiimote[wiimoteNumber].nunchuck.stickY = mesg[i].nunchuk_mesg.stick[CWIID_Y];
+ cmpwiimote->nunchuck.connected = TRUE;
+ cmpwiimote->nunchuck.accDX = ((cmpwiimote->nunchuck.accX) - (cmpwiimote->nunchuck.initAccX));
+ cmpwiimote->nunchuck.accDY = ((cmpwiimote->nunchuck.accY) - (cmpwiimote->nunchuck.initAccY));
+ cmpwiimote->nunchuck.accX = mesg[i].nunchuk_mesg.acc[CWIID_X];
+ cmpwiimote->nunchuck.accY = mesg[i].nunchuk_mesg.acc[CWIID_Y];
+ cmpwiimote->nunchuck.accZ = mesg[i].nunchuk_mesg.acc[CWIID_Z];
+ cmpwiimote->nunchuck.stickDX = ((cmpwiimote->nunchuck.stickX) - (cmpwiimote->nunchuck.initStickX));
+ cmpwiimote->nunchuck.stickDY = ((cmpwiimote->nunchuck.stickY) - (cmpwiimote->nunchuck.initStickY));
+ cmpwiimote->nunchuck.stickX = mesg[i].nunchuk_mesg.stick[CWIID_X];
+ cmpwiimote->nunchuck.stickY = mesg[i].nunchuk_mesg.stick[CWIID_Y];
break;
case CWIID_MESG_CLASSIC:
printf("Classic Report: btns=%.4X l_stick=(%d,%d) r_stick=(%d,%d) "
@@ -167,29 +166,29 @@ void wiimoteCWiiDCallback(cwiid_wiimote_t *wiimote, int mesg_count,
int min, max;
float xRange = 0.0f;
- if (ad->cWiimote[wiimoteNumber].ir[1].valid)
+ if (cmpwiimote->ir[1].valid)
{
- ad->cWiimote[wiimoteNumber].irMidX = (totalX / count);
- ad->cWiimote[wiimoteNumber].irMidY = (totalY / count);
+ cmpwiimote->irMidX = (totalX / count);
+ cmpwiimote->irMidY = (totalY / count);
}
else
{
- ad->cWiimote[wiimoteNumber].irMidX = 1.0f;
- ad->cWiimote[wiimoteNumber].irMidY = 1.0f;
+ cmpwiimote->irMidX = 1.0f;
+ cmpwiimote->irMidY = 1.0f;
}
- if (ad->cWiimote[wiimoteNumber].ir[0].valid && ad->cWiimote[wiimoteNumber].ir[1].valid)
+ if (cmpwiimote->ir[0].valid && cmpwiimote->ir[1].valid)
{
- min = findMinIR (firstDisplay, wiimoteNumber,
- ad->cWiimote[wiimoteNumber].ir[0].x,
- ad->cWiimote[wiimoteNumber].ir[1].x,
- ad->cWiimote[wiimoteNumber].ir[2].x,
- ad->cWiimote[wiimoteNumber].ir[3].x);
+ min = findMinIR (firstDisplay, cmpwiimote,
+ cmpwiimote->ir[0].x,
+ cmpwiimote->ir[1].x,
+ cmpwiimote->ir[2].x,
+ cmpwiimote->ir[3].x);
- max = findMaxIR (firstDisplay, wiimoteNumber,
- ad->cWiimote[wiimoteNumber].ir[0].x,
- ad->cWiimote[wiimoteNumber].ir[1].x,
- ad->cWiimote[wiimoteNumber].ir[2].x,
- ad->cWiimote[wiimoteNumber].ir[3].x);
+ max = findMaxIR (firstDisplay, cmpwiimote,
+ cmpwiimote->ir[0].x,
+ cmpwiimote->ir[1].x,
+ cmpwiimote->ir[2].x,
+ cmpwiimote->ir[3].x);
xRange = max - min;
}
@@ -197,6 +196,7 @@ void wiimoteCWiiDCallback(cwiid_wiimote_t *wiimote, int mesg_count,
{
xRange = 1.0;
}
- ad->cWiimote[wiimoteNumber].irDistance = (xRange / 100);
+ cmpwiimote->irDistance = (xRange / 100);
+ }
}
diff --git a/compiz-wiimote.h b/compiz-wiimote.h
index 897a554..896296f 100644
--- a/compiz-wiimote.h
+++ b/compiz-wiimote.h
@@ -317,6 +317,7 @@ typedef struct _CompWiimote
/* Timeout Handles */
CompTimeoutHandle lightsTimeoutHandle;
+ int count;
pthread_t connectWiimote; /* Threading Handler */
struct _CompWiimote *next; // The future $$$$$$ =)
@@ -378,8 +379,8 @@ CompDisplay *firstDisplay;
/* util.c*/
-int findMinIR (CompDisplay *, int, int, int, int, int); // No you can't have fminf
-int findMaxIR (CompDisplay *, int, int, int, int, int); // Or fmaxf
+int findMinIR (CompDisplay *, CompWiimote *, int, int, int, int); // No you can't have fminf
+int findMaxIR (CompDisplay *, CompWiimote *, int, int, int, int); // Or fmaxf
Bool wiimoteChangeLights(void *Wiimote);
void set_led_state(cwiid_wiimote_t *wiimote, unsigned char led_state);
void set_rpt_mode(cwiid_wiimote_t *wiimote, unsigned char rpt_mode);
@@ -390,8 +391,8 @@ Bool sendInfoToPlugin (CompDisplay *, CompOption *, int, char *, char *);
/* gesture.c */
-void wiimoteProcessButtons (CompDisplay *, int, struct cwiid_btn_mesg *);
-void wiimoteProcessNunchuckButtons (CompDisplay *, int, struct cwiid_nunchuk_mesg *);
+void wiimoteProcessButtons (CompDisplay *, CompWiimote *, struct cwiid_btn_mesg *);
+void wiimoteProcessNunchuckButtons (CompDisplay *, CompWiimote *, struct cwiid_nunchuk_mesg *);
Bool wiimoteCheckForGestures (void *vs);
/* connect.c */
diff --git a/connect.c b/connect.c
index 4c903a7..8e487cb 100644
--- a/connect.c
+++ b/connect.c
@@ -89,6 +89,7 @@ void* connectWiimote (void *vd)
CompDisplay *d = (CompDisplay *) vd;
bdaddr = *BDADDR_ANY;
CompScreen *s;
+ CompWiimote *cmpwiimote;
cwiid_wiimote_t *wiimote;
WIIMOTE_DISPLAY (d);
@@ -166,8 +167,12 @@ void* connectWiimote (void *vd)
return NULL;
}
- ad->cWiimote[ad->nWiimote].wiimote = wiimote;
- ad->cWiimote[ad->nWiimote].connected = TRUE;
+
+ /* Should be safe to assume that the most recent wiimote is the last one on the list */
+ for (cmpwiimote = ad->wiimotes; cmpwiimote->next; cmpwiimote = cmpwiimote->next) ;
+
+ cmpwiimote->wiimote = wiimote;
+ cmpwiimote->connected = TRUE;
for (s = d->screens; s; s = s->next)
{
CompOption arg[4];
@@ -212,12 +217,13 @@ void* connectWiimote (void *vd)
Bool checkConnected (void *vd)
{
CompDisplay *d = vd;
+ CompWiimote *cmpwiimote;
WIIMOTE_DISPLAY (d);
- struct cwiid_state state; /* wiimote state */
- unsigned char mesg = 0; /* Mesg Flag */
- unsigned char rpt_mode = 0; /* Reporting Flag */
- unsigned char rumble = 0; /* Rumble Flag */
- int led_state = 0; /* LED State Flag */
+ struct cwiid_state state; /* wiimote state */
+ unsigned char mesg = 0; /* Mesg Flag */
+ unsigned char rpt_mode = 0; /* Reporting Flag */
+ unsigned char rumble = 0; /* Rumble Flag */
+ int led_state = 0; /* LED State Flag */
/* FIXME:
* Remove me as all I do
@@ -225,24 +231,25 @@ Bool checkConnected (void *vd)
* not good for compiz!
*/
- cwiid_set_err(err); /* Error Handling */
-
+ cwiid_set_err(err); /* Error Handling */
+ /* Should be safe to assume that the most recent wiimote is the last one on the list */
+ for (cmpwiimote = ad->wiimotes; cmpwiimote->next; cmpwiimote = cmpwiimote->next) ;
- if (ad->cWiimote[ad->nWiimote].connected)
+ if (cmpwiimote->connected)
{
/* Connect to the wiimote */
compLogMessage ("wiimote", CompLogLevelInfo,
"Wii Remote Connection started");
if (allocateCallbackFunction
- (ad->cWiimote[ad->nWiimote].wiimote, ad->nWiimote)) // Allocate a c
+ (cmpwiimote->wiimote, ad->nWiimote)) // Allocate a c
{
compLogMessage ("wiimote", CompLogLevelInfo,
"Wii Remote is now connected");
- if (cwiid_set_rumble(ad->cWiimote[0].wiimote, rumble)) {
+ if (cwiid_set_rumble(cmpwiimote->wiimote, rumble)) {
compLogMessage ("wiimote", CompLogLevelError,
"Couldn't set rumble");
}
@@ -250,12 +257,12 @@ Bool checkConnected (void *vd)
/* Toggle Accellerometor Reporting */
toggle_bit(rpt_mode, CWIID_RPT_ACC);
- set_rpt_mode(ad->cWiimote[ad->nWiimote].wiimote, rpt_mode);
+ set_rpt_mode(cmpwiimote->wiimote, rpt_mode);
/* Toggle Button Reporting */
toggle_bit(rpt_mode, CWIID_RPT_BTN);
- set_rpt_mode(ad->cWiimote[ad->nWiimote].wiimote, rpt_mode);
+ set_rpt_mode(cmpwiimote->wiimote, rpt_mode);
/* CWIID_RPT_EXT is actually
@@ -264,7 +271,7 @@ Bool checkConnected (void *vd)
/* Toggle Extension Reporting */
toggle_bit(rpt_mode, CWIID_RPT_EXT);
- set_rpt_mode(ad->cWiimote[ad->nWiimote].wiimote, rpt_mode);
+ set_rpt_mode(cmpwiimote->wiimote, rpt_mode);
/* libwiimote picks the highest quality IR mode available with the
@@ -274,12 +281,12 @@ Bool checkConnected (void *vd)
/* Toggle IR reporting */
toggle_bit(rpt_mode, CWIID_RPT_IR);
- set_rpt_mode(ad->cWiimote[ad->nWiimote].wiimote, rpt_mode);
+ set_rpt_mode(cmpwiimote->wiimote, rpt_mode);
/* Toggle Status (Battery etc) reporting */
toggle_bit(rpt_mode, CWIID_RPT_STATUS);
- set_rpt_mode(ad->cWiimote[ad->nWiimote].wiimote, rpt_mode);
+ set_rpt_mode(cmpwiimote->wiimote, rpt_mode);
/* Check to see if there is a mesg reporting
handler (Should be wiimoteCWiiDCallbackx, where X is
@@ -287,7 +294,7 @@ Bool checkConnected (void *vd)
*/
/* FIXME !mesg is here unconditionally true */
if (!mesg) {
- if (cwiid_enable(ad->cWiimote[ad->nWiimote].wiimote, CWIID_FLAG_MESG_IFC)) {
+ if (cwiid_enable(cmpwiimote->wiimote, CWIID_FLAG_MESG_IFC)) {
compLogMessage ("wiimote", CompLogLevelError,
"Couldn't set messages. Wii remote will connect, but reporting and other things won't work!");
}
@@ -296,7 +303,7 @@ Bool checkConnected (void *vd)
}
}
else {
- if (cwiid_disable(ad->cWiimote[ad->nWiimote].wiimote, CWIID_FLAG_MESG_IFC)) {
+ if (cwiid_disable(cmpwiimote->wiimote, CWIID_FLAG_MESG_IFC)) {
compLogMessage ("wiimote", CompLogLevelError,
"Couldn't disable messages");
}
@@ -307,14 +314,14 @@ Bool checkConnected (void *vd)
/* Request Status */
- if (cwiid_request_status(ad->cWiimote[ad->nWiimote].wiimote)) {
+ if (cwiid_request_status(cmpwiimote->wiimote)) {
compLogMessage ("wiimote", CompLogLevelError,
"Error requesting status. Battery info will not work!");
}
/* Request State */
- if (cwiid_get_state(ad->cWiimote[ad->nWiimote].wiimote, &state)) {
+ if (cwiid_get_state(cmpwiimote->wiimote, &state)) {
compLogMessage ("wiimote", CompLogLevelError,
"Error requesting state. Calibration will not work!");
}
@@ -325,14 +332,16 @@ Bool checkConnected (void *vd)
*/
toggle_bit(led_state, CWIID_LED1_ON);
- set_led_state(ad->cWiimote[ad->nWiimote].wiimote, led_state);
+ set_led_state(cmpwiimote->wiimote, led_state);
/* Do a fancy thing with the LED's. Doesn't
* quite work right yet :(
*/
-
- ad->cWiimote[ad->nWiimote].lightsTimeoutHandle =
- compAddTimeout (650, 650 * 1.2 /* I'll do the math later */, wiimoteChangeLights, ad->cWiimote[ad->nWiimote].wiimote);
+
+ cmpwiimote->count = 0;
+
+ cmpwiimote->lightsTimeoutHandle =
+ compAddTimeout (650, 650 * 1.2 /* I'll do the math later */, wiimoteChangeLights, cmpwiimote);
/* Set some variables using the state interface
* FIXME: For some reason, over-querying the
@@ -343,13 +352,12 @@ Bool checkConnected (void *vd)
* _should_ be fixed in CWiiD
*/
- ad->cWiimote[ad->nWiimote].acc.initAccX = state.acc[CWIID_X];
- ad->cWiimote[ad->nWiimote].acc.initAccY = state.acc[CWIID_Y];
+ cmpwiimote->acc.initAccX = state.acc[CWIID_X];
+ cmpwiimote->acc.initAccY = state.acc[CWIID_Y];
/* Set the id */
- ad->cWiimote[ad->nWiimote].id = cwiid_get_id (ad->cWiimote[ad->nWiimote].wiimote);
-
+ cmpwiimote->id = cwiid_get_id (ad->cWiimote[ad->nWiimote].wiimote);
/* Increment the Wiimote iter to
* allow another CompWiimote to initialise
diff --git a/gesture.c b/gesture.c
index 0d77778..2f20e08 100644
--- a/gesture.c
+++ b/gesture.c
@@ -27,30 +27,29 @@
if (mesg->buttons & a) \
{ \
if (!b) \
- sendGesture(d, wiimoteNumber, c); \
+ sendGesture(d, wiimote, c); \
b = TRUE; \
} \
else \
{ \
if (b) \
- sendGesture(d, wiimoteNumber, e); \
+ sendGesture(d, wiimote, e); \
b = FALSE; \
} \
-static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
+static Bool sendGesture(CompDisplay *d, CompWiimote *wiimote, int type)
{
+ WIIMOTE_DISPLAY (d);
CompOption argument[2];
int nArgument = 0;
int i;
- WIIMOTE_DISPLAY (d);
-
- if (ad->cWiimote[wiimoteNumber].connected)
+ if (wiimote->connected)
{
- for (i = 0; i < ad->cWiimote[wiimoteNumber].nGesture; i++)
+ for (i = 0; i < wiimote->nGesture; i++)
{
- if (ad->cWiimote[wiimoteNumber].gesture[i].type == type)
+ if (wiimote->gesture[i].type == type) // Need to fix this
{
argument[nArgument].name = "window";
argument[nArgument].type = CompOptionTypeInt;
@@ -63,8 +62,8 @@ static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
nArgument++;
sendInfoToPlugin (d, argument, nArgument,
- ad->cWiimote[wiimoteNumber].gesture[i].pluginName,
- ad->cWiimote[wiimoteNumber].gesture[i].actionName);
+ wiimote->gesture[i].pluginName,
+ wiimote->gesture[i].actionName);
}
}
}
@@ -73,43 +72,40 @@ static Bool sendGesture(CompDisplay *d, int wiimoteNumber, int type)
}
void
-wiimoteProcessButtons(CompDisplay *d, int wiimoteNumber, struct cwiid_btn_mesg *mesg)
+wiimoteProcessButtons(CompDisplay *d, CompWiimote *wiimote, struct cwiid_btn_mesg *mesg)
{
- WIIMOTE_DISPLAY (d);
- CHECK_BUTTON( CWIID_BTN_A, ad->cWiimote[wiimoteNumber].buttons.A, 1, 2);
- CHECK_BUTTON( CWIID_BTN_B, ad->cWiimote[wiimoteNumber].buttons.B, 3, 4);
- CHECK_BUTTON( CWIID_BTN_UP, ad->cWiimote[wiimoteNumber].buttons.Up, 5, 6);
- CHECK_BUTTON( CWIID_BTN_DOWN, ad->cWiimote[wiimoteNumber].buttons.Down, 7, 8);
- CHECK_BUTTON( CWIID_BTN_LEFT, ad->cWiimote[wiimoteNumber].buttons.Left, 9, 10);
- CHECK_BUTTON( CWIID_BTN_RIGHT, ad->cWiimote[wiimoteNumber].buttons.Right, 11, 12);
- CHECK_BUTTON( CWIID_BTN_PLUS, ad->cWiimote[wiimoteNumber].buttons.Plus, 13, 14);
- CHECK_BUTTON( CWIID_BTN_MINUS, ad->cWiimote[wiimoteNumber].buttons.Minus, 15, 16);
- CHECK_BUTTON( CWIID_BTN_HOME, ad->cWiimote[wiimoteNumber].buttons.Home, 17, 18);
- CHECK_BUTTON( CWIID_BTN_1, ad->cWiimote[wiimoteNumber].buttons.One, 19, 20);
- CHECK_BUTTON( CWIID_BTN_2, ad->cWiimote[wiimoteNumber].buttons.Two, 21, 22);
+ CHECK_BUTTON( CWIID_BTN_A, wiimote->buttons.A, 1, 2);
+ CHECK_BUTTON( CWIID_BTN_B, wiimote->buttons.B, 3, 4);
+ CHECK_BUTTON( CWIID_BTN_UP, wiimote->buttons.Up, 5, 6);
+ CHECK_BUTTON( CWIID_BTN_DOWN, wiimote->buttons.Down, 7, 8);
+ CHECK_BUTTON( CWIID_BTN_LEFT, wiimote->buttons.Left, 9, 10);
+ CHECK_BUTTON( CWIID_BTN_RIGHT, wiimote->buttons.Right, 11, 12);
+ CHECK_BUTTON( CWIID_BTN_PLUS, wiimote->buttons.Plus, 13, 14);
+ CHECK_BUTTON( CWIID_BTN_MINUS, wiimote->buttons.Minus, 15, 16);
+ CHECK_BUTTON( CWIID_BTN_HOME, wiimote->buttons.Home, 17, 18);
+ CHECK_BUTTON( CWIID_BTN_1, wiimote->buttons.One, 19, 20);
+ CHECK_BUTTON( CWIID_BTN_2, wiimote->buttons.Two, 21, 22);
}
void
-wiimoteProcessNunchuckButtons (CompDisplay *d, int wiimoteNumber, struct cwiid_nunchuk_mesg *mesg)
+wiimoteProcessNunchuckButtons (CompDisplay *d, CompWiimote *wiimote, struct cwiid_nunchuk_mesg *mesg)
{
- WIIMOTE_DISPLAY (d);
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_C, ad->cWiimote[wiimoteNumber].nunchuck.buttons.C, 23, 24);
- CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, ad->cWiimote[wiimoteNumber].nunchuck.buttons.Z, 25, 26);
+ CHECK_BUTTON ( CWIID_NUNCHUK_BTN_C, wiimote->nunchuck.buttons.C, 23, 24);
+ CHECK_BUTTON ( CWIID_NUNCHUK_BTN_Z, wiimote->nunchuck.buttons.Z, 25, 26);
}
/* I would rather use #define, but it's bugged up, so I have to compromise */
static void
-wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, float *old, float value, int posGest, int negGest)
+wiimoteCheckGesture (CompScreen *s, CompWiimote *wiimote, float diff, float init, float *old, float value, int posGest, int negGest)
{
-
if (*old <= value - diff && value <= init)
- sendGesture (s->display, wiimoteNumber, negGest);
+ sendGesture (s->display, wiimote, negGest);
if (*old >= value + diff && value >= init)
- sendGesture (s->display, wiimoteNumber, posGest);
+ sendGesture (s->display, wiimote, posGest);
*old = value;
}
@@ -117,39 +113,39 @@ wiimoteCheckGesture (CompScreen *s, int wiimoteNumber, float diff, float init, f
Bool wiimoteCheckForGestures (void *vs)
{
CompScreen *s = (CompScreen *) vs;
- int i;
+ CompWiimote *wiimote;
float sens = wiimoteGetGestureSens (s->display);
WIIMOTE_DISPLAY (s->display);
- for (i = 0; i < MAX_WIIMOTES; i++)
+ for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next)
{
- if (ad->cWiimote[i].connected)
+ if (wiimote->connected)
{
/* Check Accellerometer */
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccY,
- &ad->cWiimote[i].acc.oldAccY,
- ad->cWiimote[i].acc.accY, 27, 28);
- wiimoteCheckGesture (s, i, sens, ad->cWiimote[i].acc.initAccX,
- &ad->cWiimote[i].acc.oldAccX,
- ad->cWiimote[i].acc.accX, 29, 30);
+ wiimoteCheckGesture (s, wiimote, sens, wiimote->acc.initAccY,
+ &wiimote->acc.oldAccY,
+ wiimote->acc.accY, 27, 28);
+ wiimoteCheckGesture (s, wiimote, sens, wiimote->acc.initAccX,
+ &wiimote->acc.oldAccX,
+ wiimote->acc.accX, 29, 30);
/* Check Nunchuk */
- if (ad->cWiimote[i].nunchuck.connected)
+ if (wiimote->nunchuck.connected)
{
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccY,
- &ad->cWiimote[i].nunchuck.oldAccY,
- ad->cWiimote[i].nunchuck.accY, 31, 32 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initAccX,
- &ad->cWiimote[i].nunchuck.oldAccX,
- ad->cWiimote[i].nunchuck.accX, 33, 34 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickY,
- &ad->cWiimote[i].nunchuck.oldStickY,
- ad->cWiimote[i].nunchuck.stickY, 35, 36 );
- wiimoteCheckGesture ( s, i, sens, ad->cWiimote[i].nunchuck.initStickX,
- &ad->cWiimote[i].nunchuck.oldStickX,
- ad->cWiimote[i].nunchuck.stickX, 37, 38 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initAccY,
+ &wiimote->nunchuck.oldAccY,
+ wiimote->nunchuck.accY, 31, 32 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initAccX,
+ &wiimote->nunchuck.oldAccX,
+ wiimote->nunchuck.accX, 33, 34 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initStickY,
+ &wiimote->nunchuck.oldStickY,
+ wiimote->nunchuck.stickY, 35, 36 );
+ wiimoteCheckGesture ( s, wiimote, sens, wiimote->nunchuck.initStickX,
+ &wiimote->nunchuck.oldStickX,
+ wiimote->nunchuck.stickX, 37, 38 );
}
}
}
diff --git a/report.c b/report.c
index d420e98..bdd9cec 100644
--- a/report.c
+++ b/report.c
@@ -25,45 +25,44 @@
Bool sendReports(void *vs)
{
CompScreen *s = vs;
+ CompWiimote *wiimote;
WIIMOTE_DISPLAY (s->display);
-
- int i = 0;
- for (i = 0; i < MAX_WIIMOTES; i++)
+ for (wiimote = ad->wiimotes; wiimote; wiimote = wiimote->next)
{
int j;
- if (ad->cWiimote[i].connected)
+ if (wiimote->connected)
{
- for (j = 0; j < ad->cWiimote[i].nReport; j++)
+ for (j = 0; j < wiimote->nReport; j++)
{
float report[3] = { 0 };
- int sens = ad->cWiimote[i].report[j].sensitivity;
+ int sens = wiimote->report[j].sensitivity;
- switch (ad->cWiimote[i].report[j].type)
+ switch (wiimote->report[j].type)
{
case WiimoteReportTypeNone:
case WiimoteReportTypeLength:
default:
break;
case WiimoteReportTypeIR:
- report[0] = ad->cWiimote[i].irMidX - (CWIID_IR_X_MAX / 4);
- report[1] = ad->cWiimote[i].irMidY - (CWIID_IR_Y_MAX / 4);
- report[2] = ad->cWiimote[i].irDistance;
+ report[0] = wiimote->irMidX - (CWIID_IR_X_MAX / 4);
+ report[1] = wiimote->irMidY - (CWIID_IR_Y_MAX / 4);
+ report[2] = wiimote->irDistance;
break;
case WiimoteReportTypeAccellerometer:
- report[0] = (float) ( (int) (ad->cWiimote[i].acc.accDX / sens));
- report[1] = (float) ( (int) (ad->cWiimote[i].acc.accDY / sens));
- report[2] = (float) ( (int) (ad->cWiimote[i].acc.accDZ / sens));
+ report[0] = (float) ( (int) (wiimote->acc.accDX / sens));
+ report[1] = (float) ( (int) (wiimote->acc.accDY / sens));
+ report[2] = (float) ( (int) (wiimote->acc.accDZ / sens));
break;
case WiimoteReportTypeNunchuckAccellerometer:
- report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDX / sens));
- report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDY / sens));
- report[2] = (float) ( (int) (ad->cWiimote[i].nunchuck.accDZ / sens));
+ report[0] = (float) ( (int) (wiimote->nunchuck.accDX / sens));
+ report[1] = (float) ( (int) (wiimote->nunchuck.accDY / sens));
+ report[2] = (float) ( (int) (wiimote->nunchuck.accDZ / sens));
break;
case WiimoteReportTypeNunchuckStick:
- report[0] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDX / sens));
- report[1] = (float) ( (int) (ad->cWiimote[i].nunchuck.stickDY / sens));
+ report[0] = (float) ( (int) (wiimote->nunchuck.stickDX / sens));
+ report[1] = (float) ( (int) (wiimote->nunchuck.stickDY / sens));
report[2] = 0.0f;
break;
}
@@ -81,61 +80,61 @@ Bool sendReports(void *vs)
argument[nArgument].value.i = s->root;
nArgument++;
- if (ad->cWiimote[i].report[j].xarg)
- argument[nArgument].name = ad->cWiimote[i].report[j].xarg;
+ if (wiimote->report[j].xarg)
+ argument[nArgument].name = wiimote->report[j].xarg;
else
argument[nArgument].name = "x";
- if (ad->cWiimote[i].report[j].dataType == 0)
+ if (wiimote->report[j].dataType == 0)
{
argument[nArgument].type = CompOptionTypeFloat;
argument[nArgument].value.f = report[0];
}
- else if (ad->cWiimote[i].report[j].dataType == 1)
+ else if (wiimote->report[j].dataType == 1)
{
argument[nArgument].type = CompOptionTypeInt;
argument[nArgument].value.i = (int) report[0];
}
nArgument++;
- if (ad->cWiimote[i].report[j].yarg)
- argument[nArgument].name = ad->cWiimote[i].report[j].yarg;
+ if (wiimote->report[j].yarg)
+ argument[nArgument].name = wiimote->report[j].yarg;
else
argument[nArgument].name = "y";
- if (ad->cWiimote[i].report[j].dataType == 0)
+ if (wiimote->report[j].dataType == 0)
{
argument[nArgument].type = CompOptionTypeFloat;
argument[nArgument].value.f = report[1];
}
- else if (ad->cWiimote[i].report[j].dataType == 1)
+ else if (wiimote->report[j].dataType == 1)
{
argument[nArgument].type = CompOptionTypeInt;
argument[nArgument].value.i = (int) report[1];
}
nArgument++;
- if (ad->cWiimote[i].report[j].yarg)
- argument[nArgument].name = ad->cWiimote[i].report[j].yarg;
+ if (wiimote->report[j].yarg)
+ argument[nArgument].name = wiimote->report[j].yarg;
else
argument[nArgument].name = "z";
- if (ad->cWiimote[i].report[j].dataType == 0)
+ if (wiimote->report[j].dataType == 0)
{
argument[nArgument].type = CompOptionTypeFloat;
argument[nArgument].value.f = report[2];
}
- else if (ad->cWiimote[i].report[j].dataType == 1)
+ else if (wiimote->report[j].dataType == 1)
{
argument[nArgument].type = CompOptionTypeInt;
argument[nArgument].value.i = (int) report[2];
}
nArgument++;
- if (ad->cWiimote[i].report[j].pluginName && ad->cWiimote[i].report[j].actionName){
+ if (wiimote->report[j].pluginName && wiimote->report[j].actionName){
sendInfoToPlugin (s->display, argument, nArgument,
- ad->cWiimote[i].report[j].pluginName,
- ad->cWiimote[i].report[j].actionName);
+ wiimote->report[j].pluginName,
+ wiimote->report[j].actionName);
}
}
}
diff --git a/util.c b/util.c
index de68e62..7110232 100644
--- a/util.c
+++ b/util.c
@@ -50,13 +50,13 @@ void set_rpt_mode(cwiid_wiimote_t *wiimote, unsigned char rpt_mode)
/* Wii Remote Light Show */
-Bool wiimoteChangeLights(void *Wiimote)
+Bool wiimoteChangeLights(void *closure)
{
- cwiid_wiimote_t *wiimote = Wiimote;
- WIIMOTE_DISPLAY (firstDisplay);
+ CompWiimote *cwiimote = (CompWiimote *) closure;
+ cwiid_wiimote_t *wiimote = cwiimote->wiimote;
int led_state = 0;
- ad->count++;
- switch (ad->count)
+ cwiimote->count++;
+ switch (cwiimote->count)
{
case 1:
{
@@ -98,7 +98,7 @@ Bool wiimoteChangeLights(void *Wiimote)
{
toggle_bit(led_state, CWIID_LED1_ON);
set_led_state(wiimote, led_state);
- ad->count = 1;
+ cwiimote->count = 1;
}
break;
}
@@ -108,33 +108,31 @@ Bool wiimoteChangeLights(void *Wiimote)
}
/* Utility */
-int findMinIR (CompDisplay *d, int wiimoteNumber, int ir1, int ir2, int ir3, int ir4)
+int findMinIR (CompDisplay *d, CompWiimote *wiimote, int ir1, int ir2, int ir3, int ir4)
{
- WIIMOTE_DISPLAY (d);
int min = ir1;
- if ((ir2 < min) && ad->cWiimote[wiimoteNumber].ir[1].valid)
+ if ((ir2 < min) && wiimote->ir[1].valid)
min = ir2;
- if ((ir3 < min) && ad->cWiimote[wiimoteNumber].ir[2].valid)
+ if ((ir3 < min) && wiimote->ir[2].valid)
min = ir3;
- if ((ir4 < min) && ad->cWiimote[wiimoteNumber].ir[3].valid)
+ if ((ir4 < min) && wiimote->ir[3].valid)
min = ir4;
return min;
}
-int findMaxIR (CompDisplay *d, int wiimoteNumber, int ir1, int ir2, int ir3, int ir4)
+int findMaxIR (CompDisplay *d, CompWiimote *wiimote, int ir1, int ir2, int ir3, int ir4)
{
- WIIMOTE_DISPLAY (d);
int max = ir1;
- if ((ir2 > max) && ad->cWiimote[wiimoteNumber].ir[1].valid)
+ if ((ir2 > max) && wiimote->ir[1].valid)
max = ir2;
- if ((ir3 > max) && ad->cWiimote[wiimoteNumber].ir[2].valid)
+ if ((ir3 > max) && wiimote->ir[2].valid)
max = ir3;
- if ((ir4 > max) && ad->cWiimote[wiimoteNumber].ir[3].valid)
+ if ((ir4 > max) && wiimote->ir[3].valid)
max = ir4;
return max;