From 1573a8c4cde1cd9528b422b2dcc598e37ffe94a7 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Thu, 2 May 2024 19:12:26 +1000 Subject: WIP merge cyclically dependent components into one big component --- src/tangara/input/device_factory.cpp | 58 ++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/tangara/input/device_factory.cpp (limited to 'src/tangara/input/device_factory.cpp') diff --git a/src/tangara/input/device_factory.cpp b/src/tangara/input/device_factory.cpp new file mode 100644 index 00000000..65f4d785 --- /dev/null +++ b/src/tangara/input/device_factory.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2023 jacqueline + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "device_factory.hpp" + +#include + +#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 services) + : services_(services) { + if (services->touchwheel()) { + wheel_ = + std::make_shared(services->nvs(), **services->touchwheel()); + } +} + +auto DeviceFactory::createInputs(drivers::NvsStorage::InputModes mode) + -> std::vector> { + std::vector> ret; + switch (mode) { + case drivers::NvsStorage::InputModes::kButtonsOnly: + ret.push_back(std::make_shared(services_->gpios())); + break; + case drivers::NvsStorage::InputModes::kDirectionalWheel: + ret.push_back(std::make_shared(services_->gpios())); + if (services_->touchwheel()) { + ret.push_back(std::make_shared(**services_->touchwheel())); + } + break; + case drivers::NvsStorage::InputModes::kRotatingWheel: + default: // Don't break input over a bad enum value. + ret.push_back(std::make_shared(services_->gpios())); + if (wheel_) { + ret.push_back(wheel_); + } + break; + } + return ret; +} + +auto DeviceFactory::createFeedbacks() + -> std::vector> { + return {std::make_shared(services_->haptics())}; +} + +} // namespace input -- cgit v1.2.3