mirror of
https://github.com/meshtastic/firmware.git
synced 2025-12-29 14:10:53 +00:00
Role picker
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -22,6 +22,7 @@ enum MenuPage : uint8_t {
|
||||
OPTIONS,
|
||||
NODE_CONFIG,
|
||||
NODE_CONFIG_LORA,
|
||||
NODE_CONFIG_ROLE,
|
||||
APPLETS,
|
||||
AUTOSHOW,
|
||||
RECENTS, // Select length of "recentlyActiveSeconds"
|
||||
|
||||
Reference in New Issue
Block a user