Permalink
Browse files

Wii controller

  • Loading branch information...
1 parent a26bcf2 commit 4fbf5f1ba7689c28c4512624dcab0f06bd4aa098 @potatono potatono committed May 19, 2012
Showing with 305 additions and 13 deletions.
  1. +1 −1 Bursts.pde
  2. +20 −10 FollowMouse.pde
  3. +6 −0 README.md
  4. +27 −0 Routine.pde
  5. +244 −0 WiiController.pde
  6. +7 −2 domeTransmitter.pde
View
2 Bursts.pde
@@ -3,7 +3,7 @@ class Bursts extends Routine {
Burst[] bursts;
boolean burst_fill = false;
- void setup(PApplet parent) {
+ void setup(PApplet parent, WiiController controller) {
super.setup(parent);
bursts = new Burst[NUMBER_OF_BURSTS];
for (int i = 0; i<NUMBER_OF_BURSTS; i++) {
View
30 FollowMouse.pde
@@ -1,22 +1,34 @@
class FollowMouse extends Routine {
int color_angle = 0;
+ color[] colors = new color[] { color(255,0,0), color(0,255,0), color(0,0,255), color(255,255,0) };
+ void buttonAPressed() {
+ color tmp = colors[0];
+ colors[0] = colors[1];
+ colors[1] = colors[2];
+ colors[2] = colors[3];
+ colors[3] = tmp;
+ }
+
void draw() {
background(0);
+ int x = int((controller.roll+90)/180*width);
+ int y = int((controller.pitch+90)/180*height);
+
for (int row = 0; row < height; row++) {
for (int col = 0; col < width; col++) {
- if(col > mouseX && row > mouseY) {
- stroke(255,0,0);
+ if(col > x && row > y) {
+ stroke(colors[0]);
}
- else if(col > mouseX && row < mouseY) {
- stroke(0,255,0);
+ else if(col > x && row < y) {
+ stroke(colors[1]);
}
- else if(col < mouseX && row > mouseY) {
- stroke(0,0,255);
+ else if(col < x && row > y) {
+ stroke(colors[2]);
}
- else if(col < mouseX && row < mouseY) {
- stroke(0,0,0);
+ else if(col < x && row < y) {
+ stroke(colors[3]);
}
else {
stroke(255,255,255);
@@ -28,6 +40,4 @@ class FollowMouse extends Routine {
color_angle = (color_angle+1)%255;
}
-
-
}
View
6 README.md
@@ -0,0 +1,6 @@
+You need oscp5 and darwiinosc for the Wii controller support. It's OSX only, sorry.
+
+http://code.google.com/p/darwiinosc/
+http://www.sojamo.de/libraries/oscP5/
+
+
View
27 Routine.pde
@@ -1,11 +1,38 @@
class Routine {
PApplet parent;
public boolean isDone = false;
+ boolean aDown = false;
+ boolean bDown = false;
void setup(PApplet parent) {
this.parent = parent;
}
+ void predraw() {
+ if (controller.buttonB) {
+ bDown = true;
+ }
+ else if (bDown) {
+ bDown = false;
+ buttonBPressed();
+ }
+
+ if (controller.buttonA) {
+ aDown = true;
+ }
+ else if (aDown) {
+ aDown = false;
+ buttonAPressed();
+ }
+ }
+
+ void buttonBPressed() {
+ newMode();
+ }
+
+ void buttonAPressed() {
+ }
+
void reset() {}
void draw() {}
void newmode() {
View
244 WiiController.pde
@@ -0,0 +1,244 @@
+import oscP5.*;
+import netP5.*;
+
+/** darwiinremoteOSC address space
+/wii/connected , i
+/wii/mousemode , i
+/wii/button/a , i
+/wii/button/b , i
+/wii/button/up , i
+/wii/button/down , i
+/wii/button/left , i
+/wii/button/right , i
+/wii/button/minus , i
+/wii/button/plus , i
+/wii/button/home , i
+/wii/button/one , i
+/wii/button/two , i
+/wii/acc , fff
+/wii/orientation , ff
+/wii/irdata , ffffffffffff
+/wii/batterylevel , f
+/nunchuk/joystick , ff
+/nunchuk/button/z , i
+/nunchuk/button/c , i
+/nunchuk/acc , fff
+/nunchuk/orientation , ff
+*/
+
+
+class WiiController {
+ WiiController singleton = null;
+
+ OscP5 osc;
+ boolean buttonA, buttonB, buttonUp, buttonDown, buttonLeft, buttonRight;
+ boolean buttonOne, buttonTwo, buttonMinus, buttonPlus, buttonHome,buttonC,buttonZ;
+ boolean isConnected;
+ float roll, pitch;
+ float nRoll, nPitch;
+ Acceleration acc;
+ float x,y;
+ float nX, nY;
+ float pNx, pNy;
+ Acceleration nAcc;
+ boolean isNunchuck = false;
+
+ float batterylevel;
+ boolean DEBUG = false;
+
+ IRdata[] ir;
+
+ String remoteAddress;
+ int remotePort;
+
+
+ WiiController() {
+ // by default darwiinremoteOSC sends OSC messages to port 5600
+ osc = new OscP5(this,5600);
+
+ // the address and the port of darwiinremoteOSC
+ remoteAddress = "127.0.0.1";
+ remotePort = 5601;
+
+
+ acc = new Acceleration();
+ nAcc = new Acceleration();
+ ir = new IRdata[4];
+
+
+ osc.plug(this,"connected","/wii/connected");// i
+ osc.plug(this,"mousemode","/wii/mousemode");// i
+ osc.plug(this,"buttonA","/wii/button/a");// i
+ osc.plug(this,"buttonB","/wii/button/b");// i
+ osc.plug(this,"buttonUp","/wii/button/up");// i
+ osc.plug(this,"buttonDown","/wii/button/down");// i
+ osc.plug(this,"buttonLeft","/wii/button/left");// i
+ osc.plug(this,"buttonRight","/wii/button/right");// i
+ osc.plug(this,"buttonMinus","/wii/button/minus");// i
+ osc.plug(this,"buttonPlus","/wii/button/plus");// i
+ osc.plug(this,"buttonHome","/wii/button/home");// i
+ osc.plug(this,"buttonOne","/wii/button/one");// i
+ osc.plug(this,"buttonTwo","/wii/button/two");// i
+ osc.plug(this,"acceleration","/wii/acc");
+ osc.plug(this,"orientation","/wii/orientation");
+ osc.plug(this,"irdata","/wii/irdata");
+ osc.plug(this,"batterylevel","/wii/batterylevel");
+ osc.plug(this,"joystick","/nunchuk/joystick");
+ osc.plug(this,"buttonZ","/nunchuk/button/z");
+ osc.plug(this,"buttonC","/nunchuk/button/c");
+ osc.plug(this,"nunchukAcceleration","/nunchuk/acc");
+ osc.plug(this,"nunchukOrientation","/nunchuk/orientation");
+ }
+
+ void connected(int theValue) {
+ isConnected = (theValue==0) ? false:true;
+ }
+
+
+ void oscEvent(OscMessage theEvent) {
+// println(theEvent.addrPattern()+"/ "+theEvent.typetag());
+ }
+
+ void acceleration(float theX, float theY, float theZ) {
+ acc.x = theX;
+ acc.y = theY;
+ acc.z = theZ;
+ if(DEBUG) {
+ println("acceleration x:"+acc.x+" y:"+acc.y+" z:"+acc.z);
+ }
+ }
+
+ void orientation(float theRoll, float thePitch) {
+ roll += (theRoll - roll)*0.04;
+ pitch += (thePitch - pitch)*0.04;
+ if(DEBUG) {
+ println("orientation roll:"+roll+" pitch:"+pitch);
+ }
+ }
+
+
+ // darwiinremoteOSC sends 12 floats containing the x,y and size values for
+ // 4 IR spots the wiimote can sense. values are between 0 and 1 for x and y
+ // values for size are 0 and bigger. if the size is 15 or 0, the IR point is not
+ // recognized by the wiimote.
+ void ir(
+ float f10, float f11,float f12,
+ float f20,float f21, float f22,
+ float f30, float f31, float f32,
+ float f40, float f41, float f42
+ ) {
+ ir[0].x = f10;
+ ir[0].y = f11;
+ ir[0].s = f12;
+ ir[1].x = f20;
+ ir[1].y = f21;
+ ir[1].s = f22;
+ ir[2].x = f30;
+ ir[2].y = f31;
+ ir[2].s = f32;
+ ir[3].x = f40;
+ ir[3].y = f41;
+ ir[3].s = f42;
+ }
+
+
+ void joystick(float theX, float theY) {
+ // the origin xy coordinates for the joystick are theX = 125, and theY=129
+ nX = theX;
+ nY = theY;
+ isNunchuck = true;
+ }
+
+ void nunchukAcceleration(float theX, float theY, float theZ) {
+ nAcc.x = theX;
+ nAcc.y = theY;
+ nAcc.z = theZ;
+ }
+
+
+ void nunchukOrientation(float theRoll, float thePitch) {
+ nRoll += (theRoll - nRoll)*0.04;
+ nPitch += (thePitch - nPitch)*0.04;
+ if(DEBUG) {
+ println("NUNCHUCK orientation roll:"+roll+" pitch:"+pitch);
+ }
+ }
+
+ void buttonA(int theValue) {
+ buttonA = (theValue==1) ? true:false;
+ }
+
+ void buttonB(int theValue) {
+ buttonB = (theValue==1) ? true:false;
+ }
+
+ void buttonOne(int theValue) {
+ buttonOne = (theValue==1) ? true:false;
+ }
+
+ void buttonTwo(int theValue) {
+ buttonTwo = (theValue==1) ? true:false;
+ }
+
+ void buttonMinus(int theValue) {
+ buttonMinus = (theValue==1) ? true:
+ false;
+ }
+
+ void buttonPlus(int theValue) {
+ buttonPlus = (theValue==1) ? true:false;
+ }
+
+ void buttonUp(int theValue) {
+ buttonUp = (theValue==1) ? true:false;
+ }
+
+ void buttonDown(int theValue) {
+ buttonDown = (theValue==1) ? true:false;
+ }
+
+ void buttonC(int theValue) {
+ buttonC = (theValue==1) ? true:false;
+ }
+
+ void buttonZ(int theValue) {
+ buttonZ = (theValue==1) ? true:false;
+ }
+
+ void buttonHome(int theValue) {
+ buttonHome = (theValue==1) ? true:false;
+ }
+
+ void batterylevel(float theValue) {
+ println("BatteryLevel: "+theValue);
+ batterylevel = theValue;
+ }
+
+ class Acceleration {
+ float x,y,z;
+ float speedX=0, speedY=0, speedZ=0;
+ }
+
+ class IRdata {
+ float x,y,s;
+ }
+
+
+
+
+ void requestBatterylevel() {
+ osc.send("/wii/batterylevel",new Object[] {},remoteAddress,remotePort);
+ }
+
+ void forcefeedback(boolean theFlag) {
+ int n = 0;
+ if(theFlag) {
+ n = 1;
+ }
+ osc.send("/wii/forcefeedback",new Object[] {new Integer(n) },remoteAddress,remotePort);
+ }
+
+ void led(int[] n) {
+ osc.send("/wii/led",new Object[] { new Integer(n[0]), new Integer(n[1]),new Integer(n[2]),new Integer(n[3])},remoteAddress,remotePort);
+ }
+}
View
9 domeTransmitter.pde
@@ -11,7 +11,7 @@ int FRAMERATE = 30;
String hostname = "127.0.0.1"; //"192.168.1.130";
int TYPICAL_MODE_TIME = 30;
-Routine[] enabledRoutines = new Routine[] {
+Routine[] enabledRoutines = new Routine[] {/*
new Greetz(),
new Bursts(),
new Flash(),
@@ -23,7 +23,7 @@ Routine[] enabledRoutines = new Routine[] {
new TargetScanner(),
new Waterfalls(),
new RGBRoutine(),
- new FlashColors(),
+ new FlashColors(),*/
new FollowMouse()
};
@@ -45,6 +45,8 @@ PGraphics fadeLayer;
int fadeOutFrames = 0;
int fadeInFrames = 0;
+WiiController controller;
+
void setup() {
// Had to enable OPENGL for some reason new fonts don't work in JAVA2D.
size(WIDTH,HEIGHT);
@@ -56,6 +58,8 @@ void setup() {
dacwes.setAddressingMode(Dacwes.ADDRESSING_VERTICAL_NORMAL);
setMode(0);
+
+ controller = new WiiController();
for (Routine r : enabledRoutines) {
r.setup(this);
@@ -108,6 +112,7 @@ void draw() {
}
}
else if (currentRoutine != null) {
+ currentRoutine.predraw();
currentRoutine.draw();
}
else {

0 comments on commit 4fbf5f1

Please sign in to comment.