M0 step 7: Settings, About, Storage, first-boot setup

- lib/apps_model (host-tested): SettingsMenu (rows, readable values,
  choices, validation messages) and SetupWizard (names, Region
  confirmation, timezone; saves only when finished)
- AppManager: modal Apps that Home/Back can't leave (setup wizard)
- SettingsApp: all settings plus Storage (usage, erase SD behind a
  dialog) and About (version, node id, battery, memory, uptime) pages,
  replacing the temporary Diagnostics App
- SetupApp: first-boot wizard, opened modally until SetupDone
- Node id and default names derived from the MAC like Meshtastic
- Widget demo is now hidden (About, then w)
- lib_ldf_mode = deep+ so libraries see each other's headers

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-02 13:47:03 +02:00
co-authored by Claude Opus 5.5
parent 05c9d9cc56
commit 51698a8011
23 changed files with 1126 additions and 154 deletions
+143
View File
@@ -0,0 +1,143 @@
#include "settings_menu.h"
#include "choices.h"
namespace roro {
namespace {
using Row = SettingsMenu::Row;
using Kind = SettingsMenu::Kind;
struct RowDef {
Row row;
Kind kind;
const char* label;
};
const RowDef kRows[] = {
{Row::LongName, Kind::Text, "Long name"}, {Row::ShortName, Kind::Text, "Short name"},
{Row::Region, Kind::Choice, "Region"}, {Row::Timezone, Kind::Choice, "Timezone"},
{Row::Brightness, Kind::Slider, "Brightness"}, {Row::DimTimeout, Kind::Choice, "Dim after"},
{Row::OffTimeout, Kind::Choice, "Screen off after"}, {Row::Sound, Kind::Toggle, "Sound & LED"},
{Row::ProbeMacs, Kind::Toggle, "Probe MACs"}, {Row::Storage, Kind::Page, "Storage"},
{Row::About, Kind::Page, "About"},
};
const int kDimSeconds[] = {10, 15, 30, 60, 120, 300};
const int kOffSeconds[] = {30, 60, 120, 300, 600, 1800};
std::string formatSeconds(int s) { return s < 60 ? std::to_string(s) + " s" : std::to_string(s / 60) + " min"; }
template <size_t N>
std::vector<std::string> labels(const Choice (&table)[N]) {
std::vector<std::string> out;
for (auto& c : table) out.push_back(c.label);
return out;
}
template <size_t N>
std::vector<std::string> durations(const int (&seconds)[N]) {
std::vector<std::string> out;
for (int s : seconds) out.push_back(formatSeconds(s));
return out;
}
template <size_t N>
int indexOf(const Choice (&table)[N], const std::string& value) {
for (size_t i = 0; i < N; i++)
if (value == table[i].value) return static_cast<int>(i);
return -1;
}
template <size_t N>
int indexOf(const int (&table)[N], int value) {
for (size_t i = 0; i < N; i++)
if (table[i] == value) return static_cast<int>(i);
return -1;
}
} // namespace
int SettingsMenu::count() const { return sizeof(kRows) / sizeof(kRows[0]); }
SettingsMenu::Row SettingsMenu::row(int i) const { return kRows[i].row; }
SettingsMenu::Kind SettingsMenu::kind(int i) const { return kRows[i].kind; }
std::string SettingsMenu::label(int i) const { return kRows[i].label; }
std::string SettingsMenu::value(int i) const {
switch (row(i)) {
case Row::LongName: return settings_.getString(Setting::LongName);
case Row::ShortName: return settings_.getString(Setting::ShortName);
case Row::Region: return settings_.getString(Setting::Region);
case Row::Timezone: {
int c = currentChoice(i);
return c >= 0 ? kTimezones[c].label : "Custom";
}
case Row::Brightness: return std::to_string(settings_.getInt(Setting::Brightness)) + "%";
case Row::DimTimeout: return formatSeconds(settings_.getInt(Setting::DimTimeoutS));
case Row::OffTimeout: return formatSeconds(settings_.getInt(Setting::OffTimeoutS));
case Row::Sound: return settings_.getBool(Setting::Sound) ? "On" : "Off";
case Row::ProbeMacs: return settings_.getBool(Setting::ProbeMacRaw) ? "Raw" : "Pseudonymised";
default: return "";
}
}
std::vector<std::string> SettingsMenu::choices(int i) const {
switch (row(i)) {
case Row::Region: return labels(kRegions);
case Row::Timezone: return labels(kTimezones);
case Row::DimTimeout: return durations(kDimSeconds);
case Row::OffTimeout: return durations(kOffSeconds);
default: return {};
}
}
int SettingsMenu::currentChoice(int i) const {
switch (row(i)) {
case Row::Region: return indexOf(kRegions, settings_.getString(Setting::Region));
case Row::Timezone: return indexOf(kTimezones, settings_.getString(Setting::Timezone));
case Row::DimTimeout: return indexOf(kDimSeconds, settings_.getInt(Setting::DimTimeoutS));
case Row::OffTimeout: return indexOf(kOffSeconds, settings_.getInt(Setting::OffTimeoutS));
default: return -1;
}
}
std::string SettingsMenu::choose(int i, int c) {
switch (row(i)) {
case Row::Region:
settings_.setString(Setting::Region, kRegions[c].value);
settings_.setBool(Setting::RegionConfirmed, true);
return "";
case Row::Timezone: settings_.setString(Setting::Timezone, kTimezones[c].value); return "";
case Row::DimTimeout:
return settings_.setInt(Setting::DimTimeoutS, kDimSeconds[c]) ? "" : "Dimming must happen before screen off";
case Row::OffTimeout:
return settings_.setInt(Setting::OffTimeoutS, kOffSeconds[c]) ? "" : "Screen off must come after dimming";
default: return "Not a choice";
}
}
void SettingsMenu::toggle(int i) {
if (row(i) == Row::Sound) settings_.setBool(Setting::Sound, !settings_.getBool(Setting::Sound));
if (row(i) == Row::ProbeMacs) settings_.setBool(Setting::ProbeMacRaw, !settings_.getBool(Setting::ProbeMacRaw));
}
void SettingsMenu::adjust(int i, int direction) {
if (row(i) != Row::Brightness) return;
int next = settings_.getInt(Setting::Brightness) + (direction > 0 ? 10 : -10);
if (next < 10) next = 10;
if (next > 100) next = 100;
settings_.setInt(Setting::Brightness, next);
}
int SettingsMenu::maxBytes(int i) const {
return row(i) == Row::ShortName ? 4 : row(i) == Row::LongName ? 39 : 0;
}
std::string SettingsMenu::setText(int i, const std::string& text) {
Setting s = row(i) == Row::ShortName ? Setting::ShortName : Setting::LongName;
if (settings_.setString(s, text)) return "";
return "Must be 1 to " + std::to_string(maxBytes(i)) + " bytes";
}
} // namespace roro
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include <string>
#include <vector>
#include "settings.h"
namespace roro {
// What the Settings App lists: one row per user-facing setting (plus sub-pages), with readable
// values, choice lists and validation messages. Rendering and navigation live in the App.
class SettingsMenu {
public:
enum class Row { LongName, ShortName, Region, Timezone, Brightness, DimTimeout, OffTimeout, Sound, ProbeMacs, Storage, About };
enum class Kind { Text, Choice, Toggle, Slider, Page };
explicit SettingsMenu(Settings& settings) : settings_(settings) {}
int count() const;
Row row(int i) const;
Kind kind(int i) const;
std::string label(int i) const;
std::string value(int i) const;
// Choice rows
std::vector<std::string> choices(int i) const;
int currentChoice(int i) const; // -1 if the current value isn't one of the choices
std::string choose(int i, int choice); // empty on success, otherwise why it was refused
// Toggle and Slider rows
void toggle(int i);
void adjust(int i, int direction);
// Text rows
int maxBytes(int i) const;
std::string setText(int i, const std::string& text); // empty on success, otherwise why
private:
Settings& settings_;
};
} // namespace roro
+88
View File
@@ -0,0 +1,88 @@
#include "setup_wizard.h"
#include "choices.h"
namespace roro {
SetupWizard::SetupWizard(Settings& settings, std::string defaultLongName, std::string defaultShortName)
: settings_(settings), longName_(std::move(defaultLongName)), shortName_(std::move(defaultShortName)) {}
int SetupWizard::choiceCount() const {
if (step_ == Step::Region) return sizeof(kRegions) / sizeof(kRegions[0]);
if (step_ == Step::Timezone) return sizeof(kTimezones) / sizeof(kTimezones[0]);
return 0;
}
std::string SetupWizard::choiceLabel(int i) const {
return step_ == Step::Region ? kRegions[i].label : kTimezones[i].label;
}
int SetupWizard::selectedChoice() const { return step_ == Step::Region ? region_ : timezone_; }
void SetupWizard::selectChoice(int i) {
if (i < 0 || i >= choiceCount()) return;
(step_ == Step::Region ? region_ : timezone_) = i;
}
void SetupWizard::enter(Step step) {
step_ = step;
error_.clear();
if (step == Step::LongName) {
editor_ = LineEditor(39);
editor_.setText(longName_);
} else if (step == Step::ShortName) {
editor_ = LineEditor(4);
editor_.setText(shortName_);
}
}
bool SetupWizard::next() {
switch (step_) {
case Step::Welcome: enter(Step::LongName); return true;
case Step::LongName:
if (editor_.text().empty()) {
error_ = "Please enter a name";
return false;
}
longName_ = editor_.text();
enter(Step::ShortName);
return true;
case Step::ShortName:
if (editor_.text().empty()) {
error_ = "Please enter 1 to 4 characters";
return false;
}
shortName_ = editor_.text();
enter(Step::Region);
return true;
case Step::Region: enter(Step::Timezone); return true;
case Step::Timezone: enter(Step::Done); return true;
case Step::Done:
save();
finished_ = true;
return true;
}
return false;
}
void SetupWizard::back() {
switch (step_) {
case Step::LongName: longName_ = editor_.text(); enter(Step::Welcome); break;
case Step::ShortName: shortName_ = editor_.text(); enter(Step::LongName); break;
case Step::Region: enter(Step::ShortName); break;
case Step::Timezone: enter(Step::Region); break;
case Step::Done: enter(Step::Timezone); break;
case Step::Welcome: break;
}
}
void SetupWizard::save() {
settings_.setString(Setting::LongName, longName_);
settings_.setString(Setting::ShortName, shortName_);
settings_.setString(Setting::Region, kRegions[region_].value);
settings_.setString(Setting::Timezone, kTimezones[timezone_].value);
settings_.setBool(Setting::RegionConfirmed, true);
settings_.setBool(Setting::SetupDone, true);
}
} // namespace roro
+46
View File
@@ -0,0 +1,46 @@
#pragma once
#include <string>
#include "line_editor.h"
#include "settings.h"
namespace roro {
// The first-boot setup flow: names, Region confirmation, timezone. Nothing is saved until the
// last step, so an interrupted setup simply starts again at the next boot.
class SetupWizard {
public:
enum class Step { Welcome, LongName, ShortName, Region, Timezone, Done };
SetupWizard(Settings& settings, std::string defaultLongName, std::string defaultShortName);
Step step() const { return step_; }
bool finished() const { return finished_; }
// Name steps edit text; Region and Timezone steps pick a choice.
LineEditor& editor() { return editor_; }
int choiceCount() const;
std::string choiceLabel(int i) const;
int selectedChoice() const;
void selectChoice(int i);
bool next(); // validates the step; false (with error()) if it can't advance
void back();
const std::string& error() const { return error_; }
private:
void enter(Step step);
void save();
Settings& settings_;
Step step_ = Step::Welcome;
bool finished_ = false;
std::string error_;
LineEditor editor_{39};
std::string longName_, shortName_;
int region_ = 0;
int timezone_ = 0;
};
} // namespace roro