I've written some Chuck code to connect with OSC using OSCulator. In some places I am tracking button presses and doing various things like toggle a variable every time I press the key, or just flip the variable when the key is held down, but restore it when I release the key. I find that the code works unreliably unless I turn off the wii/remote/1/accel/pry group of messages. If those are turned off then it behaves as I expect. If I turn them on, then my code works only one out of every several presses, but the pattern is not repeatable.
I think that every Wiimote button press or release sends 2 identical messages. parameter = 1.0 for button down and 0.0 for button up.
Any ideas as to how to make this more reliable? Because as it stands, it is not usable for performance if it only works every 2nd or 3rd time.
Here's my Chuck code.
I think that every Wiimote button press or release sends 2 identical messages. parameter = 1.0 for button down and 0.0 for button up.
Any ideas as to how to make this more reliable? Because as it stands, it is not usable for performance if it only works every 2nd or 3rd time.
Here's my Chuck code.
Code:
// OSC variables // Listen for all incoming messages on port OscIn oin; // make an OSC receiver 6449 => oin.port; // set port # oin.listenAll(); // any message at all OscMsg omsg; // message holder // OSC msg catch and parsing loop float f; 0 => int id; 0 => int buttonB; 0 => int buttonA; 0 => int button1; 0 => int button2; 0 => int buttonLEFT; 0 => int buttonUP; 0 => int buttonRIGHT; 0 => int buttonDOWN; // <<< "About to", "proc" >>>; procOSCMsgs(); float pitchLast, rollLast, yawLast, accelLast; fun void procOSCMsgs () { while(true) { oin => now; // wait for any OSC if(oin.recv(omsg)) { // <<< "got message:", omsg.address, omsg.typetag >>>; // <<< yaw, accel >>>; if(omsg.address == "/wii/1/button/Up") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (buttonUP == 0)) { 1 => buttonUP; // project9.muteIt(2, buttonUP); } if((0.0 == f) && (buttonUP == 1)) { 0 => buttonUP; } // <<< "Button UP:", buttonUP >>>; } } else if(omsg.address == "/wii/1/button/Down") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (buttonDOWN == 0)) { // <<< "Argument", f >>>; 1 => buttonDOWN; } if((0.0 == f)) { // <<< "Argument", f >>>; 0 => buttonDOWN; } // <<< "Button DOWN:", buttonDOWN >>>; } } else if(omsg.address == "/wii/1/button/Left") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (buttonLEFT == 0)) { // <<< "Argument", f >>>; 1 => buttonLEFT; } if((0.0 == f)) { // <<< "Argument", f >>>; 0 => buttonLEFT; } } } else if(omsg.address == "/wii/1/button/Right") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (buttonRIGHT == 0)) { // <<< "Argument", f >>>; 1 => buttonRIGHT; } if((0.0 == f) && (buttonRIGHT == 1)) { // <<< "Argument", f >>>; 0 => buttonRIGHT; } } } else if(omsg.address == "/wii/1/button/B") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; <<< "Button B", f >>>; if((1.0 == f) && (buttonB == 0)) { <<< "Button B", "down" >>>; 1 => buttonB; // project9.preset1(); } if((0.0 == f) && (buttonB == 1)) { <<< "Button B", "up" >>>; 0 => buttonB; } } } else if(omsg.address == "/wii/1/button/A") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; // <<< "Button A", f >>>; if((1.0 == f) && (buttonA == 0)) { <<< "Button A", "Down" >>>; 1 => buttonA; } if((0.0 == f) && (buttonA == 1)) { <<< "Button A", "Up" >>>; 0 => buttonA; } } } else if(omsg.address == "/wii/1/button/1") { if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (button1 == 0)) { <<< "Argument", f >>>; 1 => button1; } if((0.0 == f)) { <<< "Argument", f >>>; 0 => button1; } } } else if(omsg.address == "/wii/1/button/2") { 0 => int button; if(omsg.typetag == "f") { omsg.getFloat(0) => f; if((1.0 == f) && (button == 0)) { <<< "Argument", f >>>; 1 => button; } } } else if(omsg.address == "/wii/1/accel/pry") { // <<< omsg.address, omsg.typetag >>>; omsg.getFloat(0) => float pitch; omsg.getFloat(1) => float roll; omsg.getFloat(2) => float yaw; omsg.getFloat(3) => float accel; (pitch - pitchLast) => float pitchDiff; if(Math.fabs(pitchDiff) > 0.08) { pitch => pitchLast; } (roll - rollLast) => float rollDiff; if(Math.fabs(rollDiff) > 0.16) { roll => rollLast; // <<< "-------- Roll:", roll >>>; } } } } }
Comment