From c9ce88a457c9ed7124709a667d202a666f72bffa Mon Sep 17 00:00:00 2001 From: ailurux Date: Wed, 19 Mar 2025 04:25:20 +0000 Subject: ailurux/button-media-controls (#264) Splits the control scheme into separate schemes for the side buttons and touchwheel, allowing them to be configured independently of each other. At least one input must be used for navigation, and there are guards to prevent locking oneself out of any input. If the input scheme is invalid, a pop up will show alerting the user. Different behaviours can be bound to the side buttons for when the device is locked or unlocked. This PR also adds a mode for these buttons that controls media playback (prev/next on up/down, pressing both buttons toggles play/pause). There are some changes to the way inputs handle locking. Rather than the input devices tracking the current locked mode, different input devices are created on lock depending on the mode that is configured. Reviewed-on: https://codeberg.org/cool-tech-zone/tangara-fw/pulls/264 Co-authored-by: ailurux Co-committed-by: ailurux --- src/tangara/input/device_factory.cpp | 60 +++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 8 deletions(-) (limited to 'src/tangara/input/device_factory.cpp') diff --git a/src/tangara/input/device_factory.cpp b/src/tangara/input/device_factory.cpp index fe2e2485..ff597556 100644 --- a/src/tangara/input/device_factory.cpp +++ b/src/tangara/input/device_factory.cpp @@ -16,6 +16,7 @@ #include "input/input_touch_dpad.hpp" #include "input/input_touch_wheel.hpp" #include "input/input_volume_buttons.hpp" +#include "input/input_media_buttons.hpp" namespace input { @@ -26,30 +27,73 @@ DeviceFactory::DeviceFactory( wheel_ = std::make_shared(services->nvs(), **services->touchwheel()); } + reset_ = std::make_shared(services_->gpios()); } -auto DeviceFactory::createInputs(drivers::NvsStorage::InputModes mode) +auto DeviceFactory::createLockedInputs() -> std::vector> { + auto locked_mode = services_->nvs().LockedInput(); std::vector> ret; - switch (mode) { - case drivers::NvsStorage::InputModes::kButtonsOnly: - ret.push_back(std::make_shared(services_->gpios())); + switch (locked_mode) { + case drivers::NvsStorage::ButtonInputModes::kDisabled: + break; + case drivers::NvsStorage::ButtonInputModes::kMediaControls: + ret.push_back(std::make_shared(services_->gpios(), services_->track_queue())); + break; + case drivers::NvsStorage::ButtonInputModes::kNavigation: + // I don't think we want navigation to work when locked? + // ret.push_back(std::make_shared(services_->gpios())); break; - case drivers::NvsStorage::InputModes::kDirectionalWheel: + case drivers::NvsStorage::ButtonInputModes::kVolumeOnly: ret.push_back(std::make_shared(services_->gpios())); + break; + } + ret.push_back(reset_); + return ret; +} + +auto DeviceFactory::createInputs() + -> std::vector> { + std::vector> ret; + auto wheel_mode = services_->nvs().WheelInput(); + auto buttons_mode = services_->nvs().ButtonInput(); + // Make sure we always have a navigational input + if (wheel_mode == drivers::NvsStorage::WheelInputModes::kDisabled) { + if (buttons_mode != drivers::NvsStorage::ButtonInputModes::kNavigation) { + wheel_mode = drivers::NvsStorage::WheelInputModes::kRotatingWheel; + services_->nvs().WheelInput(wheel_mode); + } + } + switch (wheel_mode) { + case drivers::NvsStorage::WheelInputModes::kDisabled: + break; + case drivers::NvsStorage::WheelInputModes::kDirectionalWheel: if (services_->touchwheel()) { ret.push_back(std::make_shared(**services_->touchwheel())); } break; - case drivers::NvsStorage::InputModes::kRotatingWheel: + case drivers::NvsStorage::WheelInputModes::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; } - ret.push_back(std::make_shared(services_->gpios())); + switch (buttons_mode) { + case drivers::NvsStorage::ButtonInputModes::kDisabled: + break; + case drivers::NvsStorage::ButtonInputModes::kMediaControls: + ret.push_back(std::make_shared(services_->gpios(), services_->track_queue())); + break; + case drivers::NvsStorage::ButtonInputModes::kNavigation: + ret.push_back(std::make_shared(services_->gpios())); + break; + case drivers::NvsStorage::ButtonInputModes::kVolumeOnly: + default: + ret.push_back(std::make_shared(services_->gpios())); + break; + } + ret.push_back(reset_); return ret; } -- cgit v1.2.3