summaryrefslogtreecommitdiff
path: root/src/system_fsm
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-07-25 17:42:36 +1000
committerjacqueline <me@jacqueline.id.au>2023-07-25 17:43:12 +1000
commit80d7df910987db5201402fe987124f29f09344f3 (patch)
tree7e8c1e04ab40026087343efee95a771c7839b32f /src/system_fsm
parent7b72e5479ee6d11f76c49f7463ba0e7f4e5165c5 (diff)
downloadtangara-fw-80d7df910987db5201402fe987124f29f09344f3.tar.gz
fuck off
Diffstat (limited to 'src/system_fsm')
-rw-r--r--src/system_fsm/booting.cpp7
-rw-r--r--src/system_fsm/include/system_fsm.hpp3
-rw-r--r--src/system_fsm/running.cpp6
-rw-r--r--src/system_fsm/system_fsm.cpp7
4 files changed, 19 insertions, 4 deletions
diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp
index 48b027d2..076f4570 100644
--- a/src/system_fsm/booting.cpp
+++ b/src/system_fsm/booting.cpp
@@ -17,6 +17,7 @@
#include "spi.hpp"
#include "system_events.hpp"
#include "system_fsm.hpp"
+#include "tag_parser.hpp"
#include "track_queue.hpp"
#include "ui_fsm.hpp"
@@ -50,17 +51,20 @@ auto Booting::entry() -> void {
// Start bringing up LVGL now, since we have all of its prerequisites.
sTrackQueue.reset(new audio::TrackQueue());
+ /*
ESP_LOGI(kTag, "starting ui");
if (!ui::UiState::Init(sGpios.get(), sTrackQueue.get())) {
events::Dispatch<FatalError, SystemState, ui::UiState, audio::AudioState>(
FatalError());
return;
}
+ */
// Install everything else that is certain to be needed.
ESP_LOGI(kTag, "installing remaining drivers");
sSamd.reset(drivers::Samd::Create());
sBattery.reset(drivers::Battery::Create());
+ sTagParser.reset(new database::TagParserImpl());
if (!sSamd || !sBattery) {
events::Dispatch<FatalError, SystemState, ui::UiState, audio::AudioState>(
@@ -72,7 +76,8 @@ auto Booting::entry() -> void {
// state machines and inform them that the system is ready.
ESP_LOGI(kTag, "starting audio");
- if (!audio::AudioState::Init(sGpios.get(), sDatabase, sTrackQueue.get())) {
+ if (!audio::AudioState::Init(sGpios.get(), sDatabase, sTagParser,
+ sTrackQueue.get())) {
events::Dispatch<FatalError, SystemState, ui::UiState, audio::AudioState>(
FatalError());
return;
diff --git a/src/system_fsm/include/system_fsm.hpp b/src/system_fsm/include/system_fsm.hpp
index 3c3169d1..03b25156 100644
--- a/src/system_fsm/include/system_fsm.hpp
+++ b/src/system_fsm/include/system_fsm.hpp
@@ -16,6 +16,7 @@
#include "relative_wheel.hpp"
#include "samd.hpp"
#include "storage.hpp"
+#include "tag_parser.hpp"
#include "tinyfsm.hpp"
#include "touchwheel.hpp"
@@ -57,7 +58,9 @@ class SystemState : public tinyfsm::Fsm<SystemState> {
static std::shared_ptr<drivers::Battery> sBattery;
static std::shared_ptr<drivers::SdStorage> sStorage;
static std::shared_ptr<drivers::Display> sDisplay;
+
static std::shared_ptr<database::Database> sDatabase;
+ static std::shared_ptr<database::TagParserImpl> sTagParser;
static std::shared_ptr<audio::TrackQueue> sTrackQueue;
diff --git a/src/system_fsm/running.cpp b/src/system_fsm/running.cpp
index 1822a071..a46cb8dc 100644
--- a/src/system_fsm/running.cpp
+++ b/src/system_fsm/running.cpp
@@ -5,6 +5,7 @@
*/
#include "app_console.hpp"
+#include "file_gatherer.hpp"
#include "freertos/projdefs.h"
#include "result.hpp"
@@ -20,6 +21,8 @@ namespace states {
static const char kTag[] = "RUN";
+static database::IFileGatherer* sFileGatherer;
+
/*
* Ensure the storage and database are both available. If either of these fails
* to open, then we assume it's an issue with the underlying SD card.
@@ -38,7 +41,8 @@ void Running::entry() {
vTaskDelay(pdMS_TO_TICKS(250));
ESP_LOGI(kTag, "opening database");
- auto database_res = database::Database::Open();
+ sFileGatherer = new database::FileGathererImpl();
+ auto database_res = database::Database::Open(sFileGatherer, sTagParser.get());
if (database_res.has_error()) {
ESP_LOGW(kTag, "failed to open!");
events::Dispatch<StorageError, SystemState, audio::AudioState, ui::UiState>(
diff --git a/src/system_fsm/system_fsm.cpp b/src/system_fsm/system_fsm.cpp
index 769d5e4a..c029c6bf 100644
--- a/src/system_fsm/system_fsm.cpp
+++ b/src/system_fsm/system_fsm.cpp
@@ -9,6 +9,7 @@
#include "event_queue.hpp"
#include "relative_wheel.hpp"
#include "system_events.hpp"
+#include "tag_parser.hpp"
#include "track_queue.hpp"
namespace system_fsm {
@@ -21,7 +22,9 @@ std::shared_ptr<drivers::RelativeWheel> SystemState::sRelativeTouch;
std::shared_ptr<drivers::Battery> SystemState::sBattery;
std::shared_ptr<drivers::SdStorage> SystemState::sStorage;
std::shared_ptr<drivers::Display> SystemState::sDisplay;
+
std::shared_ptr<database::Database> SystemState::sDatabase;
+std::shared_ptr<database::TagParserImpl> SystemState::sTagParser;
std::shared_ptr<audio::TrackQueue> SystemState::sTrackQueue;
@@ -37,14 +40,14 @@ void SystemState::react(const internal::GpioInterrupt& ev) {
bool prev_key_up = sGpios->Get(drivers::Gpios::Pin::kKeyUp);
bool prev_key_down = sGpios->Get(drivers::Gpios::Pin::kKeyDown);
bool prev_key_lock = sGpios->Get(drivers::Gpios::Pin::kKeyLock);
- bool prev_has_headphones = sGpios->Get(drivers::Gpios::Pin::kPhoneDetect);
+ bool prev_has_headphones = !sGpios->Get(drivers::Gpios::Pin::kPhoneDetect);
sGpios->Read();
bool key_up = sGpios->Get(drivers::Gpios::Pin::kKeyUp);
bool key_down = sGpios->Get(drivers::Gpios::Pin::kKeyDown);
bool key_lock = sGpios->Get(drivers::Gpios::Pin::kKeyLock);
- bool has_headphones = sGpios->Get(drivers::Gpios::Pin::kPhoneDetect);
+ bool has_headphones = !sGpios->Get(drivers::Gpios::Pin::kPhoneDetect);
if (key_up != prev_key_up) {
events::Dispatch<KeyUpChanged, audio::AudioState, ui::UiState>(