Skip to content

Commit 974cb8c

Browse files
committed
Wired up commands - still a lot of work and testing
1 parent 58cb7f2 commit 974cb8c

File tree

2 files changed

+61
-22
lines changed

2 files changed

+61
-22
lines changed

src/graphics/draw/MenuHandler.cpp

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ BannerOverlayOptions createStaticBannerOptions(const char *message, const MenuOp
5959
} // namespace
6060

6161
menuHandler::screenMenus menuHandler::menuQueue = menu_none;
62+
uint32_t menuHandler::pickedNodeNum = 0;
6263
bool test_enabled = false;
6364
uint8_t test_count = 0;
6465

@@ -1284,6 +1285,10 @@ void menuHandler::NodePicker()
12841285
}
12851286
screen->showNodePicker(NODE_PICKER_TITLE, 30000, [](uint32_t nodenum) -> void {
12861287
LOG_INFO("Nodenum: %u", nodenum);
1288+
// Store the selection so the Manage Node menu knows which node to operate on
1289+
menuHandler::pickedNodeNum = nodenum;
1290+
// Keep UI favorite context in sync (used elsewhere for some node-based actions)
1291+
graphics::UIRenderer::currentFavoriteNodeNum = nodenum;
12871292
menuQueue = Manage_Node_menu;
12881293
screen->runNow();
12891294
});
@@ -1307,6 +1312,12 @@ void menuHandler::addFavoriteMenu()
13071312

13081313
void menuHandler::ManageNodeMenu()
13091314
{
1315+
// If we don't have a node selected yet, prompt for one and then return — the callback will re-enter this menu
1316+
auto node = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
1317+
if (!node) {
1318+
return;
1319+
}
1320+
13101321
enum class ManageNodeAction { Favorite, Mute, TraceRoute, KeyVerification, IgnoreNode };
13111322

13121323
static const ManageNodeOption baseOptions[] = {
@@ -1321,8 +1332,13 @@ void menuHandler::ManageNodeMenu()
13211332
constexpr size_t baseCount = sizeof(baseOptions) / sizeof(baseOptions[0]);
13221333
static std::array<const char *, baseCount> baseLabels{};
13231334

1324-
auto onSelection = [](const PositionMenuOption &option, int) -> void {
1335+
// Build a friendly title including node name (if present)
1336+
std::string title = "Manage Node";
1337+
1338+
auto onSelection = [node](const ManageNodeOption &option, int) -> void {
13251339
if (option.action == OptionsAction::Back) {
1340+
menuQueue = node_base_menu;
1341+
screen->runNow();
13261342
return;
13271343
}
13281344

@@ -1332,35 +1348,57 @@ void menuHandler::ManageNodeMenu()
13321348

13331349
auto action = static_cast<ManageNodeAction>(option.value);
13341350
switch (action) {
1335-
case ManageNodeAction::Favorite:
1336-
LOG_INFO("User selected Favorite");
1337-
// menuQueue = add_favorite;
1338-
// screen->runNow();
1351+
case ManageNodeAction::Favorite: {
1352+
// VERIFIED
1353+
LOG_INFO("Adding node %08X to favorites", menuHandler::pickedNodeNum);
1354+
nodeDB->set_favorite(true, menuHandler::pickedNodeNum);
1355+
screen->setFrames(graphics::Screen::FOCUS_PRESERVE);
13391356
break;
1340-
case ManageNodeAction::Mute:
1341-
LOG_INFO("User selected Mute");
1342-
// menuQueue = ADD_SOMETHING_HERE;
1343-
// screen->runNow();
1357+
}
1358+
case ManageNodeAction::Mute: {
1359+
// NEEDS TESTING
1360+
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
1361+
if (n) {
1362+
n->bitfield ^= (1 << NODEINFO_BITFIELD_IS_MUTED_SHIFT);
1363+
LOG_INFO("Toggled mute for node %08X (bitfield=0x%08x)", menuHandler::pickedNodeNum, n->bitfield);
1364+
nodeDB->notifyObservers(true);
1365+
screen->setFrames(graphics::Screen::FOCUS_PRESERVE);
1366+
}
13441367
break;
1345-
case ManageNodeAction::TraceRoute:
1346-
LOG_INFO("User selected TraceRoute");
1347-
// menuQueue = ADD_SOMETHING_HERE;
1348-
// screen->runNow();
1368+
}
1369+
case ManageNodeAction::TraceRoute: {
1370+
// VERIFIED
1371+
LOG_INFO("Starting traceroute to %08X", menuHandler::pickedNodeNum);
1372+
if (traceRouteModule) {
1373+
traceRouteModule->startTraceRoute(menuHandler::pickedNodeNum);
1374+
}
13491375
break;
1350-
case ManageNodeAction::KeyVerification:
1351-
LOG_INFO("User selected KeyVerification");
1352-
// menuQueue = ADD_SOMETHING_HERE;
1353-
// screen->runNow();
1376+
}
1377+
case ManageNodeAction::KeyVerification: {
1378+
// VERIFIED
1379+
LOG_INFO("Initiating key verification with %08X", menuHandler::pickedNodeNum);
1380+
if (keyVerificationModule) {
1381+
keyVerificationModule->sendInitialRequest(menuHandler::pickedNodeNum);
1382+
}
13541383
break;
1355-
case ManageNodeAction::IgnoreNode:
1356-
LOG_INFO("User selected IgnoreNode");
1357-
// menuQueue = ADD_SOMETHING_HERE;
1358-
// screen->runNow();
1384+
}
1385+
case ManageNodeAction::IgnoreNode: {
1386+
// NEEDS TESTING
1387+
auto n = nodeDB->getMeshNode(menuHandler::pickedNodeNum);
1388+
if (n) {
1389+
n->is_ignored = true;
1390+
LOG_INFO("Ignoring node %08X", menuHandler::pickedNodeNum);
1391+
nodeDB->notifyObservers(true);
1392+
}
1393+
screen->setFrames(graphics::Screen::FOCUS_PRESERVE);
13591394
break;
13601395
}
1396+
}
13611397
};
1398+
13621399
BannerOverlayOptions bannerOptions;
1363-
bannerOptions = createStaticBannerOptions("Manage Node", baseOptions, baseLabels, onSelection);
1400+
bannerOptions.message = title.c_str();
1401+
bannerOptions = createStaticBannerOptions(title.c_str(), baseOptions, baseLabels, onSelection);
13641402
screen->showOverlayBanner(bannerOptions);
13651403
}
13661404

src/graphics/draw/MenuHandler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class menuHandler
5757
DisplayUnits
5858
};
5959
static screenMenus menuQueue;
60+
static uint32_t pickedNodeNum; // node selected by NodePicker for ManageNodeMenu
6061

6162
static void OnboardMessage();
6263
static void LoraRegionPicker(uint32_t duration = 30000);

0 commit comments

Comments
 (0)