Write up the new input modes to NVS and settings
This commit is contained in:
@@ -31,6 +31,7 @@ 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";
|
static constexpr char kKeyOnboarded[] = "intro";
|
||||||
|
static constexpr char kKeyPrimaryInput[] = "in_pri";
|
||||||
|
|
||||||
auto NvsStorage::OpenSync() -> NvsStorage* {
|
auto NvsStorage::OpenSync() -> NvsStorage* {
|
||||||
esp_err_t err = nvs_flash_init();
|
esp_err_t err = nvs_flash_init();
|
||||||
@@ -166,4 +167,27 @@ auto NvsStorage::HasShownOnboarding(bool val) -> bool {
|
|||||||
return nvs_commit(handle_) == ESP_OK;
|
return nvs_commit(handle_) == ESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto NvsStorage::PrimaryInput() -> InputModes {
|
||||||
|
uint8_t out = 3;
|
||||||
|
nvs_get_u8(handle_, kKeyPrimaryInput, &out);
|
||||||
|
switch (out) {
|
||||||
|
case static_cast<uint8_t>(InputModes::kButtonsOnly):
|
||||||
|
return InputModes::kButtonsOnly;
|
||||||
|
case static_cast<uint8_t>(InputModes::kButtonsWithWheel):
|
||||||
|
return InputModes::kButtonsWithWheel;
|
||||||
|
case static_cast<uint8_t>(InputModes::kDirectionalWheel):
|
||||||
|
return InputModes::kDirectionalWheel;
|
||||||
|
case static_cast<uint8_t>(InputModes::kRotatingWheel):
|
||||||
|
return InputModes::kRotatingWheel;
|
||||||
|
default:
|
||||||
|
return InputModes::kRotatingWheel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto NvsStorage::PrimaryInput(InputModes mode) -> bool {
|
||||||
|
uint8_t as_int = static_cast<uint8_t>(mode);
|
||||||
|
nvs_set_u8(handle_, kKeyPrimaryInput, as_int);
|
||||||
|
return nvs_commit(handle_) == ESP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace drivers
|
} // namespace drivers
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ EncoderInput::EncoderInput(drivers::IGpios& gpios, drivers::TouchWheel& wheel)
|
|||||||
raw_wheel_(wheel),
|
raw_wheel_(wheel),
|
||||||
relative_wheel_(std::make_unique<drivers::RelativeWheel>(wheel)),
|
relative_wheel_(std::make_unique<drivers::RelativeWheel>(wheel)),
|
||||||
scroller_(std::make_unique<Scroller>()),
|
scroller_(std::make_unique<Scroller>()),
|
||||||
mode_(drivers::NvsStorage::InputModes::kRotatingWheel) {
|
mode_(drivers::NvsStorage::InputModes::kRotatingWheel),
|
||||||
|
is_locked_(false) {
|
||||||
lv_indev_drv_init(&driver_);
|
lv_indev_drv_init(&driver_);
|
||||||
driver_.type = LV_INDEV_TYPE_ENCODER;
|
driver_.type = LV_INDEV_TYPE_ENCODER;
|
||||||
driver_.read_cb = encoder_read;
|
driver_.read_cb = encoder_read;
|
||||||
@@ -50,6 +51,10 @@ EncoderInput::EncoderInput(drivers::IGpios& gpios, drivers::TouchWheel& wheel)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto EncoderInput::Read(lv_indev_data_t* data) -> void {
|
auto EncoderInput::Read(lv_indev_data_t* data) -> void {
|
||||||
|
if (is_locked_) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
raw_wheel_.Update();
|
raw_wheel_.Update();
|
||||||
relative_wheel_->Update();
|
relative_wheel_->Update();
|
||||||
// GPIOs updating is handled by system_fsm.
|
// GPIOs updating is handled by system_fsm.
|
||||||
|
|||||||
@@ -89,7 +89,10 @@ class Appearance : public MenuScreen {
|
|||||||
|
|
||||||
class InputMethod : public MenuScreen {
|
class InputMethod : public MenuScreen {
|
||||||
public:
|
public:
|
||||||
InputMethod(models::TopBar&);
|
InputMethod(models::TopBar&, drivers::NvsStorage& nvs);
|
||||||
|
|
||||||
|
private:
|
||||||
|
drivers::NvsStorage& nvs_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Storage : public MenuScreen {
|
class Storage : public MenuScreen {
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ struct IndexSelected : tinyfsm::Event {
|
|||||||
database::IndexInfo index;
|
database::IndexInfo index;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ControlSchemeChanged : tinyfsm::Event {};
|
||||||
|
|
||||||
struct BackPressed : tinyfsm::Event {};
|
struct BackPressed : tinyfsm::Event {};
|
||||||
struct ShowNowPlaying : tinyfsm::Event {};
|
struct ShowNowPlaying : tinyfsm::Event {};
|
||||||
struct ShowSettingsPage : tinyfsm::Event {
|
struct ShowSettingsPage : tinyfsm::Event {
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ class UiState : public tinyfsm::Fsm<UiState> {
|
|||||||
sCurrentModal.reset();
|
sCurrentModal.reset();
|
||||||
}
|
}
|
||||||
virtual void react(const internal::OnboardingNavigate&) {}
|
virtual void react(const internal::OnboardingNavigate&) {}
|
||||||
|
void react(const internal::ControlSchemeChanged&);
|
||||||
|
|
||||||
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&) {}
|
||||||
|
|||||||
+33
-12
@@ -422,19 +422,40 @@ auto Appearance::CommitBrightness() -> void {
|
|||||||
nvs_.ScreenBrightness(current_brightness_);
|
nvs_.ScreenBrightness(current_brightness_);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputMethod::InputMethod(models::TopBar& bar)
|
InputMethod::InputMethod(models::TopBar& bar, drivers::NvsStorage& nvs)
|
||||||
: MenuScreen(bar, "Input Method") {
|
: MenuScreen(bar, "Input Method"), nvs_(nvs) {
|
||||||
lv_obj_t* wheel_label = lv_label_create(content_);
|
lv_obj_t* primary_label = lv_label_create(content_);
|
||||||
lv_label_set_text(wheel_label, "What does the wheel do?");
|
lv_label_set_text(primary_label, "Control scheme");
|
||||||
lv_obj_t* wheel_dropdown = lv_dropdown_create(content_);
|
lv_obj_t* primary_dropdown = lv_dropdown_create(content_);
|
||||||
lv_dropdown_set_options(wheel_dropdown, "Scroll\nDirectional\nBig Button");
|
lv_dropdown_set_options(
|
||||||
lv_group_add_obj(group_, wheel_dropdown);
|
primary_dropdown,
|
||||||
|
"Side buttons only\nButtons and touch\nD-Pad\nClickwheel");
|
||||||
|
lv_group_add_obj(group_, primary_dropdown);
|
||||||
|
|
||||||
lv_obj_t* buttons_label = lv_label_create(content_);
|
lv_dropdown_set_selected(primary_dropdown,
|
||||||
lv_label_set_text(buttons_label, "What do the buttons do?");
|
static_cast<uint16_t>(nvs.PrimaryInput()));
|
||||||
lv_obj_t* buttons_dropdown = lv_dropdown_create(content_);
|
|
||||||
lv_dropdown_set_options(buttons_dropdown, "Volume\nScroll");
|
lv_bind(primary_dropdown, LV_EVENT_VALUE_CHANGED, [this](lv_obj_t* obj) {
|
||||||
lv_group_add_obj(group_, buttons_dropdown);
|
drivers::NvsStorage::InputModes mode;
|
||||||
|
switch (lv_dropdown_get_selected(obj)) {
|
||||||
|
case 0:
|
||||||
|
mode = drivers::NvsStorage::InputModes::kButtonsOnly;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
mode = drivers::NvsStorage::InputModes::kButtonsWithWheel;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
mode = drivers::NvsStorage::InputModes::kDirectionalWheel;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
mode = drivers::NvsStorage::InputModes::kRotatingWheel;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nvs_.PrimaryInput(mode);
|
||||||
|
events::Ui().Dispatch(internal::ControlSchemeChanged{});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Storage::Storage(models::TopBar& bar) : MenuScreen(bar, "Storage") {
|
Storage::Storage(models::TopBar& bar) : MenuScreen(bar, "Storage") {
|
||||||
|
|||||||
+9
-1
@@ -114,6 +114,13 @@ void UiState::react(const audio::QueueUpdate&) {
|
|||||||
sPlaybackModel.upcoming_tracks.set(queue.GetUpcoming(10));
|
sPlaybackModel.upcoming_tracks.set(queue.GetUpcoming(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiState::react(const internal::ControlSchemeChanged&) {
|
||||||
|
if (!sInput) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sInput->mode(sServices->nvs().PrimaryInput());
|
||||||
|
}
|
||||||
|
|
||||||
namespace states {
|
namespace states {
|
||||||
|
|
||||||
void Splash::exit() {
|
void Splash::exit() {
|
||||||
@@ -138,6 +145,7 @@ void Splash::react(const system_fsm::BootComplete& ev) {
|
|||||||
auto touchwheel = sServices->touchwheel();
|
auto touchwheel = sServices->touchwheel();
|
||||||
if (touchwheel) {
|
if (touchwheel) {
|
||||||
sInput = std::make_shared<EncoderInput>(sServices->gpios(), **touchwheel);
|
sInput = std::make_shared<EncoderInput>(sServices->gpios(), **touchwheel);
|
||||||
|
sInput->mode(sServices->nvs().PrimaryInput());
|
||||||
sTask->input(sInput);
|
sTask->input(sInput);
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(kTag, "no input devices initialised!");
|
ESP_LOGE(kTag, "no input devices initialised!");
|
||||||
@@ -252,7 +260,7 @@ void Browse::react(const internal::ShowSettingsPage& ev) {
|
|||||||
new screens::Appearance(sTopBarModel, sServices->nvs(), *sDisplay));
|
new screens::Appearance(sTopBarModel, sServices->nvs(), *sDisplay));
|
||||||
break;
|
break;
|
||||||
case internal::ShowSettingsPage::Page::kInput:
|
case internal::ShowSettingsPage::Page::kInput:
|
||||||
screen.reset(new screens::InputMethod(sTopBarModel));
|
screen.reset(new screens::InputMethod(sTopBarModel, sServices->nvs()));
|
||||||
break;
|
break;
|
||||||
case internal::ShowSettingsPage::Page::kStorage:
|
case internal::ShowSettingsPage::Page::kStorage:
|
||||||
screen.reset(new screens::Storage(sTopBarModel));
|
screen.reset(new screens::Storage(sTopBarModel));
|
||||||
|
|||||||
Reference in New Issue
Block a user