summaryrefslogtreecommitdiffstats
path: root/src/input_common/input_poller.cpp
diff options
context:
space:
mode:
authorNarr the Reg <juangerman-13@hotmail.com>2022-12-20 20:23:31 +0100
committerNarr the Reg <juangerman-13@hotmail.com>2023-01-20 01:05:20 +0100
commited5fa10e9729cf55205533f62a428e646aa5ed7c (patch)
treefe1fa3882df8a26845f937dbb0a51beb7ac7acc3 /src/input_common/input_poller.cpp
parentcore: hid: Migrate ring from emulated devices to emulated controller (diff)
downloadyuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.gz
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.bz2
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.lz
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.xz
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.tar.zst
yuzu-ed5fa10e9729cf55205533f62a428e646aa5ed7c.zip
Diffstat (limited to 'src/input_common/input_poller.cpp')
-rw-r--r--src/input_common/input_poller.cpp67
1 files changed, 67 insertions, 0 deletions
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:
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_,
@@ -966,6 +1018,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 +1117,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);
}