summaryrefslogtreecommitdiff
path: root/src/ui/ui_fsm.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-11 15:16:35 +1000
committerjacqueline <me@jacqueline.id.au>2024-04-11 15:16:35 +1000
commit33919e9e3f419e13318fa6b8217d8c8dcd86c1eb (patch)
tree9e3a1209c8f17f9a6d57249fae7067cbb81e0227 /src/ui/ui_fsm.cpp
parented82063af5f83530afa5cfb5bf5bd516f3d05f2a (diff)
downloadtangara-fw-33919e9e3f419e13318fa6b8217d8c8dcd86c1eb.tar.gz
Migrate all existing control schemes to the cool new world
Diffstat (limited to 'src/ui/ui_fsm.cpp')
-rw-r--r--src/ui/ui_fsm.cpp88
1 files changed, 21 insertions, 67 deletions
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index a9c1d3a3..eaaef450 100644
--- a/src/ui/ui_fsm.cpp
+++ b/src/ui/ui_fsm.cpp
@@ -12,9 +12,14 @@
#include "bluetooth_types.hpp"
#include "db_events.hpp"
+#include "device_factory.hpp"
#include "display_init.hpp"
+#include "feedback_haptics.hpp"
#include "freertos/portmacro.h"
#include "freertos/projdefs.h"
+#include "input_device.hpp"
+#include "input_touch_wheel.hpp"
+#include "input_volume_buttons.hpp"
#include "lua.h"
#include "lua.hpp"
@@ -62,7 +67,9 @@ namespace ui {
std::unique_ptr<UiTask> UiState::sTask;
std::shared_ptr<system_fsm::ServiceLocator> UiState::sServices;
std::unique_ptr<drivers::Display> UiState::sDisplay;
+
std::shared_ptr<input::LvglInputDriver> UiState::sInput;
+std::unique_ptr<input::DeviceFactory> UiState::sDeviceFactory;
std::stack<std::shared_ptr<Screen>> UiState::sScreens;
std::shared_ptr<Screen> UiState::sCurrentScreen;
@@ -233,59 +240,6 @@ lua::Property UiState::sDisplayBrightness{
return true;
}};
-lua::Property UiState::sControlsScheme{0, [](const lua::LuaValue& val) {
- /*
- if (!std::holds_alternative<int>(val))
- { return false;
- }
- drivers::NvsStorage::InputModes mode;
- switch (std::get<int>(val)) {
- case 0:
- mode =
- drivers::NvsStorage::InputModes::kButtonsOnly;
- break;
- case 1:
- mode =
- drivers::NvsStorage::InputModes::kButtonsWithWheel;
- break;
- case 2:
- mode =
- drivers::NvsStorage::InputModes::kDirectionalWheel;
- break;
- case 3:
- mode =
- drivers::NvsStorage::InputModes::kRotatingWheel;
- break;
- default:
- return false;
- }
- sServices->nvs().PrimaryInput(mode);
- sInput->mode(mode);
- */
- return true;
- }};
-
-lua::Property UiState::sScrollSensitivity{0, [](const lua::LuaValue& val) {
- /*
- std::optional<int> sensitivity = 0;
- std::visit(
- [&](auto&& v) {
- using T =
- std::decay_t<decltype(v)>; if
- constexpr (std::is_same_v<T, int>) {
- sensitivity = v;
- }
- },
- val);
- if (!sensitivity) {
- return false;
- }
- sInput->scroll_sensitivity(*sensitivity);
- sServices->nvs().ScrollSensitivity(*sensitivity);
- */
- return true;
- }};
-
lua::Property UiState::sLockSwitch{false};
lua::Property UiState::sDatabaseUpdating{false};
@@ -374,13 +328,6 @@ void UiState::react(const system_fsm::SamdUsbStatusChanged& ev) {
drivers::Samd::UsbStatus::kAttachedBusy);
}
-void UiState::react(const internal::ControlSchemeChanged&) {
- if (!sInput) {
- return;
- }
- // sInput->mode(sServices->nvs().PrimaryInput());
-}
-
void UiState::react(const database::event::UpdateStarted&) {
sDatabaseUpdating.Update(true);
}
@@ -484,7 +431,10 @@ void Splash::react(const system_fsm::BootComplete& ev) {
sDisplayBrightness.Update(brightness);
sDisplay->SetBrightness(brightness);
- sInput = std::make_shared<input::LvglInputDriver>(sServices);
+ sDeviceFactory = std::make_unique<input::DeviceFactory>(sServices);
+ sInput = std::make_shared<input::LvglInputDriver>(sServices->nvs(),
+ *sDeviceFactory);
+
sTask->input(sInput);
}
@@ -542,12 +492,16 @@ void Lua::entry() {
{"brightness", &sDisplayBrightness},
});
- registry.AddPropertyModule("controls",
- {
- {"scheme", &sControlsScheme},
- {"scroll_sensitivity", &sScrollSensitivity},
- {"lock_switch", &sLockSwitch},
- });
+ registry.AddPropertyModule("controls", {
+ {"scheme", &sInput->mode()},
+ {"lock_switch", &sLockSwitch},
+ });
+
+ if (sDeviceFactory->touch_wheel()) {
+ registry.AddPropertyModule(
+ "controls", {{"scroll_sensitivity",
+ &sDeviceFactory->touch_wheel()->sensitivity()}});
+ }
registry.AddPropertyModule(
"backstack",