Joysticks

From CCRMA Wiki
Revision as of 17:41, 15 March 2009 by Courtier (Talk | contribs)

Jump to: navigation, search

Mapping Joysticks

This bit of code will spit out whatever codes are being transmitted from your controller to ChucK. It's also important to test letting buttons go up and down separately to see how your controller deals with that, if it's important to you. I used it to figure out how to interpret the input from my controller or joystick.

Hid js;
HidMsg msg;

if( !js.openJoystick( 0 ) ) me.exit();
<<< "Ready?", "" >>>;

while(true)
  {
    // wait for event
    js => now;
    while( js.recv( msg ) )
      {
	js => now;
	<<< "\n\nI LIKE TO","MOVE IT MOVE IT" >>>;
	while( js.recv(msg))
	  {
	    if( msg.isAxisMotion())
	      {
		<<< "axismotion" >>>;
		<<< "axis: ", msg.which, " position: ", msg.axisPosition >>>;
	      }
	    if( msg.isButtonDown())
	      {
		<<< "buttondown: ", msg.which >>>;
	      }
	    if( msg.isButtonUp())
	      {
		<<< "buttonup: ", msg.which >>>;
	      }
	    if(msg.isHatMotion() )
	      {
		<<< "hat: ", msg.idata >>>;
	      }
	  }
      }
  }