diff options
| author | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-11 07:02:53 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2024-04-11 07:02:53 +0000 |
| commit | dd1ea595a7753706d4fa5f19b66f3dc1cbd56a02 (patch) | |
| tree | 60bfa4569af0f9506ccffe85f19e89bbe2a83332 /src/input/device_factory.cpp | |
| parent | f580928cbab797e4e8a3eae5ae1c0b18b8066066 (diff) | |
| parent | 33919e9e3f419e13318fa6b8217d8c8dcd86c1eb (diff) | |
| download | tangara-fw-dd1ea595a7753706d4fa5f19b66f3dc1cbd56a02.tar.gz | |
Merge pull request 'jqln/input-devices' (#62) from jqln/input-devices into main
Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/62
Reviewed-by: ailurux <ailurux@noreply.codeberg.org>
Diffstat (limited to 'src/input/device_factory.cpp')
| -rw-r--r-- | src/input/device_factory.cpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/input/device_factory.cpp b/src/input/device_factory.cpp new file mode 100644 index 00000000..65f4d785 --- /dev/null +++ b/src/input/device_factory.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2023 jacqueline <me@jacqueline.id.au> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "device_factory.hpp" + +#include <memory> + +#include "feedback_haptics.hpp" +#include "input_device.hpp" +#include "input_nav_buttons.hpp" +#include "input_touch_dpad.hpp" +#include "input_touch_wheel.hpp" +#include "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 |
