Skip to content

Commit

Permalink
fix: get right menu index
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Aug 14, 2024
1 parent 1304e63 commit 1351381
Show file tree
Hide file tree
Showing 2 changed files with 189 additions and 22 deletions.
174 changes: 164 additions & 10 deletions firmware/main/modules/menus_module/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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}};
37 changes: 25 additions & 12 deletions firmware/main/modules/menus_module/menus_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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() {
Expand All @@ -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 {
Expand All @@ -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();
}
Expand All @@ -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();
Expand Down

0 comments on commit 1351381

Please sign in to comment.