2019-12-15 11:58:27 +00:00
|
|
|
#pragma once
|
|
|
|
#include "controller.h"
|
|
|
|
#include <array>
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
|
|
|
|
|
|
|
class AnalogController final : public Controller
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Axis : u8
|
|
|
|
{
|
|
|
|
LeftX,
|
|
|
|
LeftY,
|
|
|
|
RightX,
|
|
|
|
RightY,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class Button : u8
|
|
|
|
{
|
|
|
|
Select = 0,
|
|
|
|
L3 = 1,
|
|
|
|
R3 = 2,
|
|
|
|
Start = 3,
|
|
|
|
Up = 4,
|
|
|
|
Right = 5,
|
|
|
|
Down = 6,
|
|
|
|
Left = 7,
|
|
|
|
L2 = 8,
|
|
|
|
R2 = 9,
|
|
|
|
L1 = 10,
|
|
|
|
R1 = 11,
|
|
|
|
Triangle = 12,
|
|
|
|
Circle = 13,
|
|
|
|
Cross = 14,
|
|
|
|
Square = 15,
|
2020-05-08 05:13:05 +00:00
|
|
|
Analog = 16,
|
2019-12-15 11:58:27 +00:00
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
enum class HalfAxis : u8
|
|
|
|
{
|
|
|
|
LLeft,
|
|
|
|
LRight,
|
|
|
|
LDown,
|
|
|
|
LUp,
|
|
|
|
RLeft,
|
|
|
|
RRight,
|
|
|
|
RDown,
|
|
|
|
RUp,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2019-12-15 13:22:53 +00:00
|
|
|
static constexpr u8 NUM_MOTORS = 2;
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
static const Controller::ControllerInfo INFO;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
AnalogController(u32 index);
|
2019-12-15 11:58:27 +00:00
|
|
|
~AnalogController() override;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
static std::unique_ptr<AnalogController> Create(u32 index);
|
2019-12-15 11:58:27 +00:00
|
|
|
|
|
|
|
ControllerType GetType() const override;
|
2022-08-16 11:23:14 +00:00
|
|
|
bool InAnalogMode() const { return m_analog_mode; }
|
2019-12-15 11:58:27 +00:00
|
|
|
|
|
|
|
void Reset() override;
|
2020-12-16 14:09:32 +00:00
|
|
|
bool DoState(StateWrapper& sw, bool ignore_input_state) override;
|
2019-12-15 11:58:27 +00:00
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
float GetBindState(u32 index) const override;
|
|
|
|
void SetBindState(u32 index, float value) override;
|
2020-12-06 05:47:00 +00:00
|
|
|
u32 GetButtonStateBits() const override;
|
2021-01-04 06:54:16 +00:00
|
|
|
std::optional<u32> GetAnalogInputBytes() const override;
|
2019-12-15 11:58:27 +00:00
|
|
|
|
|
|
|
void ResetTransferState() override;
|
|
|
|
bool Transfer(const u8 data_in, u8* data_out) override;
|
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
void LoadSettings(SettingsInterface& si, const char* section) override;
|
2020-06-30 14:33:45 +00:00
|
|
|
|
2019-12-15 11:58:27 +00:00
|
|
|
private:
|
2019-12-15 13:22:53 +00:00
|
|
|
using MotorState = std::array<u8, NUM_MOTORS>;
|
|
|
|
|
2021-01-01 01:12:55 +00:00
|
|
|
enum class Command : u8
|
2019-12-15 11:58:27 +00:00
|
|
|
{
|
|
|
|
Idle,
|
2021-02-21 23:20:31 +00:00
|
|
|
Ready,
|
2021-01-01 01:12:55 +00:00
|
|
|
ReadPad, // 0x42
|
|
|
|
ConfigModeSetMode, // 0x43
|
|
|
|
SetAnalogMode, // 0x44
|
|
|
|
GetAnalogMode, // 0x45
|
|
|
|
Command46, // 0x46
|
|
|
|
Command47, // 0x47
|
|
|
|
Command4C, // 0x4C
|
|
|
|
GetSetRumble // 0x4D
|
2019-12-15 11:58:27 +00:00
|
|
|
};
|
|
|
|
|
2021-01-01 01:12:55 +00:00
|
|
|
Command m_command = Command::Idle;
|
|
|
|
int m_command_step = 0;
|
|
|
|
|
|
|
|
// Transmit and receive buffers, not including the first Hi-Z/ack response byte
|
|
|
|
static constexpr u32 MAX_RESPONSE_LENGTH = 8;
|
|
|
|
std::array<u8, MAX_RESPONSE_LENGTH> m_rx_buffer;
|
|
|
|
std::array<u8, MAX_RESPONSE_LENGTH> m_tx_buffer;
|
|
|
|
u32 m_response_length = 0;
|
|
|
|
|
|
|
|
// Get number of response halfwords (excluding the initial controller info halfword)
|
|
|
|
u8 GetResponseNumHalfwords() const;
|
|
|
|
|
|
|
|
u8 GetModeID() const;
|
|
|
|
u8 GetIDByte() const;
|
|
|
|
|
2022-08-10 03:03:15 +00:00
|
|
|
void SetAnalogMode(bool enabled, bool show_message);
|
2021-02-22 00:12:41 +00:00
|
|
|
void ProcessAnalogModeToggle();
|
2022-07-11 13:03:29 +00:00
|
|
|
void SetMotorState(u32 motor, u8 value);
|
|
|
|
void UpdateHostVibration();
|
2020-10-29 14:30:04 +00:00
|
|
|
u8 GetExtraButtonMaskLSB() const;
|
2020-11-25 01:16:54 +00:00
|
|
|
void ResetRumbleConfig();
|
|
|
|
void SetMotorStateForConfigIndex(int index, u8 value);
|
2019-12-15 11:58:27 +00:00
|
|
|
|
2020-12-11 00:48:19 +00:00
|
|
|
bool m_force_analog_on_reset = false;
|
2020-10-29 14:30:04 +00:00
|
|
|
bool m_analog_dpad_in_digital_mode = false;
|
2022-07-11 13:03:29 +00:00
|
|
|
float m_analog_deadzone = 0.0f;
|
|
|
|
float m_analog_sensitivity = 1.33f;
|
2022-09-22 03:50:31 +00:00
|
|
|
float m_button_deadzone = 0.0f;
|
2020-09-17 09:56:26 +00:00
|
|
|
u8 m_rumble_bias = 8;
|
2022-09-22 03:50:31 +00:00
|
|
|
u8 m_invert_left_stick = 0;
|
|
|
|
u8 m_invert_right_stick = 0;
|
2020-06-30 14:33:45 +00:00
|
|
|
|
2019-12-15 11:58:27 +00:00
|
|
|
bool m_analog_mode = false;
|
2020-05-08 05:13:05 +00:00
|
|
|
bool m_analog_locked = false;
|
2021-04-14 08:13:34 +00:00
|
|
|
bool m_dualshock_enabled = false;
|
2019-12-15 11:58:27 +00:00
|
|
|
bool m_configuration_mode = false;
|
|
|
|
|
|
|
|
std::array<u8, static_cast<u8>(Axis::Count)> m_axis_state{};
|
|
|
|
|
2020-11-25 01:16:54 +00:00
|
|
|
enum : u8
|
|
|
|
{
|
|
|
|
LargeMotor = 0,
|
|
|
|
SmallMotor = 1
|
|
|
|
};
|
|
|
|
|
|
|
|
std::array<u8, 6> m_rumble_config{};
|
|
|
|
int m_rumble_config_large_motor_index = -1;
|
|
|
|
int m_rumble_config_small_motor_index = -1;
|
|
|
|
|
2020-11-24 01:35:34 +00:00
|
|
|
bool m_analog_toggle_queued = false;
|
2022-08-10 03:03:15 +00:00
|
|
|
u8 m_status_byte = 0;
|
2020-11-24 01:35:34 +00:00
|
|
|
|
2020-11-25 01:16:54 +00:00
|
|
|
// TODO: Set this with command 0x4D and increase response length in digital mode accordingly
|
2021-01-01 01:12:55 +00:00
|
|
|
u8 m_digital_mode_extra_halfwords = 0;
|
2020-11-25 01:16:54 +00:00
|
|
|
|
2019-12-15 11:58:27 +00:00
|
|
|
// buttons are active low
|
|
|
|
u16 m_button_state = UINT16_C(0xFFFF);
|
|
|
|
|
2019-12-15 13:22:53 +00:00
|
|
|
MotorState m_motor_state{};
|
2019-12-15 11:58:27 +00:00
|
|
|
|
2022-07-11 13:03:29 +00:00
|
|
|
// both directions of axis state, merged to m_axis_state
|
|
|
|
std::array<u8, static_cast<u32>(HalfAxis::Count)> m_half_axis_state{};
|
|
|
|
|
2021-01-30 08:53:43 +00:00
|
|
|
// Member variables that are no longer used, but kept and serialized for compatibility with older save states
|
2021-01-01 01:12:55 +00:00
|
|
|
u8 m_command_param = 0;
|
2021-01-30 08:53:43 +00:00
|
|
|
bool m_legacy_rumble_unlocked = false;
|
2019-12-15 11:58:27 +00:00
|
|
|
};
|