diff options
Diffstat (limited to '')
-rw-r--r-- | src/input_common/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/input_common/drivers/android.cpp | 48 | ||||
-rw-r--r-- | src/input_common/drivers/android.h | 54 | ||||
-rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 4 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/irs.cpp | 4 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/joycon_types.h | 6 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/nfc.cpp | 8 | ||||
-rw-r--r-- | src/input_common/helpers/joycon_protocol/rumble.cpp | 12 | ||||
-rw-r--r-- | src/input_common/helpers/udp_protocol.h | 2 | ||||
-rw-r--r-- | src/input_common/input_mapping.cpp | 3 | ||||
-rw-r--r-- | src/input_common/main.cpp | 22 | ||||
-rw-r--r-- | src/input_common/main.h | 7 |
12 files changed, 154 insertions, 18 deletions
diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index d2fbea488..d0a71a15b 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -2,6 +2,8 @@ # SPDX-License-Identifier: GPL-2.0-or-later add_library(input_common STATIC + drivers/android.cpp + drivers/android.h drivers/camera.cpp drivers/camera.h drivers/keyboard.cpp diff --git a/src/input_common/drivers/android.cpp b/src/input_common/drivers/android.cpp new file mode 100644 index 000000000..b6a03fdc0 --- /dev/null +++ b/src/input_common/drivers/android.cpp @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#include "input_common/drivers/android.h" + +namespace InputCommon { + +Android::Android(std::string input_engine_) : InputEngine(std::move(input_engine_)) {} + +void Android::RegisterController(std::size_t controller_number) { + PreSetController(GetIdentifier(controller_number)); +} + +void Android::SetButtonState(std::size_t controller_number, int button_id, bool value) { + const auto identifier = GetIdentifier(controller_number); + SetButton(identifier, button_id, value); +} + +void Android::SetAxisState(std::size_t controller_number, int axis_id, float value) { + const auto identifier = GetIdentifier(controller_number); + SetAxis(identifier, axis_id, value); +} + +void Android::SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x, + float gyro_y, float gyro_z, float accel_x, float accel_y, + float accel_z) { + const auto identifier = GetIdentifier(controller_number); + const BasicMotion motion_data{ + .gyro_x = gyro_x, + .gyro_y = gyro_y, + .gyro_z = gyro_z, + .accel_x = accel_x, + .accel_y = accel_y, + .accel_z = accel_z, + .delta_timestamp = delta_timestamp, + }; + SetMotion(identifier, 0, motion_data); +} + +PadIdentifier Android::GetIdentifier(std::size_t controller_number) const { + return { + .guid = Common::UUID{}, + .port = controller_number, + .pad = 0, + }; +} + +} // namespace InputCommon diff --git a/src/input_common/drivers/android.h b/src/input_common/drivers/android.h new file mode 100644 index 000000000..3f01817f6 --- /dev/null +++ b/src/input_common/drivers/android.h @@ -0,0 +1,54 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-3.0-or-later + +#pragma once + +#include "input_common/input_engine.h" + +namespace InputCommon { + +/** + * A virtual controller that is always assigned to the game input + */ +class Android final : public InputEngine { +public: + explicit Android(std::string input_engine_); + + /** + * Registers controller number to accept new inputs + * @param controller_number the controller number that will take this action + */ + void RegisterController(std::size_t controller_number); + + /** + * Sets the status of all buttons bound with the key to pressed + * @param controller_number the controller number that will take this action + * @param button_id the id of the button + * @param value indicates if the button is pressed or not + */ + void SetButtonState(std::size_t controller_number, int button_id, bool value); + + /** + * Sets the status of a analog input to a specific player index + * @param controller_number the controller number that will take this action + * @param axis_id the id of the axis to move + * @param value the analog position of the axis + */ + void SetAxisState(std::size_t controller_number, int axis_id, float value); + + /** + * Sets the status of the motion sensor to a specific player index + * @param controller_number the controller number that will take this action + * @param delta_timestamp time passed since last reading + * @param gyro_x,gyro_y,gyro_z the gyro sensor readings + * @param accel_x,accel_y,accel_z the accelerometer reading + */ + void SetMotionState(std::size_t controller_number, u64 delta_timestamp, float gyro_x, + float gyro_y, float gyro_z, float accel_x, float accel_y, float accel_z); + +private: + /// Returns the correct identifier corresponding to the player index + PadIdentifier GetIdentifier(std::size_t controller_number) const; +}; + +} // namespace InputCommon diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index 1ff296af5..f1184a5fa 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp @@ -451,11 +451,11 @@ ButtonMapping GCAdapter::GetButtonMappingForDevice(const Common::ParamPackage& p std::tuple{Settings::NativeButton::ZL, PadButton::TriggerL, PadAxes::TriggerLeft}, {Settings::NativeButton::ZR, PadButton::TriggerR, PadAxes::TriggerRight}, }; - for (const auto& [switch_button, gcadapter_buton, gcadapter_axis] : switch_to_gcadapter_axis) { + for (const auto& [switch_button, gcadapter_button, gcadapter_axis] : switch_to_gcadapter_axis) { Common::ParamPackage button_params{}; button_params.Set("engine", GetEngineName()); button_params.Set("port", params.Get("port", 0)); - button_params.Set("button", static_cast<s32>(gcadapter_buton)); + button_params.Set("button", static_cast<s32>(gcadapter_button)); button_params.Set("axis", static_cast<s32>(gcadapter_axis)); button_params.Set("threshold", 0.5f); button_params.Set("range", 1.9f); diff --git a/src/input_common/helpers/joycon_protocol/irs.cpp b/src/input_common/helpers/joycon_protocol/irs.cpp index 68b0589e3..5bf72114d 100644 --- a/src/input_common/helpers/joycon_protocol/irs.cpp +++ b/src/input_common/helpers/joycon_protocol/irs.cpp @@ -236,9 +236,9 @@ Common::Input::DriverResult IrsProtocol::WriteRegistersStep2() { .number_of_registers = 0x8, .registers = { - IrsRegister{IrRegistersAddress::LedIntensitiyMSB, + IrsRegister{IrRegistersAddress::LedIntensityMSB, static_cast<u8>(led_intensity >> 8)}, - {IrRegistersAddress::LedIntensitiyLSB, static_cast<u8>(led_intensity & 0xff)}, + {IrRegistersAddress::LedIntensityLSB, static_cast<u8>(led_intensity & 0xff)}, {IrRegistersAddress::ImageFlip, static_cast<u8>(image_flip)}, {IrRegistersAddress::DenoiseSmoothing, static_cast<u8>((denoise >> 16) & 0xff)}, {IrRegistersAddress::DenoiseEdge, static_cast<u8>((denoise >> 8) & 0xff)}, diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index 77a43c67a..792f124e1 100644 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h @@ -282,7 +282,7 @@ enum class NFCCommand : u8 { CancelAll = 0x00, StartPolling = 0x01, StopPolling = 0x02, - StartWaitingRecieve = 0x04, + StartWaitingReceive = 0x04, ReadNtag = 0x06, WriteNtag = 0x08, Mifare = 0x0F, @@ -382,8 +382,8 @@ enum class IrRegistersAddress : u16 { FinalizeConfig = 0x0700, LedFilter = 0x0e00, Leds = 0x1000, - LedIntensitiyMSB = 0x1100, - LedIntensitiyLSB = 0x1200, + LedIntensityMSB = 0x1100, + LedIntensityLSB = 0x1200, ImageFlip = 0x2d00, Resolution = 0x2e00, DigitalGainLSB = 0x2e01, diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index 09953394b..db83f9ef4 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp @@ -519,13 +519,13 @@ Common::Input::DriverResult NfcProtocol::GetMifareData( } if (output.mcu_report == MCUReport::NFCState && output.mcu_data[1] == 0x10) { - constexpr std::size_t DATA_LENGHT = 0x10 + 1; + constexpr std::size_t DATA_LENGTH = 0x10 + 1; constexpr std::size_t DATA_START = 11; const u8 number_of_elements = output.mcu_data[10]; for (std::size_t i = 0; i < number_of_elements; i++) { - out_data[i].sector = output.mcu_data[DATA_START + (i * DATA_LENGHT)]; + out_data[i].sector = output.mcu_data[DATA_START + (i * DATA_LENGTH)]; memcpy(out_data[i].data.data(), - output.mcu_data.data() + DATA_START + 1 + (i * DATA_LENGHT), + output.mcu_data.data() + DATA_START + 1 + (i * DATA_LENGTH), sizeof(MifareReadData::data)); } package_index++; @@ -659,7 +659,7 @@ Common::Input::DriverResult NfcProtocol::SendStopPollingRequest(MCUCommandRespon Common::Input::DriverResult NfcProtocol::SendNextPackageRequest(MCUCommandResponse& output, u8 packet_id) { NFCRequestState request{ - .command_argument = NFCCommand::StartWaitingRecieve, + .command_argument = NFCCommand::StartWaitingReceive, .block_id = {}, .packet_id = packet_id, .packet_flag = MCUPacketFlag::LastCommandPacket, diff --git a/src/input_common/helpers/joycon_protocol/rumble.cpp b/src/input_common/helpers/joycon_protocol/rumble.cpp index 7647f505e..9fd0b8470 100644 --- a/src/input_common/helpers/joycon_protocol/rumble.cpp +++ b/src/input_common/helpers/joycon_protocol/rumble.cpp @@ -67,7 +67,7 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { // More information about these values can be found here: // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md - static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ + static constexpr std::array<std::pair<f32, int>, 101> high_frequency_amplitude{ std::pair<f32, int>{0.0f, 0x0}, {0.01f, 0x2}, {0.012f, 0x4}, @@ -171,20 +171,20 @@ u8 RumbleProtocol::EncodeHighAmplitude(f32 amplitude) const { {1.003f, 0xc8}, }; - for (const auto& [amplitude_value, code] : high_fequency_amplitude) { + for (const auto& [amplitude_value, code] : high_frequency_amplitude) { if (amplitude <= amplitude_value) { return static_cast<u8>(code); } } - return static_cast<u8>(high_fequency_amplitude[high_fequency_amplitude.size() - 1].second); + return static_cast<u8>(high_frequency_amplitude[high_frequency_amplitude.size() - 1].second); } u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { // More information about these values can be found here: // https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/rumble_data_table.md - static constexpr std::array<std::pair<f32, int>, 101> high_fequency_amplitude{ + static constexpr std::array<std::pair<f32, int>, 101> high_frequency_amplitude{ std::pair<f32, int>{0.0f, 0x0040}, {0.01f, 0x8040}, {0.012f, 0x0041}, @@ -288,13 +288,13 @@ u16 RumbleProtocol::EncodeLowAmplitude(f32 amplitude) const { {1.003f, 0x0072}, }; - for (const auto& [amplitude_value, code] : high_fequency_amplitude) { + for (const auto& [amplitude_value, code] : high_frequency_amplitude) { if (amplitude <= amplitude_value) { return static_cast<u16>(code); } } - return static_cast<u16>(high_fequency_amplitude[high_fequency_amplitude.size() - 1].second); + return static_cast<u16>(high_frequency_amplitude[high_frequency_amplitude.size() - 1].second); } } // namespace InputCommon::Joycon diff --git a/src/input_common/helpers/udp_protocol.h b/src/input_common/helpers/udp_protocol.h index d9643ffe0..dba9f87d9 100644 --- a/src/input_common/helpers/udp_protocol.h +++ b/src/input_common/helpers/udp_protocol.h @@ -78,7 +78,7 @@ namespace Request { enum RegisterFlags : u8 { AllPads, PadID, - PadMACAdddress, + PadMACAddress, }; struct Version {}; diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 8c2ee4eb3..f1a1d7398 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp @@ -210,6 +210,9 @@ bool MappingFactory::IsDriverValid(const MappingData& data) const { if (data.engine == "analog_from_button") { return false; } + if (data.engine == "virtual_gamepad") { + return false; + } return true; } diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index c77fc04ee..f8749ebbf 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -4,6 +4,7 @@ #include <memory> #include "common/input.h" #include "common/param_package.h" +#include "input_common/drivers/android.h" #include "input_common/drivers/camera.h" #include "input_common/drivers/keyboard.h" #include "input_common/drivers/mouse.h" @@ -78,6 +79,7 @@ struct InputSubsystem::Impl { RegisterEngine("cemuhookudp", udp_client); RegisterEngine("tas", tas_input); RegisterEngine("camera", camera); + RegisterEngine("android", android); RegisterEngine("virtual_amiibo", virtual_amiibo); RegisterEngine("virtual_gamepad", virtual_gamepad); #ifdef HAVE_SDL2 @@ -109,6 +111,7 @@ struct InputSubsystem::Impl { UnregisterEngine(udp_client); UnregisterEngine(tas_input); UnregisterEngine(camera); + UnregisterEngine(android); UnregisterEngine(virtual_amiibo); UnregisterEngine(virtual_gamepad); #ifdef HAVE_SDL2 @@ -129,6 +132,8 @@ struct InputSubsystem::Impl { devices.insert(devices.end(), keyboard_devices.begin(), keyboard_devices.end()); auto mouse_devices = mouse->GetInputDevices(); devices.insert(devices.end(), mouse_devices.begin(), mouse_devices.end()); + auto android_devices = android->GetInputDevices(); + devices.insert(devices.end(), android_devices.begin(), android_devices.end()); #ifdef HAVE_LIBUSB auto gcadapter_devices = gcadapter->GetInputDevices(); devices.insert(devices.end(), gcadapter_devices.begin(), gcadapter_devices.end()); @@ -157,6 +162,9 @@ struct InputSubsystem::Impl { if (engine == mouse->GetEngineName()) { return mouse; } + if (engine == android->GetEngineName()) { + return android; + } #ifdef HAVE_LIBUSB if (engine == gcadapter->GetEngineName()) { return gcadapter; @@ -237,6 +245,9 @@ struct InputSubsystem::Impl { if (engine == mouse->GetEngineName()) { return true; } + if (engine == android->GetEngineName()) { + return true; + } #ifdef HAVE_LIBUSB if (engine == gcadapter->GetEngineName()) { return true; @@ -265,6 +276,7 @@ struct InputSubsystem::Impl { void BeginConfiguration() { keyboard->BeginConfiguration(); mouse->BeginConfiguration(); + android->BeginConfiguration(); #ifdef HAVE_LIBUSB gcadapter->BeginConfiguration(); #endif @@ -278,6 +290,7 @@ struct InputSubsystem::Impl { void EndConfiguration() { keyboard->EndConfiguration(); mouse->EndConfiguration(); + android->EndConfiguration(); #ifdef HAVE_LIBUSB gcadapter->EndConfiguration(); #endif @@ -308,6 +321,7 @@ struct InputSubsystem::Impl { std::shared_ptr<TasInput::Tas> tas_input; std::shared_ptr<CemuhookUDP::UDPClient> udp_client; std::shared_ptr<Camera> camera; + std::shared_ptr<Android> android; std::shared_ptr<VirtualAmiibo> virtual_amiibo; std::shared_ptr<VirtualGamepad> virtual_gamepad; @@ -373,6 +387,14 @@ const Camera* InputSubsystem::GetCamera() const { return impl->camera.get(); } +Android* InputSubsystem::GetAndroid() { + return impl->android.get(); +} + +const Android* InputSubsystem::GetAndroid() const { + return impl->android.get(); +} + VirtualAmiibo* InputSubsystem::GetVirtualAmiibo() { return impl->virtual_amiibo.get(); } diff --git a/src/input_common/main.h b/src/input_common/main.h index d64a6cb4c..1d19019ee 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -29,6 +29,7 @@ enum Values : int; } namespace InputCommon { +class Android; class Camera; class Keyboard; class Mouse; @@ -103,6 +104,12 @@ public: /// Retrieves the underlying camera input device. [[nodiscard]] const Camera* GetCamera() const; + /// Retrieves the underlying android input device. + [[nodiscard]] Android* GetAndroid(); + + /// Retrieves the underlying android input device. + [[nodiscard]] const Android* GetAndroid() const; + /// Retrieves the underlying virtual amiibo input device. [[nodiscard]] VirtualAmiibo* GetVirtualAmiibo(); |