diff options
| author | ailurux <ailurux@noreply.codeberg.org> | 2025-03-19 04:25:20 +0000 |
|---|---|---|
| committer | cooljqln <cooljqln@noreply.codeberg.org> | 2025-03-19 04:25:20 +0000 |
| commit | c9ce88a457c9ed7124709a667d202a666f72bffa (patch) | |
| tree | 681cba582d4e18c743029cb72ea542eee23e9907 /src/tangara/input/input_media_buttons.cpp | |
| parent | 95dd0ddec52a25a57e367e5568ac97f8e3f0d312 (diff) | |
| download | tangara-fw-c9ce88a457c9ed7124709a667d202a666f72bffa.tar.gz | |
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 <ailurux@noreply.codeberg.org>
Co-committed-by: ailurux <ailurux@noreply.codeberg.org>
Diffstat (limited to 'src/tangara/input/input_media_buttons.cpp')
| -rw-r--r-- | src/tangara/input/input_media_buttons.cpp | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/tangara/input/input_media_buttons.cpp b/src/tangara/input/input_media_buttons.cpp new file mode 100644 index 00000000..94d7dd12 --- /dev/null +++ b/src/tangara/input/input_media_buttons.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2025 ailurux <ailuruxx@gmail.com> + * + * SPDX-License-Identifier: GPL-3.0-only + */ + +#include "input/input_media_buttons.hpp" +#include "drivers/gpios.hpp" +#include "events/event_queue.hpp" +#include "input/input_hook_actions.hpp" + +namespace input { + +MediaButtons::MediaButtons(drivers::IGpios& gpios, audio::TrackQueue& queue) + : gpios_(gpios), + up_("upper", actions::nextTrack(queue), {}, {}, actions::volumeUp()), + down_("lower", actions::prevTrack(queue), {}, {}, actions::volumeDown()), + locked_(), + both_buttons_pressed_(false) {} + +auto MediaButtons::read(lv_indev_data_t* data, std::vector<InputEvent>& events) -> void { + bool up = !gpios_.Get(drivers::IGpios::Pin::kKeyUp); + bool down = !gpios_.Get(drivers::IGpios::Pin::kKeyDown); + + if ((up && down)) { + up_.cancel(); + down_.cancel(); + both_buttons_pressed_ = true; + } else if (!up && !down) { + if (both_buttons_pressed_) { + std::invoke(actions::togglePlayPause().fn, data); + both_buttons_pressed_ = false; + return; + } + } + + if (both_buttons_pressed_) { + return; + } + + up_.update(up, data); + down_.update(down, data); +} + +auto MediaButtons::name() -> std::string { + return "buttons"; +} + +auto MediaButtons::triggers() + -> std::vector<std::reference_wrapper<TriggerHooks>> { + return {up_, down_}; +} + +auto MediaButtons::onLock() -> void { + locked_ = true; +} + +auto MediaButtons::onUnlock() -> void { + locked_ = false; +} + +} // namespace input |
