Controller: Add a set-button interface in base class
This commit is contained in:
parent
da14b10e72
commit
89e9373037
|
@ -21,6 +21,8 @@ bool Controller::Transfer(const u8 data_in, u8* data_out)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Controller::SetButtonState(s32 button_code, bool pressed) {}
|
||||||
|
|
||||||
std::shared_ptr<Controller> Controller::Create(std::string_view type_name)
|
std::shared_ptr<Controller> Controller::Create(std::string_view type_name)
|
||||||
{
|
{
|
||||||
if (type_name == "DigitalController")
|
if (type_name == "DigitalController")
|
||||||
|
|
|
@ -20,6 +20,9 @@ public:
|
||||||
// Returns the value of ACK, as well as filling out_data.
|
// Returns the value of ACK, as well as filling out_data.
|
||||||
virtual bool Transfer(const u8 data_in, u8* data_out);
|
virtual bool Transfer(const u8 data_in, u8* data_out);
|
||||||
|
|
||||||
|
/// Changes the specified button state.
|
||||||
|
virtual void SetButtonState(s32 button_code, bool pressed);
|
||||||
|
|
||||||
/// Creates a new controller of the specified type.
|
/// Creates a new controller of the specified type.
|
||||||
static std::shared_ptr<Controller> Create(std::string_view type_name);
|
static std::shared_ptr<Controller> Create(std::string_view type_name);
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,14 @@ void DigitalController::SetButtonState(Button button, bool pressed)
|
||||||
m_button_state |= u16(1) << static_cast<u8>(button);
|
m_button_state |= u16(1) << static_cast<u8>(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DigitalController::SetButtonState(s32 button_code, bool pressed)
|
||||||
|
{
|
||||||
|
if (button_code < 0 || button_code >= static_cast<s32>(Button::Count))
|
||||||
|
return;
|
||||||
|
|
||||||
|
SetButtonState(static_cast<Button>(button_code), pressed);
|
||||||
|
}
|
||||||
|
|
||||||
void DigitalController::ResetTransferState()
|
void DigitalController::ResetTransferState()
|
||||||
{
|
{
|
||||||
m_transfer_state = TransferState::Idle;
|
m_transfer_state = TransferState::Idle;
|
||||||
|
|
|
@ -24,7 +24,8 @@ public:
|
||||||
Triangle = 12,
|
Triangle = 12,
|
||||||
Circle = 13,
|
Circle = 13,
|
||||||
Cross = 14,
|
Cross = 14,
|
||||||
Square = 15
|
Square = 15,
|
||||||
|
Count
|
||||||
};
|
};
|
||||||
|
|
||||||
DigitalController();
|
DigitalController();
|
||||||
|
@ -34,6 +35,7 @@ public:
|
||||||
static std::optional<s32> GetButtonCodeByName(std::string_view button_name);
|
static std::optional<s32> GetButtonCodeByName(std::string_view button_name);
|
||||||
|
|
||||||
void SetButtonState(Button button, bool pressed);
|
void SetButtonState(Button button, bool pressed);
|
||||||
|
void SetButtonState(s32 button_code, bool pressed);
|
||||||
|
|
||||||
void ResetTransferState() override;
|
void ResetTransferState() override;
|
||||||
bool Transfer(const u8 data_in, u8* data_out) override;
|
bool Transfer(const u8 data_in, u8* data_out) override;
|
||||||
|
|
Loading…
Reference in New Issue