Exemple #1
0
void PipeDevice::AddAxis(const std::string& name, double value)
{
  // Dolphin uses separate axes for left/right, which complicates things.
  PipeInput* ax_hi = new PipeInput("Axis " + name + " +");
  ax_hi->SetState(value);
  PipeInput* ax_lo = new PipeInput("Axis " + name + " -");
  ax_lo->SetState(value);
  m_axes[name + " +"] = ax_hi;
  m_axes[name + " -"] = ax_lo;
  AddAnalogInputs(ax_lo, ax_hi);
}
Exemple #2
0
evdevDevice::evdevDevice(const std::string& devnode) : m_devfile(devnode)
{
  // The device file will be read on one of the main threads, so we open in non-blocking mode.
  m_fd = open(devnode.c_str(), O_RDWR | O_NONBLOCK);
  int ret = libevdev_new_from_fd(m_fd, &m_dev);

  if (ret != 0)
  {
    // This useally fails because the device node isn't an evdev device, such as /dev/input/js0
    m_initialized = false;
    close(m_fd);
    return;
  }

  m_name = StripSpaces(libevdev_get_name(m_dev));

  // Controller buttons (and keyboard keys)
  int num_buttons = 0;
  for (int key = 0; key < KEY_MAX; key++)
    if (libevdev_has_event_code(m_dev, EV_KEY, key))
      AddInput(new Button(num_buttons++, key, m_dev));

  // Absolute axis (thumbsticks)
  int num_axis = 0;
  for (int axis = 0; axis < 0x100; axis++)
    if (libevdev_has_event_code(m_dev, EV_ABS, axis))
    {
      AddAnalogInputs(new Axis(num_axis, axis, false, m_dev),
                      new Axis(num_axis, axis, true, m_dev));
      num_axis++;
    }

  // Force feedback
  if (libevdev_has_event_code(m_dev, EV_FF, FF_PERIODIC))
  {
    for (auto type : {FF_SINE, FF_SQUARE, FF_TRIANGLE, FF_SAW_UP, FF_SAW_DOWN})
      if (libevdev_has_event_code(m_dev, EV_FF, type))
        AddOutput(new ForceFeedback(type, m_dev));
  }
  if (libevdev_has_event_code(m_dev, EV_FF, FF_RUMBLE))
  {
    AddOutput(new ForceFeedback(FF_RUMBLE, m_dev));
  }

  // TODO: Add leds as output devices

  m_initialized = true;
  m_interesting = num_axis >= 2 || num_buttons >= 8;
}
Touchscreen::Touchscreen(int padID)
	: _padID(padID)
{
	AddInput(new Button(_padID, ButtonManager::BUTTON_A));
	AddInput(new Button(_padID, ButtonManager::BUTTON_B));
	AddInput(new Button(_padID, ButtonManager::BUTTON_START));
	AddInput(new Button(_padID, ButtonManager::BUTTON_X));
	AddInput(new Button(_padID, ButtonManager::BUTTON_Y));
	AddInput(new Button(_padID, ButtonManager::BUTTON_Z));
	AddInput(new Button(_padID, ButtonManager::BUTTON_UP));
	AddInput(new Button(_padID, ButtonManager::BUTTON_DOWN));
	AddInput(new Button(_padID, ButtonManager::BUTTON_LEFT));
	AddInput(new Button(_padID, ButtonManager::BUTTON_RIGHT));
	AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_MAIN_LEFT, -1.0f), new Axis(_padID, ButtonManager::STICK_MAIN_RIGHT));
	AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_MAIN_UP, -1.0f), new Axis(_padID, ButtonManager::STICK_MAIN_DOWN));
	AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_C_UP, -1.0f), new Axis(_padID, ButtonManager::STICK_C_DOWN));
	AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_C_LEFT, -1.0f), new Axis(_padID, ButtonManager::STICK_C_RIGHT));
	AddAnalogInputs(new Axis(_padID, ButtonManager::TRIGGER_L), new Axis(_padID, ButtonManager::TRIGGER_L));
	AddAnalogInputs(new Axis(_padID, ButtonManager::TRIGGER_R), new Axis(_padID, ButtonManager::TRIGGER_R));
}
Exemple #4
0
Joystick::Joystick(SDL_Joystick* const joystick, const int sdl_index, const unsigned int index)
	: m_joystick(joystick)
	, m_sdl_index(sdl_index)
	, m_index(index)
{
	// really bad HACKS:
	// to not use SDL for an XInput device
	// too many people on the forums pick the SDL device and ask:
	// "why don't my 360 gamepad triggers/rumble work correctly"
#ifdef _WIN32
	// checking the name is probably good (and hacky) enough
	// but i'll double check with the num of buttons/axes
	std::string lcasename = GetName();
	std::transform(lcasename.begin(), lcasename.end(), lcasename.begin(), tolower);

	if ((std::string::npos != lcasename.find("xbox 360"))
		&& (10 == SDL_JoystickNumButtons(joystick))
		&& (5 == SDL_JoystickNumAxes(joystick))
		&& (1 == SDL_JoystickNumHats(joystick))
		&& (0 == SDL_JoystickNumBalls(joystick))
		)
	{
		// this device won't be used
		return;
	}
#endif

	// get buttons
	for (u8 i = 0; i != SDL_JoystickNumButtons(m_joystick); ++i)
		AddInput(new Button(i, m_joystick));
	
	// get hats
	for (u8 i = 0; i != SDL_JoystickNumHats(m_joystick); ++i)
	{
		// each hat gets 4 input instances associated with it, (up down left right)
		for (u8 d = 0; d != 4; ++d)
			AddInput(new Hat(i, m_joystick, d));
	}

	// get axes
	for (u8 i = 0; i != SDL_JoystickNumAxes(m_joystick); ++i)
	{
		// each axis gets a negative and a positive input instance associated with it
		AddAnalogInputs(new Axis(i, m_joystick, -32768),
			new Axis(i, m_joystick, 32767));
	}

#ifdef USE_SDL_HAPTIC
	// try to get supported ff effects
	m_haptic = SDL_HapticOpenFromJoystick( m_joystick );
	if (m_haptic)
	{
		//SDL_HapticSetGain( m_haptic, 1000 );
		//SDL_HapticSetAutocenter( m_haptic, 0 );

		const unsigned int supported_effects = SDL_HapticQuery( m_haptic );

		// constant effect
		if (supported_effects & SDL_HAPTIC_CONSTANT)
		{
			m_state_out.push_back(EffectIDState());
			AddOutput(new ConstantEffect(m_state_out.back()));
		}

		// ramp effect
		if (supported_effects & SDL_HAPTIC_RAMP)
		{
			m_state_out.push_back(EffectIDState());
			AddOutput(new RampEffect(m_state_out.back()));
		}

		// sine effect
		if (supported_effects & SDL_HAPTIC_SINE)
		{
			m_state_out.push_back(EffectIDState());
			AddOutput(new SineEffect(m_state_out.back()));
		}

		// square effect
		if (supported_effects & SDL_HAPTIC_SQUARE)
		{
			m_state_out.push_back(EffectIDState());
			AddOutput(new SquareEffect(m_state_out.back()));
		}

		// triangle effect
		if (supported_effects & SDL_HAPTIC_TRIANGLE)
		{
			m_state_out.push_back(EffectIDState());
			AddOutput(new TriangleEffect(m_state_out.back()));
		}
	}
#endif

}
Exemple #5
0
Touchscreen::Touchscreen(int padID) : _padID(padID)
{
  // GC
  AddInput(new Button(_padID, ButtonManager::BUTTON_A));
  AddInput(new Button(_padID, ButtonManager::BUTTON_B));
  AddInput(new Button(_padID, ButtonManager::BUTTON_START));
  AddInput(new Button(_padID, ButtonManager::BUTTON_X));
  AddInput(new Button(_padID, ButtonManager::BUTTON_Y));
  AddInput(new Button(_padID, ButtonManager::BUTTON_Z));
  AddInput(new Button(_padID, ButtonManager::BUTTON_UP));
  AddInput(new Button(_padID, ButtonManager::BUTTON_DOWN));
  AddInput(new Button(_padID, ButtonManager::BUTTON_LEFT));
  AddInput(new Button(_padID, ButtonManager::BUTTON_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_MAIN_LEFT),
                  new Axis(_padID, ButtonManager::STICK_MAIN_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_MAIN_UP),
                  new Axis(_padID, ButtonManager::STICK_MAIN_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_C_LEFT),
                  new Axis(_padID, ButtonManager::STICK_C_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::STICK_C_UP),
                  new Axis(_padID, ButtonManager::STICK_C_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TRIGGER_L),
                  new Axis(_padID, ButtonManager::TRIGGER_L));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TRIGGER_R),
                  new Axis(_padID, ButtonManager::TRIGGER_R));

  // Wiimote
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_A));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_B));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_MINUS));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_PLUS));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_HOME));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_1));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_BUTTON_2));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_UP));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_DOWN));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_LEFT));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_RIGHT));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_IR_HIDE));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_TILT_MODIFIER));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_X));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_Y));
  AddInput(new Button(_padID, ButtonManager::WIIMOTE_SHAKE_Z));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_IR_UP),
                  new Axis(_padID, ButtonManager::WIIMOTE_IR_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_IR_LEFT),
                  new Axis(_padID, ButtonManager::WIIMOTE_IR_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_IR_FORWARD),
                  new Axis(_padID, ButtonManager::WIIMOTE_IR_BACKWARD));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_SWING_UP),
                  new Axis(_padID, ButtonManager::WIIMOTE_SWING_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_SWING_LEFT),
                  new Axis(_padID, ButtonManager::WIIMOTE_SWING_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_SWING_FORWARD),
                  new Axis(_padID, ButtonManager::WIIMOTE_SWING_BACKWARD));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_TILT_LEFT),
                  new Axis(_padID, ButtonManager::WIIMOTE_TILT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::WIIMOTE_TILT_FORWARD),
                  new Axis(_padID, ButtonManager::WIIMOTE_TILT_BACKWARD));

  // Wii ext: Nunchuk
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_BUTTON_C));
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_BUTTON_Z));
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_TILT_MODIFIER));
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_X));
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_Y));
  AddInput(new Button(_padID, ButtonManager::NUNCHUK_SHAKE_Z));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_STICK_LEFT),
                  new Axis(_padID, ButtonManager::NUNCHUK_STICK_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_STICK_UP),
                  new Axis(_padID, ButtonManager::NUNCHUK_STICK_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_SWING_LEFT),
                  new Axis(_padID, ButtonManager::NUNCHUK_SWING_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_SWING_UP),
                  new Axis(_padID, ButtonManager::NUNCHUK_SWING_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_SWING_FORWARD),
                  new Axis(_padID, ButtonManager::NUNCHUK_SWING_BACKWARD));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_TILT_LEFT),
                  new Axis(_padID, ButtonManager::NUNCHUK_TILT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::NUNCHUK_TILT_FORWARD),
                  new Axis(_padID, ButtonManager::NUNCHUK_TILT_BACKWARD));

  // Wii ext: Classic
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_A));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_B));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_X));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_Y));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_MINUS));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_PLUS));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_HOME));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_ZL));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_BUTTON_ZR));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_UP));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_DOWN));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_LEFT));
  AddInput(new Button(_padID, ButtonManager::CLASSIC_DPAD_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_LEFT),
                  new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_UP),
                  new Axis(_padID, ButtonManager::CLASSIC_STICK_LEFT_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_LEFT),
                  new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_UP),
                  new Axis(_padID, ButtonManager::CLASSIC_STICK_RIGHT_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_L),
                  new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_L));
  AddAnalogInputs(new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_R),
                  new Axis(_padID, ButtonManager::CLASSIC_TRIGGER_R));

  // Wii-ext: Guitar
  AddInput(new Button(_padID, ButtonManager::GUITAR_BUTTON_MINUS));
  AddInput(new Button(_padID, ButtonManager::GUITAR_BUTTON_PLUS));
  AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_GREEN));
  AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_RED));
  AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_YELLOW));
  AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_BLUE));
  AddInput(new Button(_padID, ButtonManager::GUITAR_FRET_ORANGE));
  AddInput(new Button(_padID, ButtonManager::GUITAR_STRUM_UP));
  AddInput(new Button(_padID, ButtonManager::GUITAR_STRUM_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::GUITAR_STICK_LEFT),
                  new Axis(_padID, ButtonManager::GUITAR_STICK_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::GUITAR_STICK_UP),
                  new Axis(_padID, ButtonManager::GUITAR_STICK_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::GUITAR_WHAMMY_BAR),
                  new Axis(_padID, ButtonManager::GUITAR_WHAMMY_BAR));

  // Wii-ext: Drums
  AddInput(new Button(_padID, ButtonManager::DRUMS_BUTTON_MINUS));
  AddInput(new Button(_padID, ButtonManager::DRUMS_BUTTON_PLUS));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_RED));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_YELLOW));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_BLUE));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_GREEN));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_ORANGE));
  AddInput(new Button(_padID, ButtonManager::DRUMS_PAD_BASS));
  AddAnalogInputs(new Axis(_padID, ButtonManager::DRUMS_STICK_LEFT),
                  new Axis(_padID, ButtonManager::DRUMS_STICK_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::DRUMS_STICK_UP),
                  new Axis(_padID, ButtonManager::DRUMS_STICK_DOWN));

  // Wii-ext: Turntable
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_GREEN_LEFT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_RED_LEFT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_BLUE_LEFT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_GREEN_RIGHT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_RED_RIGHT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_BLUE_RIGHT));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_MINUS));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_PLUS));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_HOME));
  AddInput(new Button(_padID, ButtonManager::TURNTABLE_BUTTON_EUPHORIA));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_LEFT_LEFT),
                  new Axis(_padID, ButtonManager::TURNTABLE_TABLE_LEFT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_TABLE_RIGHT_LEFT),
                  new Axis(_padID, ButtonManager::TURNTABLE_TABLE_RIGHT_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_STICK_LEFT),
                  new Axis(_padID, ButtonManager::TURNTABLE_STICK_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_STICK_UP),
                  new Axis(_padID, ButtonManager::TURNTABLE_STICK_DOWN));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_LEFT),
                  new Axis(_padID, ButtonManager::TURNTABLE_CROSSFADE_RIGHT));
  AddAnalogInputs(new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL),
                  new Axis(_padID, ButtonManager::TURNTABLE_EFFECT_DIAL));
  // Rumble
  AddOutput(new Motor(_padID, ButtonManager::RUMBLE));
}