Beispiel #1
0
void check_quit_action() {
	// this is where we loop and check for joystick quit event (buttons 8 and 9);
	
	int i, status;

	const char *device = "/dev/input/js0";
	const char *calib = "/home/spike/.joystick.bak";

	js_data_struct jsd;

	signal(SIGINT, MySignalHandler);

	status = JSInit(&jsd, device, calib, JSFlagNonBlocking);

	if (status != JSSuccess) {
		printf("ERROR with joystick!\n");
		JSClose(&jsd);
		exit(EXIT_FAILURE);
	}

	printf("Initialized joystick: %s\n", jsd.name);

	runlevel = 2;
	while(runlevel >= 2) {
		if (JSUpdate(&jsd) == JSGotEvent &&
				(JSGetButtonState(&jsd, 8) && JSGetButtonState(&jsd, 9))) {
			JSClose(&jsd);
			return;
		}
		usleep(16000);
	}
}
Beispiel #2
0
static void
poll_joystick( int which )
{
  js_data_struct *joystick;
  double position;
  int fire, buttons;
  input_event_t event;
  size_t i;

  joystick = &jsd[which];

  if( JSUpdate( joystick ) != JSGotEvent ) return;

  position = JSGetAxisCoeffNZ( joystick, 0 );
  do_axis( which, position, INPUT_JOYSTICK_LEFT, INPUT_JOYSTICK_RIGHT );

  position = JSGetAxisCoeffNZ( joystick, 1 );
  do_axis( which, position, INPUT_JOYSTICK_UP,   INPUT_JOYSTICK_DOWN  );

  event.types.joystick.which = which;

  buttons = joystick->total_buttons;
  if( buttons > 10 ) buttons = 10;	/* We support 'only' 10 fire buttons */

  for( i = 0; i < buttons; i++ ) {

    fire = JSGetButtonState( joystick, i );
    if( fire == JSButtonStateOn ) {
      event.type = INPUT_EVENT_JOYSTICK_PRESS;
    } else {
      event.type = INPUT_EVENT_JOYSTICK_RELEASE;
    }

    event.types.joystick.button = INPUT_JOYSTICK_FIRE_1 + i;
  }

  input_event( &event );
}