summaryrefslogtreecommitdiff
path: root/src/tangara/input/device_factory.cpp
diff options
context:
space:
mode:
authorcooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
committercooljqln <cooljqln@noreply.codeberg.org>2024-05-03 04:48:17 +0000
commit3ceb8025ee4330c177101ed30ec17dfb0002f41e (patch)
tree58350210f15df7d00d967cac6f30eeceeb031a3c /src/tangara/input/device_factory.cpp
parent964da15a0b84f8e5f00e8abac2f7dfda0bf60488 (diff)
parent9fafd797a5504f458b5fcae4a1d28a68da936315 (diff)
downloadtangara-fw-3ceb8025ee4330c177101ed30ec17dfb0002f41e.tar.gz
Merge pull request 'Break dependency cycles with our components by merging co-dependent components together' (#68) from jqln/component-merge into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/68
Diffstat (limited to 'src/tangara/input/device_factory.cpp')
-rw-r--r--src/tangara/input/device_factory.cpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/tangara/input/device_factory.cpp b/src/tangara/input/device_factory.cpp
new file mode 100644
index 00000000..8e1c5155
--- /dev/null
+++ b/src/tangara/input/device_factory.cpp
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2023 jacqueline <me@jacqueline.id.au>
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+#include "input/device_factory.hpp"
+
+#include <memory>
+
+#include "input/feedback_haptics.hpp"
+#include "input/input_device.hpp"
+#include "input/input_nav_buttons.hpp"
+#include "input/input_touch_dpad.hpp"
+#include "input/input_touch_wheel.hpp"
+#include "input/input_volume_buttons.hpp"
+
+namespace input {
+
+DeviceFactory::DeviceFactory(
+ std::shared_ptr<system_fsm::ServiceLocator> services)
+ : services_(services) {
+ if (services->touchwheel()) {
+ wheel_ =
+ std::make_shared<TouchWheel>(services->nvs(), **services->touchwheel());
+ }
+}
+
+auto DeviceFactory::createInputs(drivers::NvsStorage::InputModes mode)
+ -> std::vector<std::shared_ptr<IInputDevice>> {
+ std::vector<std::shared_ptr<IInputDevice>> ret;
+ switch (mode) {
+ case drivers::NvsStorage::InputModes::kButtonsOnly:
+ ret.push_back(std::make_shared<NavButtons>(services_->gpios()));
+ break;
+ case drivers::NvsStorage::InputModes::kDirectionalWheel:
+ ret.push_back(std::make_shared<VolumeButtons>(services_->gpios()));
+ if (services_->touchwheel()) {
+ ret.push_back(std::make_shared<TouchDPad>(**services_->touchwheel()));
+ }
+ break;
+ case drivers::NvsStorage::InputModes::kRotatingWheel:
+ default: // Don't break input over a bad enum value.
+ ret.push_back(std::make_shared<VolumeButtons>(services_->gpios()));
+ if (wheel_) {
+ ret.push_back(wheel_);
+ }
+ break;
+ }
+ return ret;
+}
+
+auto DeviceFactory::createFeedbacks()
+ -> std::vector<std::shared_ptr<IFeedbackDevice>> {
+ return {std::make_shared<Haptics>(services_->haptics())};
+}
+
+} // namespace input