Public Access
The Storage App browses the SD card: folders first with sizes and dates, three sorts, one item at a time with a clipboard (c, x, v), rename, delete after counting what's inside, new folder, details. A listing holds 256 entries and says when a folder has more. FileOps does the card's work for the App and the console alike, one operation at a time on the storage task in turns of about 150 ms, so Logs and Captures are still written during a long copy. A copy shows progress, can be cancelled (what it wrote is taken back) and compares sizes after. The read-only rules are checked there: the firmware's top-level folders, /gemini/cache, and files being written (a Track, a Capture, an upload, today's IRC Logs). A listing reads the folder straight from FatFs: through the Arduino File, 329 entries took over two seconds. Viewers by type: text read a screen at a time whatever the file's size (logs open at the end), a hex dump, a Capture's packets as the LoRa Scanner lists them, a Track's summary, and an Update File checked as an install would check it, without writing anything. Tab shows any file as hex or text. Settings > Storage is gone: usage, Storage Clean-up and Erase are the App's Maintenance, behind a warning. The Storage Warning points there. The Clock sets the system time whatever its source, so files are dated correctly with a GNSS Fix alone (Q137). Console: cp, mv, mkdir, du, cancel; rm takes folders and follows the rules; ls shows dates; Debug Builds get `sd fill`. 424 host tests. Checked on the device: docs/milestones/F1.md. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
154 lines
6.3 KiB
C++
154 lines
6.3 KiB
C++
#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::Gnss, Kind::Toggle, "GNSS"}, {Row::GnssQuiet, Kind::Toggle, "Pause GNSS for LoRa"},
|
|
{Row::Coordinates, Kind::Toggle, "Coordinates"},
|
|
{Row::ProbeMacs, Kind::Toggle, "Probe MACs"}, {Row::Wifi, Kind::Page, "Wi-Fi"},
|
|
{Row::Firmware, Kind::Page, "Firmware"},
|
|
{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::Gnss: return settings_.getBool(Setting::GnssEnabled) ? "On" : "Off";
|
|
case Row::GnssQuiet: return settings_.getBool(Setting::GnssQuietForLora) ? "On" : "Off";
|
|
case Row::Coordinates: return settings_.getBool(Setting::CoordinatesDms) ? "Deg min sec" : "Decimal";
|
|
case Row::ProbeMacs: return settings_.getBool(Setting::ProbeMacRaw) ? "Raw" : "Pseudonymised";
|
|
case Row::Wifi: return settings_.getBool(Setting::WifiEnabled) ? "On" : "Off";
|
|
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::Gnss) settings_.setBool(Setting::GnssEnabled, !settings_.getBool(Setting::GnssEnabled));
|
|
if (row(i) == Row::GnssQuiet) settings_.setBool(Setting::GnssQuietForLora, !settings_.getBool(Setting::GnssQuietForLora));
|
|
if (row(i) == Row::Coordinates) settings_.setBool(Setting::CoordinatesDms, !settings_.getBool(Setting::CoordinatesDms));
|
|
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
|