From 854c933716f0f5e1dbf62157c5a76e65213b30b2 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 20 Sep 2021 16:41:15 -0500 Subject: input_common: Create input poller and mapping --- src/input_common/input_poller.cpp | 860 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 860 insertions(+) create mode 100644 src/input_common/input_poller.cpp (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp new file mode 100644 index 000000000..46a7dd276 --- /dev/null +++ b/src/input_common/input_poller.cpp @@ -0,0 +1,860 @@ +// Copyright 2021 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included + +#include "common/common_types.h" +#include "common/input.h" + +#include "input_common/input_engine.h" +#include "input_common/input_poller.h" + +namespace InputCommon { + +class DummyInput final : public Input::InputDevice { +public: + explicit DummyInput() {} + ~DummyInput() {} +}; + +class InputFromButton final : public Input::InputDevice { +public: + explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, + InputEngine* input_engine_) + : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), + input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::Button, + .index = button, + .callback = engine_callback, + }; + last_button_value = false; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromButton() { + input_engine->DeleteCallback(callback_key); + } + + Input::ButtonStatus GetStatus() const { + return { + .value = input_engine->GetButton(identifier, button), + .inverted = inverted, + .toggle = toggle, + }; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Button, + .button_status = GetStatus(), + }; + + if (status.button_status.value != last_button_value) { + last_button_value = status.button_status.value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 button; + const bool toggle; + const bool inverted; + int callback_key; + bool last_button_value; + InputEngine* input_engine; +}; + +class InputFromHatButton final : public Input::InputDevice { +public: + explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, + bool inverted_, InputEngine* input_engine_) + : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_), + inverted(inverted_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::HatButton, + .index = button, + .callback = engine_callback, + }; + last_button_value = false; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromHatButton() { + input_engine->DeleteCallback(callback_key); + } + + Input::ButtonStatus GetStatus() const { + return { + .value = input_engine->GetHatButton(identifier, button, direction), + .inverted = inverted, + .toggle = toggle, + }; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Button, + .button_status = GetStatus(), + }; + + if (status.button_status.value != last_button_value) { + last_button_value = status.button_status.value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 button; + const u8 direction; + const bool toggle; + const bool inverted; + int callback_key; + bool last_button_value; + InputEngine* input_engine; +}; + +class InputFromStick final : public Input::InputDevice { +public: + explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, + Input::AnalogProperties properties_x_, + Input::AnalogProperties properties_y_, InputEngine* input_engine_) + : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), + properties_y(properties_y_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier x_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_x, + .callback = engine_callback, + }; + const InputIdentifier y_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_y, + .callback = engine_callback, + }; + last_axis_x_value = 0.0f; + last_axis_y_value = 0.0f; + callback_key_x = input_engine->SetCallback(x_input_identifier); + callback_key_y = input_engine->SetCallback(y_input_identifier); + } + + ~InputFromStick() { + input_engine->DeleteCallback(callback_key_x); + input_engine->DeleteCallback(callback_key_y); + } + + Input::StickStatus GetStatus() const { + Input::StickStatus status; + status.x = { + .raw_value = input_engine->GetAxis(identifier, axis_x), + .properties = properties_x, + }; + status.y = { + .raw_value = input_engine->GetAxis(identifier, axis_y), + .properties = properties_y, + }; + return status; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Stick, + .stick_status = GetStatus(), + }; + + if (status.stick_status.x.raw_value != last_axis_x_value || + status.stick_status.y.raw_value != last_axis_y_value) { + last_axis_x_value = status.stick_status.x.raw_value; + last_axis_y_value = status.stick_status.y.raw_value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 axis_x; + const u32 axis_y; + const Input::AnalogProperties properties_x; + const Input::AnalogProperties properties_y; + int callback_key_x; + int callback_key_y; + float last_axis_x_value; + float last_axis_y_value; + InputEngine* input_engine; +}; + +class InputFromTouch final : public Input::InputDevice { +public: + explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, + bool inverted_, u32 axis_x_, u32 axis_y_, + Input::AnalogProperties properties_x_, + Input::AnalogProperties properties_y_, InputEngine* input_engine_) + : identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_), + inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), + properties_y(properties_y_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier button_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Button, + .index = button, + .callback = engine_callback, + }; + const InputIdentifier x_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_x, + .callback = engine_callback, + }; + const InputIdentifier y_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_y, + .callback = engine_callback, + }; + last_axis_x_value = 0.0f; + last_axis_y_value = 0.0f; + last_button_value = false; + callback_key_button = input_engine->SetCallback(button_input_identifier); + callback_key_x = input_engine->SetCallback(x_input_identifier); + callback_key_y = input_engine->SetCallback(y_input_identifier); + } + + ~InputFromTouch() { + input_engine->DeleteCallback(callback_key_button); + input_engine->DeleteCallback(callback_key_x); + input_engine->DeleteCallback(callback_key_y); + } + + Input::TouchStatus GetStatus() const { + Input::TouchStatus status; + status.id = touch_id; + status.pressed = { + .value = input_engine->GetButton(identifier, button), + .inverted = inverted, + .toggle = toggle, + }; + status.x = { + .raw_value = input_engine->GetAxis(identifier, axis_x), + .properties = properties_x, + }; + status.y = { + .raw_value = input_engine->GetAxis(identifier, axis_y), + .properties = properties_y, + }; + return status; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Touch, + .touch_status = GetStatus(), + }; + + if (status.touch_status.x.raw_value != last_axis_x_value || + status.touch_status.y.raw_value != last_axis_y_value || + status.touch_status.pressed.value != last_button_value) { + last_axis_x_value = status.touch_status.x.raw_value; + last_axis_y_value = status.touch_status.y.raw_value; + last_button_value = status.touch_status.pressed.value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 touch_id; + const u32 button; + const bool toggle; + const bool inverted; + const u32 axis_x; + const u32 axis_y; + const Input::AnalogProperties properties_x; + const Input::AnalogProperties properties_y; + int callback_key_button; + int callback_key_x; + int callback_key_y; + bool last_button_value; + float last_axis_x_value; + float last_axis_y_value; + InputEngine* input_engine; +}; + +class InputFromTrigger final : public Input::InputDevice { +public: + explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, + u32 axis_, Input::AnalogProperties properties_, + InputEngine* input_engine_) + : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), + axis(axis_), properties(properties_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier button_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Button, + .index = button, + .callback = engine_callback, + }; + const InputIdentifier axis_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis, + .callback = engine_callback, + }; + last_axis_value = 0.0f; + last_button_value = false; + callback_key_button = input_engine->SetCallback(button_input_identifier); + axis_callback_key = input_engine->SetCallback(axis_input_identifier); + } + + ~InputFromTrigger() { + input_engine->DeleteCallback(callback_key_button); + input_engine->DeleteCallback(axis_callback_key); + } + + Input::TriggerStatus GetStatus() const { + const Input::AnalogStatus analog_status{ + .raw_value = input_engine->GetAxis(identifier, axis), + .properties = properties, + }; + return { + .analog = analog_status, + .pressed = input_engine->GetButton(identifier, button), + }; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Trigger, + .trigger_status = GetStatus(), + }; + + if (status.trigger_status.analog.raw_value != last_axis_value || + status.trigger_status.pressed != last_button_value) { + last_axis_value = status.trigger_status.analog.raw_value; + last_button_value = status.trigger_status.pressed; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 button; + const bool toggle; + const bool inverted; + const u32 axis; + const Input::AnalogProperties properties; + int callback_key_button; + int axis_callback_key; + bool last_button_value; + float last_axis_value; + InputEngine* input_engine; +}; + +class InputFromAnalog final : public Input::InputDevice { +public: + explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, + Input::AnalogProperties properties_, InputEngine* input_engine_) + : identifier(identifier_), axis(axis_), properties(properties_), + input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis, + .callback = engine_callback, + }; + last_axis_value = 0.0f; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromAnalog() { + input_engine->DeleteCallback(callback_key); + } + + Input::AnalogStatus GetStatus() const { + return { + .raw_value = input_engine->GetAxis(identifier, axis), + .properties = properties, + }; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Analog, + .analog_status = GetStatus(), + }; + + if (status.analog_status.raw_value != last_axis_value) { + last_axis_value = status.analog_status.raw_value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 axis; + const Input::AnalogProperties properties; + int callback_key; + float last_axis_value; + InputEngine* input_engine; +}; + +class InputFromBattery final : public Input::InputDevice { +public: + explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_) + : identifier(identifier_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::Battery, + .index = 0, + .callback = engine_callback, + }; + last_battery_value = Input::BatteryStatus::Charging; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromBattery() { + input_engine->DeleteCallback(callback_key); + } + + Input::BatteryStatus GetStatus() const { + return static_cast(input_engine->GetBattery(identifier)); + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Battery, + .battery_status = GetStatus(), + }; + + if (status.battery_status != last_battery_value) { + last_battery_value = status.battery_status; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + int callback_key; + Input::BatteryStatus last_battery_value; + InputEngine* input_engine; +}; + +class InputFromMotion final : public Input::InputDevice { +public: + explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, + InputEngine* input_engine_) + : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::Motion, + .index = motion_sensor, + .callback = engine_callback, + }; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromMotion() { + input_engine->DeleteCallback(callback_key); + } + + Input::MotionStatus GetStatus() const { + const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); + Input::MotionStatus status{}; + const Input::AnalogProperties properties = { + .deadzone = 0.001f, + .range = 1.0f, + .offset = 0.0f, + }; + status.accel.x = {.raw_value = basic_motion.accel_x, .properties = properties}; + status.accel.y = {.raw_value = basic_motion.accel_y, .properties = properties}; + status.accel.z = {.raw_value = basic_motion.accel_z, .properties = properties}; + status.gyro.x = {.raw_value = basic_motion.gyro_x, .properties = properties}; + status.gyro.y = {.raw_value = basic_motion.gyro_y, .properties = properties}; + status.gyro.z = {.raw_value = basic_motion.gyro_z, .properties = properties}; + status.delta_timestamp = basic_motion.delta_timestamp; + return status; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Motion, + .motion_status = GetStatus(), + }; + + TriggerOnChange(status); + } + +private: + const PadIdentifier identifier; + const u32 motion_sensor; + int callback_key; + InputEngine* input_engine; +}; + +class InputFromAxisMotion final : public Input::InputDevice { +public: + explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, + Input::AnalogProperties properties_x_, + Input::AnalogProperties properties_y_, + Input::AnalogProperties properties_z_, InputEngine* input_engine_) + : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_), + properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_), + input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier x_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_x, + .callback = engine_callback, + }; + const InputIdentifier y_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_y, + .callback = engine_callback, + }; + const InputIdentifier z_input_identifier{ + .identifier = identifier, + .type = EngineInputType::Analog, + .index = axis_z, + .callback = engine_callback, + }; + last_axis_x_value = 0.0f; + last_axis_y_value = 0.0f; + last_axis_z_value = 0.0f; + callback_key_x = input_engine->SetCallback(x_input_identifier); + callback_key_y = input_engine->SetCallback(y_input_identifier); + callback_key_z = input_engine->SetCallback(z_input_identifier); + } + + ~InputFromAxisMotion() { + input_engine->DeleteCallback(callback_key_x); + input_engine->DeleteCallback(callback_key_y); + input_engine->DeleteCallback(callback_key_z); + } + + Input::MotionStatus GetStatus() const { + Input::MotionStatus status{}; + status.gyro.x = { + .raw_value = input_engine->GetAxis(identifier, axis_x), + .properties = properties_x, + }; + status.gyro.y = { + .raw_value = input_engine->GetAxis(identifier, axis_y), + .properties = properties_y, + }; + status.gyro.z = { + .raw_value = input_engine->GetAxis(identifier, axis_z), + .properties = properties_z, + }; + return status; + } + + void OnChange() { + const Input::CallbackStatus status{ + .type = Input::InputType::Motion, + .motion_status = GetStatus(), + }; + + if (status.motion_status.gyro.x.raw_value != last_axis_x_value || + status.motion_status.gyro.y.raw_value != last_axis_y_value || + status.motion_status.gyro.z.raw_value != last_axis_z_value) { + last_axis_x_value = status.motion_status.gyro.x.raw_value; + last_axis_y_value = status.motion_status.gyro.y.raw_value; + last_axis_z_value = status.motion_status.gyro.z.raw_value; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + const u32 axis_x; + const u32 axis_y; + const u32 axis_z; + const Input::AnalogProperties properties_x; + const Input::AnalogProperties properties_y; + const Input::AnalogProperties properties_z; + int callback_key_x; + int callback_key_y; + int callback_key_z; + float last_axis_x_value; + float last_axis_y_value; + float last_axis_z_value; + InputEngine* input_engine; +}; + +std::unique_ptr InputFactory::CreateButtonDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto button_id = static_cast(params.Get("button", 0)); + const auto keyboard_key = static_cast(params.Get("code", 0)); + const auto toggle = params.Get("toggle", false); + const auto inverted = params.Get("inverted", false); + input_engine->PreSetController(identifier); + input_engine->PreSetButton(identifier, button_id); + input_engine->PreSetButton(identifier, keyboard_key); + if (keyboard_key != 0) { + return std::make_unique(identifier, keyboard_key, toggle, inverted, + input_engine.get()); + } + return std::make_unique(identifier, button_id, toggle, inverted, + input_engine.get()); +} + +std::unique_ptr InputFactory::CreateHatButtonDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto button_id = static_cast(params.Get("hat", 0)); + const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); + const auto toggle = params.Get("toggle", false); + const auto inverted = params.Get("inverted", false); + + input_engine->PreSetController(identifier); + input_engine->PreSetHatButton(identifier, button_id); + return std::make_unique(identifier, button_id, direction, toggle, inverted, + input_engine.get()); +} + +std::unique_ptr InputFactory::CreateStickDevice( + const Common::ParamPackage& params) { + const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); + const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); + const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto axis_x = static_cast(params.Get("axis_x", 0)); + const Input::AnalogProperties properties_x = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_x", "+") == "-", + }; + + const auto axis_y = static_cast(params.Get("axis_y", 1)); + const Input::AnalogProperties properties_y = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_y", "+") != "+", + }; + input_engine->PreSetController(identifier); + input_engine->PreSetAxis(identifier, axis_x); + input_engine->PreSetAxis(identifier, axis_y); + return std::make_unique(identifier, axis_x, axis_y, properties_x, properties_y, + input_engine.get()); +} + +std::unique_ptr InputFactory::CreateAnalogDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto axis = static_cast(params.Get("axis", 0)); + const Input::AnalogProperties properties = { + .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), + .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), + .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), + .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert", "+") == "-", + }; + input_engine->PreSetController(identifier); + input_engine->PreSetAxis(identifier, axis); + return std::make_unique(identifier, axis, properties, input_engine.get()); +} + +std::unique_ptr InputFactory::CreateTriggerDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto button = static_cast(params.Get("button", 0)); + const auto toggle = params.Get("toggle", false); + const auto inverted = params.Get("inverted", false); + + const auto axis = static_cast(params.Get("axis", 0)); + const Input::AnalogProperties properties = { + .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), + .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), + .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), + .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert", false) != 0, + }; + input_engine->PreSetController(identifier); + input_engine->PreSetAxis(identifier, axis); + input_engine->PreSetButton(identifier, button); + return std::make_unique(identifier, button, toggle, inverted, axis, + properties, input_engine.get()); +} + +std::unique_ptr InputFactory::CreateTouchDevice( + const Common::ParamPackage& params) { + const auto touch_id = params.Get("touch_id", 0); + const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); + const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); + const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + const auto button = static_cast(params.Get("button", 0)); + const auto toggle = params.Get("toggle", false); + const auto inverted = params.Get("inverted", false); + + const auto axis_x = static_cast(params.Get("axis_x", 0)); + const Input::AnalogProperties properties_x = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_x", "+") == "-", + }; + + const auto axis_y = static_cast(params.Get("axis_y", 1)); + const Input::AnalogProperties properties_y = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_y", false) != 0, + }; + input_engine->PreSetController(identifier); + input_engine->PreSetAxis(identifier, axis_x); + input_engine->PreSetAxis(identifier, axis_y); + input_engine->PreSetButton(identifier, button); + return std::make_unique(identifier, touch_id, button, toggle, inverted, axis_x, + axis_y, properties_x, properties_y, input_engine.get()); +} + +std::unique_ptr InputFactory::CreateBatteryDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + input_engine->PreSetController(identifier); + return std::make_unique(identifier, input_engine.get()); +} + +std::unique_ptr InputFactory::CreateMotionDevice(Common::ParamPackage params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + if (params.Has("motion")) { + const auto motion_sensor = params.Get("motion", 0); + input_engine->PreSetController(identifier); + input_engine->PreSetMotion(identifier, motion_sensor); + return std::make_unique(identifier, motion_sensor, input_engine.get()); + } + + const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); + const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); + const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); + + const auto axis_x = static_cast(params.Get("axis_x", 0)); + const Input::AnalogProperties properties_x = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_x", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_x", "+") == "-", + }; + + const auto axis_y = static_cast(params.Get("axis_y", 1)); + const Input::AnalogProperties properties_y = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_y", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_y", "+") != "+", + }; + + const auto axis_z = static_cast(params.Get("axis_z", 1)); + const Input::AnalogProperties properties_z = { + .deadzone = deadzone, + .range = range, + .threshold = threshold, + .offset = std::clamp(params.Get("offset_z", 0.0f), -1.0f, 1.0f), + .inverted = params.Get("invert_z", "+") != "+", + }; + input_engine->PreSetController(identifier); + input_engine->PreSetAxis(identifier, axis_x); + input_engine->PreSetAxis(identifier, axis_y); + input_engine->PreSetAxis(identifier, axis_z); + return std::make_unique(identifier, axis_x, axis_y, axis_z, properties_x, + properties_y, properties_z, input_engine.get()); +} + +InputFactory::InputFactory(std::shared_ptr input_engine_) + : input_engine(std::move(input_engine_)) {} + +std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) { + if (params.Has("button") && params.Has("axis")) { + return CreateTriggerDevice(params); + } + if (params.Has("button") && params.Has("axis_x") && params.Has("axis_y")) { + return CreateTouchDevice(params); + } + if (params.Has("button") || params.Has("code")) { + return CreateButtonDevice(params); + } + if (params.Has("hat")) { + return CreateHatButtonDevice(params); + } + if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) { + return CreateMotionDevice(params); + } + if (params.Has("motion")) { + return CreateMotionDevice(params); + } + if (params.Has("axis_x") && params.Has("axis_y")) { + return CreateStickDevice(params); + } + if (params.Has("axis")) { + return CreateAnalogDevice(params); + } + if (params.Has("battery")) { + return CreateBatteryDevice(params); + } + LOG_ERROR(Input, "Invalid parameters given"); + return std::make_unique(); +} + +} // namespace InputCommon -- cgit v1.2.3 From 06a5ef5874144a70e30e577a83ba68d1dad79e78 Mon Sep 17 00:00:00 2001 From: german77 Date: Mon, 11 Oct 2021 00:43:11 -0500 Subject: core/hid: Add output devices --- src/input_common/input_poller.cpp | 40 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 46a7dd276..781012886 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -592,6 +592,28 @@ private: InputEngine* input_engine; }; +class OutputFromIdentifier final : public Input::OutputDevice { +public: + explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) + : identifier(identifier_), input_engine(input_engine_) {} + + virtual void SetLED( Input::LedStatus led_status) { + input_engine->SetLeds(identifier, led_status); + } + + virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) { + return input_engine->SetRumble(identifier, vibration_status); + } + + virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) { + return input_engine->SetPollingMode(identifier, polling_mode); + } + +private: + const PadIdentifier identifier; + InputEngine* input_engine; +}; + std::unique_ptr InputFactory::CreateButtonDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { @@ -825,7 +847,8 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par InputFactory::InputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} -std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) { +std::unique_ptr InputFactory::Create( + const Common::ParamPackage& params) { if (params.Has("button") && params.Has("axis")) { return CreateTriggerDevice(params); } @@ -857,4 +880,19 @@ std::unique_ptr InputFactory::Create(const Common::ParamPack return std::make_unique(); } +OutputFactory::OutputFactory(std::shared_ptr input_engine_) + : input_engine(std::move(input_engine_)) {} + +std::unique_ptr OutputFactory::Create( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast(params.Get("port", 0)), + .pad = static_cast(params.Get("pad", 0)), + }; + + input_engine->PreSetController(identifier); + return std::make_unique(identifier, input_engine.get()); +} + } // namespace InputCommon -- cgit v1.2.3 From e0da5c1bbcdf85676f968b63c8ae2587f0464193 Mon Sep 17 00:00:00 2001 From: german77 Date: Fri, 15 Oct 2021 19:07:47 -0500 Subject: kraken: Fix errors from rebase and format files --- src/input_common/input_poller.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 781012886..62ade951c 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -597,7 +597,7 @@ public: explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) : identifier(identifier_), input_engine(input_engine_) {} - virtual void SetLED( Input::LedStatus led_status) { + virtual void SetLED(Input::LedStatus led_status) { input_engine->SetLeds(identifier, led_status); } @@ -847,8 +847,7 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par InputFactory::InputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} -std::unique_ptr InputFactory::Create( - const Common::ParamPackage& params) { +std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) { if (params.Has("button") && params.Has("axis")) { return CreateTriggerDevice(params); } @@ -883,8 +882,7 @@ std::unique_ptr InputFactory::Create( OutputFactory::OutputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} -std::unique_ptr OutputFactory::Create( - const Common::ParamPackage& params) { +std::unique_ptr OutputFactory::Create(const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, .port = static_cast(params.Get("port", 0)), -- cgit v1.2.3 From c6c32daf40ae1c720f0a2897c538bb1117371ea5 Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 24 Oct 2021 20:28:54 -0500 Subject: input_common: Add manual update options to input devices --- src/input_common/input_poller.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 62ade951c..024bd28ef 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -45,6 +45,16 @@ public: }; } + void ForceUpdate() { + const Input::CallbackStatus status{ + .type = Input::InputType::Button, + .button_status = GetStatus(), + }; + + last_button_value = status.button_status.value; + TriggerOnChange(status); + } + void OnChange() { const Input::CallbackStatus status{ .type = Input::InputType::Button, @@ -96,6 +106,16 @@ public: }; } + void ForceUpdate() { + const Input::CallbackStatus status{ + .type = Input::InputType::Button, + .button_status = GetStatus(), + }; + + last_button_value = status.button_status.value; + TriggerOnChange(status); + } + void OnChange() { const Input::CallbackStatus status{ .type = Input::InputType::Button, -- cgit v1.2.3 From 064ddacf49aa7155e26add55983b81fdda997077 Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 24 Oct 2021 23:23:54 -0500 Subject: core/hid: Rework battery mappings --- src/input_common/input_poller.cpp | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 024bd28ef..6edb8d900 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -183,6 +183,17 @@ public: return status; } + void ForceUpdate() { + const Input::CallbackStatus status{ + .type = Input::InputType::Stick, + .stick_status = GetStatus(), + }; + + last_axis_x_value = status.stick_status.x.raw_value; + last_axis_y_value = status.stick_status.y.raw_value; + TriggerOnChange(status); + } + void OnChange() { const Input::CallbackStatus status{ .type = Input::InputType::Stick, @@ -448,6 +459,16 @@ public: return static_cast(input_engine->GetBattery(identifier)); } + void ForceUpdate() { + const Input::CallbackStatus status{ + .type = Input::InputType::Battery, + .battery_status = GetStatus(), + }; + + last_battery_value = status.battery_status; + TriggerOnChange(status); + } + void OnChange() { const Input::CallbackStatus status{ .type = Input::InputType::Battery, @@ -579,6 +600,18 @@ public: return status; } + void ForceUpdate() { + const Input::CallbackStatus status{ + .type = Input::InputType::Motion, + .motion_status = GetStatus(), + }; + + last_axis_x_value = status.motion_status.gyro.x.raw_value; + last_axis_y_value = status.motion_status.gyro.y.raw_value; + last_axis_z_value = status.motion_status.gyro.z.raw_value; + TriggerOnChange(status); + } + void OnChange() { const Input::CallbackStatus status{ .type = Input::InputType::Motion, @@ -868,6 +901,9 @@ InputFactory::InputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) { + if (params.Has("battery")) { + return CreateBatteryDevice(params); + } if (params.Has("button") && params.Has("axis")) { return CreateTriggerDevice(params); } @@ -892,9 +928,6 @@ std::unique_ptr InputFactory::Create(const Common::ParamPack if (params.Has("axis")) { return CreateAnalogDevice(params); } - if (params.Has("battery")) { - return CreateBatteryDevice(params); - } LOG_ERROR(Input, "Invalid parameters given"); return std::make_unique(); } -- cgit v1.2.3 From 2b1b0c2a30e242b08ec120e09803ec54d5445703 Mon Sep 17 00:00:00 2001 From: german77 Date: Sat, 30 Oct 2021 22:23:10 -0500 Subject: kraken: Address comments from review start lion review --- src/input_common/input_poller.cpp | 202 ++++++++++++++++++++------------------ 1 file changed, 105 insertions(+), 97 deletions(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 6edb8d900..2b3b77938 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -10,13 +10,13 @@ namespace InputCommon { -class DummyInput final : public Input::InputDevice { +class DummyInput final : public Common::Input::InputDevice { public: explicit DummyInput() {} ~DummyInput() {} }; -class InputFromButton final : public Input::InputDevice { +class InputFromButton final : public Common::Input::InputDevice { public: explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, InputEngine* input_engine_) @@ -37,7 +37,7 @@ public: input_engine->DeleteCallback(callback_key); } - Input::ButtonStatus GetStatus() const { + Common::Input::ButtonStatus GetStatus() const { return { .value = input_engine->GetButton(identifier, button), .inverted = inverted, @@ -46,8 +46,8 @@ public: } void ForceUpdate() { - const Input::CallbackStatus status{ - .type = Input::InputType::Button, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Button, .button_status = GetStatus(), }; @@ -56,8 +56,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Button, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Button, .button_status = GetStatus(), }; @@ -77,7 +77,7 @@ private: InputEngine* input_engine; }; -class InputFromHatButton final : public Input::InputDevice { +class InputFromHatButton final : public Common::Input::InputDevice { public: explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, bool inverted_, InputEngine* input_engine_) @@ -98,7 +98,7 @@ public: input_engine->DeleteCallback(callback_key); } - Input::ButtonStatus GetStatus() const { + Common::Input::ButtonStatus GetStatus() const { return { .value = input_engine->GetHatButton(identifier, button, direction), .inverted = inverted, @@ -107,8 +107,8 @@ public: } void ForceUpdate() { - const Input::CallbackStatus status{ - .type = Input::InputType::Button, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Button, .button_status = GetStatus(), }; @@ -117,8 +117,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Button, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Button, .button_status = GetStatus(), }; @@ -139,11 +139,12 @@ private: InputEngine* input_engine; }; -class InputFromStick final : public Input::InputDevice { +class InputFromStick final : public Common::Input::InputDevice { public: explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, - Input::AnalogProperties properties_x_, - Input::AnalogProperties properties_y_, InputEngine* input_engine_) + Common::Input::AnalogProperties properties_x_, + Common::Input::AnalogProperties properties_y_, + InputEngine* input_engine_) : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), properties_y(properties_y_), input_engine(input_engine_) { UpdateCallback engine_callback{[this]() { OnChange(); }}; @@ -170,8 +171,8 @@ public: input_engine->DeleteCallback(callback_key_y); } - Input::StickStatus GetStatus() const { - Input::StickStatus status; + Common::Input::StickStatus GetStatus() const { + Common::Input::StickStatus status; status.x = { .raw_value = input_engine->GetAxis(identifier, axis_x), .properties = properties_x, @@ -184,8 +185,8 @@ public: } void ForceUpdate() { - const Input::CallbackStatus status{ - .type = Input::InputType::Stick, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Stick, .stick_status = GetStatus(), }; @@ -195,8 +196,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Stick, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Stick, .stick_status = GetStatus(), }; @@ -212,8 +213,8 @@ private: const PadIdentifier identifier; const u32 axis_x; const u32 axis_y; - const Input::AnalogProperties properties_x; - const Input::AnalogProperties properties_y; + const Common::Input::AnalogProperties properties_x; + const Common::Input::AnalogProperties properties_y; int callback_key_x; int callback_key_y; float last_axis_x_value; @@ -221,12 +222,13 @@ private: InputEngine* input_engine; }; -class InputFromTouch final : public Input::InputDevice { +class InputFromTouch final : public Common::Input::InputDevice { public: explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, bool inverted_, u32 axis_x_, u32 axis_y_, - Input::AnalogProperties properties_x_, - Input::AnalogProperties properties_y_, InputEngine* input_engine_) + Common::Input::AnalogProperties properties_x_, + Common::Input::AnalogProperties properties_y_, + InputEngine* input_engine_) : identifier(identifier_), touch_id(touch_id_), button(button_), toggle(toggle_), inverted(inverted_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), properties_y(properties_y_), input_engine(input_engine_) { @@ -263,8 +265,8 @@ public: input_engine->DeleteCallback(callback_key_y); } - Input::TouchStatus GetStatus() const { - Input::TouchStatus status; + Common::Input::TouchStatus GetStatus() const { + Common::Input::TouchStatus status; status.id = touch_id; status.pressed = { .value = input_engine->GetButton(identifier, button), @@ -283,8 +285,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Touch, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Touch, .touch_status = GetStatus(), }; @@ -306,8 +308,8 @@ private: const bool inverted; const u32 axis_x; const u32 axis_y; - const Input::AnalogProperties properties_x; - const Input::AnalogProperties properties_y; + const Common::Input::AnalogProperties properties_x; + const Common::Input::AnalogProperties properties_y; int callback_key_button; int callback_key_x; int callback_key_y; @@ -317,10 +319,10 @@ private: InputEngine* input_engine; }; -class InputFromTrigger final : public Input::InputDevice { +class InputFromTrigger final : public Common::Input::InputDevice { public: explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, - u32 axis_, Input::AnalogProperties properties_, + u32 axis_, Common::Input::AnalogProperties properties_, InputEngine* input_engine_) : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), axis(axis_), properties(properties_), input_engine(input_engine_) { @@ -348,8 +350,8 @@ public: input_engine->DeleteCallback(axis_callback_key); } - Input::TriggerStatus GetStatus() const { - const Input::AnalogStatus analog_status{ + Common::Input::TriggerStatus GetStatus() const { + const Common::Input::AnalogStatus analog_status{ .raw_value = input_engine->GetAxis(identifier, axis), .properties = properties, }; @@ -360,8 +362,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Trigger, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Trigger, .trigger_status = GetStatus(), }; @@ -379,7 +381,7 @@ private: const bool toggle; const bool inverted; const u32 axis; - const Input::AnalogProperties properties; + const Common::Input::AnalogProperties properties; int callback_key_button; int axis_callback_key; bool last_button_value; @@ -387,10 +389,11 @@ private: InputEngine* input_engine; }; -class InputFromAnalog final : public Input::InputDevice { +class InputFromAnalog final : public Common::Input::InputDevice { public: explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, - Input::AnalogProperties properties_, InputEngine* input_engine_) + Common::Input::AnalogProperties properties_, + InputEngine* input_engine_) : identifier(identifier_), axis(axis_), properties(properties_), input_engine(input_engine_) { UpdateCallback engine_callback{[this]() { OnChange(); }}; @@ -408,7 +411,7 @@ public: input_engine->DeleteCallback(callback_key); } - Input::AnalogStatus GetStatus() const { + Common::Input::AnalogStatus GetStatus() const { return { .raw_value = input_engine->GetAxis(identifier, axis), .properties = properties, @@ -416,8 +419,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Analog, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Analog, .analog_status = GetStatus(), }; @@ -430,13 +433,13 @@ public: private: const PadIdentifier identifier; const u32 axis; - const Input::AnalogProperties properties; + const Common::Input::AnalogProperties properties; int callback_key; float last_axis_value; InputEngine* input_engine; }; -class InputFromBattery final : public Input::InputDevice { +class InputFromBattery final : public Common::Input::InputDevice { public: explicit InputFromBattery(PadIdentifier identifier_, InputEngine* input_engine_) : identifier(identifier_), input_engine(input_engine_) { @@ -447,7 +450,7 @@ public: .index = 0, .callback = engine_callback, }; - last_battery_value = Input::BatteryStatus::Charging; + last_battery_value = Common::Input::BatteryStatus::Charging; callback_key = input_engine->SetCallback(input_identifier); } @@ -455,13 +458,13 @@ public: input_engine->DeleteCallback(callback_key); } - Input::BatteryStatus GetStatus() const { - return static_cast(input_engine->GetBattery(identifier)); + Common::Input::BatteryStatus GetStatus() const { + return static_cast(input_engine->GetBattery(identifier)); } void ForceUpdate() { - const Input::CallbackStatus status{ - .type = Input::InputType::Battery, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Battery, .battery_status = GetStatus(), }; @@ -470,8 +473,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Battery, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Battery, .battery_status = GetStatus(), }; @@ -484,11 +487,11 @@ public: private: const PadIdentifier identifier; int callback_key; - Input::BatteryStatus last_battery_value; + Common::Input::BatteryStatus last_battery_value; InputEngine* input_engine; }; -class InputFromMotion final : public Input::InputDevice { +class InputFromMotion final : public Common::Input::InputDevice { public: explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, InputEngine* input_engine_) @@ -507,10 +510,10 @@ public: input_engine->DeleteCallback(callback_key); } - Input::MotionStatus GetStatus() const { + Common::Input::MotionStatus GetStatus() const { const auto basic_motion = input_engine->GetMotion(identifier, motion_sensor); - Input::MotionStatus status{}; - const Input::AnalogProperties properties = { + Common::Input::MotionStatus status{}; + const Common::Input::AnalogProperties properties = { .deadzone = 0.001f, .range = 1.0f, .offset = 0.0f, @@ -526,8 +529,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Motion, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Motion, .motion_status = GetStatus(), }; @@ -541,12 +544,13 @@ private: InputEngine* input_engine; }; -class InputFromAxisMotion final : public Input::InputDevice { +class InputFromAxisMotion final : public Common::Input::InputDevice { public: explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, - Input::AnalogProperties properties_x_, - Input::AnalogProperties properties_y_, - Input::AnalogProperties properties_z_, InputEngine* input_engine_) + Common::Input::AnalogProperties properties_x_, + Common::Input::AnalogProperties properties_y_, + Common::Input::AnalogProperties properties_z_, + InputEngine* input_engine_) : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), axis_z(axis_z_), properties_x(properties_x_), properties_y(properties_y_), properties_z(properties_z_), input_engine(input_engine_) { @@ -583,8 +587,8 @@ public: input_engine->DeleteCallback(callback_key_z); } - Input::MotionStatus GetStatus() const { - Input::MotionStatus status{}; + Common::Input::MotionStatus GetStatus() const { + Common::Input::MotionStatus status{}; status.gyro.x = { .raw_value = input_engine->GetAxis(identifier, axis_x), .properties = properties_x, @@ -601,8 +605,8 @@ public: } void ForceUpdate() { - const Input::CallbackStatus status{ - .type = Input::InputType::Motion, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Motion, .motion_status = GetStatus(), }; @@ -613,8 +617,8 @@ public: } void OnChange() { - const Input::CallbackStatus status{ - .type = Input::InputType::Motion, + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Motion, .motion_status = GetStatus(), }; @@ -633,9 +637,9 @@ private: const u32 axis_x; const u32 axis_y; const u32 axis_z; - const Input::AnalogProperties properties_x; - const Input::AnalogProperties properties_y; - const Input::AnalogProperties properties_z; + const Common::Input::AnalogProperties properties_x; + const Common::Input::AnalogProperties properties_y; + const Common::Input::AnalogProperties properties_z; int callback_key_x; int callback_key_y; int callback_key_z; @@ -645,20 +649,21 @@ private: InputEngine* input_engine; }; -class OutputFromIdentifier final : public Input::OutputDevice { +class OutputFromIdentifier final : public Common::Input::OutputDevice { public: explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) : identifier(identifier_), input_engine(input_engine_) {} - virtual void SetLED(Input::LedStatus led_status) { + virtual void SetLED(Common::Input::LedStatus led_status) { input_engine->SetLeds(identifier, led_status); } - virtual Input::VibrationError SetVibration(Input::VibrationStatus vibration_status) { + virtual Common::Input::VibrationError SetVibration( + Common::Input::VibrationStatus vibration_status) { return input_engine->SetRumble(identifier, vibration_status); } - virtual Input::PollingError SetPollingMode(Input::PollingMode polling_mode) { + virtual Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) { return input_engine->SetPollingMode(identifier, polling_mode); } @@ -667,7 +672,7 @@ private: InputEngine* input_engine; }; -std::unique_ptr InputFactory::CreateButtonDevice( +std::unique_ptr InputFactory::CreateButtonDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, @@ -690,7 +695,7 @@ std::unique_ptr InputFactory::CreateButtonDevice( input_engine.get()); } -std::unique_ptr InputFactory::CreateHatButtonDevice( +std::unique_ptr InputFactory::CreateHatButtonDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, @@ -709,7 +714,7 @@ std::unique_ptr InputFactory::CreateHatButtonDevice( input_engine.get()); } -std::unique_ptr InputFactory::CreateStickDevice( +std::unique_ptr InputFactory::CreateStickDevice( const Common::ParamPackage& params) { const auto deadzone = std::clamp(params.Get("deadzone", 0.15f), 0.0f, 1.0f); const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); @@ -721,7 +726,7 @@ std::unique_ptr InputFactory::CreateStickDevice( }; const auto axis_x = static_cast(params.Get("axis_x", 0)); - const Input::AnalogProperties properties_x = { + const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -730,7 +735,7 @@ std::unique_ptr InputFactory::CreateStickDevice( }; const auto axis_y = static_cast(params.Get("axis_y", 1)); - const Input::AnalogProperties properties_y = { + const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -744,7 +749,7 @@ std::unique_ptr InputFactory::CreateStickDevice( input_engine.get()); } -std::unique_ptr InputFactory::CreateAnalogDevice( +std::unique_ptr InputFactory::CreateAnalogDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, @@ -753,7 +758,7 @@ std::unique_ptr InputFactory::CreateAnalogDevice( }; const auto axis = static_cast(params.Get("axis", 0)); - const Input::AnalogProperties properties = { + const Common::Input::AnalogProperties properties = { .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), @@ -765,7 +770,7 @@ std::unique_ptr InputFactory::CreateAnalogDevice( return std::make_unique(identifier, axis, properties, input_engine.get()); } -std::unique_ptr InputFactory::CreateTriggerDevice( +std::unique_ptr InputFactory::CreateTriggerDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, @@ -778,7 +783,7 @@ std::unique_ptr InputFactory::CreateTriggerDevice( const auto inverted = params.Get("inverted", false); const auto axis = static_cast(params.Get("axis", 0)); - const Input::AnalogProperties properties = { + const Common::Input::AnalogProperties properties = { .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), @@ -792,7 +797,7 @@ std::unique_ptr InputFactory::CreateTriggerDevice( properties, input_engine.get()); } -std::unique_ptr InputFactory::CreateTouchDevice( +std::unique_ptr InputFactory::CreateTouchDevice( const Common::ParamPackage& params) { const auto touch_id = params.Get("touch_id", 0); const auto deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f); @@ -809,7 +814,7 @@ std::unique_ptr InputFactory::CreateTouchDevice( const auto inverted = params.Get("inverted", false); const auto axis_x = static_cast(params.Get("axis_x", 0)); - const Input::AnalogProperties properties_x = { + const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -818,7 +823,7 @@ std::unique_ptr InputFactory::CreateTouchDevice( }; const auto axis_y = static_cast(params.Get("axis_y", 1)); - const Input::AnalogProperties properties_y = { + const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -833,7 +838,7 @@ std::unique_ptr InputFactory::CreateTouchDevice( axis_y, properties_x, properties_y, input_engine.get()); } -std::unique_ptr InputFactory::CreateBatteryDevice( +std::unique_ptr InputFactory::CreateBatteryDevice( const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, @@ -845,7 +850,8 @@ std::unique_ptr InputFactory::CreateBatteryDevice( return std::make_unique(identifier, input_engine.get()); } -std::unique_ptr InputFactory::CreateMotionDevice(Common::ParamPackage params) { +std::unique_ptr InputFactory::CreateMotionDevice( + Common::ParamPackage params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, .port = static_cast(params.Get("port", 0)), @@ -864,7 +870,7 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); const auto axis_x = static_cast(params.Get("axis_x", 0)); - const Input::AnalogProperties properties_x = { + const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -873,7 +879,7 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par }; const auto axis_y = static_cast(params.Get("axis_y", 1)); - const Input::AnalogProperties properties_y = { + const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -882,7 +888,7 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par }; const auto axis_z = static_cast(params.Get("axis_z", 1)); - const Input::AnalogProperties properties_z = { + const Common::Input::AnalogProperties properties_z = { .deadzone = deadzone, .range = range, .threshold = threshold, @@ -900,7 +906,8 @@ std::unique_ptr InputFactory::CreateMotionDevice(Common::Par InputFactory::InputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} -std::unique_ptr InputFactory::Create(const Common::ParamPackage& params) { +std::unique_ptr InputFactory::Create( + const Common::ParamPackage& params) { if (params.Has("battery")) { return CreateBatteryDevice(params); } @@ -935,7 +942,8 @@ std::unique_ptr InputFactory::Create(const Common::ParamPack OutputFactory::OutputFactory(std::shared_ptr input_engine_) : input_engine(std::move(input_engine_)) {} -std::unique_ptr OutputFactory::Create(const Common::ParamPackage& params) { +std::unique_ptr OutputFactory::Create( + const Common::ParamPackage& params) { const PadIdentifier identifier = { .guid = Common::UUID{params.Get("guid", "")}, .port = static_cast(params.Get("port", 0)), -- cgit v1.2.3 From 730f07830247cfcdc551c253d30c6717fc16316c Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 31 Oct 2021 10:41:44 -0500 Subject: settings: Fix Debug controller type options --- src/input_common/input_poller.cpp | 89 +++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 42 deletions(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 2b3b77938..01c435802 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -18,7 +18,7 @@ public: class InputFromButton final : public Common::Input::InputDevice { public: - explicit InputFromButton(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, + explicit InputFromButton(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_, InputEngine* input_engine_) : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), input_engine(input_engine_) { @@ -69,7 +69,7 @@ public: private: const PadIdentifier identifier; - const u32 button; + const int button; const bool toggle; const bool inverted; int callback_key; @@ -79,7 +79,7 @@ private: class InputFromHatButton final : public Common::Input::InputDevice { public: - explicit InputFromHatButton(PadIdentifier identifier_, u32 button_, u8 direction_, bool toggle_, + explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool toggle_, bool inverted_, InputEngine* input_engine_) : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_), inverted(inverted_), input_engine(input_engine_) { @@ -130,7 +130,7 @@ public: private: const PadIdentifier identifier; - const u32 button; + const int button; const u8 direction; const bool toggle; const bool inverted; @@ -141,7 +141,7 @@ private: class InputFromStick final : public Common::Input::InputDevice { public: - explicit InputFromStick(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, + explicit InputFromStick(PadIdentifier identifier_, int axis_x_, int axis_y_, Common::Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_y_, InputEngine* input_engine_) @@ -211,8 +211,8 @@ public: private: const PadIdentifier identifier; - const u32 axis_x; - const u32 axis_y; + const int axis_x; + const int axis_y; const Common::Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_y; int callback_key_x; @@ -224,8 +224,8 @@ private: class InputFromTouch final : public Common::Input::InputDevice { public: - explicit InputFromTouch(PadIdentifier identifier_, u32 touch_id_, u32 button_, bool toggle_, - bool inverted_, u32 axis_x_, u32 axis_y_, + explicit InputFromTouch(PadIdentifier identifier_, int touch_id_, int button_, bool toggle_, + bool inverted_, int axis_x_, int axis_y_, Common::Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_y_, InputEngine* input_engine_) @@ -302,12 +302,12 @@ public: private: const PadIdentifier identifier; - const u32 touch_id; - const u32 button; + const int touch_id; + const int button; const bool toggle; const bool inverted; - const u32 axis_x; - const u32 axis_y; + const int axis_x; + const int axis_y; const Common::Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_y; int callback_key_button; @@ -321,8 +321,8 @@ private: class InputFromTrigger final : public Common::Input::InputDevice { public: - explicit InputFromTrigger(PadIdentifier identifier_, u32 button_, bool toggle_, bool inverted_, - u32 axis_, Common::Input::AnalogProperties properties_, + explicit InputFromTrigger(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_, + int axis_, Common::Input::AnalogProperties properties_, InputEngine* input_engine_) : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), axis(axis_), properties(properties_), input_engine(input_engine_) { @@ -355,9 +355,14 @@ public: .raw_value = input_engine->GetAxis(identifier, axis), .properties = properties, }; + const Common::Input::ButtonStatus button_status{ + .value = input_engine->GetButton(identifier, button), + .inverted = inverted, + .toggle = toggle, + }; return { .analog = analog_status, - .pressed = input_engine->GetButton(identifier, button), + .pressed = button_status, }; } @@ -368,19 +373,19 @@ public: }; if (status.trigger_status.analog.raw_value != last_axis_value || - status.trigger_status.pressed != last_button_value) { + status.trigger_status.pressed.value != last_button_value) { last_axis_value = status.trigger_status.analog.raw_value; - last_button_value = status.trigger_status.pressed; + last_button_value = status.trigger_status.pressed.value; TriggerOnChange(status); } } private: const PadIdentifier identifier; - const u32 button; + const int button; const bool toggle; const bool inverted; - const u32 axis; + const int axis; const Common::Input::AnalogProperties properties; int callback_key_button; int axis_callback_key; @@ -391,7 +396,7 @@ private: class InputFromAnalog final : public Common::Input::InputDevice { public: - explicit InputFromAnalog(PadIdentifier identifier_, u32 axis_, + explicit InputFromAnalog(PadIdentifier identifier_, int axis_, Common::Input::AnalogProperties properties_, InputEngine* input_engine_) : identifier(identifier_), axis(axis_), properties(properties_), @@ -432,7 +437,7 @@ public: private: const PadIdentifier identifier; - const u32 axis; + const int axis; const Common::Input::AnalogProperties properties; int callback_key; float last_axis_value; @@ -493,7 +498,7 @@ private: class InputFromMotion final : public Common::Input::InputDevice { public: - explicit InputFromMotion(PadIdentifier identifier_, u32 motion_sensor_, + explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, InputEngine* input_engine_) : identifier(identifier_), motion_sensor(motion_sensor_), input_engine(input_engine_) { UpdateCallback engine_callback{[this]() { OnChange(); }}; @@ -539,14 +544,14 @@ public: private: const PadIdentifier identifier; - const u32 motion_sensor; + const int motion_sensor; int callback_key; InputEngine* input_engine; }; class InputFromAxisMotion final : public Common::Input::InputDevice { public: - explicit InputFromAxisMotion(PadIdentifier identifier_, u32 axis_x_, u32 axis_y_, u32 axis_z_, + explicit InputFromAxisMotion(PadIdentifier identifier_, int axis_x_, int axis_y_, int axis_z_, Common::Input::AnalogProperties properties_x_, Common::Input::AnalogProperties properties_y_, Common::Input::AnalogProperties properties_z_, @@ -634,9 +639,9 @@ public: private: const PadIdentifier identifier; - const u32 axis_x; - const u32 axis_y; - const u32 axis_z; + const int axis_x; + const int axis_y; + const int axis_z; const Common::Input::AnalogProperties properties_x; const Common::Input::AnalogProperties properties_y; const Common::Input::AnalogProperties properties_z; @@ -680,8 +685,8 @@ std::unique_ptr InputFactory::CreateButtonDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto button_id = static_cast(params.Get("button", 0)); - const auto keyboard_key = static_cast(params.Get("code", 0)); + const auto button_id = params.Get("button", 0); + const auto keyboard_key = params.Get("code", 0); const auto toggle = params.Get("toggle", false); const auto inverted = params.Get("inverted", false); input_engine->PreSetController(identifier); @@ -703,7 +708,7 @@ std::unique_ptr InputFactory::CreateHatButtonDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto button_id = static_cast(params.Get("hat", 0)); + const auto button_id = params.Get("hat", 0); const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); const auto toggle = params.Get("toggle", false); const auto inverted = params.Get("inverted", false); @@ -725,7 +730,7 @@ std::unique_ptr InputFactory::CreateStickDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto axis_x = static_cast(params.Get("axis_x", 0)); + const auto axis_x = params.Get("axis_x", 0); const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, @@ -734,7 +739,7 @@ std::unique_ptr InputFactory::CreateStickDevice( .inverted = params.Get("invert_x", "+") == "-", }; - const auto axis_y = static_cast(params.Get("axis_y", 1)); + const auto axis_y = params.Get("axis_y", 1); const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, @@ -757,7 +762,7 @@ std::unique_ptr InputFactory::CreateAnalogDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto axis = static_cast(params.Get("axis", 0)); + const auto axis = params.Get("axis", 0); const Common::Input::AnalogProperties properties = { .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f), @@ -778,11 +783,11 @@ std::unique_ptr InputFactory::CreateTriggerDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto button = static_cast(params.Get("button", 0)); + const auto button = params.Get("button", 0); const auto toggle = params.Get("toggle", false); const auto inverted = params.Get("inverted", false); - const auto axis = static_cast(params.Get("axis", 0)); + const auto axis = params.Get("axis", 0); const Common::Input::AnalogProperties properties = { .deadzone = std::clamp(params.Get("deadzone", 0.0f), 0.0f, 1.0f), .range = std::clamp(params.Get("range", 1.0f), 0.25f, 2.50f), @@ -809,11 +814,11 @@ std::unique_ptr InputFactory::CreateTouchDevice( .pad = static_cast(params.Get("pad", 0)), }; - const auto button = static_cast(params.Get("button", 0)); + const auto button = params.Get("button", 0); const auto toggle = params.Get("toggle", false); const auto inverted = params.Get("inverted", false); - const auto axis_x = static_cast(params.Get("axis_x", 0)); + const auto axis_x = params.Get("axis_x", 0); const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, @@ -822,7 +827,7 @@ std::unique_ptr InputFactory::CreateTouchDevice( .inverted = params.Get("invert_x", "+") == "-", }; - const auto axis_y = static_cast(params.Get("axis_y", 1)); + const auto axis_y = params.Get("axis_y", 1); const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, @@ -869,7 +874,7 @@ std::unique_ptr InputFactory::CreateMotionDevice( const auto range = std::clamp(params.Get("range", 1.0f), 0.25f, 1.50f); const auto threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f); - const auto axis_x = static_cast(params.Get("axis_x", 0)); + const auto axis_x = params.Get("axis_x", 0); const Common::Input::AnalogProperties properties_x = { .deadzone = deadzone, .range = range, @@ -878,7 +883,7 @@ std::unique_ptr InputFactory::CreateMotionDevice( .inverted = params.Get("invert_x", "+") == "-", }; - const auto axis_y = static_cast(params.Get("axis_y", 1)); + const auto axis_y = params.Get("axis_y", 1); const Common::Input::AnalogProperties properties_y = { .deadzone = deadzone, .range = range, @@ -887,7 +892,7 @@ std::unique_ptr InputFactory::CreateMotionDevice( .inverted = params.Get("invert_y", "+") != "+", }; - const auto axis_z = static_cast(params.Get("axis_z", 1)); + const auto axis_z = params.Get("axis_z", 1); const Common::Input::AnalogProperties properties_z = { .deadzone = deadzone, .range = range, -- cgit v1.2.3 From c35af8d1c05d94028b215df7721e5235083bcb97 Mon Sep 17 00:00:00 2001 From: german77 Date: Wed, 3 Nov 2021 17:06:21 -0600 Subject: input_common: Fix motion from 3 axis --- src/input_common/input_poller.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 01c435802..92cf690cd 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -606,6 +606,8 @@ public: .raw_value = input_engine->GetAxis(identifier, axis_z), .properties = properties_z, }; + status.delta_timestamp = 5000; + status.force_update = true; return status; } -- cgit v1.2.3 From c4760489a0386cdeaed68ecbed7f87532193743e Mon Sep 17 00:00:00 2001 From: german77 Date: Sun, 21 Nov 2021 12:59:51 -0600 Subject: input_common: Fix SDL controller with inverted axis --- src/input_common/input_poller.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/input_common/input_poller.cpp') diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index 92cf690cd..7e4eafded 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -146,7 +146,8 @@ public: Common::Input::AnalogProperties properties_y_, InputEngine* input_engine_) : identifier(identifier_), axis_x(axis_x_), axis_y(axis_y_), properties_x(properties_x_), - properties_y(properties_y_), input_engine(input_engine_) { + properties_y(properties_y_), + input_engine(input_engine_), invert_axis_y{input_engine_->GetEngineName() == "sdl"} { UpdateCallback engine_callback{[this]() { OnChange(); }}; const InputIdentifier x_input_identifier{ .identifier = identifier, @@ -181,6 +182,11 @@ public: .raw_value = input_engine->GetAxis(identifier, axis_y), .properties = properties_y, }; + // This is a workaround too keep compatibility with old yuzu versions. Vertical axis is + // inverted on SDL compared to Nintendo + if (invert_axis_y) { + status.y.raw_value = -status.y.raw_value; + } return status; } @@ -220,6 +226,7 @@ private: float last_axis_x_value; float last_axis_y_value; InputEngine* input_engine; + const bool invert_axis_y; }; class InputFromTouch final : public Common::Input::InputDevice { -- cgit v1.2.3