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/lua/lua_controls.cpp | 50 +++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'src/tangara/lua/lua_controls.cpp') diff --git a/src/tangara/lua/lua_controls.cpp b/src/tangara/lua/lua_controls.cpp index bc2588ac..69053f43 100644 --- a/src/tangara/lua/lua_controls.cpp +++ b/src/tangara/lua/lua_controls.cpp @@ -23,37 +23,64 @@ namespace lua { [[maybe_unused]] static constexpr char kTag[] = "lua_controls"; -static auto controls_schemes(lua_State* L) -> int { +static auto wheel_schemes(lua_State* L) -> int { lua_newtable(L); - lua_pushliteral(L, "Buttons Only"); + lua_pushliteral(L, "Disabled"); lua_rawseti(L, -2, - static_cast(drivers::NvsStorage::InputModes::kButtonsOnly)); + static_cast(drivers::NvsStorage::WheelInputModes::kDisabled)); lua_pushliteral(L, "D-Pad"); + lua_rawseti(L, -2, + static_cast(drivers::NvsStorage::WheelInputModes::kDirectionalWheel)); + + lua_pushliteral(L, "Touchwheel"); + lua_rawseti( + L, -2, static_cast(drivers::NvsStorage::WheelInputModes::kRotatingWheel)); + + return 1; +} + +static auto button_schemes(lua_State* L) -> int { + lua_newtable(L); + + lua_pushliteral(L, "Disabled"); lua_rawseti( L, -2, - static_cast(drivers::NvsStorage::InputModes::kDirectionalWheel)); + static_cast(drivers::NvsStorage::ButtonInputModes::kDisabled)); - lua_pushliteral(L, "Touchwheel"); + lua_pushliteral(L, "Volume Only"); + lua_rawseti( + L, -2, + static_cast(drivers::NvsStorage::ButtonInputModes::kVolumeOnly)); + lua_pushliteral(L, "Media Controls"); lua_rawseti( - L, -2, static_cast(drivers::NvsStorage::InputModes::kRotatingWheel)); + L, -2, + static_cast(drivers::NvsStorage::ButtonInputModes::kMediaControls)); + lua_pushliteral(L, "Navigation"); + lua_rawseti( + L, -2, + static_cast(drivers::NvsStorage::ButtonInputModes::kNavigation)); return 1; } -static auto locked_controls_schemes(lua_State* L) -> int { +static auto locked_button_schemes(lua_State* L) -> int { lua_newtable(L); lua_pushliteral(L, "Disabled"); lua_rawseti( L, -2, - static_cast(drivers::NvsStorage::LockedInputModes::kDisabled)); + static_cast(drivers::NvsStorage::ButtonInputModes::kDisabled)); lua_pushliteral(L, "Volume Only"); lua_rawseti( L, -2, - static_cast(drivers::NvsStorage::LockedInputModes::kVolumeOnly)); + static_cast(drivers::NvsStorage::ButtonInputModes::kVolumeOnly)); + lua_pushliteral(L, "Media Controls"); + lua_rawseti( + L, -2, + static_cast(drivers::NvsStorage::ButtonInputModes::kMediaControls)); return 1; } @@ -77,8 +104,9 @@ static auto haptics_modes(lua_State* L) -> int { return 1; } -static const struct luaL_Reg kControlsFuncs[] = {{"schemes", controls_schemes}, - {"locked_schemes", locked_controls_schemes}, +static const struct luaL_Reg kControlsFuncs[] = {{"wheel_schemes", wheel_schemes}, + {"button_schemes", button_schemes}, + {"locked_schemes", locked_button_schemes}, {"haptics_modes", haptics_modes}, {NULL, NULL}}; -- cgit v1.2.3