diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp index a9784c6091..6cec31795b 100644 --- a/src/core/hle/service/hid/hid.cpp +++ b/src/core/hle/service/hid/hid.cpp @@ -60,7 +60,10 @@ private: std::transform(Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_BEGIN, Settings::values.buttons.begin() + Settings::NativeButton::BUTTON_HID_END, buttons.begin(), Input::CreateDevice); - // TODO(shinyquagsire23): sticks, gyro, touch, mouse, keyboard + std::transform(Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_BEGIN, + Settings::values.analogs.begin() + Settings::NativeAnalog::STICK_HID_END, + sticks.begin(), Input::CreateDevice); + // TODO(shinyquagsire23): gyro, touch, mouse, keyboard } void UpdatePadCallback(u64 userdata, int cycles_late) { @@ -136,7 +139,13 @@ private: state.sl.Assign(buttons[SL - BUTTON_HID_BEGIN]->GetStatus()); state.sr.Assign(buttons[SR - BUTTON_HID_BEGIN]->GetStatus()); - // TODO(shinyquagsire23): Analog stick vals + float stick_l_x_f, stick_l_y_f, stick_r_x_f, stick_r_y_f; + std::tie(stick_l_x_f, stick_l_y_f) = sticks[Joystick_Left]->GetStatus(); + std::tie(stick_r_x_f, stick_r_y_f) = sticks[Joystick_Right]->GetStatus(); + entry.joystick_left_x = static_cast(stick_l_x_f * HID_JOYSTICK_MAX); + entry.joystick_left_y = static_cast(stick_l_y_f * HID_JOYSTICK_MAX); + entry.joystick_right_x = static_cast(stick_r_x_f * HID_JOYSTICK_MAX); + entry.joystick_right_y = static_cast(stick_r_y_f * HID_JOYSTICK_MAX); } } @@ -200,6 +209,7 @@ private: std::atomic is_device_reload_pending{true}; std::array, Settings::NativeButton::NUM_BUTTONS_HID> buttons; + std::array, Settings::NativeAnalog::NUM_STICKS_HID> sticks; }; class IActiveVibrationDeviceList final : public ServiceFramework { diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h index 350174ccdb..30f3d8649e 100644 --- a/src/core/hle/service/hid/hid.h +++ b/src/core/hle/service/hid/hid.h @@ -48,6 +48,13 @@ enum ControllerConnectionState { ConnectionState_Wired = 1 << 1, }; +enum ControllerJoystick { + Joystick_Left = 0, + Joystick_Right = 1, + + Joystick_NumSticks = 2, +}; + enum ControllerID { Controller_Player1 = 0, Controller_Player2 = 1, @@ -283,10 +290,10 @@ struct ControllerInputEntry { u64 timestamp; u64 timestamp_2; ControllerPadState buttons; - u32 joystick_left_x; - u32 joystick_left_y; - u32 joystick_right_x; - u32 joystick_right_y; + s32 joystick_left_x; + s32 joystick_left_y; + s32 joystick_right_x; + s32 joystick_right_y; u64 connection_state; }; static_assert(sizeof(ControllerInputEntry) == 0x30, diff --git a/src/core/settings.h b/src/core/settings.h index 2c94caab7c..cfec63c210 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -99,6 +99,10 @@ enum Values { NumAnalogs, }; +constexpr int STICK_HID_BEGIN = LStick; +constexpr int STICK_HID_END = NumAnalogs; +constexpr int NUM_STICKS_HID = NumAnalogs; + static const std::array mapping = {{ "lstick", "rstick",