Flesh out onboarding a little, and add a way to get into it

custom
jacqueline 2 years ago
parent 64d9cec8b0
commit b0d745d02d
  1. 3
      src/drivers/include/nvs.hpp
  2. 16
      src/drivers/nvs.cpp
  3. 3
      src/ui/include/screen_onboarding.hpp
  4. 4
      src/ui/include/ui_fsm.hpp
  5. 13
      src/ui/screen_onboarding.cpp
  6. 9
      src/ui/ui_fsm.cpp

@ -43,6 +43,9 @@ class NvsStorage {
auto AmpCurrentVolume() -> std::future<uint16_t>; auto AmpCurrentVolume() -> std::future<uint16_t>;
auto AmpCurrentVolume(uint16_t) -> std::future<bool>; auto AmpCurrentVolume(uint16_t) -> std::future<bool>;
auto HasShownOnboarding() -> std::future<bool>;
auto HasShownOnboarding(bool) -> std::future<bool>;
explicit NvsStorage(std::unique_ptr<tasks::Worker>, nvs_handle_t); explicit NvsStorage(std::unique_ptr<tasks::Worker>, nvs_handle_t);
~NvsStorage(); ~NvsStorage();

@ -30,6 +30,7 @@ static constexpr char kKeyOutput[] = "out";
static constexpr char kKeyBrightness[] = "bright"; static constexpr char kKeyBrightness[] = "bright";
static constexpr char kKeyAmpMaxVolume[] = "hp_vol_max"; static constexpr char kKeyAmpMaxVolume[] = "hp_vol_max";
static constexpr char kKeyAmpCurrentVolume[] = "hp_vol"; static constexpr char kKeyAmpCurrentVolume[] = "hp_vol";
static constexpr char kKeyOnboarded[] = "intro";
auto NvsStorage::OpenSync() -> NvsStorage* { auto NvsStorage::OpenSync() -> NvsStorage* {
esp_err_t err = nvs_flash_init(); esp_err_t err = nvs_flash_init();
@ -187,4 +188,19 @@ auto NvsStorage::AmpCurrentVolume(uint16_t val) -> std::future<bool> {
}); });
} }
auto NvsStorage::HasShownOnboarding() -> std::future<bool> {
return writer_->Dispatch<bool>([&]() -> bool {
uint8_t out = true;
nvs_get_u8(handle_, kKeyOnboarded, &out);
return out;
});
}
auto NvsStorage::HasShownOnboarding(bool val) -> std::future<bool> {
return writer_->Dispatch<bool>([&]() {
nvs_set_u8(handle_, kKeyOnboarded, val);
return nvs_commit(handle_) == ESP_OK;
});
}
} // namespace drivers } // namespace drivers

@ -33,14 +33,17 @@ class Onboarding : public Screen {
namespace onboarding { namespace onboarding {
class LinkToManual : public Onboarding { class LinkToManual : public Onboarding {
public:
LinkToManual(); LinkToManual();
}; };
class Controls : public Onboarding { class Controls : public Onboarding {
public:
Controls(); Controls();
}; };
class FormatSdCard : public Onboarding { class FormatSdCard : public Onboarding {
public:
FormatSdCard(); FormatSdCard();
}; };

@ -6,6 +6,7 @@
#pragma once #pragma once
#include <stdint.h>
#include <memory> #include <memory>
#include <stack> #include <stack>
@ -101,6 +102,9 @@ class Onboarding : public UiState {
void entry() override; void entry() override;
using UiState::react; using UiState::react;
private:
uint8_t progress_;
}; };
class Browse : public UiState { class Browse : public UiState {

@ -6,6 +6,7 @@
#include "screen_onboarding.hpp" #include "screen_onboarding.hpp"
#include "core/lv_obj_pos.h"
#include "draw/lv_draw_rect.h" #include "draw/lv_draw_rect.h"
#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"
@ -26,23 +27,31 @@ Onboarding::Onboarding(const std::string& title,
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_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_group_add_obj(group_, next_button_);
} }
content_ = lv_win_get_content(window_); 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 { namespace onboarding {
LinkToManual::LinkToManual() : Onboarding("Welcome!", false, true) { LinkToManual::LinkToManual() : Onboarding("Welcome!", false, true) {
lv_obj_t* intro = lv_label_create(content_); 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_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)); lv_qrcode_update(qr, kManualUrl, sizeof(kManualUrl));
} }

@ -23,6 +23,7 @@
#include "relative_wheel.hpp" #include "relative_wheel.hpp"
#include "screen.hpp" #include "screen.hpp"
#include "screen_menu.hpp" #include "screen_menu.hpp"
#include "screen_onboarding.hpp"
#include "screen_playing.hpp" #include "screen_playing.hpp"
#include "screen_settings.hpp" #include "screen_settings.hpp"
#include "screen_splash.hpp" #include "screen_splash.hpp"
@ -150,7 +151,15 @@ void Splash::react(const system_fsm::BootComplete& ev) {
ESP_LOGE(kTag, "no input devices initialised!"); ESP_LOGE(kTag, "no input devices initialised!");
} }
if (sServices->nvs().HasShownOnboarding().get()) {
transit<Browse>(); transit<Browse>();
} else {
transit<Onboarding>();
}
}
void Onboarding::entry() {
sCurrentScreen.reset(new screens::onboarding::LinkToManual());
} }
void Browse::entry() {} void Browse::entry() {}

Loading…
Cancel
Save