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
|
|
|
|
};
|
|
|
|
|
2019-12-15 13:22:53 +00:00
|
|
|
static constexpr u8 NUM_MOTORS = 2;
|
|
|
|
|
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
|
|
|
static std::optional<s32> StaticGetAxisCodeByName(std::string_view axis_name);
|
|
|
|
static std::optional<s32> StaticGetButtonCodeByName(std::string_view button_name);
|
2020-01-02 06:10:42 +00:00
|
|
|
static AxisList StaticGetAxisNames();
|
|
|
|
static ButtonList StaticGetButtonNames();
|
2020-04-14 06:34:39 +00:00
|
|
|
static u32 StaticGetVibrationMotorCount();
|
2020-06-30 14:33:45 +00:00
|
|
|
static SettingList StaticGetSettings();
|
2019-12-15 11:58:27 +00:00
|
|
|
|
|
|
|
ControllerType GetType() const override;
|
|
|
|
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
|
|
|
std::optional<s32> GetButtonCodeByName(std::string_view button_name) const override;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
void SetAxisState(s32 axis_code, float value) override;
|
|
|
|
void SetButtonState(s32 button_code, bool pressed) 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;
|
|
|
|
|
|
|
|
void SetAxisState(Axis axis, u8 value);
|
|
|
|
void SetButtonState(Button button, bool pressed);
|
|
|
|
|
2019-12-15 13:22:53 +00:00
|
|
|
u32 GetVibrationMotorCount() const override;
|
|
|
|
float GetVibrationMotorStrength(u32 motor) override;
|
|
|
|
|
2020-07-31 07:09:18 +00:00
|
|
|
void LoadSettings(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-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;
|
|
|
|
|
|
|
|
// TODO: Return 0x00 on manual toggles
|
|
|
|
constexpr u8 GetStatusByte() const { return 0x5A; };
|
|
|
|
|
2019-12-15 13:22:53 +00:00
|
|
|
void SetAnalogMode(bool enabled);
|
|
|
|
void SetMotorState(u8 motor, u8 value);
|
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-05-08 05:32:39 +00:00
|
|
|
u32 m_index;
|
2020-05-08 05:13:05 +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;
|
2020-11-12 07:55:23 +00:00
|
|
|
float m_axis_scale = 1.00f;
|
2020-09-17 09:56:26 +00:00
|
|
|
u8 m_rumble_bias = 8;
|
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;
|
2019-12-15 11:58:27 +00:00
|
|
|
bool m_rumble_unlocked = false;
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
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
|
|
|
};
|