summaryrefslogtreecommitdiffstats
path: root/src/input_common/input_poller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/input_poller.cpp')
-rw-r--r--src/input_common/input_poller.cpp78
1 files changed, 73 insertions, 5 deletions
diff --git a/src/input_common/input_poller.cpp b/src/input_common/input_poller.cpp
index fb8be42e2..15cbf7e5f 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_,
@@ -754,11 +806,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 +819,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);
}
@@ -966,6 +1019,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 +1118,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);
}