diff options
Diffstat (limited to 'src/input_common/input_engine.cpp')
| -rw-r--r-- | src/input_common/input_engine.cpp | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 61cfd0911..e4c5b5b3c 100644 --- a/src/input_common/input_engine.cpp +++ b/src/input_common/input_engine.cpp | |||
| @@ -79,6 +79,17 @@ void InputEngine::SetBattery(const PadIdentifier& identifier, Common::Input::Bat | |||
| 79 | TriggerOnBatteryChange(identifier, value); | 79 | TriggerOnBatteryChange(identifier, value); |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | void InputEngine::SetColor(const PadIdentifier& identifier, Common::Input::BodyColorStatus value) { | ||
| 83 | { | ||
| 84 | std::scoped_lock lock{mutex}; | ||
| 85 | ControllerData& controller = controller_list.at(identifier); | ||
| 86 | if (!configuring) { | ||
| 87 | controller.color = value; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | TriggerOnColorChange(identifier, value); | ||
| 91 | } | ||
| 92 | |||
| 82 | void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) { | 93 | void InputEngine::SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value) { |
| 83 | { | 94 | { |
| 84 | std::scoped_lock lock{mutex}; | 95 | std::scoped_lock lock{mutex}; |
| @@ -176,6 +187,18 @@ Common::Input::BatteryLevel InputEngine::GetBattery(const PadIdentifier& identif | |||
| 176 | return controller.battery; | 187 | return controller.battery; |
| 177 | } | 188 | } |
| 178 | 189 | ||
| 190 | Common::Input::BodyColorStatus InputEngine::GetColor(const PadIdentifier& identifier) const { | ||
| 191 | std::scoped_lock lock{mutex}; | ||
| 192 | const auto controller_iter = controller_list.find(identifier); | ||
| 193 | if (controller_iter == controller_list.cend()) { | ||
| 194 | LOG_ERROR(Input, "Invalid identifier guid={}, pad={}, port={}", identifier.guid.RawString(), | ||
| 195 | identifier.pad, identifier.port); | ||
| 196 | return {}; | ||
| 197 | } | ||
| 198 | const ControllerData& controller = controller_iter->second; | ||
| 199 | return controller.color; | ||
| 200 | } | ||
| 201 | |||
| 179 | BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { | 202 | BasicMotion InputEngine::GetMotion(const PadIdentifier& identifier, int motion) const { |
| 180 | std::scoped_lock lock{mutex}; | 203 | std::scoped_lock lock{mutex}; |
| 181 | const auto controller_iter = controller_list.find(identifier); | 204 | const auto controller_iter = controller_list.find(identifier); |
| @@ -328,6 +351,20 @@ void InputEngine::TriggerOnBatteryChange(const PadIdentifier& identifier, | |||
| 328 | } | 351 | } |
| 329 | } | 352 | } |
| 330 | 353 | ||
| 354 | void InputEngine::TriggerOnColorChange(const PadIdentifier& identifier, | ||
| 355 | [[maybe_unused]] Common::Input::BodyColorStatus value) { | ||
| 356 | std::scoped_lock lock{mutex_callback}; | ||
| 357 | for (const auto& poller_pair : callback_list) { | ||
| 358 | const InputIdentifier& poller = poller_pair.second; | ||
| 359 | if (!IsInputIdentifierEqual(poller, identifier, EngineInputType::Color, 0)) { | ||
| 360 | continue; | ||
| 361 | } | ||
| 362 | if (poller.callback.on_change) { | ||
| 363 | poller.callback.on_change(); | ||
| 364 | } | ||
| 365 | } | ||
| 366 | } | ||
| 367 | |||
| 331 | void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 368 | void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 332 | const BasicMotion& value) { | 369 | const BasicMotion& value) { |
| 333 | std::scoped_lock lock{mutex_callback}; | 370 | std::scoped_lock lock{mutex_callback}; |
| @@ -343,13 +380,16 @@ void InputEngine::TriggerOnMotionChange(const PadIdentifier& identifier, int mot | |||
| 343 | if (!configuring || !mapping_callback.on_data) { | 380 | if (!configuring || !mapping_callback.on_data) { |
| 344 | return; | 381 | return; |
| 345 | } | 382 | } |
| 383 | const auto old_value = GetMotion(identifier, motion); | ||
| 346 | bool is_active = false; | 384 | bool is_active = false; |
| 347 | if (std::abs(value.accel_x) > 1.5f || std::abs(value.accel_y) > 1.5f || | 385 | if (std::abs(value.accel_x - old_value.accel_x) > 1.5f || |
| 348 | std::abs(value.accel_z) > 1.5f) { | 386 | std::abs(value.accel_y - old_value.accel_y) > 1.5f || |
| 387 | std::abs(value.accel_z - old_value.accel_z) > 1.5f) { | ||
| 349 | is_active = true; | 388 | is_active = true; |
| 350 | } | 389 | } |
| 351 | if (std::abs(value.gyro_x) > 0.6f || std::abs(value.gyro_y) > 0.6f || | 390 | if (std::abs(value.gyro_x - old_value.gyro_x) > 0.6f || |
| 352 | std::abs(value.gyro_z) > 0.6f) { | 391 | std::abs(value.gyro_y - old_value.gyro_y) > 0.6f || |
| 392 | std::abs(value.gyro_z - old_value.gyro_z) > 0.6f) { | ||
| 353 | is_active = true; | 393 | is_active = true; |
| 354 | } | 394 | } |
| 355 | if (!is_active) { | 395 | if (!is_active) { |