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>custom
parent
95dd0ddec5
commit
c9ce88a457
@ -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
|
@ -0,0 +1,43 @@ |
||||
/*
|
||||
* Copyright 2025 ailurux <ailuruxx@gmail.com> |
||||
* |
||||
* SPDX-License-Identifier: GPL-3.0-only |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <cstdint> |
||||
|
||||
#include "indev/lv_indev.h" |
||||
|
||||
#include "drivers/gpios.hpp" |
||||
#include "drivers/haptics.hpp" |
||||
#include "drivers/touchwheel.hpp" |
||||
#include "input/input_device.hpp" |
||||
#include "input/input_hook.hpp" |
||||
|
||||
namespace input { |
||||
|
||||
class MediaButtons : public IInputDevice { |
||||
public: |
||||
MediaButtons(drivers::IGpios&, audio::TrackQueue& queue); |
||||
|
||||
auto read(lv_indev_data_t* data, std::vector<InputEvent>& events) -> void override; |
||||
|
||||
auto name() -> std::string override; |
||||
auto triggers() -> std::vector<std::reference_wrapper<TriggerHooks>> override; |
||||
|
||||
auto onLock() -> void override; |
||||
auto onUnlock() -> void override; |
||||
|
||||
private: |
||||
drivers::IGpios& gpios_; |
||||
|
||||
TriggerHooks up_; |
||||
TriggerHooks down_; |
||||
|
||||
bool locked_; |
||||
bool both_buttons_pressed_; |
||||
}; |
||||
|
||||
} // namespace input
|
Loading…
Reference in new issue