Jump to content

Joysticks: Difference between revisions

From CCRMA Wiki
Courtier (talk | contribs)
No edit summary
Courtier (talk | contribs)
No edit summary
Line 1: Line 1:
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.


== Mapping Joysticks ==
== 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.


<pre>
<pre>

Revision as of 00:41, 16 March 2009

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 >>>;
	      }
	  }
      }
  }