summaryrefslogtreecommitdiff
path: root/src/system_fsm
diff options
context:
space:
mode:
authorailurux <ailuruxx@gmail.com>2024-03-28 16:17:39 +1100
committerailurux <ailuruxx@gmail.com>2024-03-28 16:17:39 +1100
commitc8e67cbd80b53a4e889ce0485546042d5490918c (patch)
treef06314fef2bb9afaf04b924355b34f5277d69241 /src/system_fsm
parentf1c8866b815a92aeda3133fd27051ce7c873cc57 (diff)
parent35a822fe602cdc9e3a3482df3913ea33af6fc8c2 (diff)
downloadtangara-fw-c8e67cbd80b53a4e889ce0485546042d5490918c.tar.gz
Merge branch 'main' into themes
Diffstat (limited to 'src/system_fsm')
-rw-r--r--src/system_fsm/booting.cpp2
-rw-r--r--src/system_fsm/idle.cpp9
-rw-r--r--src/system_fsm/include/system_fsm.hpp4
-rw-r--r--src/system_fsm/running.cpp8
4 files changed, 17 insertions, 6 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp
index eb931192..bd394428 100644
--- a/src/system_fsm/booting.cpp
+++ b/src/system_fsm/booting.cpp
@@ -63,7 +63,7 @@ auto Booting::entry() -> void {
std::unique_ptr<drivers::NvsStorage>(drivers::NvsStorage::OpenSync()));
// HACK: fix up the switch polarity on newer dev units
- sServices->nvs().LockPolarity(false);
+ // sServices->nvs().LockPolarity(false);
// I2C and SPI are both always needed. We can't even power down or show an
// error without these.
diff --git a/src/system_fsm/idle.cpp b/src/system_fsm/idle.cpp
index b6bb2572..e28864b3 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,12 @@ void Idle::react(const internal::IdleTimeout& ev) {
transit<Running>();
return;
}
+ if (sServices->samd().GetChargeStatus() !=
+ drivers::Samd::ChargeStatus::kDischarging) {
+ // 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/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp
index cc60e43b..a129829e 100644
--- a/src/system_fsm/include/system_fsm.hpp
+++ b/src/system_fsm/include/system_fsm.hpp
@@ -63,7 +63,7 @@ class SystemState : public tinyfsm::Fsm<SystemState> {
virtual void react(const SdDetectChanged&) {}
virtual void react(const SamdUsbMscChanged&) {}
virtual void react(const database::event::UpdateFinished&) {}
- virtual void react(const audio::PlaybackStopped&) {}
+ virtual void react(const audio::PlaybackUpdate&) {}
virtual void react(const internal::IdleTimeout&) {}
virtual void react(const internal::UnmountTimeout&) {}
@@ -101,7 +101,7 @@ class Running : public SystemState {
void react(const KeyLockChanged&) override;
void react(const SdDetectChanged&) override;
- void react(const audio::PlaybackStopped&) override;
+ void react(const audio::PlaybackUpdate&) override;
void react(const database::event::UpdateFinished&) override;
void react(const SamdUsbMscChanged&) override;
void react(const internal::UnmountTimeout&) override;
diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp
index d1d02fab..a6ab5d47 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() {
@@ -52,7 +56,7 @@ void Running::react(const KeyLockChanged& ev) {
checkIdle();
}
-void Running::react(const audio::PlaybackStopped& ev) {
+void Running::react(const audio::PlaybackUpdate& ev) {
checkIdle();
}