Public Access
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:
@@ -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
|
||||
Reference in New Issue
Block a user