From 89e9373037e94db80e41ac92c54023bf1c137e66 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 9 Dec 2019 01:06:58 +1000 Subject: [PATCH] Controller: Add a set-button interface in base class --- src/core/controller.cpp | 2 ++ src/core/controller.h | 3 +++ src/core/digital_controller.cpp | 8 ++++++++ src/core/digital_controller.h | 4 +++- 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/controller.cpp b/src/core/controller.cpp index d588aee2a..0f087615d 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -21,6 +21,8 @@ bool Controller::Transfer(const u8 data_in, u8* data_out) return false; } +void Controller::SetButtonState(s32 button_code, bool pressed) {} + std::shared_ptr Controller::Create(std::string_view type_name) { if (type_name == "DigitalController") diff --git a/src/core/controller.h b/src/core/controller.h index c65b33aa7..7766e2f1b 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -20,6 +20,9 @@ public: // Returns the value of ACK, as well as filling out_data. 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. static std::shared_ptr Create(std::string_view type_name); diff --git a/src/core/digital_controller.cpp b/src/core/digital_controller.cpp index 8b78ad478..480951193 100644 --- a/src/core/digital_controller.cpp +++ b/src/core/digital_controller.cpp @@ -14,6 +14,14 @@ void DigitalController::SetButtonState(Button button, bool pressed) m_button_state |= u16(1) << static_cast(button); } +void DigitalController::SetButtonState(s32 button_code, bool pressed) +{ + if (button_code < 0 || button_code >= static_cast(Button::Count)) + return; + + SetButtonState(static_cast