2015-05-24 06:55:12 +02:00
|
|
|
// Copyright 2010 Dolphin Emulator Project
|
2021-07-05 03:22:19 +02:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-02-10 13:54:46 -05:00
|
|
|
|
|
|
|
#pragma once
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-02-05 15:32:13 -06:00
|
|
|
#include <SDL.h>
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2020-09-15 04:34:41 -07:00
|
|
|
#include "InputCommon/ControllerInterface/CoreDevice.h"
|
2022-10-22 16:13:35 -05:00
|
|
|
#include "InputCommon/ControllerInterface/InputBackend.h"
|
2017-11-09 14:06:58 -08:00
|
|
|
|
2019-06-17 16:39:24 -04:00
|
|
|
namespace ciface::SDL
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2022-10-22 16:13:35 -05:00
|
|
|
std::unique_ptr<ciface::InputBackend> CreateInputBackend(ControllerInterface* controller_interface);
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2023-08-03 16:30:26 +02:00
|
|
|
class GameController : public Core::Device
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
2023-08-03 16:30:26 +02:00
|
|
|
// GameController inputs
|
2013-06-16 20:07:10 -04:00
|
|
|
class Button : public Core::Device::Input
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-29 01:34:26 -04:00
|
|
|
std::string GetName() const override;
|
2023-08-03 16:30:26 +02:00
|
|
|
Button(SDL_GameController* gc, SDL_GameControllerButton button) : m_gc(gc), m_button(button) {}
|
2013-10-29 01:34:26 -04:00
|
|
|
ControlState GetState() const override;
|
2023-08-03 16:30:26 +02:00
|
|
|
bool IsMatchingName(std::string_view name) const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
private:
|
2023-08-03 16:30:26 +02:00
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
const SDL_GameControllerButton m_button;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2013-06-16 20:07:10 -04:00
|
|
|
class Axis : public Core::Device::Input
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-29 01:34:26 -04:00
|
|
|
std::string GetName() const override;
|
2023-08-03 16:30:26 +02:00
|
|
|
Axis(SDL_GameController* gc, Sint16 range, SDL_GameControllerAxis axis)
|
|
|
|
: m_gc(gc), m_range(range), m_axis(axis)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
const Sint16 m_range;
|
|
|
|
const SDL_GameControllerAxis m_axis;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Legacy inputs
|
|
|
|
class LegacyButton : public Core::Device::Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const override;
|
2024-01-15 15:19:24 +01:00
|
|
|
LegacyButton(SDL_Joystick* js, int index, bool is_detectable)
|
2023-08-03 16:30:26 +02:00
|
|
|
: m_js(js), m_index(index), m_is_detectable(is_detectable)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
bool IsDetectable() const override { return m_is_detectable; }
|
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_Joystick* const m_js;
|
|
|
|
const int m_index;
|
|
|
|
const bool m_is_detectable;
|
|
|
|
};
|
|
|
|
|
|
|
|
class LegacyAxis : public Core::Device::Input
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::string GetName() const override;
|
2024-01-15 15:19:24 +01:00
|
|
|
LegacyAxis(SDL_Joystick* js, int index, s16 range, bool is_detectable)
|
|
|
|
: m_js(js), m_index(index), m_range(range), m_is_detectable(is_detectable)
|
2023-08-03 16:30:26 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
bool IsDetectable() const override { return m_is_detectable; }
|
2013-10-29 01:34:26 -04:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
SDL_Joystick* const m_js;
|
2024-01-15 15:19:24 +01:00
|
|
|
const int m_index;
|
|
|
|
const s16 m_range;
|
2023-08-03 16:30:26 +02:00
|
|
|
const bool m_is_detectable;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2023-08-03 16:30:26 +02:00
|
|
|
class LegacyHat : public Input
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2013-10-29 01:34:26 -04:00
|
|
|
std::string GetName() const override;
|
2024-01-15 15:19:24 +01:00
|
|
|
LegacyHat(SDL_Joystick* js, int index, u8 direction, bool is_detectable)
|
|
|
|
: m_js(js), m_index(index), m_direction(direction), m_is_detectable(is_detectable)
|
2011-03-14 01:20:11 +00:00
|
|
|
{
|
|
|
|
}
|
2023-08-03 16:30:26 +02:00
|
|
|
bool IsDetectable() const override { return m_is_detectable; }
|
2013-10-29 01:34:26 -04:00
|
|
|
ControlState GetState() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2010-04-02 02:48:24 +00:00
|
|
|
private:
|
2011-03-14 01:20:11 +00:00
|
|
|
SDL_Joystick* const m_js;
|
2024-01-15 15:19:24 +01:00
|
|
|
const int m_index;
|
2011-03-14 01:20:11 +00:00
|
|
|
const u8 m_direction;
|
2023-08-03 16:30:26 +02:00
|
|
|
const bool m_is_detectable;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Rumble
|
|
|
|
class Motor : public Output
|
|
|
|
{
|
|
|
|
public:
|
2024-01-15 15:19:41 +01:00
|
|
|
explicit Motor(SDL_GameController* gc) : m_gc(gc) {}
|
2023-08-03 16:30:26 +02:00
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MotorL : public Output
|
|
|
|
{
|
|
|
|
public:
|
2024-01-15 15:19:41 +01:00
|
|
|
explicit MotorL(SDL_GameController* gc) : m_gc(gc) {}
|
2023-08-03 16:30:26 +02:00
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MotorR : public Output
|
|
|
|
{
|
|
|
|
public:
|
2024-01-15 15:19:41 +01:00
|
|
|
explicit MotorR(SDL_GameController* gc) : m_gc(gc) {}
|
2023-08-03 16:30:26 +02:00
|
|
|
std::string GetName() const override;
|
|
|
|
void SetState(ControlState state) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SDL_GameController* const m_gc;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
|
|
|
|
2014-11-13 00:49:18 -08:00
|
|
|
class HapticEffect : public Output
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 10:25:13 -06:00
|
|
|
HapticEffect(SDL_Haptic* haptic);
|
|
|
|
~HapticEffect();
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2014-11-13 00:49:18 -08:00
|
|
|
protected:
|
2019-01-08 10:25:13 -06:00
|
|
|
virtual bool UpdateParameters(s16 value) = 0;
|
|
|
|
static void SetDirection(SDL_HapticDirection* dir);
|
|
|
|
|
|
|
|
SDL_HapticEffect m_effect = {};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-01-08 10:25:13 -06:00
|
|
|
static constexpr u16 DISABLED_EFFECT_TYPE = 0;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-08 13:37:06 +01:00
|
|
|
private:
|
|
|
|
virtual void SetState(ControlState state) override final;
|
2019-01-08 10:25:13 -06:00
|
|
|
void UpdateEffect();
|
|
|
|
SDL_Haptic* const m_haptic;
|
|
|
|
int m_id = -1;
|
2014-11-13 00:49:18 -08:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2014-11-13 00:49:18 -08:00
|
|
|
class ConstantEffect : public HapticEffect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-08 10:25:13 -06:00
|
|
|
ConstantEffect(SDL_Haptic* haptic);
|
2014-03-08 01:54:44 +01:00
|
|
|
std::string GetName() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 10:25:13 -06:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2014-11-13 00:49:18 -08:00
|
|
|
class RampEffect : public HapticEffect
|
2010-04-02 02:48:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 10:25:13 -06:00
|
|
|
RampEffect(SDL_Haptic* haptic);
|
2014-03-08 01:54:44 +01:00
|
|
|
std::string GetName() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 10:25:13 -06:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-01-08 10:25:13 -06:00
|
|
|
class PeriodicEffect : public HapticEffect
|
2015-01-06 19:17:43 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-01-08 10:25:13 -06:00
|
|
|
PeriodicEffect(SDL_Haptic* haptic, u16 waveform);
|
2015-01-06 19:17:43 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 10:25:13 -06:00
|
|
|
bool UpdateParameters(s16 value) override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2019-01-08 10:25:13 -06:00
|
|
|
const u16 m_waveform;
|
2015-01-06 19:17:43 +00:00
|
|
|
};
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-06 19:17:43 +00:00
|
|
|
class LeftRightEffect : public HapticEffect
|
|
|
|
{
|
|
|
|
public:
|
2019-01-17 10:13:32 -06:00
|
|
|
enum class Motor : u8
|
|
|
|
{
|
|
|
|
Weak,
|
|
|
|
Strong,
|
|
|
|
};
|
|
|
|
|
|
|
|
LeftRightEffect(SDL_Haptic* haptic, Motor motor);
|
2015-01-06 19:17:43 +00:00
|
|
|
std::string GetName() const override;
|
2016-06-24 10:43:46 +02:00
|
|
|
|
2015-01-08 15:17:29 +00:00
|
|
|
private:
|
2019-01-08 10:25:13 -06:00
|
|
|
bool UpdateParameters(s16 value) override;
|
|
|
|
|
2019-01-17 10:13:32 -06:00
|
|
|
const Motor m_motor;
|
2015-01-06 19:17:43 +00:00
|
|
|
};
|
2021-08-06 11:10:44 -04:00
|
|
|
|
|
|
|
class MotionInput : public Input
|
|
|
|
{
|
|
|
|
public:
|
2022-11-24 14:49:11 -06:00
|
|
|
MotionInput(std::string name, SDL_GameController* gc, SDL_SensorType type, int index,
|
2021-08-06 11:10:44 -04:00
|
|
|
ControlState scale)
|
2022-11-24 14:49:11 -06:00
|
|
|
: m_name(std::move(name)), m_gc(gc), m_type(type), m_index(index), m_scale(scale){};
|
2021-08-06 11:10:44 -04:00
|
|
|
|
|
|
|
std::string GetName() const override { return m_name; };
|
|
|
|
bool IsDetectable() const override { return false; };
|
|
|
|
ControlState GetState() const override;
|
|
|
|
|
|
|
|
private:
|
2022-11-24 14:49:11 -06:00
|
|
|
std::string m_name;
|
2021-08-06 11:10:44 -04:00
|
|
|
|
|
|
|
SDL_GameController* const m_gc;
|
|
|
|
SDL_SensorType const m_type;
|
|
|
|
int const m_index;
|
|
|
|
|
|
|
|
ControlState const m_scale;
|
|
|
|
};
|
|
|
|
|
2011-03-14 01:20:11 +00:00
|
|
|
public:
|
2023-08-03 16:30:26 +02:00
|
|
|
GameController(SDL_GameController* const gamecontroller, SDL_Joystick* const joystick,
|
|
|
|
const int sdl_index);
|
|
|
|
~GameController();
|
2010-04-02 02:48:24 +00:00
|
|
|
|
2013-10-29 01:34:26 -04:00
|
|
|
std::string GetName() const override;
|
|
|
|
std::string GetSource() const override;
|
2023-08-03 16:30:26 +02:00
|
|
|
int GetSDLIndex() const;
|
2010-04-02 02:48:24 +00:00
|
|
|
|
|
|
|
private:
|
2023-08-03 16:30:26 +02:00
|
|
|
SDL_GameController* const m_gamecontroller;
|
2017-11-09 14:04:31 -08:00
|
|
|
std::string m_name;
|
2023-08-03 16:30:26 +02:00
|
|
|
int m_sdl_index;
|
|
|
|
SDL_Joystick* const m_joystick;
|
2022-04-16 09:00:00 -07:00
|
|
|
SDL_Haptic* m_haptic = nullptr;
|
2010-04-02 02:48:24 +00:00
|
|
|
};
|
2019-06-17 16:39:24 -04:00
|
|
|
} // namespace ciface::SDL
|