Make the onboarding flow basically work. Much still to do!
This commit is contained in:
@@ -51,7 +51,7 @@ class Display {
|
|||||||
private:
|
private:
|
||||||
IGpios& gpio_;
|
IGpios& gpio_;
|
||||||
spi_device_handle_t handle_;
|
spi_device_handle_t handle_;
|
||||||
spi_transaction_t *transaction_;
|
spi_transaction_t* transaction_;
|
||||||
|
|
||||||
bool display_on_;
|
bool display_on_;
|
||||||
uint_fast8_t brightness_;
|
uint_fast8_t brightness_;
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ namespace drivers {
|
|||||||
|
|
||||||
extern const char* kStoragePath;
|
extern const char* kStoragePath;
|
||||||
|
|
||||||
|
enum class SdState {
|
||||||
|
kNotPresent,
|
||||||
|
kNotFormatted,
|
||||||
|
kNotMounted,
|
||||||
|
kMounted,
|
||||||
|
};
|
||||||
|
|
||||||
class SdStorage {
|
class SdStorage {
|
||||||
public:
|
public:
|
||||||
enum Error {
|
enum Error {
|
||||||
|
|||||||
+1
-1
@@ -190,7 +190,7 @@ auto NvsStorage::AmpCurrentVolume(uint16_t val) -> std::future<bool> {
|
|||||||
|
|
||||||
auto NvsStorage::HasShownOnboarding() -> std::future<bool> {
|
auto NvsStorage::HasShownOnboarding() -> std::future<bool> {
|
||||||
return writer_->Dispatch<bool>([&]() -> bool {
|
return writer_->Dispatch<bool>([&]() -> bool {
|
||||||
uint8_t out = true;
|
uint8_t out = false;
|
||||||
nvs_get_u8(handle_, kKeyOnboarded, &out);
|
nvs_get_u8(handle_, kKeyOnboarded, &out);
|
||||||
return out;
|
return out;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "gpios.hpp"
|
#include "gpios.hpp"
|
||||||
#include "nvs.hpp"
|
#include "nvs.hpp"
|
||||||
#include "samd.hpp"
|
#include "samd.hpp"
|
||||||
|
#include "storage.hpp"
|
||||||
#include "tag_parser.hpp"
|
#include "tag_parser.hpp"
|
||||||
#include "touchwheel.hpp"
|
#include "touchwheel.hpp"
|
||||||
#include "track_queue.hpp"
|
#include "track_queue.hpp"
|
||||||
@@ -22,7 +23,7 @@ namespace system_fsm {
|
|||||||
|
|
||||||
class ServiceLocator {
|
class ServiceLocator {
|
||||||
public:
|
public:
|
||||||
static auto instance() -> ServiceLocator&;
|
ServiceLocator();
|
||||||
|
|
||||||
auto gpios() -> drivers::Gpios& {
|
auto gpios() -> drivers::Gpios& {
|
||||||
assert(gpios_ != nullptr);
|
assert(gpios_ != nullptr);
|
||||||
@@ -45,6 +46,10 @@ class ServiceLocator {
|
|||||||
|
|
||||||
auto nvs(std::unique_ptr<drivers::NvsStorage> i) { nvs_ = std::move(i); }
|
auto nvs(std::unique_ptr<drivers::NvsStorage> i) { nvs_ = std::move(i); }
|
||||||
|
|
||||||
|
auto sd() -> drivers::SdState& { return sd_; }
|
||||||
|
|
||||||
|
auto sd(drivers::SdState s) { sd_ = s; }
|
||||||
|
|
||||||
auto bluetooth() -> drivers::Bluetooth& {
|
auto bluetooth() -> drivers::Bluetooth& {
|
||||||
assert(bluetooth_ != nullptr);
|
assert(bluetooth_ != nullptr);
|
||||||
return *bluetooth_;
|
return *bluetooth_;
|
||||||
@@ -96,6 +101,10 @@ class ServiceLocator {
|
|||||||
queue_ = std::move(i);
|
queue_ = std::move(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Not copyable or movable.
|
||||||
|
ServiceLocator(const ServiceLocator&) = delete;
|
||||||
|
ServiceLocator& operator=(const ServiceLocator&) = delete;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<drivers::Gpios> gpios_;
|
std::unique_ptr<drivers::Gpios> gpios_;
|
||||||
std::unique_ptr<drivers::Samd> samd_;
|
std::unique_ptr<drivers::Samd> samd_;
|
||||||
@@ -108,6 +117,8 @@ class ServiceLocator {
|
|||||||
|
|
||||||
std::shared_ptr<database::Database> database_;
|
std::shared_ptr<database::Database> database_;
|
||||||
std::unique_ptr<database::ITagParser> tag_parser_;
|
std::unique_ptr<database::ITagParser> tag_parser_;
|
||||||
|
|
||||||
|
drivers::SdState sd_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace system_fsm
|
} // namespace system_fsm
|
||||||
|
|||||||
@@ -35,6 +35,15 @@ void Running::entry() {
|
|||||||
auto storage_res = drivers::SdStorage::Create(sServices->gpios());
|
auto storage_res = drivers::SdStorage::Create(sServices->gpios());
|
||||||
if (storage_res.has_error()) {
|
if (storage_res.has_error()) {
|
||||||
ESP_LOGW(kTag, "failed to mount!");
|
ESP_LOGW(kTag, "failed to mount!");
|
||||||
|
switch (storage_res.error()) {
|
||||||
|
case drivers::SdStorage::FAILED_TO_MOUNT:
|
||||||
|
sServices->sd(drivers::SdState::kNotFormatted);
|
||||||
|
break;
|
||||||
|
case drivers::SdStorage::FAILED_TO_READ:
|
||||||
|
default:
|
||||||
|
sServices->sd(drivers::SdState::kNotPresent);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
events::System().Dispatch(StorageError{});
|
events::System().Dispatch(StorageError{});
|
||||||
events::Audio().Dispatch(StorageError{});
|
events::Audio().Dispatch(StorageError{});
|
||||||
@@ -42,6 +51,7 @@ void Running::entry() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sStorage.reset(storage_res.value());
|
sStorage.reset(storage_res.value());
|
||||||
|
sServices->sd(drivers::SdState::kMounted);
|
||||||
|
|
||||||
ESP_LOGI(kTag, "opening database");
|
ESP_LOGI(kTag, "opening database");
|
||||||
sFileGatherer = new database::FileGathererImpl();
|
sFileGatherer = new database::FileGathererImpl();
|
||||||
|
|||||||
@@ -9,13 +9,11 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "nvs.hpp"
|
#include "nvs.hpp"
|
||||||
|
#include "storage.hpp"
|
||||||
#include "touchwheel.hpp"
|
#include "touchwheel.hpp"
|
||||||
|
|
||||||
namespace system_fsm {
|
namespace system_fsm {
|
||||||
|
|
||||||
auto ServiceLocator::instance() -> ServiceLocator& {
|
ServiceLocator::ServiceLocator() : sd_(drivers::SdState::kNotPresent) {}
|
||||||
static ServiceLocator sInstance{};
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace system_fsm
|
} // namespace system_fsm
|
||||||
|
|||||||
@@ -42,11 +42,21 @@ class Controls : public Onboarding {
|
|||||||
Controls();
|
Controls();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MissingSdCard : public Onboarding {
|
||||||
|
public:
|
||||||
|
MissingSdCard();
|
||||||
|
};
|
||||||
|
|
||||||
class FormatSdCard : public Onboarding {
|
class FormatSdCard : public Onboarding {
|
||||||
public:
|
public:
|
||||||
FormatSdCard();
|
FormatSdCard();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InitDatabase : public Onboarding {
|
||||||
|
public:
|
||||||
|
InitDatabase();
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace onboarding
|
} // namespace onboarding
|
||||||
|
|
||||||
} // namespace screens
|
} // namespace screens
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ struct ShowSettingsPage : tinyfsm::Event {
|
|||||||
kAbout,
|
kAbout,
|
||||||
} page;
|
} page;
|
||||||
};
|
};
|
||||||
|
struct OnboardingNavigate : tinyfsm::Event {
|
||||||
|
bool forwards;
|
||||||
|
};
|
||||||
|
|
||||||
struct ModalConfirmPressed : tinyfsm::Event {};
|
struct ModalConfirmPressed : tinyfsm::Event {};
|
||||||
struct ModalCancelPressed : tinyfsm::Event {};
|
struct ModalCancelPressed : tinyfsm::Event {};
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
|
|||||||
virtual void react(const internal::ModalConfirmPressed&) {
|
virtual void react(const internal::ModalConfirmPressed&) {
|
||||||
sCurrentModal.reset();
|
sCurrentModal.reset();
|
||||||
}
|
}
|
||||||
|
virtual void react(const internal::OnboardingNavigate&) {}
|
||||||
|
|
||||||
virtual void react(const system_fsm::DisplayReady&) {}
|
virtual void react(const system_fsm::DisplayReady&) {}
|
||||||
virtual void react(const system_fsm::BootComplete&) {}
|
virtual void react(const system_fsm::BootComplete&) {}
|
||||||
@@ -101,10 +102,13 @@ class Onboarding : public UiState {
|
|||||||
public:
|
public:
|
||||||
void entry() override;
|
void entry() override;
|
||||||
|
|
||||||
|
void react(const internal::OnboardingNavigate&) override;
|
||||||
|
|
||||||
using UiState::react;
|
using UiState::react;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8_t progress_;
|
uint8_t progress_;
|
||||||
|
bool has_formatted_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Browse : public UiState {
|
class Browse : public UiState {
|
||||||
|
|||||||
@@ -6,12 +6,15 @@
|
|||||||
|
|
||||||
#include "screen_onboarding.hpp"
|
#include "screen_onboarding.hpp"
|
||||||
|
|
||||||
|
#include "core/lv_event.h"
|
||||||
#include "core/lv_obj_pos.h"
|
#include "core/lv_obj_pos.h"
|
||||||
#include "draw/lv_draw_rect.h"
|
#include "draw/lv_draw_rect.h"
|
||||||
|
#include "event_queue.hpp"
|
||||||
#include "extra/libs/qrcode/lv_qrcode.h"
|
#include "extra/libs/qrcode/lv_qrcode.h"
|
||||||
#include "extra/widgets/win/lv_win.h"
|
#include "extra/widgets/win/lv_win.h"
|
||||||
#include "font/lv_symbol_def.h"
|
#include "font/lv_symbol_def.h"
|
||||||
#include "misc/lv_color.h"
|
#include "misc/lv_color.h"
|
||||||
|
#include "ui_events.hpp"
|
||||||
#include "widgets/lv_btn.h"
|
#include "widgets/lv_btn.h"
|
||||||
#include "widgets/lv_label.h"
|
#include "widgets/lv_label.h"
|
||||||
#include "widgets/lv_switch.h"
|
#include "widgets/lv_switch.h"
|
||||||
@@ -21,17 +24,27 @@ static const char kManualUrl[] = "https://tangara.gay/onboarding";
|
|||||||
namespace ui {
|
namespace ui {
|
||||||
namespace screens {
|
namespace screens {
|
||||||
|
|
||||||
|
static void next_btn_cb(lv_event_t* ev) {
|
||||||
|
events::Ui().Dispatch(internal::OnboardingNavigate{.forwards = true});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void prev_btn_cb(lv_event_t* ev) {
|
||||||
|
events::Ui().Dispatch(internal::OnboardingNavigate{.forwards = false});
|
||||||
|
}
|
||||||
|
|
||||||
Onboarding::Onboarding(const std::string& title,
|
Onboarding::Onboarding(const std::string& title,
|
||||||
bool show_prev,
|
bool show_prev,
|
||||||
bool show_next) {
|
bool show_next) {
|
||||||
window_ = lv_win_create(root_, 18);
|
window_ = lv_win_create(root_, 18);
|
||||||
if (show_prev) {
|
if (show_prev) {
|
||||||
prev_button_ = lv_win_add_btn(window_, LV_SYMBOL_LEFT, 20);
|
prev_button_ = lv_win_add_btn(window_, LV_SYMBOL_LEFT, 20);
|
||||||
|
lv_obj_add_event_cb(prev_button_, prev_btn_cb, LV_EVENT_CLICKED, NULL);
|
||||||
lv_group_add_obj(group_, prev_button_);
|
lv_group_add_obj(group_, prev_button_);
|
||||||
}
|
}
|
||||||
title_ = lv_win_add_title(window_, title.c_str());
|
title_ = lv_win_add_title(window_, title.c_str());
|
||||||
if (show_next) {
|
if (show_next) {
|
||||||
next_button_ = lv_win_add_btn(window_, LV_SYMBOL_RIGHT, 20);
|
next_button_ = lv_win_add_btn(window_, LV_SYMBOL_RIGHT, 20);
|
||||||
|
lv_obj_add_event_cb(next_button_, next_btn_cb, LV_EVENT_CLICKED, NULL);
|
||||||
lv_group_add_obj(group_, next_button_);
|
lv_group_add_obj(group_, next_button_);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,23 +92,51 @@ Controls::Controls() : Onboarding("Controls", true, true) {
|
|||||||
create_radio_button(content_, "Scroll");
|
create_radio_button(content_, "Scroll");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MissingSdCard::MissingSdCard() : Onboarding("SD Card", true, false) {
|
||||||
|
lv_obj_t* label = lv_label_create(content_);
|
||||||
|
lv_label_set_text(label,
|
||||||
|
"It looks like there isn't an SD card present. Please "
|
||||||
|
"insert one to continue.");
|
||||||
|
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_size(label, lv_pct(100), LV_SIZE_CONTENT);
|
||||||
|
}
|
||||||
|
|
||||||
FormatSdCard::FormatSdCard() : Onboarding("SD Card", true, false) {
|
FormatSdCard::FormatSdCard() : Onboarding("SD Card", true, false) {
|
||||||
lv_obj_t* label = lv_label_create(content_);
|
lv_obj_t* label = lv_label_create(content_);
|
||||||
lv_label_set_text(
|
lv_label_set_text(label,
|
||||||
label, "this screen is optional. it offers to format your sd card.");
|
"It looks like there is an SD card present, but it has not "
|
||||||
|
"been formatted. Would you like to format it?");
|
||||||
|
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_size(label, lv_pct(100), LV_SIZE_CONTENT);
|
||||||
|
|
||||||
lv_obj_t* button = lv_btn_create(content_);
|
lv_obj_t* button = lv_btn_create(content_);
|
||||||
label = lv_label_create(button);
|
label = lv_label_create(button);
|
||||||
lv_label_set_text(label, "Format");
|
lv_label_set_text(label, "Format");
|
||||||
|
|
||||||
label = lv_label_create(content_);
|
lv_obj_t* exfat_con = lv_obj_create(content_);
|
||||||
lv_label_set_text(label, "Advanced");
|
lv_obj_set_layout(exfat_con, LV_LAYOUT_FLEX);
|
||||||
|
lv_obj_set_size(exfat_con, lv_pct(100), LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(exfat_con, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_flex_align(exfat_con, LV_FLEX_ALIGN_SPACE_EVENLY,
|
||||||
|
LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||||
|
|
||||||
lv_obj_t* advanced_container = lv_obj_create(content_);
|
label = lv_label_create(exfat_con);
|
||||||
|
|
||||||
label = lv_label_create(advanced_container);
|
|
||||||
lv_label_set_text(label, "Use exFAT");
|
lv_label_set_text(label, "Use exFAT");
|
||||||
lv_switch_create(advanced_container);
|
lv_switch_create(exfat_con);
|
||||||
|
}
|
||||||
|
|
||||||
|
InitDatabase::InitDatabase() : Onboarding("Database", true, true) {
|
||||||
|
lv_obj_t* label = lv_label_create(content_);
|
||||||
|
lv_label_set_text(label,
|
||||||
|
"Many of Tangara's browsing features rely building an "
|
||||||
|
"index of your music. Would you like to do this now? It "
|
||||||
|
"will take some time if you have a large collection.");
|
||||||
|
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
|
||||||
|
lv_obj_set_size(label, lv_pct(100), LV_SIZE_CONTENT);
|
||||||
|
|
||||||
|
lv_obj_t* button = lv_btn_create(content_);
|
||||||
|
label = lv_label_create(button);
|
||||||
|
lv_label_set_text(label, "Index");
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace onboarding
|
} // namespace onboarding
|
||||||
|
|||||||
+67
-6
@@ -29,6 +29,7 @@
|
|||||||
#include "screen_splash.hpp"
|
#include "screen_splash.hpp"
|
||||||
#include "screen_track_browser.hpp"
|
#include "screen_track_browser.hpp"
|
||||||
#include "source.hpp"
|
#include "source.hpp"
|
||||||
|
#include "storage.hpp"
|
||||||
#include "system_events.hpp"
|
#include "system_events.hpp"
|
||||||
#include "touchwheel.hpp"
|
#include "touchwheel.hpp"
|
||||||
#include "track_queue.hpp"
|
#include "track_queue.hpp"
|
||||||
@@ -160,18 +161,78 @@ void Splash::react(const system_fsm::BootComplete& ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Onboarding::entry() {
|
void Onboarding::entry() {
|
||||||
|
progress_ = 0;
|
||||||
|
has_formatted_ = false;
|
||||||
sCurrentScreen.reset(new screens::onboarding::LinkToManual());
|
sCurrentScreen.reset(new screens::onboarding::LinkToManual());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browse::entry() {}
|
void Onboarding::react(const internal::OnboardingNavigate& ev) {
|
||||||
|
int dir = ev.forwards ? 1 : -1;
|
||||||
|
progress_ += dir;
|
||||||
|
|
||||||
void Browse::react(const system_fsm::StorageMounted& ev) {
|
for (;;) {
|
||||||
auto db = sServices->database().lock();
|
if (progress_ == 0) {
|
||||||
if (!db) {
|
sCurrentScreen.reset(new screens::onboarding::LinkToManual());
|
||||||
// TODO(jacqueline): Hmm.
|
return;
|
||||||
|
} else if (progress_ == 1) {
|
||||||
|
sCurrentScreen.reset(new screens::onboarding::Controls());
|
||||||
|
return;
|
||||||
|
} else if (progress_ == 2) {
|
||||||
|
if (sServices->sd() == drivers::SdState::kNotPresent) {
|
||||||
|
sCurrentScreen.reset(new screens::onboarding::MissingSdCard());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
progress_ += dir;
|
||||||
|
}
|
||||||
|
} else if (progress_ == 3) {
|
||||||
|
if (sServices->sd() == drivers::SdState::kNotFormatted) {
|
||||||
|
has_formatted_ = true;
|
||||||
|
sCurrentScreen.reset(new screens::onboarding::FormatSdCard());
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
progress_ += dir;
|
||||||
|
}
|
||||||
|
} else if (progress_ == 4) {
|
||||||
|
if (has_formatted_) {
|
||||||
|
// If we formatted the SD card during this onboarding flow, then there
|
||||||
|
// is no music that needs indexing.
|
||||||
|
progress_ += dir;
|
||||||
|
} else {
|
||||||
|
sCurrentScreen.reset(new screens::onboarding::InitDatabase());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PushScreen(std::make_shared<screens::Menu>(db->GetIndexes()));
|
} else {
|
||||||
|
// We finished onboarding! Ensure this flow doesn't appear again.
|
||||||
|
sServices->nvs().HasShownOnboarding(true);
|
||||||
|
|
||||||
|
transit<Browse>();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool sBrowseFirstEntry = true;
|
||||||
|
|
||||||
|
void Browse::entry() {
|
||||||
|
if (sBrowseFirstEntry) {
|
||||||
|
auto db = sServices->database().lock();
|
||||||
|
if (!db) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sCurrentScreen = std::make_shared<screens::Menu>(db->GetIndexes());
|
||||||
|
sBrowseFirstEntry = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Browse::react(const system_fsm::StorageMounted& ev) {
|
||||||
|
if (sBrowseFirstEntry) {
|
||||||
|
auto db = sServices->database().lock();
|
||||||
|
if (!db) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sCurrentScreen = std::make_shared<screens::Menu>(db->GetIndexes());
|
||||||
|
sBrowseFirstEntry = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Browse::react(const internal::ShowNowPlaying& ev) {
|
void Browse::react(const internal::ShowNowPlaying& ev) {
|
||||||
|
|||||||
Reference in New Issue
Block a user