mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-07-26 23:08:11 +00:00
Settings: add Home Pages visibility control
New "Home Pages" section in Settings lets the user toggle which pages appear in the home screen carousel. Settings and Messages are always shown; Clock, Recent, Radio, Bluetooth, Advert, GPS, Sensors, Tools and Shutdown can each be hidden individually. - NodePrefs: home_pages_mask uint16_t (bit per page, 0=all visible) - HomeScreen: isPageVisible/navPage skip hidden pages; dots indicator counts only visible pages; enforces visible page on re-entry - SettingsScreen: SECTION_HOME_PAGES with per-page ON/OFF toggles - DataStore: persisted at offset 1598 - Default: all pages visible (0x01FF) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -251,6 +251,9 @@ void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& no
|
||||
file.read((uint8_t *)&_prefs.ringtone_len, sizeof(_prefs.ringtone_len)); // 1564
|
||||
if (_prefs.ringtone_len > 32) _prefs.ringtone_len = 0;
|
||||
file.read((uint8_t *)_prefs.ringtone_notes, sizeof(_prefs.ringtone_notes)); // 1565
|
||||
if (file.available()) {
|
||||
file.read((uint8_t *)&_prefs.home_pages_mask, sizeof(_prefs.home_pages_mask)); // 1598
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -308,6 +311,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
|
||||
file.write((uint8_t *)&_prefs.ringtone_bpm_idx, sizeof(_prefs.ringtone_bpm_idx)); // 1563
|
||||
file.write((uint8_t *)&_prefs.ringtone_len, sizeof(_prefs.ringtone_len)); // 1564
|
||||
file.write((uint8_t *)_prefs.ringtone_notes, sizeof(_prefs.ringtone_notes)); // 1565
|
||||
file.write((uint8_t *)&_prefs.home_pages_mask, sizeof(_prefs.home_pages_mask)); // 1598
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
@@ -867,6 +867,7 @@ MyMesh::MyMesh(mesh::Radio &radio, mesh::RNG &rng, mesh::RTCClock &rtc, SimpleMe
|
||||
_prefs.buzzer_volume = 4; // max volume by default
|
||||
_prefs.ringtone_bpm_idx = 2; // 120 bpm default
|
||||
_prefs.ringtone_len = 0; // no custom ringtone by default
|
||||
_prefs.home_pages_mask = 0x01FF; // all pages visible
|
||||
_prefs.auto_off_secs = 15; // 15 seconds auto-off by default
|
||||
_prefs.tz_offset_hours = 0; // UTC by default
|
||||
_prefs.low_batt_mv = 3400; // auto-shutdown at 3.4V by default
|
||||
|
||||
@@ -48,4 +48,5 @@ struct NodePrefs { // persisted to file
|
||||
uint8_t ringtone_bpm_idx; // index into {60,90,120,150,180}
|
||||
uint8_t ringtone_len; // number of notes in custom ringtone (0 = use default)
|
||||
uint8_t ringtone_notes[32]; // packed: bits0-2=pitch, bits3-4=octave-4, bits5-6=dur_idx
|
||||
uint16_t home_pages_mask; // bitmask of visible home pages (bit0=Clock..bit8=Shutdown); 0=all visible
|
||||
};
|
||||
@@ -84,6 +84,19 @@ public:
|
||||
|
||||
static const int QUICK_MSGS_MAX = 10;
|
||||
|
||||
// Bit positions for NodePrefs::home_pages_mask.
|
||||
// Bit=1 means page is shown. 0 in the field means ALL visible (default/unset).
|
||||
static const uint16_t HP_CLOCK = 1 << 0;
|
||||
static const uint16_t HP_RECENT = 1 << 1;
|
||||
static const uint16_t HP_RADIO = 1 << 2;
|
||||
static const uint16_t HP_BLUETOOTH = 1 << 3;
|
||||
static const uint16_t HP_ADVERT = 1 << 4;
|
||||
static const uint16_t HP_GPS = 1 << 5;
|
||||
static const uint16_t HP_SENSORS = 1 << 6;
|
||||
static const uint16_t HP_TOOLS = 1 << 7;
|
||||
static const uint16_t HP_SHUTDOWN = 1 << 8;
|
||||
static const uint16_t HP_ALL = 0x01FF;
|
||||
|
||||
// On-screen keyboard layout (4 rows × 10 cols)
|
||||
static const char KB_CHARS[4][10] = {
|
||||
{'a','b','c','d','e','f','g','h','i','j'},
|
||||
@@ -117,6 +130,16 @@ class SettingsScreen : public UIScreen {
|
||||
SECTION_SOUND,
|
||||
BUZZER,
|
||||
BUZZER_VOLUME,
|
||||
// Home pages section
|
||||
SECTION_HOME_PAGES,
|
||||
HOME_CLOCK, HOME_RECENT, HOME_RADIO, HOME_BT, HOME_ADVERT,
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
HOME_GPS,
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
HOME_SENSORS,
|
||||
#endif
|
||||
HOME_TOOLS, HOME_SHUTDOWN,
|
||||
// Radio section
|
||||
SECTION_RADIO,
|
||||
TX_POWER,
|
||||
@@ -198,6 +221,7 @@ class SettingsScreen : public UIScreen {
|
||||
|
||||
bool isSection(int item) const {
|
||||
return item == SECTION_DISPLAY || item == SECTION_SOUND ||
|
||||
item == SECTION_HOME_PAGES ||
|
||||
item == SECTION_RADIO || item == SECTION_SYSTEM ||
|
||||
item == SECTION_CONTACTS || item == SECTION_MESSAGES
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
@@ -207,18 +231,74 @@ class SettingsScreen : public UIScreen {
|
||||
}
|
||||
|
||||
const char* sectionName(int item) const {
|
||||
if (item == SECTION_DISPLAY) return "Display";
|
||||
if (item == SECTION_SOUND) return "Sound";
|
||||
if (item == SECTION_RADIO) return "Radio";
|
||||
if (item == SECTION_SYSTEM) return "System";
|
||||
if (item == SECTION_CONTACTS) return "Contacts";
|
||||
if (item == SECTION_MESSAGES) return "Messages";
|
||||
if (item == SECTION_DISPLAY) return "Display";
|
||||
if (item == SECTION_SOUND) return "Sound";
|
||||
if (item == SECTION_HOME_PAGES) return "Home Pages";
|
||||
if (item == SECTION_RADIO) return "Radio";
|
||||
if (item == SECTION_SYSTEM) return "System";
|
||||
if (item == SECTION_CONTACTS) return "Contacts";
|
||||
if (item == SECTION_MESSAGES) return "Messages";
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
if (item == SECTION_GPS) return "GPS";
|
||||
if (item == SECTION_GPS) return "GPS";
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
bool isHomePage(int item) const {
|
||||
return item == HOME_CLOCK || item == HOME_RECENT || item == HOME_RADIO ||
|
||||
item == HOME_BT || item == HOME_ADVERT || item == HOME_TOOLS ||
|
||||
item == HOME_SHUTDOWN
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
|| item == HOME_GPS
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
|| item == HOME_SENSORS
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
uint16_t homePageBit(int item) const {
|
||||
if (item == HOME_CLOCK) return HP_CLOCK;
|
||||
if (item == HOME_RECENT) return HP_RECENT;
|
||||
if (item == HOME_RADIO) return HP_RADIO;
|
||||
if (item == HOME_BT) return HP_BLUETOOTH;
|
||||
if (item == HOME_ADVERT) return HP_ADVERT;
|
||||
if (item == HOME_TOOLS) return HP_TOOLS;
|
||||
if (item == HOME_SHUTDOWN) return HP_SHUTDOWN;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
if (item == HOME_GPS) return HP_GPS;
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
if (item == HOME_SENSORS) return HP_SENSORS;
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char* homePageLabel(int item) const {
|
||||
if (item == HOME_CLOCK) return "Clock";
|
||||
if (item == HOME_RECENT) return "Recent";
|
||||
if (item == HOME_RADIO) return "Radio";
|
||||
if (item == HOME_BT) return "Bluetooth";
|
||||
if (item == HOME_ADVERT) return "Advert";
|
||||
if (item == HOME_TOOLS) return "Tools";
|
||||
if (item == HOME_SHUTDOWN) return "Shutdown";
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
if (item == HOME_GPS) return "GPS";
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
if (item == HOME_SENSORS) return "Sensors";
|
||||
#endif
|
||||
return "";
|
||||
}
|
||||
|
||||
bool homePageVisible(int item, const NodePrefs* p) const {
|
||||
uint16_t bit = homePageBit(item);
|
||||
if (!bit) return false;
|
||||
uint16_t mask = p ? p->home_pages_mask : HP_ALL;
|
||||
if (mask == 0) mask = HP_ALL;
|
||||
return (mask & bit) != 0;
|
||||
}
|
||||
|
||||
bool isMsgSlot(int item) const {
|
||||
return item >= MSG_SLOT_0 && item <= MSG_SLOT_9;
|
||||
}
|
||||
@@ -283,6 +363,10 @@ class SettingsScreen : public UIScreen {
|
||||
display.setCursor(VAL_X, y);
|
||||
display.print("N/A");
|
||||
#endif
|
||||
} else if (isHomePage(item)) {
|
||||
display.print(homePageLabel(item));
|
||||
display.setCursor(VAL_X, y);
|
||||
display.print(homePageVisible(item, p) ? "ON" : "OFF");
|
||||
} else if (item == TX_POWER) {
|
||||
display.print("TX Pwr");
|
||||
char buf[8];
|
||||
@@ -594,6 +678,13 @@ public:
|
||||
#endif
|
||||
return right || left;
|
||||
}
|
||||
if (isHomePage(_selected) && p && (left || right || enter)) {
|
||||
uint16_t bit = homePageBit(_selected);
|
||||
uint16_t mask = p->home_pages_mask ? p->home_pages_mask : HP_ALL;
|
||||
p->home_pages_mask = mask ^ bit;
|
||||
_dirty = true;
|
||||
return true;
|
||||
}
|
||||
if (_selected == TX_POWER && p) {
|
||||
if (right && p->tx_power_dbm < 22) { p->tx_power_dbm++; _task->applyTxPower(); _dirty = true; return true; }
|
||||
if (left && p->tx_power_dbm > 2) { p->tx_power_dbm--; _task->applyTxPower(); _dirty = true; return true; }
|
||||
@@ -2057,6 +2148,38 @@ class HomeScreen : public UIScreen {
|
||||
bool _shutdown_init;
|
||||
AdvertPath recent[UI_RECENT_LIST_SIZE];
|
||||
|
||||
int pageBit(int page) const {
|
||||
if (page == CLOCK) return 0;
|
||||
if (page == RECENT) return 1;
|
||||
if (page == RADIO) return 2;
|
||||
if (page == BLUETOOTH) return 3;
|
||||
if (page == ADVERT) return 4;
|
||||
#if ENV_INCLUDE_GPS == 1
|
||||
if (page == GPS) return 5;
|
||||
#endif
|
||||
#if UI_SENSORS_PAGE == 1
|
||||
if (page == SENSORS) return 6;
|
||||
#endif
|
||||
if (page == TOOLS) return 7;
|
||||
if (page == SHUTDOWN) return 8;
|
||||
return -1; // SETTINGS, QUICK_MSG always visible
|
||||
}
|
||||
|
||||
bool isPageVisible(int page) const {
|
||||
int bit = pageBit(page);
|
||||
if (bit < 0) return true;
|
||||
uint16_t mask = _node_prefs ? _node_prefs->home_pages_mask : HP_ALL;
|
||||
if (mask == 0) mask = HP_ALL;
|
||||
return (mask >> bit) & 1;
|
||||
}
|
||||
|
||||
int navPage(int from, int dir) const {
|
||||
for (int i = 1; i < (int)Count; i++) {
|
||||
int next = ((from + dir * i) % (int)Count + (int)Count) % (int)Count;
|
||||
if (isPageVisible(next)) return next;
|
||||
}
|
||||
return from;
|
||||
}
|
||||
|
||||
void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) {
|
||||
#ifndef BATT_MIN_MILLIVOLTS
|
||||
@@ -2201,14 +2324,27 @@ public:
|
||||
// battery voltage
|
||||
renderBatteryIndicator(display, _task->getBattMilliVolts());
|
||||
|
||||
// curr page indicator
|
||||
int y = 14;
|
||||
int x = display.width() / 2 - 5 * (HomePage::Count-1);
|
||||
for (uint8_t i = 0; i < HomePage::Count; i++, x += 10) {
|
||||
if (i == _page) {
|
||||
display.fillRect(x-1, y-1, 3, 3);
|
||||
} else {
|
||||
display.fillRect(x, y, 1, 1);
|
||||
// ensure current page is visible (e.g. after settings change)
|
||||
if (!isPageVisible(_page)) {
|
||||
for (int i = 0; i < (int)Count; i++) { if (isPageVisible(i)) { _page = i; break; } }
|
||||
}
|
||||
|
||||
// curr page indicator — only visible pages get a dot
|
||||
{
|
||||
int vis_count = 0, curr_vis = 0;
|
||||
for (int i = 0; i < (int)Count; i++) {
|
||||
if (!isPageVisible(i)) continue;
|
||||
if (i == _page) curr_vis = vis_count;
|
||||
vis_count++;
|
||||
}
|
||||
int y = 14;
|
||||
int x = display.width() / 2 - 5 * (vis_count - 1);
|
||||
int vi = 0;
|
||||
for (int i = 0; i < (int)Count; i++) {
|
||||
if (!isPageVisible(i)) continue;
|
||||
if (vi == curr_vis) display.fillRect(x-1, y-1, 3, 3);
|
||||
else display.fillRect(x, y, 1, 1);
|
||||
x += 10; vi++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2451,11 +2587,11 @@ public:
|
||||
|
||||
bool handleInput(char c) override {
|
||||
if (c == KEY_LEFT || c == KEY_PREV) {
|
||||
_page = (_page + HomePage::Count - 1) % HomePage::Count;
|
||||
_page = navPage(_page, -1);
|
||||
return true;
|
||||
}
|
||||
if (c == KEY_NEXT || c == KEY_RIGHT) {
|
||||
_page = (_page + 1) % HomePage::Count;
|
||||
_page = navPage(_page, +1);
|
||||
if (_page == HomePage::RECENT) {
|
||||
_task->showAlert("Recent adverts", 800);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user