aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-10-05 20:03:21 +0000
committerIOhannes m zmölnig <zmoelnig@users.sourceforge.net>2009-10-05 20:03:21 +0000
commit3264cf646b621655547660bc076be9db79ebbad5 (patch)
tree9db68727845b28b9dd817975d93ac963bf6fddcb
parentacfbe807f7a03d5edd5bf0ddf15e194acdb6e6b0 (diff)
use a simplified queue unti li figure out, why the cwiid mesg pipe will block with a timetagged queue.
seems like the cwiid_callback is very sensitive at not taking too long to execute svn path=/trunk/externals/hardware/wiimote/; revision=12534
-rw-r--r--wiimote.c75
1 files changed, 63 insertions, 12 deletions
diff --git a/wiimote.c b/wiimote.c
index ae4a0a6..ffcb765 100644
--- a/wiimote.c
+++ b/wiimote.c
@@ -542,26 +542,30 @@ static void wiimote_cwiid_message(t_wiimote *x, union cwiid_mesg*mesg) {
}
}
+#if 0
+// queuing with sorted lists leads to "Mesg pipe overflow"
static void wiimote_dequeue(void*nada)
{
/* get all the messages from the queue that are scheduled until now */
+
+ const int dyndelay=0; /* set this to 1 use dynamic delays for compensation of asynchronicity */
+
t_wiimoteMsgList*wl=g_wiimoteMsgList;
t_wiimoteMsgList*next=NULL;
double now=0;
double nexttime=0.;
- // post("dequeuing messages until %f", now);
-
-
if(NULL==wl) {
/* no messages to dequeue; this should never happen */
}
while(wl) {
- now=clock_gettimesince(wl->x->baselogicaltime);
- if(now+1.<wl->timestamp) {
- /* no more messages to do for now, aborting */
- break;
+ if(dyndelay) {
+ now=clock_gettimesince(wl->x->baselogicaltime);
+ if(now+1.<wl->timestamp) {
+ /* no more messages to do for now, aborting */
+ break;
+ }
}
next=wl->next;
wiimote_cwiid_message(wl->x, wl->mesg);
@@ -577,10 +581,12 @@ static void wiimote_dequeue(void*nada)
g_wiimoteMsgList=wl;
/* reschedule clock */
- if(wl) {
- double delay=wl->timestamp - now;
- if(delay<1.)delay=1.;
- clock_delay(g_clock, delay);
+ if(dyndelay) {
+ if(wl) {
+ double delay=wl->timestamp - now;
+ if(delay<1.)delay=1.;
+ clock_delay(g_clock, delay);
+ }
}
}
@@ -623,8 +629,53 @@ static void wiimote_queue(t_wiimote*x, union cwiid_mesg*mesg, double timestamp)
/* reset the clock */
clock_delay(g_clock, 0);
}
+#else
+static void wiimote_dequeue(void*nada)
+{
+ /* get all the messages from the queue that are scheduled until now */
+ t_wiimoteMsgList*wl=g_wiimoteMsgList;
+ t_wiimoteMsgList*next=NULL;
+
+ if(NULL==wl) {
+ /* no messages to dequeue */
+ return;
+ }
+ while(wl) {
+ next=wl->next;
+ wiimote_cwiid_message(wl->x, wl->mesg);
+ wl->x=NULL;
+ wl->timestamp=0.;
+ freebytes(wl->mesg, sizeof( union cwiid_mesg));
+ wl->mesg=NULL;
+ wl->next=NULL;
+ freebytes(wl, sizeof(t_wiimoteMsgList));
+ wl=next;
+ }
+
+ g_wiimoteMsgList=NULL;
+}
+static void wiimote_queue(t_wiimote*x, union cwiid_mesg*mesg, double timestamp)
+{
+ /* add mesg to the queue with a Pd timestamp */
+ t_wiimoteMsgList*wl=g_wiimoteMsgList;
+
+ /* insert the current message into the list */
+ t_wiimoteMsgList*newentry=(t_wiimoteMsgList*)getbytes(sizeof(t_wiimoteMsgList));
+ newentry->next=g_wiimoteMsgList;
+ newentry->x=x;
+ newentry->mesg=(union cwiid_mesg*)getbytes(sizeof( union cwiid_mesg));
+ memcpy(newentry->mesg, mesg, (sizeof( union cwiid_mesg)));
+ newentry->timestamp=timestamp;
+
+ g_wiimoteMsgList=newentry;
+
+ /* reset the clock */
+ clock_delay(g_clock, 0);
+}
+#endif
+
// The CWiid library invokes a callback function whenever events are
// generated by the wiimote. This function is specified when connecting
// to the wiimote (in the cwiid_open function).
@@ -658,7 +709,7 @@ static void cwiid_callback(cwiid_wiimote_t *wiimote, int mesg_count,
pd_timestamp=wiimote_timestamp2logicaltime(x, timestamp);
for (i=0; i < mesg_count; i++) {
-#if 0
+#if 1
wiimote_queue(x, mesg_array+i, pd_timestamp);
#else
wiimote_cwiid_message(x, mesg_array+i);