2019-09-20 06:47:41 +00:00
|
|
|
#pragma once
|
2019-12-08 14:51:52 +00:00
|
|
|
#include "controller.h"
|
2019-09-20 06:47:41 +00:00
|
|
|
#include <memory>
|
2019-12-08 14:46:04 +00:00
|
|
|
#include <optional>
|
|
|
|
#include <string_view>
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2019-12-08 14:51:52 +00:00
|
|
|
class DigitalController final : public Controller
|
2019-09-20 06:47:41 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
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,
|
2019-12-08 15:06:58 +00:00
|
|
|
Square = 15,
|
|
|
|
Count
|
2019-09-20 06:47:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DigitalController();
|
|
|
|
~DigitalController() override;
|
|
|
|
|
2019-12-14 13:20:24 +00:00
|
|
|
static std::unique_ptr<DigitalController> Create();
|
2019-12-14 14:31:07 +00:00
|
|
|
static std::optional<s32> StaticGetAxisCodeByName(std::string_view button_name);
|
2019-12-14 14:17:43 +00:00
|
|
|
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();
|
2019-12-14 14:17:43 +00:00
|
|
|
|
|
|
|
ControllerType GetType() const override;
|
2019-12-14 14:31:07 +00:00
|
|
|
std::optional<s32> GetAxisCodeByName(std::string_view axis_name) const override;
|
2019-12-14 14:17:43 +00:00
|
|
|
std::optional<s32> GetButtonCodeByName(std::string_view button_name) const override;
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2020-04-25 15:18:15 +00:00
|
|
|
void Reset() override;
|
|
|
|
bool DoState(StateWrapper& sw) override;
|
|
|
|
|
2019-12-14 14:31:07 +00:00
|
|
|
void SetAxisState(s32 axis_code, float value) override;
|
|
|
|
void SetButtonState(s32 button_code, bool pressed) override;
|
2019-09-20 06:47:41 +00:00
|
|
|
|
2019-09-29 15:07:38 +00:00
|
|
|
void ResetTransferState() override;
|
2019-09-20 06:47:41 +00:00
|
|
|
bool Transfer(const u8 data_in, u8* data_out) override;
|
|
|
|
|
2019-12-14 14:31:07 +00:00
|
|
|
void SetButtonState(Button button, bool pressed);
|
|
|
|
|
2019-09-20 06:47:41 +00:00
|
|
|
private:
|
2019-10-26 12:33:23 +00:00
|
|
|
enum class TransferState : u8
|
|
|
|
{
|
|
|
|
Idle,
|
|
|
|
IDMSB,
|
|
|
|
ButtonsLSB,
|
|
|
|
ButtonsMSB
|
|
|
|
};
|
2019-09-20 06:47:41 +00:00
|
|
|
|
|
|
|
// buttons are active low
|
|
|
|
u16 m_button_state = UINT16_C(0xFFFF);
|
|
|
|
|
2019-10-26 12:33:23 +00:00
|
|
|
TransferState m_transfer_state = TransferState::Idle;
|
2019-09-20 06:47:41 +00:00
|
|
|
};
|