diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/frontend/input.h | 7 | ||||
| -rw-r--r-- | src/core/hle/service/hid/hid.cpp | 11 | ||||
| -rw-r--r-- | src/core/settings.h | 14 |
3 files changed, 30 insertions, 2 deletions
diff --git a/src/core/frontend/input.h b/src/core/frontend/input.h index 63e64ac67..0a5713dc0 100644 --- a/src/core/frontend/input.h +++ b/src/core/frontend/input.h | |||
| @@ -100,4 +100,11 @@ std::unique_ptr<InputDeviceType> CreateDevice(const std::string& params) { | |||
| 100 | */ | 100 | */ |
| 101 | using ButtonDevice = InputDevice<bool>; | 101 | using ButtonDevice = InputDevice<bool>; |
| 102 | 102 | ||
| 103 | /** | ||
| 104 | * An analog device is an input device that returns a tuple of x and y coordinates as status. The | ||
| 105 | * coordinates are within the unit circle. x+ is defined as right direction, and y+ is defined as up | ||
| 106 | * direction | ||
| 107 | */ | ||
| 108 | using AnalogDevice = InputDevice<std::tuple<float, float>>; | ||
| 109 | |||
| 103 | } // namespace Input | 110 | } // namespace Input |
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index 0da731418..b19e831fe 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp | |||
| @@ -51,6 +51,7 @@ constexpr u64 gyroscope_update_ticks = BASE_CLOCK_RATE_ARM11 / 101; | |||
| 51 | static std::atomic<bool> is_device_reload_pending; | 51 | static std::atomic<bool> is_device_reload_pending; |
| 52 | static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> | 52 | static std::array<std::unique_ptr<Input::ButtonDevice>, Settings::NativeButton::NUM_BUTTONS_HID> |
| 53 | buttons; | 53 | buttons; |
| 54 | static std::unique_ptr<Input::AnalogDevice> circle_pad; | ||
| 54 | 55 | ||
| 55 | static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) { | 56 | static PadState GetCirclePadDirectionState(s16 circle_pad_x, s16 circle_pad_y) { |
| 56 | // 30 degree and 60 degree are angular thresholds for directions | 57 | // 30 degree and 60 degree are angular thresholds for directions |
| @@ -86,12 +87,15 @@ static void LoadInputDevices() { | |||
| 86 | std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, | 87 | std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, |
| 87 | Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, | 88 | Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, |
| 88 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); | 89 | buttons.begin(), Input::CreateDevice<Input::ButtonDevice>); |
| 90 | circle_pad = Input::CreateDevice<Input::AnalogDevice>( | ||
| 91 | Settings::values.analogs[Settings::NativeAnalog::CirclePad]); | ||
| 89 | } | 92 | } |
| 90 | 93 | ||
| 91 | static void UnloadInputDevices() { | 94 | static void UnloadInputDevices() { |
| 92 | for (auto& button : buttons) { | 95 | for (auto& button : buttons) { |
| 93 | button.reset(); | 96 | button.reset(); |
| 94 | } | 97 | } |
| 98 | circle_pad.reset(); | ||
| 95 | } | 99 | } |
| 96 | 100 | ||
| 97 | static void UpdatePadCallback(u64 userdata, int cycles_late) { | 101 | static void UpdatePadCallback(u64 userdata, int cycles_late) { |
| @@ -116,8 +120,11 @@ static void UpdatePadCallback(u64 userdata, int cycles_late) { | |||
| 116 | state.select.Assign(buttons[Select - BUTTON_HID_BEGIN]->GetStatus()); | 120 | state.select.Assign(buttons[Select - BUTTON_HID_BEGIN]->GetStatus()); |
| 117 | 121 | ||
| 118 | // Get current circle pad position and update circle pad direction | 122 | // Get current circle pad position and update circle pad direction |
| 119 | s16 circle_pad_x, circle_pad_y; | 123 | float circle_pad_x_f, circle_pad_y_f; |
| 120 | std::tie(circle_pad_x, circle_pad_y) = VideoCore::g_emu_window->GetCirclePadState(); | 124 | std::tie(circle_pad_x_f, circle_pad_y_f) = circle_pad->GetStatus(); |
| 125 | constexpr int MAX_CIRCLEPAD_POS = 0x9C; // Max value for a circle pad position | ||
| 126 | s16 circle_pad_x = static_cast<s16>(circle_pad_x_f * MAX_CIRCLEPAD_POS); | ||
| 127 | s16 circle_pad_y = static_cast<s16>(circle_pad_y_f * MAX_CIRCLEPAD_POS); | ||
| 121 | state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex; | 128 | state.hex |= GetCirclePadDirectionState(circle_pad_x, circle_pad_y).hex; |
| 122 | 129 | ||
| 123 | mem->pad.current_state.hex = state.hex; | 130 | mem->pad.current_state.hex = state.hex; |
diff --git a/src/core/settings.h b/src/core/settings.h index dba57bd6c..4f83d285c 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -111,6 +111,19 @@ static const std::array<const char*, NumButtons> mapping = {{ | |||
| 111 | }}; | 111 | }}; |
| 112 | } // namespace NativeButton | 112 | } // namespace NativeButton |
| 113 | 113 | ||
| 114 | namespace NativeAnalog { | ||
| 115 | enum Values { | ||
| 116 | CirclePad, | ||
| 117 | CStick, | ||
| 118 | |||
| 119 | NumAnalogs, | ||
| 120 | }; | ||
| 121 | |||
| 122 | static const std::array<const char*, NumAnalogs> mapping = {{ | ||
| 123 | "circle_pad", "c_stick", | ||
| 124 | }}; | ||
| 125 | } // namespace NumAnalog | ||
| 126 | |||
| 114 | struct Values { | 127 | struct Values { |
| 115 | // CheckNew3DS | 128 | // CheckNew3DS |
| 116 | bool is_new_3ds; | 129 | bool is_new_3ds; |
| @@ -120,6 +133,7 @@ struct Values { | |||
| 120 | float pad_circle_modifier_scale; | 133 | float pad_circle_modifier_scale; |
| 121 | 134 | ||
| 122 | std::array<std::string, NativeButton::NumButtons> buttons; | 135 | std::array<std::string, NativeButton::NumButtons> buttons; |
| 136 | std::array<std::string, NativeAnalog::NumAnalogs> analogs; | ||
| 123 | 137 | ||
| 124 | // Core | 138 | // Core |
| 125 | bool use_cpu_jit; | 139 | bool use_cpu_jit; |