--- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b4-src/wiiremote.c 2006-12-23 09:52:07.000000000 -0500 +++ wiiremote.c 2006-12-28 18:11:52.000000000 -0500 @@ -444,7 +444,7 @@ Boolean writeData(WiiRemoteRef wiiremote, const unsigned char *data, unsigned long address, size_t length) { unsigned char cmd[22]; - int i; + unsigned int i; for(i=0 ; i +#include #include +#include +#include typedef struct { int x, y, s; --- /Users/hans/Documents/Research/HID/wiiremote/aka.wiiremote-b4-src/aka.wiiremote.c 2006-12-22 19:18:31.000000000 -0500 +++ aka.wiiremote.c 2006-12-28 18:09:23.000000000 -0500 @@ -4,15 +4,27 @@ // 1.0B2 : 2006.12.15 // 1.0B3 : 2006.12.20 +#ifdef PD +#include "m_pd.h" +#define SETLONG SETFLOAT +static t_class *wiiremote_class; +#else /* Max */ #include "ext.h" +#endif /* PD */ + #include "wiiremote.h" +#include #define kInterval 100 #define kMaxTrial 100 typedef struct _akawiiremote { +#ifdef PD + t_object x_obj; +#else /* Max */ struct object obj; +#endif WiiRemoteRef wiiremote; @@ -45,7 +57,11 @@ void *akawiiremote_new(t_symbol *s, short ac, t_atom *av); void akawiiremote_free(t_akawiiremote *x); +#ifdef PD +void wiiremote_setup() +#else /* Max */ void main() +#endif /* PD */ { NumVersion outSoftwareVersion; BluetoothHCIVersionInfo outHardwareVersion; @@ -64,6 +80,32 @@ return; } + post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu"); + +#ifdef PD + post("\tPd port by Hans-Christoph Steiner"); + + wiiremote_class = class_new(gensym("wiiremote"), + (t_newmethod)akawiiremote_new, + (t_method)akawiiremote_free, + sizeof(t_akawiiremote), + CLASS_DEFAULT, + A_GIMME,0); + + class_addbang(wiiremote_class,(t_method)akawiiremote_bang); + class_addmethod(wiiremote_class,(t_method)akawiiremote_connect,gensym("connect"),0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_disconnect,gensym("disconnect"),0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_motionsensor,gensym("motionsensor"), A_DEFFLOAT, 0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("irsensor"), A_DEFFLOAT, 0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_vibration,gensym("vibration"), A_DEFFLOAT, 0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_led,gensym("led"), A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, 0); + + class_addmethod(wiiremote_class,(t_method)akawiiremote_getbatterylevel,gensym("getbatterylevel"),0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansionstatus,gensym("getexpansionstatus"),0); + class_addmethod(wiiremote_class,(t_method)akawiiremote_getledstatus,gensym("getledstatus"),0); + + class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0); +#else /* Max */ setup((t_messlist **)&akawiiremote_class, (method)akawiiremote_new, (method)akawiiremote_free, (short)sizeof(t_akawiiremote), 0L, A_GIMME, 0); addbang((method)akawiiremote_bang); @@ -79,9 +121,7 @@ addmess((method)akawiiremote_getledstatus,"getledstatus",0); addmess((method)akawiiremote_assist,"assist",A_CANT,0); - - post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu"); - +#endif /* PD */ } //-------------------------------------------------------------------------------------------- @@ -93,7 +133,11 @@ if (x->wiiremote->device == nil) return; // do nothing +#ifdef PD + outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData); +#else /* Max */ outlet_int(x->buttonsOut, x->wiiremote->buttonData); +#endif /* PD */ if (x->wiiremote->isIRSensorEnabled) { @@ -241,11 +285,13 @@ void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s) { +#ifndef PD /* Max */ if (m==ASSIST_INLET) { sprintf(s,"connect, bang, disconnect...."); } else +#endif /* NOT PD */ { switch(a) { @@ -261,6 +307,20 @@ void *akawiiremote_new(t_symbol *s, short ac, t_atom *av) { +#ifdef PD + t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class); + + if (x->wiiremote != nil) + wiiremote_init(x->wiiremote); + + x->clock = clock_new(x, (t_method)akawiiremote_clock); + + /* create anything outlet used for HID data */ + x->statusOut = outlet_new(&x->x_obj, 0); + x->buttonsOut = outlet_new(&x->x_obj, &s_float); + x->irOut = outlet_new(&x->x_obj, &s_list); + x->accOut = outlet_new(&x->x_obj, &s_list); +#else /* Max */ t_akawiiremote *x; x = (t_akawiiremote *)newobject(akawiiremote_class); @@ -270,13 +330,14 @@ wiiremote_init(x->wiiremote); x->clock = clock_new(x, (method)akawiiremote_clock); - x->trial = 0; - x->interval = kInterval; x->statusOut = outlet_new(x, 0); x->buttonsOut = intout(x); x->irOut = listout(x); x->accOut = listout(x); +#endif /* PD */ + x->trial = 0; + x->interval = kInterval; return x; } @@ -290,6 +351,10 @@ } clock_unset(x->clock); +#ifdef PD + clock_free(x->clock); +#else /* Max */ freeobject((t_object *)x->clock); +#endif /* PD */ }