diff options
| author | 2020-06-24 11:39:30 -0400 | |
|---|---|---|
| committer | 2020-06-24 11:39:30 -0400 | |
| commit | c18dc9c707235d7ba6fe230cb3045f2c13d04e62 (patch) | |
| tree | 1d59dca6a2bb959572d7c12cdff1d3fdcd4abab5 /src | |
| parent | cleanup check access, read, and factory GetNextInput funcs. Use size rather t... (diff) | |
| download | yuzu-c18dc9c707235d7ba6fe230cb3045f2c13d04e62.tar.gz yuzu-c18dc9c707235d7ba6fe230cb3045f2c13d04e62.tar.xz yuzu-c18dc9c707235d7ba6fe230cb3045f2c13d04e62.zip | |
padbutton enum class and struct initiailization
Diffstat (limited to 'src')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 31 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.h | 30 | ||||
| -rw-r--r-- | src/input_common/gcadapter/gc_poller.cpp | 7 |
3 files changed, 32 insertions, 36 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 9437d628f..bba9bcc69 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -33,11 +33,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa | |||
| 33 | adapter_controllers_status[port] = type; | 33 | adapter_controllers_status[port] = type; |
| 34 | 34 | ||
| 35 | constexpr std::array<PadButton, 8> b1_buttons{ | 35 | constexpr std::array<PadButton, 8> b1_buttons{ |
| 36 | PAD_BUTTON_A, PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, | 36 | PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, PadButton::PAD_BUTTON_X, |
| 37 | PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP}; | 37 | PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, |
| 38 | PadButton::PAD_BUTTON_DOWN, PadButton::PAD_BUTTON_UP}; | ||
| 38 | 39 | ||
| 39 | constexpr std::array<PadButton, 4> b2_buttons{PAD_BUTTON_START, PAD_TRIGGER_Z, PAD_TRIGGER_R, | 40 | constexpr std::array<PadButton, 4> b2_buttons{ |
| 40 | PAD_TRIGGER_L}; | 41 | PadButton::PAD_BUTTON_START, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, |
| 42 | PadButton::PAD_TRIGGER_L}; | ||
| 41 | 43 | ||
| 42 | if (adapter_controllers_status[port] != ControllerTypes::None) { | 44 | if (adapter_controllers_status[port] != ControllerTypes::None) { |
| 43 | const u8 b1 = adapter_payload[1 + (9 * port) + 1]; | 45 | const u8 b1 = adapter_payload[1 + (9 * port) + 1]; |
| @@ -45,13 +47,13 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa | |||
| 45 | 47 | ||
| 46 | for (int i = 0; i < b1_buttons.size(); i++) { | 48 | for (int i = 0; i < b1_buttons.size(); i++) { |
| 47 | if (b1 & (1 << i)) { | 49 | if (b1 & (1 << i)) { |
| 48 | pad.button |= b1_buttons[i]; | 50 | pad.button |= static_cast<u16>(b1_buttons[i]); |
| 49 | } | 51 | } |
| 50 | } | 52 | } |
| 51 | 53 | ||
| 52 | for (int j = 0; j < b2_buttons.size(); j++) { | 54 | for (int j = 0; j < b2_buttons.size(); j++) { |
| 53 | if (b2 & (1 << j)) { | 55 | if (b2 & (1 << j)) { |
| 54 | pad.button |= b2_buttons[j]; | 56 | pad.button |= static_cast<u16>(b2_buttons[j]); |
| 55 | } | 57 | } |
| 56 | } | 58 | } |
| 57 | 59 | ||
| @@ -70,18 +72,11 @@ GCPadStatus Adapter::GetPadStatus(int port, const std::array<u8, 37>& adapter_pa | |||
| 70 | } | 72 | } |
| 71 | 73 | ||
| 72 | void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { | 74 | void Adapter::PadToState(const GCPadStatus& pad, GCState& state) { |
| 73 | state.buttons.insert_or_assign(PAD_BUTTON_A, pad.button & PAD_BUTTON_A); | 75 | for (auto button : PadButtonArray) { |
| 74 | state.buttons.insert_or_assign(PAD_BUTTON_B, pad.button & PAD_BUTTON_B); | 76 | u16 button_value = static_cast<u16>(button); |
| 75 | state.buttons.insert_or_assign(PAD_BUTTON_X, pad.button & PAD_BUTTON_X); | 77 | state.buttons.insert_or_assign(button_value, pad.button & button_value); |
| 76 | state.buttons.insert_or_assign(PAD_BUTTON_Y, pad.button & PAD_BUTTON_Y); | 78 | } |
| 77 | state.buttons.insert_or_assign(PAD_BUTTON_LEFT, pad.button & PAD_BUTTON_LEFT); | 79 | |
| 78 | state.buttons.insert_or_assign(PAD_BUTTON_RIGHT, pad.button & PAD_BUTTON_RIGHT); | ||
| 79 | state.buttons.insert_or_assign(PAD_BUTTON_DOWN, pad.button & PAD_BUTTON_DOWN); | ||
| 80 | state.buttons.insert_or_assign(PAD_BUTTON_UP, pad.button & PAD_BUTTON_UP); | ||
| 81 | state.buttons.insert_or_assign(PAD_BUTTON_START, pad.button & PAD_BUTTON_START); | ||
| 82 | state.buttons.insert_or_assign(PAD_TRIGGER_Z, pad.button & PAD_TRIGGER_Z); | ||
| 83 | state.buttons.insert_or_assign(PAD_TRIGGER_L, pad.button & PAD_TRIGGER_L); | ||
| 84 | state.buttons.insert_or_assign(PAD_TRIGGER_R, pad.button & PAD_TRIGGER_R); | ||
| 85 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickX), pad.stick_x); | 80 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickX), pad.stick_x); |
| 86 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickY), pad.stick_y); | 81 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::StickY), pad.stick_y); |
| 87 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::SubstickX), pad.substick_x); | 82 | state.axes.insert_or_assign(static_cast<u8>(PadAxes::SubstickX), pad.substick_x); |
diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index abfe0d7b3..91aa9622b 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h | |||
| @@ -19,7 +19,7 @@ enum { | |||
| 19 | PAD_ERR_STATUS = 0x8000, | 19 | PAD_ERR_STATUS = 0x8000, |
| 20 | }; | 20 | }; |
| 21 | 21 | ||
| 22 | enum PadButton { | 22 | enum class PadButton { |
| 23 | PAD_BUTTON_LEFT = 0x0001, | 23 | PAD_BUTTON_LEFT = 0x0001, |
| 24 | PAD_BUTTON_RIGHT = 0x0002, | 24 | PAD_BUTTON_RIGHT = 0x0002, |
| 25 | PAD_BUTTON_DOWN = 0x0004, | 25 | PAD_BUTTON_DOWN = 0x0004, |
| @@ -34,14 +34,14 @@ enum PadButton { | |||
| 34 | PAD_BUTTON_START = 0x1000, | 34 | PAD_BUTTON_START = 0x1000, |
| 35 | // Below is for compatibility with "AxisButton" type | 35 | // Below is for compatibility with "AxisButton" type |
| 36 | PAD_STICK = 0x2000, | 36 | PAD_STICK = 0x2000, |
| 37 | |||
| 38 | }; | 37 | }; |
| 39 | 38 | ||
| 40 | /// Used to loop through the and assign button in poller | 39 | /// Used to loop through the and assign button in poller |
| 41 | static constexpr std::array<PadButton, 12> PadButtonArray{ | 40 | static constexpr std::array<PadButton, 12> PadButtonArray{ |
| 42 | PAD_BUTTON_LEFT, PAD_BUTTON_RIGHT, PAD_BUTTON_DOWN, PAD_BUTTON_UP, | 41 | PadButton::PAD_BUTTON_LEFT, PadButton::PAD_BUTTON_RIGHT, PadButton::PAD_BUTTON_DOWN, |
| 43 | PAD_TRIGGER_Z, PAD_TRIGGER_R, PAD_TRIGGER_L, PAD_BUTTON_A, | 42 | PadButton::PAD_BUTTON_UP, PadButton::PAD_TRIGGER_Z, PadButton::PAD_TRIGGER_R, |
| 44 | PAD_BUTTON_B, PAD_BUTTON_X, PAD_BUTTON_Y, PAD_BUTTON_START}; | 43 | PadButton::PAD_TRIGGER_L, PadButton::PAD_BUTTON_A, PadButton::PAD_BUTTON_B, |
| 44 | PadButton::PAD_BUTTON_X, PadButton::PAD_BUTTON_Y, PadButton::PAD_BUTTON_START}; | ||
| 45 | 45 | ||
| 46 | enum class PadAxes : u8 { | 46 | enum class PadAxes : u8 { |
| 47 | StickX, | 47 | StickX, |
| @@ -54,13 +54,13 @@ enum class PadAxes : u8 { | |||
| 54 | }; | 54 | }; |
| 55 | 55 | ||
| 56 | struct GCPadStatus { | 56 | struct GCPadStatus { |
| 57 | u16 button; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits | 57 | u16 button{}; // Or-ed PAD_BUTTON_* and PAD_TRIGGER_* bits |
| 58 | u8 stick_x; // 0 <= stick_x <= 255 | 58 | u8 stick_x{}; // 0 <= stick_x <= 255 |
| 59 | u8 stick_y; // 0 <= stick_y <= 255 | 59 | u8 stick_y{}; // 0 <= stick_y <= 255 |
| 60 | u8 substick_x; // 0 <= substick_x <= 255 | 60 | u8 substick_x{}; // 0 <= substick_x <= 255 |
| 61 | u8 substick_y; // 0 <= substick_y <= 255 | 61 | u8 substick_y{}; // 0 <= substick_y <= 255 |
| 62 | u8 trigger_left; // 0 <= trigger_left <= 255 | 62 | u8 trigger_left{}; // 0 <= trigger_left <= 255 |
| 63 | u8 trigger_right; // 0 <= trigger_right <= 255 | 63 | u8 trigger_right{}; // 0 <= trigger_right <= 255 |
| 64 | 64 | ||
| 65 | static constexpr u8 MAIN_STICK_CENTER_X = 0x80; | 65 | static constexpr u8 MAIN_STICK_CENTER_X = 0x80; |
| 66 | static constexpr u8 MAIN_STICK_CENTER_Y = 0x80; | 66 | static constexpr u8 MAIN_STICK_CENTER_Y = 0x80; |
| @@ -71,9 +71,9 @@ struct GCPadStatus { | |||
| 71 | static constexpr u8 TRIGGER_CENTER = 20; | 71 | static constexpr u8 TRIGGER_CENTER = 20; |
| 72 | static constexpr u8 THRESHOLD = 10; | 72 | static constexpr u8 THRESHOLD = 10; |
| 73 | 73 | ||
| 74 | u8 port; | 74 | u8 port{}; |
| 75 | PadAxes axis = PadAxes::Undefined; | 75 | PadAxes axis{PadAxes::Undefined}; |
| 76 | u8 axis_value = 255; | 76 | u8 axis_value{255}; |
| 77 | }; | 77 | }; |
| 78 | 78 | ||
| 79 | struct GCState { | 79 | struct GCState { |
diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 977261884..06e16880f 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp | |||
| @@ -96,8 +96,9 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { | |||
| 96 | // or to use a while loop shifting the bits to test and set the value. | 96 | // or to use a while loop shifting the bits to test and set the value. |
| 97 | 97 | ||
| 98 | for (auto button : GCAdapter::PadButtonArray) { | 98 | for (auto button : GCAdapter::PadButtonArray) { |
| 99 | if (pad.button & button) { | 99 | u16 button_value = static_cast<u16>(button); |
| 100 | params.Set("button", button); | 100 | if (pad.button & button_value) { |
| 101 | params.Set("button", button_value); | ||
| 101 | break; | 102 | break; |
| 102 | } | 103 | } |
| 103 | } | 104 | } |
| @@ -105,7 +106,7 @@ Common::ParamPackage GCButtonFactory::GetNextInput() { | |||
| 105 | // For Axis button implementation | 106 | // For Axis button implementation |
| 106 | if (pad.axis != GCAdapter::PadAxes::Undefined) { | 107 | if (pad.axis != GCAdapter::PadAxes::Undefined) { |
| 107 | params.Set("axis", static_cast<u8>(pad.axis)); | 108 | params.Set("axis", static_cast<u8>(pad.axis)); |
| 108 | params.Set("button", GCAdapter::PAD_STICK); | 109 | params.Set("button", static_cast<u16>(GCAdapter::PadButton::PAD_STICK)); |
| 109 | if (pad.axis_value > 128) { | 110 | if (pad.axis_value > 128) { |
| 110 | params.Set("direction", "+"); | 111 | params.Set("direction", "+"); |
| 111 | params.Set("threshold", "0.5"); | 112 | params.Set("threshold", "0.5"); |