diff options
Diffstat (limited to 'src/input_common/input_poller.cpp')
-rw-r--r-- | src/input_common/input_poller.cpp | 135 |
1 files changed, 115 insertions, 20 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp index fb8be42e2..870e76ab0 100644 --- a/src/input_common/input_poller.cpp +++ b/src/input_common/input_poller.cpp @@ -16,10 +16,10 @@ public: class InputFromButton final : public Common::Input::InputDevice { public: - explicit InputFromButton(PadIdentifier identifier_, int button_, bool toggle_, bool inverted_, - InputEngine* input_engine_) - : identifier(identifier_), button(button_), toggle(toggle_), inverted(inverted_), - input_engine(input_engine_) { + explicit InputFromButton(PadIdentifier identifier_, int button_, bool turbo_, bool toggle_, + bool inverted_, InputEngine* input_engine_) + : identifier(identifier_), button(button_), turbo(turbo_), toggle(toggle_), + inverted(inverted_), input_engine(input_engine_) { UpdateCallback engine_callback{[this]() { OnChange(); }}; const InputIdentifier input_identifier{ .identifier = identifier, @@ -40,6 +40,7 @@ public: .value = input_engine->GetButton(identifier, button), .inverted = inverted, .toggle = toggle, + .turbo = turbo, }; } @@ -68,6 +69,7 @@ public: private: const PadIdentifier identifier; const int button; + const bool turbo; const bool toggle; const bool inverted; int callback_key; @@ -77,10 +79,10 @@ private: class InputFromHatButton final : public Common::Input::InputDevice { public: - explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool toggle_, - bool inverted_, InputEngine* input_engine_) - : identifier(identifier_), button(button_), direction(direction_), toggle(toggle_), - inverted(inverted_), input_engine(input_engine_) { + explicit InputFromHatButton(PadIdentifier identifier_, int button_, u8 direction_, bool turbo_, + bool toggle_, bool inverted_, InputEngine* input_engine_) + : identifier(identifier_), button(button_), direction(direction_), turbo(turbo_), + toggle(toggle_), inverted(inverted_), input_engine(input_engine_) { UpdateCallback engine_callback{[this]() { OnChange(); }}; const InputIdentifier input_identifier{ .identifier = identifier, @@ -101,6 +103,7 @@ public: .value = input_engine->GetHatButton(identifier, button, direction), .inverted = inverted, .toggle = toggle, + .turbo = turbo, }; } @@ -130,6 +133,7 @@ private: const PadIdentifier identifier; const int button; const u8 direction; + const bool turbo; const bool toggle; const bool inverted; int callback_key; @@ -498,6 +502,58 @@ private: InputEngine* input_engine; }; +class InputFromColor final : public Common::Input::InputDevice { +public: + explicit InputFromColor(PadIdentifier identifier_, InputEngine* input_engine_) + : identifier(identifier_), input_engine(input_engine_) { + UpdateCallback engine_callback{[this]() { OnChange(); }}; + const InputIdentifier input_identifier{ + .identifier = identifier, + .type = EngineInputType::Color, + .index = 0, + .callback = engine_callback, + }; + last_color_value = {}; + callback_key = input_engine->SetCallback(input_identifier); + } + + ~InputFromColor() override { + input_engine->DeleteCallback(callback_key); + } + + Common::Input::BodyColorStatus GetStatus() const { + return input_engine->GetColor(identifier); + } + + void ForceUpdate() override { + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Color, + .color_status = GetStatus(), + }; + + last_color_value = status.color_status; + TriggerOnChange(status); + } + + void OnChange() { + const Common::Input::CallbackStatus status{ + .type = Common::Input::InputType::Color, + .color_status = GetStatus(), + }; + + if (status.color_status.body != last_color_value.body) { + last_color_value = status.color_status; + TriggerOnChange(status); + } + } + +private: + const PadIdentifier identifier; + int callback_key; + Common::Input::BodyColorStatus last_color_value; + InputEngine* input_engine; +}; + class InputFromMotion final : public Common::Input::InputDevice { public: explicit InputFromMotion(PadIdentifier identifier_, int motion_sensor_, float gyro_threshold_, @@ -611,7 +667,7 @@ public: .raw_value = input_engine->GetAxis(identifier, axis_z), .properties = properties_z, }; - status.delta_timestamp = 5000; + status.delta_timestamp = 1000; status.force_update = true; return status; } @@ -736,8 +792,7 @@ public: const Common::Input::CallbackStatus status{ .type = Common::Input::InputType::Nfc, - .nfc_status = nfc_status.state, - .raw_data = nfc_status.data, + .nfc_status = nfc_status, }; TriggerOnChange(status); @@ -754,11 +809,11 @@ public: explicit OutputFromIdentifier(PadIdentifier identifier_, InputEngine* input_engine_) : identifier(identifier_), input_engine(input_engine_) {} - void SetLED(const Common::Input::LedStatus& led_status) override { - input_engine->SetLeds(identifier, led_status); + Common::Input::DriverResult SetLED(const Common::Input::LedStatus& led_status) override { + return input_engine->SetLeds(identifier, led_status); } - Common::Input::VibrationError SetVibration( + Common::Input::DriverResult SetVibration( const Common::Input::VibrationStatus& vibration_status) override { return input_engine->SetVibration(identifier, vibration_status); } @@ -767,11 +822,12 @@ public: return input_engine->IsVibrationEnabled(identifier); } - Common::Input::PollingError SetPollingMode(Common::Input::PollingMode polling_mode) override { + Common::Input::DriverResult SetPollingMode(Common::Input::PollingMode polling_mode) override { return input_engine->SetPollingMode(identifier, polling_mode); } - Common::Input::CameraError SetCameraFormat(Common::Input::CameraFormat camera_format) override { + Common::Input::DriverResult SetCameraFormat( + Common::Input::CameraFormat camera_format) override { return input_engine->SetCameraFormat(identifier, camera_format); } @@ -779,10 +835,31 @@ public: return input_engine->SupportsNfc(identifier); } + Common::Input::NfcState StartNfcPolling() { + return input_engine->StartNfcPolling(identifier); + } + + Common::Input::NfcState StopNfcPolling() { + return input_engine->StopNfcPolling(identifier); + } + + Common::Input::NfcState ReadAmiiboData(std::vector<u8>& out_data) { + return input_engine->ReadAmiiboData(identifier, out_data); + } + Common::Input::NfcState WriteNfcData(const std::vector<u8>& data) override { return input_engine->WriteNfcData(identifier, data); } + Common::Input::NfcState ReadMifareData(const Common::Input::MifareRequest& request, + Common::Input::MifareRequest& out_data) { + return input_engine->ReadMifareData(identifier, request, out_data); + } + + Common::Input::NfcState WriteMifareData(const Common::Input::MifareRequest& request) { + return input_engine->WriteMifareData(identifier, request); + } + private: const PadIdentifier identifier; InputEngine* input_engine; @@ -800,14 +877,15 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateButtonDevice( const auto keyboard_key = params.Get("code", 0); const auto toggle = params.Get("toggle", false) != 0; const auto inverted = params.Get("inverted", false) != 0; + const auto turbo = params.Get("turbo", false) != 0; input_engine->PreSetController(identifier); input_engine->PreSetButton(identifier, button_id); input_engine->PreSetButton(identifier, keyboard_key); if (keyboard_key != 0) { - return std::make_unique<InputFromButton>(identifier, keyboard_key, toggle, inverted, + return std::make_unique<InputFromButton>(identifier, keyboard_key, turbo, toggle, inverted, input_engine.get()); } - return std::make_unique<InputFromButton>(identifier, button_id, toggle, inverted, + return std::make_unique<InputFromButton>(identifier, button_id, turbo, toggle, inverted, input_engine.get()); } @@ -823,11 +901,12 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateHatButtonDevice( const auto direction = input_engine->GetHatButtonId(params.Get("direction", "")); const auto toggle = params.Get("toggle", false) != 0; const auto inverted = params.Get("inverted", false) != 0; + const auto turbo = params.Get("turbo", false) != 0; input_engine->PreSetController(identifier); input_engine->PreSetHatButton(identifier, button_id); - return std::make_unique<InputFromHatButton>(identifier, button_id, direction, toggle, inverted, - input_engine.get()); + return std::make_unique<InputFromHatButton>(identifier, button_id, direction, turbo, toggle, + inverted, input_engine.get()); } std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateStickDevice( @@ -880,6 +959,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice( .threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f), .offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f), .inverted = params.Get("invert", "+") == "-", + .inverted_button = params.Get("inverted", false) != 0, .toggle = params.Get("toggle", false) != 0, }; input_engine->PreSetController(identifier); @@ -966,6 +1046,18 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateBatteryDevice( return std::make_unique<InputFromBattery>(identifier, input_engine.get()); } +std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateColorDevice( + const Common::ParamPackage& params) { + const PadIdentifier identifier = { + .guid = Common::UUID{params.Get("guid", "")}, + .port = static_cast<std::size_t>(params.Get("port", 0)), + .pad = static_cast<std::size_t>(params.Get("pad", 0)), + }; + + input_engine->PreSetController(identifier); + return std::make_unique<InputFromColor>(identifier, input_engine.get()); +} + std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateMotionDevice( Common::ParamPackage params) { const PadIdentifier identifier = { @@ -1053,6 +1145,9 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::Create( if (params.Has("battery")) { return CreateBatteryDevice(params); } + if (params.Has("color")) { + return CreateColorDevice(params); + } if (params.Has("camera")) { return CreateCameraDevice(params); } |