Example #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);
	}
}
Example #2
0
bool VistaJswJoystickDriver::DoSensorUpdate(VistaType::microtime nTs)
{
	if(JSUpdate(&m_jsd) == JSGotEvent)
	{
		_sJoyMeasure nState;

		for(unsigned int n=0; n < 16; ++n)
		{
			if(JSIsAxisAllocated(&m_jsd, n))
			{
				// ok, we have that axis
				js_axis_struct *axis_ptr = m_jsd.axis[n];
				nState.m_nAxesTs[n]        = axis_ptr->time;
				nState.m_nAxes[n]          = axis_ptr->cur;
			}
			else
			{
				nState.m_nAxesTs[n] = 0;
				nState.m_nAxes[n] = 0;
			}
		}

		for(unsigned int b=0; b < 32; ++b)
		{
			if(JSIsButtonAllocated(&m_jsd, b))
			{
				js_button_struct *button_ptr = m_jsd.button[b];
				nState.m_nButtons[b]   = (button_ptr->state ? true : false);
				nState.m_nButtonsTs[b] = button_ptr->time;
			}
			else
			{
				nState.m_nButtons[b] = false;
				nState.m_nButtonsTs[b] = 0;
			}

		}

		VistaDeviceSensor *pSensor = GetSensorByIndex(0);

		VistaSensorMeasure *pM = MeasureStart( 0, nTs, true );
		std::memcpy( (*pM).getWrite<void>(), &nState, sizeof(_sJoyMeasure) );
		MeasureStop( 0 );
		pSensor->SetUpdateTimeStamp(nTs);

	}
	return true;
}
Example #3
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 );
}