summaryrefslogtreecommitdiff
path: root/src/ui/ui_fsm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/ui_fsm.cpp')
-rw-r--r--src/ui/ui_fsm.cpp100
1 files changed, 23 insertions, 77 deletions
diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp
index 739c4598..1c296ac7 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"
@@ -30,19 +35,18 @@
#include "lauxlib.h"
#include "lua_thread.hpp"
#include "luavgl.h"
+#include "lvgl_input_driver.hpp"
#include "memory_resource.hpp"
#include "misc/lv_gc.h"
#include "audio_events.hpp"
#include "display.hpp"
-#include "encoder_input.hpp"
#include "event_queue.hpp"
#include "gpios.hpp"
#include "lua_registry.hpp"
#include "lvgl_task.hpp"
#include "nvs.hpp"
#include "property.hpp"
-#include "relative_wheel.hpp"
#include "samd.hpp"
#include "screen.hpp"
#include "screen_lua.hpp"
@@ -63,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<EncoderInput> UiState::sInput;
+
+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;
@@ -234,52 +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};
@@ -368,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);
}
@@ -478,22 +431,11 @@ void Splash::react(const system_fsm::BootComplete& ev) {
sDisplayBrightness.Update(brightness);
sDisplay->SetBrightness(brightness);
- auto touchwheel = sServices->touchwheel();
- if (touchwheel) {
- sInput = std::make_shared<EncoderInput>(sServices->gpios(), **touchwheel);
+ sDeviceFactory = std::make_unique<input::DeviceFactory>(sServices);
+ sInput = std::make_shared<input::LvglInputDriver>(sServices->nvs(),
+ *sDeviceFactory);
- auto mode = sServices->nvs().PrimaryInput();
- sInput->mode(mode);
- sControlsScheme.Update(static_cast<int>(mode));
-
- auto sensitivity = sServices->nvs().ScrollSensitivity();
- sInput->scroll_sensitivity(sensitivity);
- sScrollSensitivity.Update(static_cast<int>(sensitivity));
-
- sTask->input(sInput);
- } else {
- ESP_LOGE(kTag, "no input devices initialised!");
- }
+ sTask->input(sInput);
}
void Splash::react(const system_fsm::StorageMounted&) {
@@ -550,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",