From 13513810570007fd54c68b88dfa39afe9413c5c8 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 14 Aug 2024 17:37:50 -0600 Subject: [PATCH] fix: get right menu index --- firmware/main/modules/menus_module/menus.h | 174 +++++++++++++++++- .../main/modules/menus_module/menus_module.c | 37 ++-- 2 files changed, 189 insertions(+), 22 deletions(-) diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index de66f88..d33a963 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -89,13 +89,6 @@ typedef struct { uint8_t** submenus_idx; } menus_manager_t; -void apps_exit_cb() { - printf("apps_exit_cb\n"); -} -void apps_enter_cb() { - printf("apps_enter_cb\n"); -} - menu_t menus[] = {{.display_name = "Must Not See This", .menu_idx = MENU_MAIN_2, .parent_idx = -1, @@ -107,8 +100,8 @@ menu_t menus[] = {{.display_name = "Must Not See This", .menu_idx = MENU_APPLICATIONS_2, .parent_idx = MENU_MAIN_2, .input_cb = NULL, - .on_enter_cb = apps_enter_cb, - .on_exit_cb = apps_exit_cb, + .on_enter_cb = NULL, + .on_exit_cb = NULL, .is_visible = true}, {.display_name = "Settings", .menu_idx = MENU_SETTINGS_2, @@ -158,7 +151,7 @@ menu_t menus[] = {{.display_name = "Must Not See This", .input_cb = NULL, .on_enter_cb = NULL, .on_exit_cb = NULL, - .is_visible = false}, + .is_visible = true}, {.display_name = "Analyzer", .menu_idx = MENU_WIFI_ANALIZER_2, .parent_idx = MENU_WIFI_APPS_2, @@ -200,4 +193,165 @@ menu_t menus[] = {{.display_name = "Must Not See This", .input_cb = NULL, .on_enter_cb = NULL, .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Channel", + .menu_idx = MENU_WIFI_ANALYZER_CHANNEL_2, + .parent_idx = MENU_WIFI_ANALYZER_SETTINGS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Destination", + .menu_idx = MENU_WIFI_ANALYZER_DESTINATION_2, + .parent_idx = MENU_WIFI_ANALYZER_SETTINGS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Trakers scan", + .menu_idx = MENU_BLUETOOTH_TRAKERS_SCAN_2, + .parent_idx = MENU_BLUETOOTH_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Spam", + .menu_idx = MENU_BLUETOOTH_SPAM_2, + .parent_idx = MENU_BLUETOOTH_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Spoofing", + .menu_idx = MENU_ZIGBEE_SPOOFING_2, + .parent_idx = MENU_ZIGBEE_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Sniffer", + .menu_idx = MENU_ZIGBEE_SWITCH_2, + .parent_idx = MENU_ZIGBEE_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Switch", + .menu_idx = MENU_ZIGBEE_LIGHT_2, + .parent_idx = MENU_ZIGBEE_SPOOFING_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Light", + .menu_idx = MENU_ZIGBEE_SNIFFER_2, + .parent_idx = MENU_ZIGBEE_SPOOFING_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Broadcast", + .menu_idx = MENU_THREAD_BROADCAST_2, + .parent_idx = MENU_THREAD_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Sniffer", + .menu_idx = MENU_THREAD_SNIFFER_2, + .parent_idx = MENU_THREAD_APPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Run", + .menu_idx = MENU_THREAD_SNIFFER_RUN_2, + .parent_idx = MENU_THREAD_SNIFFER_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Wardriving", + .menu_idx = MENU_GPS_WARDRIVING_2, + .parent_idx = MENU_GPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Date & Time", + .menu_idx = MENU_GPS_DATE_TIME_2, + .parent_idx = MENU_GPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Location", + .menu_idx = MENU_GPS_LOCATION_2, + .parent_idx = MENU_GPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Speed", + .menu_idx = MENU_GPS_SPEED_2, + .parent_idx = MENU_GPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Help", + .menu_idx = MENU_GPS_HELP_2, + .parent_idx = MENU_GPS_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Start", + .menu_idx = MENU_GPS_WARDRIVING_START_2, + .parent_idx = MENU_GPS_WARDRIVING_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Help", + .menu_idx = MENU_GPS_WARDRIVING_HELP_2, + .parent_idx = MENU_GPS_WARDRIVING_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Version", + .menu_idx = MENU_ABOUT_VERSION_2, + .parent_idx = MENU_ABOUT_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "License", + .menu_idx = MENU_ABOUT_LICENSE_2, + .parent_idx = MENU_ABOUT_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Credits", + .menu_idx = MENU_ABOUT_CREDITS_2, + .parent_idx = MENU_ABOUT_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Legal", + .menu_idx = MENU_ABOUT_LEGAL_2, + .parent_idx = MENU_ABOUT_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, + .is_visible = true}, + {.display_name = "Update", + .menu_idx = MENU_ABOUT_UPDATE_2, + .parent_idx = MENU_ABOUT_2, + .input_cb = NULL, + .on_enter_cb = NULL, + .on_exit_cb = NULL, .is_visible = true}}; \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus_module.c b/firmware/main/modules/menus_module/menus_module.c index 8b05832..68c1ee2 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -10,8 +10,20 @@ menus_manager_t* menus_ctx; static void menus_input_cb(uint8_t button_name, uint8_t button_event); +static uint8_t get_menu_idx(menu_idx_t menu_idx) { + for (uint8_t i = 0; i < menus_ctx->menus_count; i++) { + if (menus[i].menu_idx == menu_idx) { + return i; + } + } + return 0; +} + static void update_menus() { if (menus_ctx->submenus_idx != NULL) { + for (uint8_t i = 0; i < menus_ctx->submenus_count; i++) { + free(menus_ctx->submenus_idx[i]); + } free(menus_ctx->submenus_idx); } menus_ctx->submenus_idx = NULL; @@ -21,19 +33,19 @@ static void update_menus() { menus_ctx->submenus_count++; } } - printf("Count: %d\n", menus_ctx->submenus_count); - menus_ctx->submenus_idx = malloc(menus_ctx->submenus_count); + if (!menus_ctx->submenus_count) { + return; + } + menus_ctx->submenus_idx = + malloc(menus_ctx->submenus_count * sizeof(uint8_t*)); uint8_t submenu_idx = 0; for (uint8_t i = 0; i < menus_ctx->menus_count; i++) { - printf("+++++++++++: %d\n", i); if (menus[i].is_visible && menus[i].parent_idx == menus_ctx->current_menu) { - printf("Submenu: %d\tMenuIdx: %d\n", submenu_idx, i); - menus_ctx->submenus_idx[submenu_idx++] = &menus[i].menu_idx; - printf("%s\n", menus[i].display_name); + menus_ctx->submenus_idx[submenu_idx] = malloc(sizeof(uint8_t)); + *menus_ctx->submenus_idx[submenu_idx] = i; + submenu_idx++; } - printf("+++++++++++: %d\n", i); } - printf("LINE: %d\n", __LINE__); } static void display_menus() { @@ -59,7 +71,7 @@ static void navigation_down() { } static void set_input_cb() { - void (*cb)() = menus[menus_ctx->current_menu].input_cb; + void (*cb)() = menus[get_menu_idx(menus_ctx->current_menu)].input_cb; if (cb) { menu_screens_set_app_state(true, cb); } else { @@ -74,7 +86,7 @@ static void navigation_enter() { menus[*menus_ctx->submenus_idx[menus_ctx->selected_submenu]].menu_idx; menus_ctx->selected_submenu = 0; refresh_menus(); - void (*cb)() = menus[menus_ctx->current_menu].on_enter_cb; + void (*cb)() = menus[get_menu_idx(menus_ctx->current_menu)].on_enter_cb; if (cb) { cb(); } @@ -85,11 +97,12 @@ static void navigation_exit() { if (menus_ctx->current_menu == MENU_MAIN_2) { return; } - void (*cb)() = menus[menus_ctx->current_menu].on_exit_cb; + void (*cb)() = menus[get_menu_idx(menus_ctx->current_menu)].on_exit_cb; if (cb) { cb(); } - menus_ctx->current_menu = menus[menus_ctx->current_menu].parent_idx; + menus_ctx->current_menu = + menus[get_menu_idx(menus_ctx->current_menu)].parent_idx; menus_ctx->selected_submenu = 0; refresh_menus(); set_input_cb();