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