diff options
| author | 2024-01-10 22:06:54 -0600 | |
|---|---|---|
| committer | 2024-01-15 23:15:40 -0600 | |
| commit | 2cacb9d48c98603176e52ecc94f2374a934797fb (patch) | |
| tree | 12badf5b4eede22b22dece03a9074197ec631a1e /src/hid_core/frontend | |
| parent | Merge pull request #12686 from szepeviktor/typos3 (diff) | |
| download | yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.gz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.tar.xz yuzu-2cacb9d48c98603176e52ecc94f2374a934797fb.zip | |
service: hid: Fully implement abstract vibration
Diffstat (limited to 'src/hid_core/frontend')
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.cpp | 40 | ||||
| -rw-r--r-- | src/hid_core/frontend/emulated_controller.h | 20 |
2 files changed, 52 insertions, 8 deletions
diff --git a/src/hid_core/frontend/emulated_controller.cpp b/src/hid_core/frontend/emulated_controller.cpp index 2ab93402d..b6c48aba8 100644 --- a/src/hid_core/frontend/emulated_controller.cpp +++ b/src/hid_core/frontend/emulated_controller.cpp | |||
| @@ -144,8 +144,8 @@ void EmulatedController::ReloadColorsFromSettings() { | |||
| 144 | 144 | ||
| 145 | void EmulatedController::LoadDevices() { | 145 | void EmulatedController::LoadDevices() { |
| 146 | // TODO(german77): Use more buttons to detect the correct device | 146 | // TODO(german77): Use more buttons to detect the correct device |
| 147 | const auto left_joycon = button_params[Settings::NativeButton::DRight]; | 147 | const auto& left_joycon = button_params[Settings::NativeButton::DRight]; |
| 148 | const auto right_joycon = button_params[Settings::NativeButton::A]; | 148 | const auto& right_joycon = button_params[Settings::NativeButton::A]; |
| 149 | 149 | ||
| 150 | // Triggers for GC controllers | 150 | // Triggers for GC controllers |
| 151 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; | 151 | trigger_params[LeftIndex] = button_params[Settings::NativeButton::ZL]; |
| @@ -1208,20 +1208,43 @@ void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) { | |||
| 1208 | controller.nfc_state = controller.nfc_values; | 1208 | controller.nfc_state = controller.nfc_values; |
| 1209 | } | 1209 | } |
| 1210 | 1210 | ||
| 1211 | bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) { | 1211 | bool EmulatedController::SetVibration(bool should_vibrate) { |
| 1212 | VibrationValue vibration_value = DEFAULT_VIBRATION_VALUE; | ||
| 1213 | if (should_vibrate) { | ||
| 1214 | vibration_value.high_amplitude = 1.0f; | ||
| 1215 | vibration_value.low_amplitude = 1.0f; | ||
| 1216 | } | ||
| 1217 | |||
| 1218 | return SetVibration(DeviceIndex::Left, vibration_value); | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | bool EmulatedController::SetVibration(u32 slot, Core::HID::VibrationGcErmCommand erm_command) { | ||
| 1222 | VibrationValue vibration_value = DEFAULT_VIBRATION_VALUE; | ||
| 1223 | if (erm_command == Core::HID::VibrationGcErmCommand::Start) { | ||
| 1224 | vibration_value.high_amplitude = 1.0f; | ||
| 1225 | vibration_value.low_amplitude = 1.0f; | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | return SetVibration(DeviceIndex::Left, vibration_value); | ||
| 1229 | } | ||
| 1230 | |||
| 1231 | bool EmulatedController::SetVibration(DeviceIndex device_index, const VibrationValue& vibration) { | ||
| 1212 | if (!is_initialized) { | 1232 | if (!is_initialized) { |
| 1213 | return false; | 1233 | return false; |
| 1214 | } | 1234 | } |
| 1215 | if (device_index >= output_devices.size()) { | 1235 | if (device_index >= DeviceIndex::MaxDeviceIndex) { |
| 1216 | return false; | 1236 | return false; |
| 1217 | } | 1237 | } |
| 1218 | if (!output_devices[device_index]) { | 1238 | const std::size_t index = static_cast<std::size_t>(device_index); |
| 1239 | if (!output_devices[index]) { | ||
| 1219 | return false; | 1240 | return false; |
| 1220 | } | 1241 | } |
| 1221 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); | 1242 | const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type); |
| 1222 | const auto& player = Settings::values.players.GetValue()[player_index]; | 1243 | const auto& player = Settings::values.players.GetValue()[player_index]; |
| 1223 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; | 1244 | const f32 strength = static_cast<f32>(player.vibration_strength) / 100.0f; |
| 1224 | 1245 | ||
| 1246 | last_vibration_value = vibration; | ||
| 1247 | |||
| 1225 | if (!player.vibration_enabled) { | 1248 | if (!player.vibration_enabled) { |
| 1226 | return false; | 1249 | return false; |
| 1227 | } | 1250 | } |
| @@ -1239,8 +1262,11 @@ bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue v | |||
| 1239 | .high_frequency = vibration.high_frequency, | 1262 | .high_frequency = vibration.high_frequency, |
| 1240 | .type = type, | 1263 | .type = type, |
| 1241 | }; | 1264 | }; |
| 1242 | return output_devices[device_index]->SetVibration(status) == | 1265 | return output_devices[index]->SetVibration(status) == Common::Input::DriverResult::Success; |
| 1243 | Common::Input::DriverResult::Success; | 1266 | } |
| 1267 | |||
| 1268 | VibrationValue EmulatedController::GetActualVibrationValue(DeviceIndex device_index) const { | ||
| 1269 | return last_vibration_value; | ||
| 1244 | } | 1270 | } |
| 1245 | 1271 | ||
| 1246 | bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { | 1272 | bool EmulatedController::IsVibrationEnabled(std::size_t device_index) { |
diff --git a/src/hid_core/frontend/emulated_controller.h b/src/hid_core/frontend/emulated_controller.h index 90e536e07..168abe089 100644 --- a/src/hid_core/frontend/emulated_controller.h +++ b/src/hid_core/frontend/emulated_controller.h | |||
| @@ -356,10 +356,27 @@ public: | |||
| 356 | const NfcState& GetNfc() const; | 356 | const NfcState& GetNfc() const; |
| 357 | 357 | ||
| 358 | /** | 358 | /** |
| 359 | * Sends an on/off vibration to the left device | ||
| 360 | * @return true if vibration had no errors | ||
| 361 | */ | ||
| 362 | bool SetVibration(bool should_vibrate); | ||
| 363 | |||
| 364 | /** | ||
| 365 | * Sends an GC vibration to the left device | ||
| 366 | * @return true if vibration had no errors | ||
| 367 | */ | ||
| 368 | bool SetVibration(u32 slot, Core::HID::VibrationGcErmCommand erm_command); | ||
| 369 | |||
| 370 | /** | ||
| 359 | * Sends a specific vibration to the output device | 371 | * Sends a specific vibration to the output device |
| 360 | * @return true if vibration had no errors | 372 | * @return true if vibration had no errors |
| 361 | */ | 373 | */ |
| 362 | bool SetVibration(std::size_t device_index, VibrationValue vibration); | 374 | bool SetVibration(DeviceIndex device_index, const VibrationValue& vibration); |
| 375 | |||
| 376 | /** | ||
| 377 | * @return The last sent vibration | ||
| 378 | */ | ||
| 379 | VibrationValue GetActualVibrationValue(DeviceIndex device_index) const; | ||
| 363 | 380 | ||
| 364 | /** | 381 | /** |
| 365 | * Sends a small vibration to the output device | 382 | * Sends a small vibration to the output device |
| @@ -564,6 +581,7 @@ private: | |||
| 564 | f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard}; | 581 | f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard}; |
| 565 | u32 turbo_button_state{0}; | 582 | u32 turbo_button_state{0}; |
| 566 | std::size_t nfc_handles{0}; | 583 | std::size_t nfc_handles{0}; |
| 584 | VibrationValue last_vibration_value{DEFAULT_VIBRATION_VALUE}; | ||
| 567 | 585 | ||
| 568 | // Temporary values to avoid doing changes while the controller is in configuring mode | 586 | // Temporary values to avoid doing changes while the controller is in configuring mode |
| 569 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; | 587 | NpadStyleIndex tmp_npad_type{NpadStyleIndex::None}; |