Update of /cvsroot/pure-data/externals/io/wiiremote In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28500
Modified Files: aka.wiiremote.c wiiremote.c wiiremote.h Log Message: merged in b6 and got it compiling, lots of warning, I would be surprised if it actually works
Index: wiiremote.c =================================================================== RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.c,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** wiiremote.c 28 Dec 2006 23:16:03 -0000 1.4 --- wiiremote.c 17 May 2007 05:33:45 -0000 1.5 *************** *** 10,15 ****
#define kTrial 10
- //static WiiRemoteRec gWiiRemote; // remove in 1.0B4
//-------------------------------------------------------------------------------------------- --- 10,23 ----
#define kTrial 10 + #define kWait 10000 [...1365 lines suppressed...] + if ((ret = writeData(wiiremote, (darr){0x08}, 0x04B00030, 1)) == false) return ret; + usleep(kWait); + + requestUpdates(wiiremote); + } + else + { + // probably should do some writes to power down the camera, save battery + // but don't know how yet. + + ret = wiiremote_motionsensor(wiiremote, wiiremote->isMotionSensorEnabled); + ret = wiiremote_vibration(wiiremote, wiiremote->isVibrationEnabled); + ret = wiiremote_expansion(wiiremote, wiiremote->isExpansionPortEnabled); + } + + return ret; + } + Boolean wiiremote_getstatus(WiiRemoteRef wiiremote) {
Index: wiiremote.h =================================================================== RCS file: /cvsroot/pure-data/externals/io/wiiremote/wiiremote.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** wiiremote.h 28 Dec 2006 23:16:03 -0000 1.3 --- wiiremote.h 17 May 2007 05:33:45 -0000 1.4 *************** *** 9,16 **** --- 9,94 ---- #include <string.h>
+ // Macros for PD for compability with Max macros + #ifdef PD + #define SETSYM SETSYMBOL + #define SETLONG SETFLOAT + #endif + + typedef unsigned char WiiIRModeType; + enum { + kWiiIRModeBasic = 0x01, + kWiiIRModeExtended = 0x03, + kWiiIRModeFull = 0x05 + }; + typedef struct { int x, y, s; } IRData;
+ typedef struct { + unsigned char accX_zero, accY_zero, accZ_zero, accX_1g, accY_1g, accZ_1g; + } WiiAccCalibData; + + typedef struct { + unsigned char x_min, x_max, x_center, y_min, y_max, y_center; + } WiiJoyStickCalibData; + + typedef UInt16 WiiButtonType; + enum { + WiiRemoteAButton, + WiiRemoteBButton, + WiiRemoteOneButton, + WiiRemoteTwoButton, + WiiRemoteMinusButton, + WiiRemoteHomeButton, + WiiRemotePlusButton, + WiiRemoteUpButton, + WiiRemoteDownButton, + WiiRemoteLeftButton, + WiiRemoteRightButton, + + WiiNunchukZButton, + WiiNunchukCButton, + + WiiClassicControllerXButton, + WiiClassicControllerYButton, + WiiClassicControllerAButton, + WiiClassicControllerBButton, + WiiClassicControllerLButton, + WiiClassicControllerRButton, + WiiClassicControllerZLButton, + WiiClassicControllerZRButton, + WiiClassicControllerUpButton, + WiiClassicControllerDownButton, + WiiClassicControllerLeftButton, + WiiClassicControllerRightButton, + WiiClassicControllerMinusButton, + WiiClassicControllerHomeButton, + WiiClassicControllerPlusButton + }; + + + typedef UInt16 WiiExpansionPortType; + enum{ + WiiExpNotAttached, + WiiNunchuk, + WiiClassicController + }; + + typedef UInt16 WiiAccelerationSensorType; + enum{ + WiiRemoteAccelerationSensor, + WiiNunchukAccelerationSensor + }; + + + typedef UInt16 WiiJoyStickType; + enum{ + WiiNunchukJoyStick, + WiiClassicControllerLeftJoyStick, + WiiClassicControllerRightJoyStick + }; + + typedef struct _WiiRemoteRec { *************** *** 19,22 **** --- 97,102 ---- IOBluetoothL2CAPChannelRef ichan; IOBluetoothL2CAPChannelRef cchan; + + CFStringRef address;
unsigned char accX; *************** *** 29,45 **** int orientation; int leftPoint; // is point 0 or 1 on the left. -1 when not tracking. float posX; float posY; float angle; Boolean tracking; ! IRData irData[4]; double batteryLevel; ! Boolean isIRSensorEnabled; Boolean isMotionSensorEnabled; Boolean isVibrationEnabled; ! ! Boolean isExpansionPortUsed; Boolean isLED1Illuminated; Boolean isLED2Illuminated; --- 109,131 ---- int orientation; int leftPoint; // is point 0 or 1 on the left. -1 when not tracking. + float posX; float posY; float angle; Boolean tracking; ! ! WiiExpansionPortType expType; ! WiiAccCalibData wiiCalibData, nunchukCalibData; ! WiiJoyStickCalibData nunchukJoyStickCalibData; ! WiiIRModeType wiiIRMode; IRData irData[4]; double batteryLevel; ! Boolean readingRegister; Boolean isMotionSensorEnabled; + Boolean isIRSensorEnabled; Boolean isVibrationEnabled; ! Boolean isExpansionPortEnabled; ! Boolean initExpPort; Boolean isLED1Illuminated; Boolean isLED2Illuminated; *************** *** 47,62 **** Boolean isLED4Illuminated; IOBluetoothUserNotificationRef disconnectNotification; } WiiRemoteRec, *WiiRemoteRef;
void wiiremote_init(WiiRemoteRef wiiremote); Boolean wiiremote_isconnected(WiiRemoteRef wiiremote); ! Boolean wiiremote_search(WiiRemoteRef wiiremote); Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote); Boolean wiiremote_connect(WiiRemoteRef wiiremote); Boolean wiiremote_disconnect(WiiRemoteRef wiiremote); Boolean wiiremote_motionsensor(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_irsensor(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_vibration(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_led(WiiRemoteRef wiiremote, Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4); Boolean wiiremote_getstatus(WiiRemoteRef wiiremote); --- 133,175 ---- Boolean isLED4Illuminated; + Boolean isExpansionPortAttached; + IOBluetoothUserNotificationRef disconnectNotification; + + //nunchuk + unsigned char nStickX; + unsigned char nStickY; + unsigned char nAccX; + unsigned char nAccY; + unsigned char nAccZ; + unsigned char nButtonData; + + float nLowZ; + float nLowX; + int nOrientation; + + //classic controller + unsigned short cButtonData; + unsigned char cStickX1; + unsigned char cStickY1; + unsigned char cStickX2; + unsigned char cStickY2; + unsigned char cAnalogL; + unsigned char cAnalogR; + } WiiRemoteRec, *WiiRemoteRef;
void wiiremote_init(WiiRemoteRef wiiremote); Boolean wiiremote_isconnected(WiiRemoteRef wiiremote); ! Boolean wiiremote_search(WiiRemoteRef wiiremote, char *address); Boolean wiiremote_stopsearch(WiiRemoteRef wiiremote); Boolean wiiremote_connect(WiiRemoteRef wiiremote); Boolean wiiremote_disconnect(WiiRemoteRef wiiremote); + void wiiremote_getaddress(WiiRemoteRef wiiremote, char *address); Boolean wiiremote_motionsensor(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_irsensor(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_vibration(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_led(WiiRemoteRef wiiremote, Boolean enabled1, Boolean enabled2, Boolean enabled3, Boolean enabled4); + Boolean wiiremote_expansion(WiiRemoteRef wiiremote, Boolean enabled); Boolean wiiremote_getstatus(WiiRemoteRef wiiremote); +
Index: aka.wiiremote.c =================================================================== RCS file: /cvsroot/pure-data/externals/io/wiiremote/aka.wiiremote.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** aka.wiiremote.c 3 Jan 2007 01:01:08 -0000 1.6 --- aka.wiiremote.c 17 May 2007 05:33:45 -0000 1.7 *************** *** 1,11 **** --- 1,17 ---- // aka.wiiremote.c // Copyright by Masayuki Akamatsu + // Code for PD by Hans-Christoph Steiner // 1.0B1 : 2006.12.12 // 1.0B2 : 2006.12.15 // 1.0B3 : 2006.12.20 + // 1.0B4 : 2006.12.24 + // 1.0B5 : 2007.02.03 + // 1.0B6 : 2007.04.24
#ifdef PD #include "m_pd.h" + #define SETSYM SETSYMBOL #define SETLONG SETFLOAT + #define method t_method static t_class *wiiremote_class; #else /* Max */ *************** *** 28,40 **** WiiRemoteRef wiiremote; void *clock; ! long interval; ! long trial; void *statusOut; ! void *buttonsOut; ! void *irOut; ! void *accOut; } t_akawiiremote;
--- 34,44 ---- WiiRemoteRef wiiremote; + char address[32]; void *clock; ! Boolean connected; void *statusOut; ! void *dataOut } t_akawiiremote;
*************** *** 42,45 **** --- 46,50 ----
void akawiiremote_bang(t_akawiiremote *x); + void akawiiremote_address(t_akawiiremote *x, t_symbol *s); void akawiiremote_connect(t_akawiiremote *x); void akawiiremote_disconnect(t_akawiiremote *x); *************** *** 48,55 **** void akawiiremote_vibration(t_akawiiremote *x, long enable); void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4);
! void akawiiremote_getbatterylevel(t_akawiiremote *x); ! void akawiiremote_getexpansionstatus(t_akawiiremote *x); ! void akawiiremote_getledstatus(t_akawiiremote *x);
void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s); --- 53,63 ---- void akawiiremote_vibration(t_akawiiremote *x, long enable); void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4); + void akawiiremote_expansion(t_akawiiremote *x, long enable);
! void akawiiremote_getbattery(t_akawiiremote *x); ! void akawiiremote_getexpansion(t_akawiiremote *x); ! void akawiiremote_getled(t_akawiiremote *x); ! void akawiiremote_getaddress(t_akawiiremote *x); ! void akawiiremote_getcalibration(t_akawiiremote *x);
void akawiiremote_assist(t_akawiiremote *x, void *b, long m, long a, char *s); *************** *** 58,61 **** --- 66,73 ---- void akawiiremote_free(t_akawiiremote *x);
+ char remoteStr[] = "remote"; + char nunchukStr[] = "nunchuk"; + char classicStr[] = "classic"; + #ifdef PD void wiiremote_setup() *************** *** 67,70 **** --- 79,84 ---- BluetoothHCIVersionInfo outHardwareVersion; + post("aka.wiiremote 1.0B6-UB by Masayuki Akamatsu"); + if (IOBluetoothGetVersion(&outSoftwareVersion, &outHardwareVersion)==kIOReturnSuccess) { *************** *** 81,86 **** }
- post("aka.wiiremote 1.0B4-UB by Masayuki Akamatsu"); - #ifdef PD post("\tPd port by Hans-Christoph Steiner"); --- 95,98 ---- *************** *** 96,107 **** 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); --- 108,119 ---- 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("motion"), A_DEFFLOAT, 0); ! class_addmethod(wiiremote_class,(t_method)akawiiremote_irsensor,gensym("ir"), 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_getbattery,gensym("getbattery"),0); ! class_addmethod(wiiremote_class,(t_method)akawiiremote_getexpansion,gensym("getexpansion"),0); ! class_addmethod(wiiremote_class,(t_method)akawiiremote_getled,gensym("getled"),0); class_addmethod(wiiremote_class,(t_method)akawiiremote_assist,gensym("assist"),A_CANT,0); *************** *** 110,123 ****
addbang((method)akawiiremote_bang); ! addmess((method)akawiiremote_connect,"connect",0); addmess((method)akawiiremote_disconnect,"disconnect",0); ! addmess((method)akawiiremote_motionsensor,"motionsensor", A_DEFLONG, 0); ! addmess((method)akawiiremote_irsensor,"irsensor", A_DEFLONG, 0); addmess((method)akawiiremote_vibration,"vibration", A_DEFLONG, 0); addmess((method)akawiiremote_led,"led", A_DEFLONG, A_DEFLONG, A_DEFLONG, A_DEFLONG, 0);
! addmess((method)akawiiremote_getbatterylevel,"getbatterylevel",0); ! addmess((method)akawiiremote_getexpansionstatus,"getexpansionstatus",0); ! addmess((method)akawiiremote_getledstatus,"getledstatus",0); addmess((method)akawiiremote_assist,"assist",A_CANT,0); --- 122,140 ----
addbang((method)akawiiremote_bang); ! addmess((method)akawiiremote_address,"address",A_DEFSYM, 0); ! addmess((method)akawiiremote_connect,"connect", 0); addmess((method)akawiiremote_disconnect,"disconnect",0); ! addmess((method)akawiiremote_motionsensor,"motion", A_DEFLONG, 0); ! addmess((method)akawiiremote_irsensor,"ir", A_DEFLONG, 0); addmess((method)akawiiremote_vibration,"vibration", A_DEFLONG, 0); addmess((method)akawiiremote_led,"led", A_DEFLONG, A_DEFLONG, A_DEFLONG, A_DEFLONG, 0); + addmess((method)akawiiremote_expansion,"expansion", A_DEFLONG, 0); + addmess((method)akawiiremote_expansion,"nunchuk", A_DEFLONG, 0);
! addmess((method)akawiiremote_getbattery,"getbattery",0); ! addmess((method)akawiiremote_getexpansion,"getexpansion",0); ! addmess((method)akawiiremote_getled,"getled",0); ! addmess((method)akawiiremote_getaddress,"getaddress",0); ! addmess((method)akawiiremote_getcalibration,"getcalibration", 0); addmess((method)akawiiremote_assist,"assist",A_CANT,0); *************** *** 129,164 **** void akawiiremote_bang(t_akawiiremote *x) { ! t_atom list[4]; 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) { ! SETFLOAT(list, x->wiiremote->posX); ! SETFLOAT(list + 1, x->wiiremote->posY); ! SETFLOAT(list + 2, x->wiiremote->angle); ! SETLONG (list + 3, x->wiiremote->tracking); ! outlet_list(x->irOut, 0L, 4, list); }
if (x->wiiremote->isMotionSensorEnabled) { ! SETLONG(list, x->wiiremote->accX); ! SETLONG(list + 1, x->wiiremote->accY); ! SETLONG(list + 2, x->wiiremote->accZ); ! SETLONG(list + 3, x->wiiremote->orientation); ! outlet_list(x->accOut, 0L, 4, list); } - - //wiiremote_getstatus(); // stopped in B3 }
void akawiiremote_connect(t_akawiiremote *x) { --- 146,257 ---- void akawiiremote_bang(t_akawiiremote *x) { ! t_atom av[5]; if (x->wiiremote->device == nil) return; // do nothing ! //#ifdef PD ! // outlet_float(x->buttonsOut, (t_float) x->wiiremote->buttonData); ! //#else /* Max */ ! //#endif /* PD */
+ if (x->wiiremote->isExpansionPortAttached && x->wiiremote->isExpansionPortEnabled) + { + // Classic Controller + if (x->wiiremote->expType == WiiClassicController) + { + // Buttons + SETSYM(av, gensym("buttons")); + SETLONG(av + 1, x->wiiremote->cButtonData); + outlet_anything(x->dataOut, gensym(classicStr), 2, av); + + // Joystick 1 + SETSYM(av, gensym("stick1")); + SETLONG(av + 1, x->wiiremote->cStickX1); + SETLONG(av + 2, x->wiiremote->cStickY1); + outlet_anything(x->dataOut, gensym(classicStr), 3, av); + + // Joystick 2 + SETSYM(av, gensym("stick2")); + SETLONG(av + 1, x->wiiremote->cStickX2); + SETLONG(av + 2, x->wiiremote->cStickY2); + outlet_anything(x->dataOut, gensym(classicStr), 3, av); + + // Analog + SETSYM(av, gensym("analog")); + SETLONG(av + 1, x->wiiremote->cAnalogL); + SETLONG(av + 2, x->wiiremote->cAnalogR); + outlet_anything(x->dataOut, gensym(classicStr), 3, av); + } + + // Nunchuk + if (x->wiiremote->expType == WiiNunchuk) + { + // Buttons + SETSYM(av, gensym("buttons")); + SETLONG(av + 1, x->wiiremote->nButtonData); + outlet_anything(x->dataOut, gensym(nunchukStr), 2, av); + + // Joystick + SETSYM(av, gensym("stick")); + SETLONG(av + 1, x->wiiremote->nStickX); + SETLONG(av + 2, x->wiiremote->nStickY); + outlet_anything(x->dataOut, gensym(nunchukStr), 3, av); + + // Motion Sensor + if (x->wiiremote->isMotionSensorEnabled) + { + SETSYM(av, gensym("motion")); + SETLONG(av + 1, x->wiiremote->nAccX); + SETLONG(av + 2, x->wiiremote->nAccY); + SETLONG(av + 3, x->wiiremote->nAccZ); + SETLONG(av + 4, x->wiiremote->nOrientation); + outlet_anything(x->dataOut, gensym(nunchukStr), 5, av); + } + } + } + + // Wii Remote + + // Buttons + SETSYM(av, gensym("buttons")); + SETLONG(av + 1, x->wiiremote->buttonData); + outlet_anything(x->dataOut, gensym(remoteStr), 2, av); + + // IR Sensor if (x->wiiremote->isIRSensorEnabled) { ! SETSYM(av, gensym("ir")); ! SETFLOAT(av + 1, x->wiiremote->posX); // posX and posY are "float"???? ! SETFLOAT(av + 2, x->wiiremote->posY); ! SETFLOAT(av + 3, x->wiiremote->angle); ! SETLONG (av + 4, x->wiiremote->tracking); ! outlet_anything(x->dataOut, gensym(remoteStr), 5, av); }
+ // Motion Sensor if (x->wiiremote->isMotionSensorEnabled) { ! SETSYM(av, gensym("motion")); ! SETLONG(av + 1, x->wiiremote->accX); ! SETLONG(av + 2, x->wiiremote->accY); ! SETLONG(av + 3, x->wiiremote->accZ); ! SETLONG(av + 4, x->wiiremote->orientation); ! outlet_anything(x->dataOut, gensym(remoteStr), 5, av); } }
+ //-------------------------------------------------------------------------------------------- + + void akawiiremote_address(t_akawiiremote *x, t_symbol *s) + { + if (*(s->s_name) == 0) // if null string + *(x->address) = 0; + else + strcpy(x->address, s->s_name); + } + + //-------------------------------------------------------------------------------------------- + void akawiiremote_connect(t_akawiiremote *x) { *************** *** 173,178 **** else { ! result = wiiremote_search(x->wiiremote); // start searching the device ! x->trial = 0; clock_unset(x->clock); // stop clock clock_delay(x->clock, 0); // start clock to check the device found --- 266,271 ---- else { ! result = wiiremote_search(x->wiiremote, x->address); // start searching the device ! x->connected = false; clock_unset(x->clock); // stop clock clock_delay(x->clock, 0); // start clock to check the device found *************** *** 189,244 **** t_atom status; result = wiiremote_disconnect(x->wiiremote); SETLONG(&status, result); ! outlet_anything(x->statusOut, gensym("disconnect"), 1, &status); }
void akawiiremote_motionsensor(t_akawiiremote *x, long enable) { ! wiiremote_motionsensor(x->wiiremote, enable); }
void akawiiremote_irsensor(t_akawiiremote *x, long enable) { ! wiiremote_irsensor(x->wiiremote, enable); }
void akawiiremote_vibration(t_akawiiremote *x, long enable) { ! wiiremote_vibration(x->wiiremote, enable); }
void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4) { ! wiiremote_led(x->wiiremote, enable1, enable2, enable3, enable4); }
//--------------------------------------------------------------------------------------------
! void akawiiremote_getbatterylevel(t_akawiiremote *x) { ! t_atom status;
! SETFLOAT(&status, x->wiiremote->batteryLevel); ! outlet_anything(x->statusOut, gensym("batterylevel"), 1, &status); }
! void akawiiremote_getexpansionstatus(t_akawiiremote *x) { ! t_atom status; ! ! SETLONG(&status, x->wiiremote->isExpansionPortUsed); ! outlet_anything(x->statusOut, gensym("expansionstatus"), 1, &status); }
! void akawiiremote_getledstatus(t_akawiiremote *x) { ! t_atom list[4]; ! ! SETLONG(list, x->wiiremote->isLED1Illuminated); ! SETLONG(list + 1, x->wiiremote->isLED2Illuminated); ! SETLONG(list + 2, x->wiiremote->isLED3Illuminated); ! SETLONG(list + 3, x->wiiremote->isLED4Illuminated); ! outlet_anything(x->statusOut, gensym("ledstatus"), 4, list); }
--- 282,460 ---- t_atom status; + clock_unset(x->clock); // stop clock + wiiremote_stopsearch(x->wiiremote); + result = wiiremote_disconnect(x->wiiremote); SETLONG(&status, result); ! outlet_anything(x->statusOut, gensym("disconnect"), 1, &status); ! ! x->connected = !result; }
+ //-------------------------------------------------------------------------------------------- + void akawiiremote_motionsensor(t_akawiiremote *x, long enable) { ! Boolean result; ! t_atom status; ! ! result = wiiremote_motionsensor(x->wiiremote, enable); ! //SETLONG(&status, result); ! //outlet_anything(x->statusOut, gensym("motion"), 1, &status); }
void akawiiremote_irsensor(t_akawiiremote *x, long enable) { ! Boolean result; ! t_atom status; ! ! result = wiiremote_irsensor(x->wiiremote, enable); ! //SETLONG(&status, result); ! //outlet_anything(x->statusOut, gensym("ir"), 1, &status); ! } ! ! void akawiiremote_expansion(t_akawiiremote *x, long enable) ! { ! Boolean result; ! t_atom status; ! ! result = wiiremote_expansion(x->wiiremote, enable); ! //SETLONG(&status, result); ! //outlet_anything(x->statusOut, gensym("nunchuk"), 1, &status); }
void akawiiremote_vibration(t_akawiiremote *x, long enable) { ! Boolean result; ! t_atom status; ! ! result = wiiremote_vibration(x->wiiremote, enable); ! //SETLONG(&status, result); ! //outlet_anything(x->statusOut, gensym("vibration"), 1, &status); }
void akawiiremote_led(t_akawiiremote *x, long enable1, long enable2, long enable3, long enable4) { ! Boolean result; ! t_atom status; ! ! result = wiiremote_led(x->wiiremote, enable1, enable2, enable3, enable4); ! //SETLONG(&status, result); ! //outlet_anything(x->statusOut, gensym("led"), 1, &status); }
//--------------------------------------------------------------------------------------------
! void akawiiremote_getbattery(t_akawiiremote *x) { ! if (x->wiiremote->device == nil) ! { ! outlet_anything(x->statusOut, gensym("battery"), 0, nil); ! } ! else ! { ! t_atom status; ! ! SETFLOAT(&status, x->wiiremote->batteryLevel); ! outlet_anything(x->statusOut, gensym("battery"), 1, &status); ! } ! }
! void akawiiremote_getexpansion(t_akawiiremote *x) ! { ! if (x->wiiremote->device == nil) ! { ! outlet_anything(x->statusOut, gensym("expansion"), 0, nil); ! } ! else ! { ! t_atom status; ! if (x->wiiremote->isExpansionPortAttached) ! SETLONG(&status, x->wiiremote->expType); ! else ! SETLONG(&status, 0); ! outlet_anything(x->statusOut, gensym("expansion"), 1, &status); ! } }
! void akawiiremote_getled(t_akawiiremote *x) { ! if (x->wiiremote->device == nil) ! { ! outlet_anything(x->statusOut, gensym("led"), 0, nil); ! } ! else ! { ! t_atom list[4]; ! ! SETLONG(list, x->wiiremote->isLED1Illuminated); ! SETLONG(list + 1, x->wiiremote->isLED2Illuminated); ! SETLONG(list + 2, x->wiiremote->isLED3Illuminated); ! SETLONG(list + 3, x->wiiremote->isLED4Illuminated); ! outlet_anything(x->statusOut, gensym("led"), 4, list); ! } }
! void akawiiremote_getcalibration(t_akawiiremote *x) { ! if (x->wiiremote->device == nil) ! { ! outlet_anything(x->statusOut, gensym("calibration"), 0, nil); ! } ! else ! { ! t_atom list[8]; ! ! if (x->wiiremote->isExpansionPortAttached) ! { ! SETSYM(list, gensym(nunchukStr)); ! SETSYM(list + 1, gensym("stick")); ! SETLONG(list + 2, x->wiiremote->nunchukJoyStickCalibData.x_max); ! SETLONG(list + 3, x->wiiremote->nunchukJoyStickCalibData.x_min); ! SETLONG(list + 4, x->wiiremote->nunchukJoyStickCalibData.x_center); ! SETLONG(list + 5, x->wiiremote->nunchukJoyStickCalibData.y_max); ! SETLONG(list + 6, x->wiiremote->nunchukJoyStickCalibData.y_min); ! SETLONG(list + 7, x->wiiremote->nunchukJoyStickCalibData.y_center); ! outlet_anything(x->statusOut, gensym("calibration"), 8, list); ! ! SETSYM(list + 1, gensym("motion")); ! SETLONG(list + 2, x->wiiremote->nunchukCalibData.accX_zero); ! SETLONG(list + 3, x->wiiremote->nunchukCalibData.accY_zero); ! SETLONG(list + 4, x->wiiremote->nunchukCalibData.accZ_zero); ! SETLONG(list + 5, x->wiiremote->nunchukCalibData.accX_1g); ! SETLONG(list + 6, x->wiiremote->nunchukCalibData.accY_1g); ! SETLONG(list + 7, x->wiiremote->nunchukCalibData.accZ_1g); ! outlet_anything(x->statusOut, gensym("calibration"), 8, list); ! } ! ! SETSYM(list, gensym(remoteStr)); ! SETSYM(list + 1, gensym("motion")); ! SETLONG(list + 2, x->wiiremote->wiiCalibData.accX_zero); ! SETLONG(list + 3, x->wiiremote->wiiCalibData.accY_zero); ! SETLONG(list + 4, x->wiiremote->wiiCalibData.accZ_zero); ! SETLONG(list + 5, x->wiiremote->wiiCalibData.accX_1g); ! SETLONG(list + 6, x->wiiremote->wiiCalibData.accY_1g); ! SETLONG(list + 7, x->wiiremote->wiiCalibData.accZ_1g); ! outlet_anything(x->statusOut, gensym("calibration"), 8, list); ! } ! } ! ! //-------------------------------------------------------------------------------------------- ! ! void akawiiremote_getaddress(t_akawiiremote *x) ! { ! if (x->wiiremote->device == nil) ! { ! outlet_anything(x->statusOut, gensym("address"), 0, nil); ! } ! else ! { ! char str[32]; ! t_atom address; ! ! wiiremote_getaddress(x->wiiremote, str); ! SETSYM(&address, gensym(str)); ! outlet_anything(x->statusOut, gensym("address"), 1, &address); ! } }
*************** *** 247,283 **** void akawiiremote_clock(t_akawiiremote *x) { ! //Boolean result; t_atom status; ! if (wiiremote_isconnected(x->wiiremote)) // if the device is connected... { ! clock_unset(x->clock); // stop clock ! ! wiiremote_stopsearch(x->wiiremote); ! //result = wiiremote_connect(); // remove in B3 ! wiiremote_getstatus(x->wiiremote); // add in B3 SETLONG(&status, 1); outlet_anything(x->statusOut, gensym("connect"), 1, &status); } ! else // if the device is not connected... { ! x->trial++; ! //SETLONG(&status, x->trial); ! //outlet_anything(x->statusOut, gensym("searching"), 1, &status); ! ! if (x->trial >= kMaxTrial) // if trial is over ! { ! clock_unset(x->clock); // stop clock ! ! wiiremote_stopsearch(x->wiiremote); ! SETLONG(&status, 0); ! outlet_anything(x->statusOut, gensym("connect"), 1, &status); ! } ! else ! { ! //post("trial %d",x->trial); ! clock_delay(x->clock, x->interval); // restart clock ! } } }
--- 463,487 ---- void akawiiremote_clock(t_akawiiremote *x) { ! Boolean connection; t_atom status; ! connection = wiiremote_isconnected(x->wiiremote); ! ! if (x->connected == false && connection == true) // if the device is connected... { ! wiiremote_getstatus(x->wiiremote); ! x->connected = true; SETLONG(&status, 1); outlet_anything(x->statusOut, gensym("connect"), 1, &status); } ! ! if (x->connected == true && connection == false) { ! x->connected = false; ! SETLONG(&status, 0); ! outlet_anything(x->statusOut, gensym("connect"), 1, &status); } + + clock_delay(x->clock, kInterval); // restart clock }
*************** *** 296,303 **** switch(a) { ! case 0: sprintf(s,"list(acc-x acc-y acc-z orientation)"); break; ! case 1: sprintf(s,"list(pos-x pos-y angle tracking)"); break; ! case 2: sprintf(s,"int(buttons)"); break; ! case 3: sprintf(s,"message(status)"); break; } } --- 500,505 ---- switch(a) { ! case 0: sprintf(s,"data messages"); break; ! case 2: sprintf(s,"status messages"); break; } } *************** *** 308,343 **** void *akawiiremote_new(t_symbol *s, short ac, t_atom *av) { - #ifdef PD - t_akawiiremote *x = (t_akawiiremote *)pd_new(wiiremote_class); - - x->wiiremote = (WiiRemoteRef)getbytes(sizeof(WiiRemoteRec)); // add in 1.0B4 - 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); ! x->wiiremote = (WiiRemoteRef)getbytes(sizeof(WiiRemoteRec)); // add in 1.0B4 if (x->wiiremote != nil) wiiremote_init(x->wiiremote); x->clock = clock_new(x, (method)akawiiremote_clock); 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; --- 510,550 ---- void *akawiiremote_new(t_symbol *s, short ac, t_atom *av) { t_akawiiremote *x; + #ifdef PD + x = (t_akawiiremote *)pd_new(wiiremote_class); + #else /* Max */ x = (t_akawiiremote *)newobject(akawiiremote_class); + #endif /* PD */ ! x->wiiremote = (WiiRemoteRef)getbytes(sizeof(WiiRemoteRec)); if (x->wiiremote != nil) + { wiiremote_init(x->wiiremote); + x->wiiremote->isMotionSensorEnabled = true; + x->wiiremote->isIRSensorEnabled = false; + x->wiiremote->isVibrationEnabled = false; + x->wiiremote->isExpansionPortEnabled = false; + x->wiiremote->isLED1Illuminated = false; + x->wiiremote->isLED2Illuminated = false; + x->wiiremote->isLED3Illuminated = false; + x->wiiremote->isLED4Illuminated = false; + } x->clock = clock_new(x, (method)akawiiremote_clock); + #ifdef PD + if (ac>0 && av[0].a_type == A_SYMBOL) + strcpy(x->address, av[0].a_w.w_symbol->s_name); + + x->statusOut = outlet_new(&x->x_obj, 0); + x->dataOut = outlet_new(&x->x_obj, 0); + #else /* Max */ + if (ac>0 && av[0].a_type == A_SYM) + strcpy(x->address, av[0].a_w.w_sym->s_name); x->statusOut = outlet_new(x, 0); ! x->dataOut = outlet_new(x, 0); #endif /* PD */ ! x->connected = false;
return x; *************** *** 346,353 **** void akawiiremote_free(t_akawiiremote *x) { ! if (x->wiiremote != nil) // add in 1.0B4 { ! wiiremote_disconnect(x->wiiremote); ! freebytes(x->wiiremote, sizeof(WiiRemoteRec)); // add in 1.0B4 } --- 553,562 ---- void akawiiremote_free(t_akawiiremote *x) { ! if (x->wiiremote != nil) { ! if (wiiremote_isconnected(x->wiiremote)) ! wiiremote_disconnect(x->wiiremote); ! freebytes(x->wiiremote, sizeof(WiiRemoteRec)); ! x->wiiremote = nil; }