diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h index 57fe480e9..e083f7451 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuAction.h @@ -62,6 +62,11 @@ enum MenuAction { SET_REGION_KZ_863, SET_REGION_NP_865, SET_REGION_BR_902, + // Device Roles + SET_ROLE_CLIENT, + SET_ROLE_CLIENT_MUTE, + SET_ROLE_ROUTER, + SET_ROLE_REPEATER, }; } // namespace NicheGraphics::InkHUD diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp index 4560d462f..cf4205a9b 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuApplet.cpp @@ -199,6 +199,20 @@ static void applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode region) rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000; } +static void applyDeviceRole(meshtastic_Config_DeviceConfig_Role role) +{ + if (config.device.role == role) + return; + + config.device.role = role; + + nodeDB->saveToDisk(SEGMENT_CONFIG); + + service->reloadConfig(SEGMENT_CONFIG); + + rebootAtMsec = millis() + DEFAULT_REBOOT_SECONDS * 1000; +} + // Perform action for a menu item, then change page // Behaviors for MenuActions are defined here void InkHUD::MenuApplet::execute(MenuItem item) @@ -320,6 +334,7 @@ void InkHUD::MenuApplet::execute(MenuItem item) rebootAtMsec = millis() + 2000; break; + // Regions case SET_REGION_US: applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_US); break; @@ -423,6 +438,23 @@ void InkHUD::MenuApplet::execute(MenuItem item) applyLoRaRegion(meshtastic_Config_LoRaConfig_RegionCode_BR_902); break; + // Roles + case SET_ROLE_CLIENT: + applyDeviceRole(meshtastic_Config_DeviceConfig_Role_CLIENT); + break; + + case SET_ROLE_CLIENT_MUTE: + applyDeviceRole(meshtastic_Config_DeviceConfig_Role_CLIENT_MUTE); + break; + + case SET_ROLE_ROUTER: + applyDeviceRole(meshtastic_Config_DeviceConfig_Role_ROUTER); + break; + + case SET_ROLE_REPEATER: + applyDeviceRole(meshtastic_Config_DeviceConfig_Role_REPEATER); + break; + default: LOG_WARN("Action not implemented"); } @@ -528,7 +560,7 @@ void InkHUD::MenuApplet::showPage(MenuPage page) // Role const char *role = DisplayFormatters::getDeviceRole(config.device.role); nodeConfigLabels.emplace_back("Role: " + std::string(role)); - items.push_back(MenuItem(nodeConfigLabels.back().c_str(), MenuAction::NO_ACTION, MenuPage::NODE_CONFIG_LORA)); + items.push_back(MenuItem(nodeConfigLabels.back().c_str(), MenuAction::NO_ACTION, MenuPage::NODE_CONFIG_ROLE)); // Preset const char *preset = @@ -578,6 +610,16 @@ void InkHUD::MenuApplet::showPage(MenuPage page) items.push_back(MenuItem("Exit", MenuPage::EXIT)); break; + case NODE_CONFIG_ROLE: { + + items.push_back(MenuItem("Client", MenuAction::SET_ROLE_CLIENT, MenuPage::EXIT)); + items.push_back(MenuItem("Client Mute", MenuAction::SET_ROLE_CLIENT_MUTE, MenuPage::EXIT)); + items.push_back(MenuItem("Router", MenuAction::SET_ROLE_ROUTER, MenuPage::EXIT)); + items.push_back(MenuItem("Repeater", MenuAction::SET_ROLE_REPEATER, MenuPage::EXIT)); + items.push_back(MenuItem("Exit", MenuPage::NODE_CONFIG_LORA)); + break; + } + case EXIT: sendToBackground(); // Menu applet dismissed, allow normal behavior to resume break; diff --git a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuPage.h b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuPage.h index 14924eb50..a7746cd25 100644 --- a/src/graphics/niche/InkHUD/Applets/System/Menu/MenuPage.h +++ b/src/graphics/niche/InkHUD/Applets/System/Menu/MenuPage.h @@ -22,6 +22,7 @@ enum MenuPage : uint8_t { OPTIONS, NODE_CONFIG, NODE_CONFIG_LORA, + NODE_CONFIG_ROLE, APPLETS, AUTOSHOW, RECENTS, // Select length of "recentlyActiveSeconds"