From 8013e5e7a0574db98e391139988a3eb16b8e475b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Sun, 4 Oct 2009 18:34:05 +0000 Subject: blabla svn path=/trunk/externals/hardware/wiimote/; revision=12525 --- wiiremote.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/wiiremote.c b/wiiremote.c index 2491163..99af4fb 100644 --- a/wiiremote.c +++ b/wiiremote.c @@ -345,18 +345,35 @@ static void wiiremote_cwiid_balance(t_wiiremote *x, struct cwiid_balance_mesg *m #ifdef CWIID_RPT_MOTIONPLUS static void wiiremote_cwiid_motionplus(t_wiiremote *x, struct cwiid_motionplus_mesg *mesg) { - t_atom ap[3]; - t_float scale = 1.f / ((uint16_t)0xFFFF); + t_atom ap[4]; + t_float scale = 1.f;// / ((uint16_t)0xFFFF); t_float phi = scale*mesg->angle_rate[CWIID_PHI]; t_float theta= scale*mesg->angle_rate[CWIID_THETA]; t_float psi = scale*mesg->angle_rate[CWIID_PSI]; - SETFLOAT(ap+0, phi); - SETFLOAT(ap+1, theta); - SETFLOAT(ap+2, psi); + t_float phi_speed = 1.; + t_float theta_speed = 1.; + t_float psi_speed = 1.; - outlet_anything(x->outlet_data, gensym("motionplus"), 3, ap); + + SETSYMBOL(ap+0, gensym("low_speed")); +#ifdef HAVE_CWIID_MOTIONPLUS_LOWSPEED + phi_speed = mesg->low_speed[CWIID_PHI]; + theta_speed= mesg->low_speed[CWIID_THETA]; + psi_speed = mesg->low_speed[CWIID_PSI]; +#endif + SETFLOAT (ap+1, phi_speed); + SETFLOAT (ap+2, theta_speed); + SETFLOAT (ap+3, psi_speed); + outlet_anything(x->outlet_data, gensym("motionplus"), 4, ap); + + + SETSYMBOL(ap+0, gensym("angle_rate")); + SETFLOAT (ap+1, phi); + SETFLOAT (ap+2, theta); + SETFLOAT (ap+3, psi); + outlet_anything(x->outlet_data, gensym("motionplus"), 4, ap); } #endif @@ -439,6 +456,21 @@ static void wiiremote_cwiid_message(t_wiiremote *x, union cwiid_mesg mesg) { } +static void print_timestamp(struct timespec*timestamp, struct timespec*reference) { + double t0=timestamp->tv_sec*1000. + (timestamp->tv_nsec) / 1000000.; + double t1=0; + double t=0; + if(reference) { + t1=reference->tv_sec*1000. + (reference->tv_nsec) / 1000000.; + } + + t=t0-t1; + + post("timestamp: %f", (t)); + +} + + // The CWiid library invokes a callback function whenever events are // generated by the wiiremote. This function is specified when connecting // to the wiiremote (in the cwiid_open function). @@ -459,6 +491,13 @@ static void cwiid_callback(cwiid_wiimote_t *wiiremote, int mesg_count, int i; t_wiiremote *x=NULL; + static struct timespec*ts=NULL; + if(NULL==ts) { + ts=(struct timespec*)getbytes(sizeof(struct timespec)); + ts->tv_sec =timestamp->tv_sec; + ts->tv_nsec =timestamp->tv_nsec; + } + if(g_wiiremoteList==NULL||wiiremote==NULL) { post("no wii's known"); return; @@ -468,7 +507,8 @@ static void cwiid_callback(cwiid_wiimote_t *wiiremote, int mesg_count, post("no wiiremote loaded: %d%",cwiid_get_id(wiiremote)); return; } - + + //print_timestamp(timestamp, ts); for (i=0; i < mesg_count; i++) { wiiremote_cwiid_message(x, mesg_array[i]); } @@ -483,7 +523,6 @@ static void wiiremote_status(t_wiiremote *x) pd_error(x, "error requesting status message"); } } - } -- cgit v1.2.1