summaryrefslogtreecommitdiff
path: root/connect.c
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 /connect.c
parentad4a2000161d801454163789fa4628156ea30da0 (diff)
downloadwiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.gz
wiimote-11c94add14eda814490eb82bb73027dfae98bb6d.tar.bz2
* Use dynamically allocated memory, options don't work -- yet
Diffstat (limited to 'connect.c')
-rw-r--r--connect.c66
1 files changed, 37 insertions, 29 deletions
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