diff options
| author | ailurux <ailuruxx@gmail.com> | 2024-03-28 16:17:39 +1100 |
|---|---|---|
| committer | ailurux <ailuruxx@gmail.com> | 2024-03-28 16:17:39 +1100 |
| commit | c8e67cbd80b53a4e889ce0485546042d5490918c (patch) | |
| tree | f06314fef2bb9afaf04b924355b34f5277d69241 /src/ui | |
| parent | f1c8866b815a92aeda3133fd27051ce7c873cc57 (diff) | |
| parent | 35a822fe602cdc9e3a3482df3913ea33af6fc8c2 (diff) | |
| download | tangara-fw-c8e67cbd80b53a4e889ce0485546042d5490918c.tar.gz | |
Merge branch 'main' into themes
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/include/screen.hpp | 2 | ||||
| -rw-r--r-- | src/ui/include/screen_lua.hpp | 2 | ||||
| -rw-r--r-- | src/ui/include/screen_splash.hpp | 2 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 4 | ||||
| -rw-r--r-- | src/ui/screen_lua.cpp | 19 | ||||
| -rw-r--r-- | src/ui/ui_fsm.cpp | 49 |
6 files changed, 58 insertions, 20 deletions
diff --git a/src/ui/include/screen.hpp b/src/ui/include/screen.hpp index 4241c712..40284fda 100644 --- a/src/ui/include/screen.hpp +++ b/src/ui/include/screen.hpp @@ -43,6 +43,8 @@ class Screen { return group_; } + virtual auto canPop() -> bool = 0; + protected: lv_obj_t* const root_; lv_obj_t* content_; diff --git a/src/ui/include/screen_lua.hpp b/src/ui/include/screen_lua.hpp index 0ed3a508..41d97a1e 100644 --- a/src/ui/include/screen_lua.hpp +++ b/src/ui/include/screen_lua.hpp @@ -21,6 +21,8 @@ class Lua : public Screen { auto onShown() -> void override; auto onHidden() -> void override; + auto canPop() -> bool override; + auto SetObjRef(lua_State*) -> void; private: diff --git a/src/ui/include/screen_splash.hpp b/src/ui/include/screen_splash.hpp index 1ee7dd89..6e746345 100644 --- a/src/ui/include/screen_splash.hpp +++ b/src/ui/include/screen_splash.hpp @@ -20,6 +20,8 @@ class Splash : public Screen { Splash(); ~Splash(); + auto canPop() -> bool override { return false; } + private: lv_obj_t* container_; lv_obj_t* label_; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 579cc2bb..5e1cc487 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -57,8 +57,6 @@ class UiState : public tinyfsm::Fsm<UiState> { virtual void react(const system_fsm::StorageMounted&) {} void react(const system_fsm::BatteryStateChanged&); - void react(const audio::PlaybackStarted&); - void react(const audio::PlaybackStopped&); void react(const audio::PlaybackUpdate&); void react(const audio::QueueUpdate&); @@ -132,6 +130,8 @@ class UiState : public tinyfsm::Fsm<UiState> { static lua::Property sLockSwitch; static lua::Property sDatabaseUpdating; + + static lua::Property sUsbMassStorageEnabled; }; namespace states { diff --git a/src/ui/screen_lua.cpp b/src/ui/screen_lua.cpp index 1ad4a8e8..d43c7ee7 100644 --- a/src/ui/screen_lua.cpp +++ b/src/ui/screen_lua.cpp @@ -61,6 +61,25 @@ auto Lua::onHidden() -> void { lua_pop(s_, 1); } +auto Lua::canPop() -> bool { + if (!s_ || !obj_ref_) { + return true; + } + lua_rawgeti(s_, LUA_REGISTRYINDEX, *obj_ref_); + lua_pushliteral(s_, "canPop"); + + if (lua_gettable(s_, -2) == LUA_TFUNCTION) { + // If we got a callback instead of a value, then invoke it to turn it into + // value. + lua_pushvalue(s_, -2); + lua::CallProtected(s_, 1, 1); + } + bool ret = lua_toboolean(s_, -1); + + lua_pop(s_, 2); + return ret; +} + auto Lua::SetObjRef(lua_State* s) -> void { assert(s_ == nullptr); s_ = s; diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index 5582dabe..835da19e 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -114,14 +114,11 @@ lua::Property UiState::sBluetoothDevices{ lua::Property UiState::sPlaybackPlaying{ false, [](const lua::LuaValue& val) { - bool current_val = std::get<bool>(sPlaybackPlaying.Get()); if (!std::holds_alternative<bool>(val)) { return false; } bool new_val = std::get<bool>(val); - if (current_val != new_val) { - events::Audio().Dispatch(audio::TogglePlayPause{}); - } + events::Audio().Dispatch(audio::TogglePlayPause{.set_to = new_val}); return true; }}; @@ -135,12 +132,13 @@ lua::Property UiState::sPlaybackPosition{ int new_val = std::get<int>(val); if (current_val != new_val) { auto track = sPlaybackTrack.Get(); - if (!std::holds_alternative<audio::Track>(track)) { + if (!std::holds_alternative<audio::TrackInfo>(track)) { return false; } - events::Audio().Dispatch(audio::SeekFile{ - .offset = (uint32_t)new_val, - .filename = std::get<audio::Track>(track).filepath}); + events::Audio().Dispatch(audio::SetTrack{ + .new_track = std::get<audio::TrackInfo>(track).uri, + .seek_to_second = (uint32_t)new_val, + }); } return true; }}; @@ -285,6 +283,17 @@ lua::Property UiState::sLockSwitch{false}; lua::Property UiState::sDatabaseUpdating{false}; +lua::Property UiState::sUsbMassStorageEnabled{ + false, [](const lua::LuaValue& val) { + if (!std::holds_alternative<bool>(val)) { + return false; + } + bool enable = std::get<bool>(val); + // FIXME: Check for system busy. + events::System().Dispatch(system_fsm::SamdUsbMscChanged{.en = enable}); + return true; + }}; + auto UiState::InitBootSplash(drivers::IGpios& gpios, drivers::NvsStorage& nvs) -> bool { // Init LVGL first, since the display driver registers itself with LVGL. @@ -382,17 +391,14 @@ void UiState::react(const audio::QueueUpdate&) { sQueueReplay.Update(queue.replay()); } -void UiState::react(const audio::PlaybackStarted& ev) { - sPlaybackPlaying.Update(true); -} - void UiState::react(const audio::PlaybackUpdate& ev) { - sPlaybackTrack.Update(*ev.track); - sPlaybackPosition.Update(static_cast<int>(ev.seconds_elapsed)); -} - -void UiState::react(const audio::PlaybackStopped&) { - sPlaybackPlaying.Update(false); + if (ev.current_track) { + sPlaybackTrack.Update(*ev.current_track); + } else { + sPlaybackTrack.Update(std::monostate{}); + } + sPlaybackPlaying.Update(!ev.paused); + sPlaybackPosition.Update(static_cast<int>(ev.track_position.value_or(0))); } void UiState::react(const audio::VolumeChanged& ev) { @@ -554,6 +560,10 @@ void Lua::entry() { registry.AddPropertyModule("database", { {"updating", &sDatabaseUpdating}, }); + registry.AddPropertyModule("usb", + { + {"msc_enabled", &sUsbMassStorageEnabled}, + }); auto bt = sServices->bluetooth(); sBluetoothEnabled.Update(bt.IsEnabled()); @@ -611,6 +621,9 @@ auto Lua::QueuePrevious(lua_State*) -> int { } auto Lua::PopLuaScreen(lua_State* s) -> int { + if (!sCurrentScreen->canPop()) { + return 0; + } PopScreen(); luavgl_set_root(s, sCurrentScreen->content()); lv_group_set_default(sCurrentScreen->group()); |
