// Tether (GameTrak) animation/debugging // by Perry R. Cook, May 2012 float tether1[3]; float tether2[3]; 0 => int footbutton; MAUI_View myWinder; MAUI_Button exitButt, footButt; MAUI_Slider tethers[2][3]; MAUI_LED rPos, lPos; MAUI_Button rZ, lZ; float bL[3]; float bR[3]; doSetup(); 0 => int gotTether; spork ~ getTether(); 1 => int notDone; while (notDone) { 0.05 :: second => now; if (gotTether) { for (0 => int i; i < 3; i++) { tether1[i] => tethers[0][i].value; tether2[i] => tethers[1][i].value; } footbutton => footButt.state; } else { for (0 => int i; i < 3; i++) { tethers[0][i].value() => tether1[i]; tethers[1][i].value() => tether2[i]; } } // if (footButt.state()) { // 0 => notDone; // } tethers[0][0].value()*230 => bL[0]; 90+(1.0-tethers[0][1].value())*180 => bL[1]; tethers[0][2].value()*100 => bL[2]; lPos.position(bL[0],bL[1]); lZ.size(48,45+bL[2]); lZ.position(8+bL[0],6+bL[1]-bL[2]); tethers[1][0].value()*230 => bR[0]; 90+(1.0-tethers[1][1].value())*180 => bR[1]; tethers[1][2].value()*100 => bR[2]; rPos.position(330+bR[0],bR[1]); rZ.size(48,45+bR[2]); rZ.position(338+bR[0],6+bR[1]-bR[2]); if (exitButt.state()==1) 0 => notDone; } myWinder.destroy(); fun void doSetup() { myWinder.name("Tether Animation"); myWinder.size(620.0,470.0); myWinder.position(400,400); MAUI_Button borders[2][4]; borders[0][0].size(290,45); borders[1][0].size(290,45); borders[0][1].size(290,45); borders[1][1].size(290,45); borders[0][0].position(0,85); borders[1][0].position(330,85); borders[0][1].position(0,290); borders[1][1].position(330,290); borders[0][2].size(45,250); borders[1][2].size(45,250); borders[0][3].size(45,250); borders[1][3].size(45,250); borders[0][2].position(0,85); borders[1][2].position(330,85); borders[0][3].position(250,85); borders[1][3].position(580,85); for (0 => int i; i < 4; i++) { myWinder.addElement(borders[0][i]); myWinder.addElement(borders[1][i]); } for (0 => int i; i < 3; i++) { tethers[0][i].size(290,70);tethers[1][i].size(290,70); tethers[0][i].position(0,310+i*45);tethers[1][i].position(330,310+i*45); tethers[0][i].range(0.0,1.0);tethers[1][i].range(0.0,1.0); 0.5 => tethers[0][i].value => tethers[1][i].value; myWinder.addElement(tethers[0][i]); myWinder.addElement(tethers[1][i]); } footButt.size(85,100); footButt.name("Tether\nFoot\nSwitch"); footButt.toggleType(); footButt.position(270,330); myWinder.addElement(footButt); tethers[0][0].name("Tether L X"); tethers[1][0].name("Tether R X"); tethers[0][1].name("Tether L Y"); tethers[1][1].name("Tether R Y"); tethers[0][2].name("Tether L Z"); tethers[1][2].name("Tether R Z"); exitButt.name("Exit"); exitButt.toggleType(); // EXIT exitButt.size(70,65); exitButt.position(275,410); // exitButt.position(560,350); myWinder.addElement(exitButt); lPos.color(2); lPos.light(); rPos.color(2); rPos.light(); myWinder.addElement(lPos); myWinder.addElement(rPos); lZ.size(47,80); rZ.size(47,80); lZ.toggleType(); 1 => lZ.state; rZ.toggleType(); 1 => rZ.state; myWinder.addElement(lZ); myWinder.addElement(rZ); myWinder.display(); } //tether input fun void getTether() { Hid hi; HidMsg msg; 0 => int device; if( me.args() ) me.arg(0) => Std.atoi => device; if( !hi.openJoystick( device ) ) { 0 => gotTether; return; } 1 => gotTether; <<< "joystick '" + hi.name() + "' ready", "" >>>; while( notDone ) { 30::ms => now; hi => now; while( hi.recv( msg ) ) { if( msg.isAxisMotion() ) // joystick axis motion { //<<< "joystick axis", msg.which, ":", msg.axisPosition >>>; if ( msg.which == 0 ) 0.5*(1.0+msg.axisPosition) => tether1[0]; else if( msg.which == 1 ) 0.5*(1.0+msg.axisPosition) => tether1[1]; else if( msg.which == 2 ) 0.5*(1.0-msg.axisPosition) => tether1[2]; else if( msg.which == 3 ) 0.5*(1.0+msg.axisPosition) => tether2[0]; else if( msg.which == 4 ) 0.5*(1.0+msg.axisPosition) => tether2[1]; else if( msg.which == 5 ) 0.5*(1.0-msg.axisPosition) => tether2[2]; // <<< tether1[0], tether1[1], tether1[2], tether2[0], tether2[1], tether2[2] >>>; } else if( msg.isButtonDown() ) // joystick button down { 1 => footbutton; <<< "joystick button", msg.which, "down" >>>; //footbutton_call(footbutton_state); // pedalhit.signal(); } else if( msg.isButtonUp() ) // joystick button up { 0 => footbutton; <<< "joystick button", msg.which, "up" >>>; //footbutton_call(footbutton_state); } } } }