diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 35 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/joycon_types.h | 1 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/nfc.cpp | 10 | ||||
| -rw-r--r-- | src/input_common/helpers/joycon_protocol/nfc.h | 6 |
4 files changed, 42 insertions, 10 deletions
diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index 7f9e8dbb9..9a0439bb5 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp | |||
| @@ -109,14 +109,37 @@ public: | |||
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | bool RumblePlay(const Common::Input::VibrationStatus vibration) { | 111 | bool RumblePlay(const Common::Input::VibrationStatus vibration) { |
| 112 | constexpr u32 rumble_max_duration_ms = 1000; | 112 | constexpr u32 rumble_max_duration_ms = 2000; |
| 113 | constexpr f32 low_start_sensitivity_limit = 140.0; | ||
| 114 | constexpr f32 low_width_sensitivity_limit = 400.0; | ||
| 115 | constexpr f32 high_start_sensitivity_limit = 200.0; | ||
| 116 | constexpr f32 high_width_sensitivity_limit = 700.0; | ||
| 117 | // Try to provide some feeling of the frequency by reducing the amplitude depending on it. | ||
| 118 | f32 low_frequency_scale = 1.0; | ||
| 119 | if (vibration.low_frequency > low_start_sensitivity_limit) { | ||
| 120 | low_frequency_scale = | ||
| 121 | std::max(1.0f - (vibration.low_frequency - low_start_sensitivity_limit) / | ||
| 122 | low_width_sensitivity_limit, | ||
| 123 | 0.3f); | ||
| 124 | } | ||
| 125 | f32 low_amplitude = vibration.low_amplitude * low_frequency_scale; | ||
| 126 | |||
| 127 | f32 high_frequency_scale = 1.0; | ||
| 128 | if (vibration.high_frequency > high_start_sensitivity_limit) { | ||
| 129 | high_frequency_scale = | ||
| 130 | std::max(1.0f - (vibration.high_frequency - high_start_sensitivity_limit) / | ||
| 131 | high_width_sensitivity_limit, | ||
| 132 | 0.3f); | ||
| 133 | } | ||
| 134 | f32 high_amplitude = vibration.high_amplitude * high_frequency_scale; | ||
| 135 | |||
| 113 | if (sdl_controller) { | 136 | if (sdl_controller) { |
| 114 | return SDL_GameControllerRumble( | 137 | return SDL_GameControllerRumble(sdl_controller.get(), static_cast<u16>(low_amplitude), |
| 115 | sdl_controller.get(), static_cast<u16>(vibration.low_amplitude), | 138 | static_cast<u16>(high_amplitude), |
| 116 | static_cast<u16>(vibration.high_amplitude), rumble_max_duration_ms) != -1; | 139 | rumble_max_duration_ms) != -1; |
| 117 | } else if (sdl_joystick) { | 140 | } else if (sdl_joystick) { |
| 118 | return SDL_JoystickRumble(sdl_joystick.get(), static_cast<u16>(vibration.low_amplitude), | 141 | return SDL_JoystickRumble(sdl_joystick.get(), static_cast<u16>(low_amplitude), |
| 119 | static_cast<u16>(vibration.high_amplitude), | 142 | static_cast<u16>(high_amplitude), |
| 120 | rumble_max_duration_ms) != -1; | 143 | rumble_max_duration_ms) != -1; |
| 121 | } | 144 | } |
| 122 | 145 | ||
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index b03143e04..1c8d294b0 100644 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h | |||
| @@ -394,6 +394,7 @@ enum class DriverResult { | |||
| 394 | InvalidHandle, | 394 | InvalidHandle, |
| 395 | NotSupported, | 395 | NotSupported, |
| 396 | Disabled, | 396 | Disabled, |
| 397 | Delayed, | ||
| 397 | Unknown, | 398 | Unknown, |
| 398 | }; | 399 | }; |
| 399 | 400 | ||
diff --git a/src/input_common/helpers/joycon_protocol/nfc.cpp b/src/input_common/helpers/joycon_protocol/nfc.cpp index 77ea6d5cf..14818ae33 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.cpp +++ b/src/input_common/helpers/joycon_protocol/nfc.cpp | |||
| @@ -72,6 +72,11 @@ DriverResult NfcProtocol::StartNFCPollingMode() { | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) { | 74 | DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) { |
| 75 | if (update_counter++ < AMIIBO_UPDATE_DELAY) { | ||
| 76 | return DriverResult::Delayed; | ||
| 77 | } | ||
| 78 | update_counter = 0; | ||
| 79 | |||
| 75 | LOG_DEBUG(Input, "Start NFC pooling Mode"); | 80 | LOG_DEBUG(Input, "Start NFC pooling Mode"); |
| 76 | ScopedSetBlocking sb(this); | 81 | ScopedSetBlocking sb(this); |
| 77 | DriverResult result{DriverResult::Success}; | 82 | DriverResult result{DriverResult::Success}; |
| @@ -87,7 +92,7 @@ DriverResult NfcProtocol::ScanAmiibo(std::vector<u8>& data) { | |||
| 87 | result = WaitUntilNfcIsReady(); | 92 | result = WaitUntilNfcIsReady(); |
| 88 | } | 93 | } |
| 89 | if (result == DriverResult::Success) { | 94 | if (result == DriverResult::Success) { |
| 90 | result = StartPolling(tag_data); | 95 | result = StartPolling(tag_data, 7); |
| 91 | } | 96 | } |
| 92 | if (result == DriverResult::Success) { | 97 | if (result == DriverResult::Success) { |
| 93 | result = GetAmiiboData(data); | 98 | result = GetAmiiboData(data); |
| @@ -129,9 +134,8 @@ DriverResult NfcProtocol::WaitUntilNfcIsReady() { | |||
| 129 | return DriverResult::Success; | 134 | return DriverResult::Success; |
| 130 | } | 135 | } |
| 131 | 136 | ||
| 132 | DriverResult NfcProtocol::StartPolling(TagFoundData& data) { | 137 | DriverResult NfcProtocol::StartPolling(TagFoundData& data, std::size_t timeout_limit) { |
| 133 | LOG_DEBUG(Input, "Start Polling for tag"); | 138 | LOG_DEBUG(Input, "Start Polling for tag"); |
| 134 | constexpr std::size_t timeout_limit = 7; | ||
| 135 | MCUCommandResponse output{}; | 139 | MCUCommandResponse output{}; |
| 136 | std::size_t tries = 0; | 140 | std::size_t tries = 0; |
| 137 | 141 | ||
diff --git a/src/input_common/helpers/joycon_protocol/nfc.h b/src/input_common/helpers/joycon_protocol/nfc.h index 11e263e07..4cb992d1d 100644 --- a/src/input_common/helpers/joycon_protocol/nfc.h +++ b/src/input_common/helpers/joycon_protocol/nfc.h | |||
| @@ -32,6 +32,9 @@ public: | |||
| 32 | bool IsEnabled() const; | 32 | bool IsEnabled() const; |
| 33 | 33 | ||
| 34 | private: | 34 | private: |
| 35 | // Number of times the function will be delayed until it outputs valid data | ||
| 36 | static constexpr std::size_t AMIIBO_UPDATE_DELAY = 15; | ||
| 37 | |||
| 35 | struct TagFoundData { | 38 | struct TagFoundData { |
| 36 | u8 type; | 39 | u8 type; |
| 37 | std::vector<u8> uuid; | 40 | std::vector<u8> uuid; |
| @@ -39,7 +42,7 @@ private: | |||
| 39 | 42 | ||
| 40 | DriverResult WaitUntilNfcIsReady(); | 43 | DriverResult WaitUntilNfcIsReady(); |
| 41 | 44 | ||
| 42 | DriverResult StartPolling(TagFoundData& data); | 45 | DriverResult StartPolling(TagFoundData& data, std::size_t timeout_limit = 1); |
| 43 | 46 | ||
| 44 | DriverResult ReadTag(const TagFoundData& data); | 47 | DriverResult ReadTag(const TagFoundData& data); |
| 45 | 48 | ||
| @@ -56,6 +59,7 @@ private: | |||
| 56 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; | 59 | NFCReadBlockCommand GetReadBlockCommand(NFCPages pages) const; |
| 57 | 60 | ||
| 58 | bool is_enabled{}; | 61 | bool is_enabled{}; |
| 62 | std::size_t update_counter{}; | ||
| 59 | }; | 63 | }; |
| 60 | 64 | ||
| 61 | } // namespace InputCommon::Joycon | 65 | } // namespace InputCommon::Joycon |