diff options
| author | jacqueline <me@jacqueline.id.au> | 2024-03-21 11:51:48 +1100 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2024-03-21 11:51:48 +1100 |
| commit | dadac304dd930ddf4c5aebcc069c5d9f881b2b60 (patch) | |
| tree | 70613be70cffae36b005d89c28b86e2bd3301f2f /src | |
| parent | 7305820aa9657e71153ada579ad67cf8bcbba6be (diff) | |
| download | tangara-fw-dadac304dd930ddf4c5aebcc069c5d9f881b2b60.tar.gz | |
Add very basic usb msc ui
Diffstat (limited to 'src')
| -rw-r--r-- | src/system_fsm/idle.cpp | 10 | ||||
| -rw-r--r-- | src/system_fsm/running.cpp | 6 | ||||
| -rw-r--r-- | src/ui/include/ui_fsm.hpp | 2 | ||||
| -rw-r--r-- | src/ui/ui_fsm.cpp | 15 |
4 files changed, 31 insertions, 2 deletions
diff --git a/src/system_fsm/idle.cpp b/src/system_fsm/idle.cpp index b6bb2572..980f0c94 100644 --- a/src/system_fsm/idle.cpp +++ b/src/system_fsm/idle.cpp @@ -13,6 +13,7 @@ #include "audio_fsm.hpp" #include "event_queue.hpp" +#include "samd.hpp" #include "storage.hpp" #include "system_events.hpp" #include "system_fsm.hpp" @@ -40,7 +41,7 @@ void Idle::entry() { events::Audio().Dispatch(OnIdle{}); events::Ui().Dispatch(OnIdle{}); - sIdleTimeout = xTimerCreate("idle_timeout", kTicksBeforeSleep, false, NULL, + sIdleTimeout = xTimerCreate("idle_timeout", kTicksBeforeSleep, true, NULL, timer_callback); xTimerStart(sIdleTimeout, portMAX_DELAY); } @@ -63,6 +64,13 @@ void Idle::react(const internal::IdleTimeout& ev) { transit<Running>(); return; } + auto s = static_cast<int>(sServices->samd().GetUsbStatus()); + ESP_LOGI(kTag, "usb status is %i", s); + if (sServices->samd().GetUsbStatus() != drivers::Samd::UsbStatus::kDetached) { + // Stay powered on if we're plugged in, in order to charge faster, sync + // files, flash updates, etc. + return; + } ESP_LOGI(kTag, "system shutting down"); // FIXME: It would be neater to just free a bunch of our pointers, deinit the diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp index d1d02fab..d80809e6 100644 --- a/src/system_fsm/running.cpp +++ b/src/system_fsm/running.cpp @@ -41,7 +41,11 @@ void Running::entry() { sUnmountTimer = xTimerCreate("unmount_timeout", kTicksBeforeUnmount, false, NULL, timer_callback); } - mountStorage(); + // Only mount our storage immediately if we know it's not currently in use + // by the SAMD. + if (!sServices->samd().UsbMassStorage()) { + mountStorage(); + } } void Running::exit() { diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 579cc2bb..f7fde1dd 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -132,6 +132,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/ui_fsm.cpp b/src/ui/ui_fsm.cpp index c11f66a7..a913a339 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -285,6 +285,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. @@ -553,6 +564,10 @@ void Lua::entry() { registry.AddPropertyModule("database", { {"updating", &sDatabaseUpdating}, }); + registry.AddPropertyModule("usb", + { + {"msc_enabled", &sUsbMassStorageEnabled}, + }); auto bt = sServices->bluetooth(); sBluetoothEnabled.Update(bt.IsEnabled()); |
