From b0d745d02dcfd6ab9b1ad14e9060b39bf9ad7bb8 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Fri, 8 Sep 2023 16:58:30 +1000 Subject: [PATCH] Flesh out onboarding a little, and add a way to get into it --- src/drivers/include/nvs.hpp | 3 +++ src/drivers/nvs.cpp | 16 ++++++++++++++++ src/ui/include/screen_onboarding.hpp | 3 +++ src/ui/include/ui_fsm.hpp | 4 ++++ src/ui/screen_onboarding.cpp | 13 +++++++++++-- src/ui/ui_fsm.cpp | 11 ++++++++++- 6 files changed, 47 insertions(+), 3 deletions(-) diff --git a/src/drivers/include/nvs.hpp b/src/drivers/include/nvs.hpp index d7b3dfdd..91b68bc4 100644 --- a/src/drivers/include/nvs.hpp +++ b/src/drivers/include/nvs.hpp @@ -43,6 +43,9 @@ class NvsStorage { auto AmpCurrentVolume() -> std::future; auto AmpCurrentVolume(uint16_t) -> std::future; + auto HasShownOnboarding() -> std::future; + auto HasShownOnboarding(bool) -> std::future; + explicit NvsStorage(std::unique_ptr, nvs_handle_t); ~NvsStorage(); diff --git a/src/drivers/nvs.cpp b/src/drivers/nvs.cpp index 7bd1afe2..0a466b16 100644 --- a/src/drivers/nvs.cpp +++ b/src/drivers/nvs.cpp @@ -30,6 +30,7 @@ static constexpr char kKeyOutput[] = "out"; static constexpr char kKeyBrightness[] = "bright"; static constexpr char kKeyAmpMaxVolume[] = "hp_vol_max"; static constexpr char kKeyAmpCurrentVolume[] = "hp_vol"; +static constexpr char kKeyOnboarded[] = "intro"; auto NvsStorage::OpenSync() -> NvsStorage* { esp_err_t err = nvs_flash_init(); @@ -187,4 +188,19 @@ auto NvsStorage::AmpCurrentVolume(uint16_t val) -> std::future { }); } +auto NvsStorage::HasShownOnboarding() -> std::future { + return writer_->Dispatch([&]() -> bool { + uint8_t out = true; + nvs_get_u8(handle_, kKeyOnboarded, &out); + return out; + }); +} + +auto NvsStorage::HasShownOnboarding(bool val) -> std::future { + return writer_->Dispatch([&]() { + nvs_set_u8(handle_, kKeyOnboarded, val); + return nvs_commit(handle_) == ESP_OK; + }); +} + } // namespace drivers diff --git a/src/ui/include/screen_onboarding.hpp b/src/ui/include/screen_onboarding.hpp index d7751926..73f2333d 100644 --- a/src/ui/include/screen_onboarding.hpp +++ b/src/ui/include/screen_onboarding.hpp @@ -33,14 +33,17 @@ class Onboarding : public Screen { namespace onboarding { class LinkToManual : public Onboarding { + public: LinkToManual(); }; class Controls : public Onboarding { + public: Controls(); }; class FormatSdCard : public Onboarding { + public: FormatSdCard(); }; diff --git a/src/ui/include/ui_fsm.hpp b/src/ui/include/ui_fsm.hpp index 7ac9c7b6..de97354e 100644 --- a/src/ui/include/ui_fsm.hpp +++ b/src/ui/include/ui_fsm.hpp @@ -6,6 +6,7 @@ #pragma once +#include #include #include @@ -101,6 +102,9 @@ class Onboarding : public UiState { void entry() override; using UiState::react; + + private: + uint8_t progress_; }; class Browse : public UiState { diff --git a/src/ui/screen_onboarding.cpp b/src/ui/screen_onboarding.cpp index ea8223ba..e908b744 100644 --- a/src/ui/screen_onboarding.cpp +++ b/src/ui/screen_onboarding.cpp @@ -6,6 +6,7 @@ #include "screen_onboarding.hpp" +#include "core/lv_obj_pos.h" #include "draw/lv_draw_rect.h" #include "extra/libs/qrcode/lv_qrcode.h" #include "extra/widgets/win/lv_win.h" @@ -26,23 +27,31 @@ Onboarding::Onboarding(const std::string& title, window_ = lv_win_create(root_, 18); if (show_prev) { prev_button_ = lv_win_add_btn(window_, LV_SYMBOL_LEFT, 20); + lv_group_add_obj(group_, prev_button_); } title_ = lv_win_add_title(window_, title.c_str()); if (show_next) { next_button_ = lv_win_add_btn(window_, LV_SYMBOL_RIGHT, 20); + lv_group_add_obj(group_, next_button_); } content_ = lv_win_get_content(window_); + lv_obj_set_layout(content_, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(content_, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(content_, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, + LV_FLEX_ALIGN_CENTER); } namespace onboarding { LinkToManual::LinkToManual() : Onboarding("Welcome!", false, true) { lv_obj_t* intro = lv_label_create(content_); - lv_label_set_text(intro, "this screen links you to better instructions"); + lv_label_set_text(intro, "For full instructions, see the manual:"); + lv_label_set_long_mode(intro, LV_LABEL_LONG_WRAP); + lv_obj_set_size(intro, lv_pct(100), LV_SIZE_CONTENT); lv_obj_t* qr = - lv_qrcode_create(content_, 100, lv_color_black(), lv_color_white()); + lv_qrcode_create(content_, 80, lv_color_black(), lv_color_white()); lv_qrcode_update(qr, kManualUrl, sizeof(kManualUrl)); } diff --git a/src/ui/ui_fsm.cpp b/src/ui/ui_fsm.cpp index c463933f..70a77c2a 100644 --- a/src/ui/ui_fsm.cpp +++ b/src/ui/ui_fsm.cpp @@ -23,6 +23,7 @@ #include "relative_wheel.hpp" #include "screen.hpp" #include "screen_menu.hpp" +#include "screen_onboarding.hpp" #include "screen_playing.hpp" #include "screen_settings.hpp" #include "screen_splash.hpp" @@ -150,7 +151,15 @@ void Splash::react(const system_fsm::BootComplete& ev) { ESP_LOGE(kTag, "no input devices initialised!"); } - transit(); + if (sServices->nvs().HasShownOnboarding().get()) { + transit(); + } else { + transit(); + } +} + +void Onboarding::entry() { + sCurrentScreen.reset(new screens::onboarding::LinkToManual()); } void Browse::entry() {}