diff options
Diffstat (limited to '')
| -rw-r--r-- | src/input_common/drivers/joycon.cpp | 11 | ||||
| -rw-r--r-- | src/input_common/input_engine.cpp | 37 | ||||
| -rw-r--r-- | src/input_common/input_engine.h | 6 | ||||
| -rw-r--r-- | src/input_common/input_poller.cpp | 67 | ||||
| -rw-r--r-- | src/input_common/input_poller.h | 11 |
5 files changed, 131 insertions, 1 deletions
diff --git a/src/input_common/drivers/joycon.cpp b/src/input_common/drivers/joycon.cpp index 1fca11d34..c6f78c989 100644 --- a/src/input_common/drivers/joycon.cpp +++ b/src/input_common/drivers/joycon.cpp | |||
| @@ -335,7 +335,16 @@ void Joycons::OnBatteryUpdate(std::size_t port, Joycon::ControllerType type, | |||
| 335 | } | 335 | } |
| 336 | 336 | ||
| 337 | void Joycons::OnColorUpdate(std::size_t port, Joycon::ControllerType type, | 337 | void Joycons::OnColorUpdate(std::size_t port, Joycon::ControllerType type, |
| 338 | const Joycon::Color& value) {} | 338 | const Joycon::Color& value) { |
| 339 | const auto identifier = GetIdentifier(port, type); | ||
| 340 | Common::Input::BodyColorStatus color{ | ||
| 341 | .body = value.body, | ||
| 342 | .buttons = value.buttons, | ||
| 343 | .left_grip = value.left_grip, | ||
| 344 | .right_grip = value.right_grip, | ||
| 345 | }; | ||
| 346 | SetColor(identifier, color); | ||
| 347 | } | ||
| 339 | 348 | ||
| 340 | void Joycons::OnButtonUpdate(std::size_t port, Joycon::ControllerType type, int id, bool value) { | 349 | void Joycons::OnButtonUpdate(std::size_t port, Joycon::ControllerType type, int id, bool value) { |
| 341 | const auto identifier = GetIdentifier(port, type); | 350 | const auto identifier = GetIdentifier(port, type); |
diff --git a/src/input_common/input_engine.cpp b/src/input_common/input_engine.cpp index 61cfd0911..91aa96aa7 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}; |
diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index 6cbcf5207..6301c5719 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h | |||
| @@ -40,6 +40,7 @@ enum class EngineInputType { | |||
| 40 | Battery, | 40 | Battery, |
| 41 | Button, | 41 | Button, |
| 42 | Camera, | 42 | Camera, |
| 43 | Color, | ||
| 43 | HatButton, | 44 | HatButton, |
| 44 | Motion, | 45 | Motion, |
| 45 | Nfc, | 46 | Nfc, |
| @@ -199,6 +200,7 @@ public: | |||
| 199 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; | 200 | bool GetHatButton(const PadIdentifier& identifier, int button, u8 direction) const; |
| 200 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; | 201 | f32 GetAxis(const PadIdentifier& identifier, int axis) const; |
| 201 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; | 202 | Common::Input::BatteryLevel GetBattery(const PadIdentifier& identifier) const; |
| 203 | Common::Input::BodyColorStatus GetColor(const PadIdentifier& identifier) const; | ||
| 202 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; | 204 | BasicMotion GetMotion(const PadIdentifier& identifier, int motion) const; |
| 203 | Common::Input::CameraStatus GetCamera(const PadIdentifier& identifier) const; | 205 | Common::Input::CameraStatus GetCamera(const PadIdentifier& identifier) const; |
| 204 | Common::Input::NfcStatus GetNfc(const PadIdentifier& identifier) const; | 206 | Common::Input::NfcStatus GetNfc(const PadIdentifier& identifier) const; |
| @@ -212,6 +214,7 @@ protected: | |||
| 212 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); | 214 | void SetHatButton(const PadIdentifier& identifier, int button, u8 value); |
| 213 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); | 215 | void SetAxis(const PadIdentifier& identifier, int axis, f32 value); |
| 214 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 216 | void SetBattery(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 217 | void SetColor(const PadIdentifier& identifier, Common::Input::BodyColorStatus value); | ||
| 215 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); | 218 | void SetMotion(const PadIdentifier& identifier, int motion, const BasicMotion& value); |
| 216 | void SetCamera(const PadIdentifier& identifier, const Common::Input::CameraStatus& value); | 219 | void SetCamera(const PadIdentifier& identifier, const Common::Input::CameraStatus& value); |
| 217 | void SetNfc(const PadIdentifier& identifier, const Common::Input::NfcStatus& value); | 220 | void SetNfc(const PadIdentifier& identifier, const Common::Input::NfcStatus& value); |
| @@ -227,6 +230,7 @@ private: | |||
| 227 | std::unordered_map<int, float> axes; | 230 | std::unordered_map<int, float> axes; |
| 228 | std::unordered_map<int, BasicMotion> motions; | 231 | std::unordered_map<int, BasicMotion> motions; |
| 229 | Common::Input::BatteryLevel battery{}; | 232 | Common::Input::BatteryLevel battery{}; |
| 233 | Common::Input::BodyColorStatus color{}; | ||
| 230 | Common::Input::CameraStatus camera{}; | 234 | Common::Input::CameraStatus camera{}; |
| 231 | Common::Input::NfcStatus nfc{}; | 235 | Common::Input::NfcStatus nfc{}; |
| 232 | }; | 236 | }; |
| @@ -235,6 +239,8 @@ private: | |||
| 235 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); | 239 | void TriggerOnHatButtonChange(const PadIdentifier& identifier, int button, u8 value); |
| 236 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); | 240 | void TriggerOnAxisChange(const PadIdentifier& identifier, int axis, f32 value); |
| 237 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); | 241 | void TriggerOnBatteryChange(const PadIdentifier& identifier, Common::Input::BatteryLevel value); |
| 242 | void TriggerOnColorChange(const PadIdentifier& identifier, | ||
| 243 | Common::Input::BodyColorStatus value); | ||
| 238 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, | 244 | void TriggerOnMotionChange(const PadIdentifier& identifier, int motion, |
| 239 | const BasicMotion& value); | 245 | const BasicMotion& value); |
| 240 | void TriggerOnCameraChange(const PadIdentifier& identifier, | 246 | void TriggerOnCameraChange(const PadIdentifier& identifier, |
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index fb8be42e2..368ffbdd5 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp | |||
| @@ -498,6 +498,58 @@ private: | |||
| 498 | InputEngine* input_engine; | 498 | InputEngine* input_engine; |
| 499 | }; | 499 | }; |
| 500 | 500 | ||
| 501 | class InputFromColor final : public Common::Input::InputDevice { | ||
| 502 | public: | ||
| 503 | explicit InputFromColor(PadIdentifier identifier_, InputEngine* input_engine_) | ||
| 504 | : identifier(identifier_), input_engine(input_engine_) { | ||
| 505 | UpdateCallback engine_callback{[this]() { OnChange(); }}; | ||
| 506 | const InputIdentifier input_identifier{ | ||
| 507 | .identifier = identifier, | ||
| 508 | .type = EngineInputType::Color, | ||
| 509 | .index = 0, | ||
| 510 | .callback = engine_callback, | ||
| 511 | }; | ||
| 512 | last_color_value = {}; | ||
| 513 | callback_key = input_engine->SetCallback(input_identifier); | ||
| 514 | } | ||
| 515 | |||
| 516 | ~InputFromColor() override { | ||
| 517 | input_engine->DeleteCallback(callback_key); | ||
| 518 | } | ||
| 519 | |||
| 520 | Common::Input::BodyColorStatus GetStatus() const { | ||
| 521 | return input_engine->GetColor(identifier); | ||
| 522 | } | ||
| 523 | |||
| 524 | void ForceUpdate() override { | ||
| 525 | const Common::Input::CallbackStatus status{ | ||
| 526 | .type = Common::Input::InputType::Color, | ||
| 527 | .color_status = GetStatus(), | ||
| 528 | }; | ||
| 529 | |||
| 530 | last_color_value = status.color_status; | ||
| 531 | TriggerOnChange(status); | ||
| 532 | } | ||
| 533 | |||
| 534 | void OnChange() { | ||
| 535 | const Common::Input::CallbackStatus status{ | ||
| 536 | .type = Common::Input::InputType::Color, | ||
| 537 | .color_status = GetStatus(), | ||
| 538 | }; | ||
| 539 | |||
| 540 | if (status.color_status.body != last_color_value.body) { | ||
| 541 | last_color_value = status.color_status; | ||
| 542 | TriggerOnChange(status); | ||
| 543 | } | ||
| 544 | } | ||
| 545 | |||
| 546 | private: | ||
| 547 | const PadIdentifier identifier; | ||
| 548 | int callback_key; | ||
| 549 | Common::Input::BodyColorStatus last_color_value; | ||
| 550 | InputEngine* input_engine; | ||
| 551 | }; | ||
| 552 | |||
| 501 | class InputFromMotion final : public Common::Input::InputDevice { | 553 | class InputFromMotion final : public Common::Input::InputDevice { |
| 502 | public: | 554 | public: |
| 503 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, | 555 | explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, |
| @@ -966,6 +1018,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( | |||
| 966 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); | 1018 | return std::make_unique<InputFromBattery>(identifier, input_engine.get()); |
| 967 | } | 1019 | } |
| 968 | 1020 | ||
| 1021 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice( | ||
| 1022 | const Common::ParamPackage& params) { | ||
| 1023 | const PadIdentifier identifier = { | ||
| 1024 | .guid = Common::UUID{params.Get("guid", "")}, | ||
| 1025 | .port = static_cast<std::size_t>(params.Get("port", 0)), | ||
| 1026 | .pad = static_cast<std::size_t>(params.Get("pad", 0)), | ||
| 1027 | }; | ||
| 1028 | |||
| 1029 | input_engine->PreSetController(identifier); | ||
| 1030 | return std::make_unique<InputFromColor>(identifier, input_engine.get()); | ||
| 1031 | } | ||
| 1032 | |||
| 969 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( | 1033 | std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( |
| 970 | Common::ParamPackage params) { | 1034 | Common::ParamPackage params) { |
| 971 | const PadIdentifier identifier = { | 1035 | const PadIdentifier identifier = { |
| @@ -1053,6 +1117,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( | |||
| 1053 | if (params.Has("battery")) { | 1117 | if (params.Has("battery")) { |
| 1054 | return CreateBatteryDevice(params); | 1118 | return CreateBatteryDevice(params); |
| 1055 | } | 1119 | } |
| 1120 | if (params.Has("color")) { | ||
| 1121 | return CreateColorDevice(params); | ||
| 1122 | } | ||
| 1056 | if (params.Has("camera")) { | 1123 | if (params.Has("camera")) { |
| 1057 | return CreateCameraDevice(params); | 1124 | return CreateCameraDevice(params); |
| 1058 | } | 1125 | } |
diff --git a/src/input_common/input_poller.h b/src/input_common/input_poller.h index d7db13ce4..e097e254c 100644 --- a/src/input_common/input_poller.h +++ b/src/input_common/input_poller.h | |||
| @@ -191,6 +191,17 @@ private: | |||
| 191 | const Common::ParamPackage& params); | 191 | const Common::ParamPackage& params); |
| 192 | 192 | ||
| 193 | /** | 193 | /** |
| 194 | * Creates a color device from the parameters given. | ||
| 195 | * @param params contains parameters for creating the device: | ||
| 196 | * - "guid": text string for identifying controllers | ||
| 197 | * - "port": port of the connected device | ||
| 198 | * - "pad": slot of the connected controller | ||
| 199 | * @returns a unique input device with the parameters specified | ||
| 200 | */ | ||
| 201 | std::unique_ptr<Common::Input::InputDevice> CreateColorDevice( | ||
| 202 | const Common::ParamPackage& params); | ||
| 203 | |||
| 204 | /** | ||
| 194 | * Creates a motion device from the parameters given. | 205 | * Creates a motion device from the parameters given. |
| 195 | * @param params contains parameters for creating the device: | 206 | * @param params contains parameters for creating the device: |
| 196 | * - "axis_x": the controller horizontal axis id to bind with the input | 207 | * - "axis_x": the controller horizontal axis id to bind with the input |