From a4fbdd2c6488c0c99cb9c8635f8f0ff9d89dd84b Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 16 Aug 2024 20:21:28 -0600 Subject: [PATCH 1/7] refactor: file manager module over new menus system --- firmware/main/main.c | 2 +- firmware/main/modules/file_manager/file_manager_module.c | 3 +-- firmware/main/modules/menus_module/menus.h | 6 ++++-- firmware/main/modules/menus_module/menus_module.c | 2 +- firmware/main/modules/menus_module/menus_module.h | 1 + firmware/main/modules/settings/settings_module.c | 2 +- .../modules/web_file_browser/http_server/web_file_browser.c | 2 +- .../modules/web_file_browser/http_server/web_file_browser.h | 2 +- .../main/modules/web_file_browser/web_file_browser_module.c | 6 +++--- .../main/modules/web_file_browser/web_file_browser_module.h | 2 +- 10 files changed, 15 insertions(+), 13 deletions(-) diff --git a/firmware/main/main.c b/firmware/main/main.c index 048909cd..e2ba59b4 100644 --- a/firmware/main/main.c +++ b/firmware/main/main.c @@ -58,5 +58,5 @@ void app_main() { preferences_put_bool("wifi_connected", false); // cat_console_begin(); - trackers_module_begin(); + // trackers_module_begin(); } diff --git a/firmware/main/modules/file_manager/file_manager_module.c b/firmware/main/modules/file_manager/file_manager_module.c index bab43fa2..201e2c8a 100644 --- a/firmware/main/modules/file_manager/file_manager_module.c +++ b/firmware/main/modules/file_manager/file_manager_module.c @@ -131,8 +131,7 @@ static file_manager_context_t* file_manager_context_alloc() { static void file_manager_module_exit() { clear_items(); free(fm_ctx); - menu_screens_exit_submenu(); - menus_module_set_app_state(false, NULL); + menus_module_exit_app(); } static void navigation_up() { diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 6200045a..2da009bb 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -4,7 +4,9 @@ #include "apps/ble/hid_device/hid_module.h" #include "apps/ble/trackers/trackers_module.h" +#include "file_manager_module.h" #include "ota_module.h" +#include "web_file_browser_module.h" typedef enum { MENU_MAIN_2 = 0, @@ -466,7 +468,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_FILE_MANAGER_LOCAL_2, .parent_idx = MENU_FILE_MANAGER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = file_manager_module_init, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -475,7 +477,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_FILE_MANAGER_WEB_2, .parent_idx = MENU_FILE_MANAGER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = web_file_browser_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif diff --git a/firmware/main/modules/menus_module/menus_module.c b/firmware/main/modules/menus_module/menus_module.c index c8fc3d94..85c37713 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -156,7 +156,7 @@ static void show_logo() { buzzer_stop(); } -void screen_module_set_reset_screen(menu_idx_t menu) { +void menus_module_set_reset_screen(menu_idx_t menu) { preferences_put_int("MENUNUMBER", menu); modals_module_show_banner("Exiting..."); } diff --git a/firmware/main/modules/menus_module/menus_module.h b/firmware/main/modules/menus_module/menus_module.h index 6e692b2b..0cb52774 100644 --- a/firmware/main/modules/menus_module/menus_module.h +++ b/firmware/main/modules/menus_module/menus_module.h @@ -23,4 +23,5 @@ void menus_module_disable_input(); void menus_module_set_app_state(bool in_app, input_callback_t input_cb); menu_idx_t menus_module_get_current_menu(); bool menus_module_get_app_state(); +void menus_module_set_reset_screen(menu_idx_t menu); void menus_module_exit_app(); \ No newline at end of file diff --git a/firmware/main/modules/settings/settings_module.c b/firmware/main/modules/settings/settings_module.c index 41cb52f8..e10fe304 100644 --- a/firmware/main/modules/settings/settings_module.c +++ b/firmware/main/modules/settings/settings_module.c @@ -77,7 +77,7 @@ void settings_module_enter_submenu_cb(screen_module_menu_t user_selection) { file_manager_module_init(); break; case MENU_FILE_MANAGER_WEB: - web_file_browser_module_init(); + web_file_browser_module_begin(); break; case MENU_SETTINGS_DISPLAY: display_config_module_begin(); diff --git a/firmware/main/modules/web_file_browser/http_server/web_file_browser.c b/firmware/main/modules/web_file_browser/http_server/web_file_browser.c index 32dcb3d0..d72775a8 100644 --- a/firmware/main/modules/web_file_browser/http_server/web_file_browser.c +++ b/firmware/main/modules/web_file_browser/http_server/web_file_browser.c @@ -39,7 +39,7 @@ static void web_file_browser_show_event(uint8_t event, void* context) { } } -void web_file_browser_init() { +void web_file_browser_begin() { #if !defined(CONFIG_WEB_FILE_BROWSER_DEBUG) esp_log_level_set(TAG, ESP_LOG_NONE); #endif diff --git a/firmware/main/modules/web_file_browser/http_server/web_file_browser.h b/firmware/main/modules/web_file_browser/http_server/web_file_browser.h index 5a22447e..1ae7646e 100644 --- a/firmware/main/modules/web_file_browser/http_server/web_file_browser.h +++ b/firmware/main/modules/web_file_browser/http_server/web_file_browser.h @@ -14,6 +14,6 @@ typedef enum { typedef void (*web_file_browser_show_event_cb_t)(uint8_t, void*); web_file_browser_show_event_cb_t wfb_show_event_cb = NULL; -void web_file_browser_init(); +void web_file_browser_begin(); void web_file_browser_stop(); void web_file_browser_set_show_event_cb(web_file_browser_show_event_cb_t cb); \ No newline at end of file diff --git a/firmware/main/modules/web_file_browser/web_file_browser_module.c b/firmware/main/modules/web_file_browser/web_file_browser_module.c index 451f7dd6..0e32f19c 100644 --- a/firmware/main/modules/web_file_browser/web_file_browser_module.c +++ b/firmware/main/modules/web_file_browser/web_file_browser_module.c @@ -15,7 +15,7 @@ static void web_file_browser_input_cb(uint8_t button_name, uint8_t button_event); static void web_file_browser_module_exit(); -void web_file_browser_module_init() { +void web_file_browser_module_begin() { oled_screen_clear(); menus_module_set_app_state(true, web_file_browser_input_cb); if (sd_card_mount() == ESP_OK || flash_fs_mount() == ESP_OK) { @@ -25,7 +25,7 @@ void web_file_browser_module_init() { } // wifi_ap_init(); web_file_browser_set_show_event_cb(web_file_browse_show_event_handler); - web_file_browser_init(); + web_file_browser_begin(); } else { oled_screen_display_text(" SD Card ", 0, 3, OLED_DISPLAY_NORMAL); oled_screen_display_text(" Mount Failed ", 0, 4, OLED_DISPLAY_NORMAL); @@ -34,7 +34,7 @@ void web_file_browser_module_init() { } } void web_file_browser_module_exit() { - screen_module_set_screen(MENU_FILE_MANAGER_WEB); + menus_module_set_reset_screen(MENU_FILE_MANAGER_2); esp_restart(); } static void web_file_browser_input_cb(uint8_t button_name, diff --git a/firmware/main/modules/web_file_browser/web_file_browser_module.h b/firmware/main/modules/web_file_browser/web_file_browser_module.h index c8eb2f3c..8f33c52b 100644 --- a/firmware/main/modules/web_file_browser/web_file_browser_module.h +++ b/firmware/main/modules/web_file_browser/web_file_browser_module.h @@ -1,3 +1,3 @@ #pragma once -void web_file_browser_module_init(); \ No newline at end of file +void web_file_browser_module_begin(); \ No newline at end of file From 663c009cd9ad9ce20dd113a80dc1dd5bb8dd7293 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 16 Aug 2024 20:50:29 -0600 Subject: [PATCH 2/7] refactor: display module over new menus system TODO: screen saver selection from array --- firmware/main/modules/menus_module/menus.h | 3 ++- firmware/main/modules/settings/display/display_settings.c | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 2da009bb..39181009 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -4,6 +4,7 @@ #include "apps/ble/hid_device/hid_module.h" #include "apps/ble/trackers/trackers_module.h" +#include "display_settings.h" #include "file_manager_module.h" #include "ota_module.h" #include "web_file_browser_module.h" @@ -417,7 +418,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_SETTINGS_DISPLAY_2, .parent_idx = MENU_SETTINGS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = display_config_module_begin, .on_exit_cb = NULL, .is_visible = true}, {.display_name = "System", diff --git a/firmware/main/modules/settings/display/display_settings.c b/firmware/main/modules/settings/display/display_settings.c index 9629c652..e2638f7a 100644 --- a/firmware/main/modules/settings/display/display_settings.c +++ b/firmware/main/modules/settings/display/display_settings.c @@ -115,8 +115,7 @@ static void display_config_module_state_machine(uint8_t button_name, } switch (button_name) { case BUTTON_LEFT: - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); break; case BUTTON_RIGHT: ESP_LOGI(TAG_DISPLAY_CONFIG, "Selected item: %d", selected_item); From 7bc430834423ae4c722bec9381fb6c3ef712647c Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 16 Aug 2024 21:49:29 -0600 Subject: [PATCH 3/7] feat: screen saver runs by pressing back on Main menu --- firmware/main/modules/menus_module/menus.h | 3 ++- firmware/main/modules/menus_module/menus_module.c | 14 +++++--------- firmware/main/modules/screen_saver/screen_saver.c | 2 +- .../modules/settings/stealth_mode/stealth_mode.c | 3 +-- 4 files changed, 9 insertions(+), 13 deletions(-) diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 39181009..044e8296 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -7,6 +7,7 @@ #include "display_settings.h" #include "file_manager_module.h" #include "ota_module.h" +#include "stealth_mode.h" #include "web_file_browser_module.h" typedef enum { @@ -487,6 +488,6 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_STEALTH_MODE_2, .parent_idx = MENU_SETTINGS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = stealth_mode_open_menu, .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 85c37713..8150efc9 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -2,7 +2,7 @@ #include -#include "leds.h" +#include "led_events.h" #include "menu_screens_modules.h" #include "menus_screens.h" #include "modals_module.h" @@ -93,6 +93,7 @@ static void navigation_enter() { static void navigation_exit() { if (menus_ctx->current_menu == MENU_MAIN_2) { + screen_saver_run(); return; } menus[get_menu_idx(menus_ctx->current_menu)].last_selected_submenu = @@ -149,11 +150,9 @@ static void menus_input_cb(uint8_t button_name, uint8_t button_event) { static void show_logo() { oled_screen_clear(); - leds_on(); - buzzer_play(); + led_control_run_effect(led_control_pulse_leds); + buzzer_play_for(100); screen_saver_run(); - vTaskDelay(500 / portTICK_PERIOD_MS); - buzzer_stop(); } void menus_module_set_reset_screen(menu_idx_t menu) { @@ -163,12 +162,9 @@ void menus_module_set_reset_screen(menu_idx_t menu) { static void get_reset_menu() { menus_ctx->current_menu = preferences_get_int("MENUNUMBER", MENU_MAIN_2); - - if ((int) menus_ctx->current_menu == MENU_MAIN) { - preferences_put_int("logo_show", 1); + if ((int) menus_ctx->current_menu == MENU_MAIN_2) { show_logo(); } else { - preferences_put_int("logo_show", 0); preferences_put_int("MENUNUMBER", MENU_MAIN_2); screen_saver_get_idle_state(); refresh_menus(); diff --git a/firmware/main/modules/screen_saver/screen_saver.c b/firmware/main/modules/screen_saver/screen_saver.c index 9f870445..2e16d635 100644 --- a/firmware/main/modules/screen_saver/screen_saver.c +++ b/firmware/main/modules/screen_saver/screen_saver.c @@ -16,7 +16,7 @@ esp_timer_handle_t screen_savar_idle_timer2; void screen_saver_run(); static void timer_callback() { - if (menus_module_get_app_state()) { + if (menus_module_get_app_state() || screen_saver_running) { return; } diff --git a/firmware/main/modules/settings/stealth_mode/stealth_mode.c b/firmware/main/modules/settings/stealth_mode/stealth_mode.c index 916817c3..ed8ef026 100644 --- a/firmware/main/modules/settings/stealth_mode/stealth_mode.c +++ b/firmware/main/modules/settings/stealth_mode/stealth_mode.c @@ -24,8 +24,7 @@ static void set_stealth_status() { buzzer_enable(); leds_begin(); } - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); vTaskDelete(NULL); } From 85d9ef7b111352142bd23644dc199b1ece80f7b9 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Sun, 18 Aug 2024 09:28:02 -0600 Subject: [PATCH 4/7] refactor: thread apps working over new menus system --- firmware/main/modules/menus_module/menus.h | 11 +-- .../modules/open_thread/open_thread_module.c | 71 ++++++++----------- .../modules/open_thread/open_thread_module.h | 12 ++-- 3 files changed, 42 insertions(+), 52 deletions(-) diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 044e8296..9f689cfa 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -6,6 +6,7 @@ #include "display_settings.h" #include "file_manager_module.h" +#include "open_thread_module.h" #include "ota_module.h" #include "stealth_mode.h" #include "web_file_browser_module.h" @@ -318,8 +319,8 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_THREAD_BROADCAST_2, .parent_idx = MENU_THREAD_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = open_thread_module_broadcast_enter, + .on_exit_cb = open_thread_module_exit, .is_visible = true}, #endif #ifdef CONFIG_THREAD_APP_SNIFFER @@ -327,14 +328,14 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_THREAD_SNIFFER_2, .parent_idx = MENU_THREAD_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = open_thread_module_sniffer_enter, + .on_exit_cb = open_thread_module_exit, .is_visible = true}, {.display_name = "Run", .menu_idx = MENU_THREAD_SNIFFER_RUN_2, .parent_idx = MENU_THREAD_SNIFFER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = open_thread_module_sniffer_run, .on_exit_cb = NULL, .is_visible = true}, #endif diff --git a/firmware/main/modules/open_thread/open_thread_module.c b/firmware/main/modules/open_thread/open_thread_module.c index 18ab944f..62f9808b 100644 --- a/firmware/main/modules/open_thread/open_thread_module.c +++ b/firmware/main/modules/open_thread/open_thread_module.c @@ -15,48 +15,12 @@ uint8_t channel = 15; static void thread_broadcast_input(uint8_t button_name, uint8_t button_event); static void thread_sniffer_input(uint8_t button_name, uint8_t button_event); -static void open_thread_module_exit_submenu_cb(); -static void open_thread_module_enter_submenu_cb( - screen_module_menu_t user_selection); void open_thread_module_begin() { #if !defined(CONFIG_OPEN_THREAD_MODULE_DEBUG) esp_log_level_set(TAG_OT_MODULE, ESP_LOG_NONE); #endif radio_selector_set_thread(); - menu_screens_register_enter_submenu_cb(open_thread_module_enter_submenu_cb); - menu_screens_register_exit_submenu_cb(open_thread_module_exit_submenu_cb); -} - -void open_thread_module_exit() { - screen_module_set_screen(MENU_THREAD_SNIFFER); - esp_restart(); -} - -static void open_thread_module_enter_submenu_cb( - screen_module_menu_t user_selection) { - oled_screen_clear(); - switch (user_selection) { - case MENU_THREAD_BROADCAST: - menus_module_set_app_state(true, thread_broadcast_input); - led_control_run_effect(led_control_zigbee_scanning); - open_thread_screens_display_broadcast_mode(channel); - thread_broadcast_set_on_msg_recieve_cb( - open_thread_screens_show_new_message); - thread_broadcast_init(); - break; - case MENU_THREAD_SNIFFER: - thread_sniffer_set_show_event_cb(thread_sniffer_show_event_handler); - thread_sniffer_init(); - break; - case MENU_THREAD_SNIFFER_RUN: - menus_module_set_app_state(true, thread_sniffer_input); - led_control_run_effect(led_control_zigbee_scanning); - thread_sniffer_run(); - break; - default: - break; - } } static void open_thread_module_exit_submenu_cb() { @@ -73,15 +37,39 @@ static void open_thread_module_exit_submenu_cb() { } } +void open_thread_module_exit() { + menus_module_set_reset_screen(MENU_THREAD_APPS_2); + esp_restart(); +} + +void open_thread_module_broadcast_enter() { + radio_selector_set_thread(); + menus_module_set_app_state(true, thread_broadcast_input); + led_control_run_effect(led_control_zigbee_scanning); + open_thread_screens_display_broadcast_mode(channel); + thread_broadcast_set_on_msg_recieve_cb(open_thread_screens_show_new_message); + thread_broadcast_init(); +} + +void open_thread_module_sniffer_enter() { + radio_selector_set_thread(); + thread_sniffer_set_show_event_cb(thread_sniffer_show_event_handler); + thread_sniffer_init(); +} +void open_thread_module_sniffer_run() { + menus_module_set_app_state(true, thread_sniffer_input); + led_control_run_effect(led_control_zigbee_scanning); + thread_sniffer_run(); +} + static void thread_broadcast_input(uint8_t button_name, uint8_t button_event) { - if (button_event != BUTTON_SINGLE_CLICK) { + if (button_event != BUTTON_PRESS_DOWN) { return; } switch (button_name) { case BUTTON_LEFT: led_control_stop(); - screen_module_set_screen(MENU_THREAD_BROADCAST); - esp_restart(); + open_thread_module_exit(); break; case BUTTON_RIGHT: case BUTTON_UP: @@ -102,15 +90,14 @@ static void thread_broadcast_input(uint8_t button_name, uint8_t button_event) { } static void thread_sniffer_input(uint8_t button_name, uint8_t button_event) { - if (button_event != BUTTON_SINGLE_CLICK) { + if (button_event != BUTTON_PRESS_DOWN) { return; } switch (button_name) { case BUTTON_LEFT: thread_sniffer_stop(); led_control_stop(); - menu_screens_exit_submenu(); - menus_module_set_app_state(false, NULL); + menus_module_exit_app(); break; case BUTTON_RIGHT: break; diff --git a/firmware/main/modules/open_thread/open_thread_module.h b/firmware/main/modules/open_thread/open_thread_module.h index 5c471d22..d2612cc3 100644 --- a/firmware/main/modules/open_thread/open_thread_module.h +++ b/firmware/main/modules/open_thread/open_thread_module.h @@ -1,10 +1,12 @@ #pragma once #define TAG_OT_MODULE "open_thread:main" -/** - * @brief Begin the bluetooth module - * - * @param app_selected The selected app - */ + void open_thread_module_begin(); void open_thread_module_exit(); + +void open_thread_module_broadcast_enter(); + +void open_thread_module_sniffer_enter(); + +void open_thread_module_sniffer_run(); \ No newline at end of file From 6eca7946bff947eed6591e0fa9c0ec48fd45b804 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Sun, 18 Aug 2024 09:44:16 -0600 Subject: [PATCH 5/7] refactor: zigbee working over new menus system --- firmware/main/modules/menus_module/menus.h | 5 +- firmware/main/modules/zigbee/zigbee_module.c | 161 +++++++++---------- firmware/main/modules/zigbee/zigbee_module.h | 5 + 3 files changed, 86 insertions(+), 85 deletions(-) diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 9f689cfa..d5509694 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -10,6 +10,7 @@ #include "ota_module.h" #include "stealth_mode.h" #include "web_file_browser_module.h" +#include "zigbee_module.h" typedef enum { MENU_MAIN_2 = 0, @@ -285,7 +286,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_ZIGBEE_LIGHT_2, .parent_idx = MENU_ZIGBEE_SPOOFING_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = zigbee_module_switch_enter, .on_exit_cb = NULL, .is_visible = true}, {.display_name = "Light", @@ -301,7 +302,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_ZIGBEE_SWITCH_2, .parent_idx = MENU_ZIGBEE_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = zigbee_module_sniffer_enter, .on_exit_cb = NULL, .is_visible = true}, #endif diff --git a/firmware/main/modules/zigbee/zigbee_module.c b/firmware/main/modules/zigbee/zigbee_module.c index a5473b44..99c7a778 100644 --- a/firmware/main/modules/zigbee/zigbee_module.c +++ b/firmware/main/modules/zigbee/zigbee_module.c @@ -23,8 +23,8 @@ static TaskHandle_t zigbee_task_display_animation = NULL; static TaskHandle_t zigbee_task_sniffer = NULL; static void zigbee_module_app_selector(); -static void zigbee_module_state_machine(uint8_t button_name, - uint8_t button_event); +static void switch_input_cb(uint8_t button_name, uint8_t button_event); +static void sniffer_input_cb(uint8_t button_name, uint8_t button_event); static void zigbee_module_display_records_cb(uint8_t* packet, uint8_t packet_length) { @@ -41,106 +41,62 @@ void zigbee_module_begin(int app_selected) { #if !defined(CONFIG_ZIGBEE_MODULE_DEBUG) esp_log_level_set(TAG_ZIGBEE_MODULE, ESP_LOG_NONE); #endif - - ESP_LOGI(TAG_ZIGBEE_MODULE, - "Initializing zigbee module screen state machine"); - app_screen_state_information.app_selected = app_selected; - - menus_module_set_app_state(true, zigbee_module_state_machine); - oled_screen_clear(OLED_DISPLAY_NORMAL); - zigbee_module_app_selector(); }; void zigbee_module_app_selector() { switch (app_screen_state_information.app_selected) { case MENU_ZIGBEE_SWITCH: - radio_selector_set_zigbee_switch(); - zigbee_switch_set_display_status_cb(zigbee_screens_module_display_status); - zigbee_switch_init(); break; case MENU_ZIGBEE_SNIFFER: - radio_selector_set_zigbee_sniffer(); - zigbee_screens_display_device_ad(); - vTaskDelay(8000 / portTICK_PERIOD_MS); - ieee_sniffer_register_cb(zigbee_module_display_records_cb); - zigbee_screens_display_zigbee_sniffer_text(); - animations_task_run(zigbee_screens_display_scanning_animation, 200, NULL); - xTaskCreate(ieee_sniffer_begin, "ieee_sniffer_task", 4096, NULL, 5, - &zigbee_task_sniffer); - led_control_run_effect(led_control_zigbee_scanning); break; default: break; } } -void zigbee_module_state_machine(uint8_t button_name, uint8_t button_event) { - switch (app_screen_state_information.app_selected) { - case MENU_ZIGBEE_SWITCH: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Switch Entered"); - switch (button_name) { - case BUTTON_RIGHT: - switch (button_event) { - case BUTTON_PRESS_DOWN: - if (zigbee_switch_is_light_connected()) { - zigbee_screens_module_toogle_pressed(); - } - break; - case BUTTON_PRESS_UP: - if (zigbee_switch_is_light_connected()) { - zigbee_screens_module_toggle_released(); - zigbee_switch_toggle(); - } - break; +void zigbee_module_switch_enter() { + radio_selector_set_zigbee_switch(); + menus_module_set_app_state(true, switch_input_cb); + zigbee_switch_set_display_status_cb(zigbee_screens_module_display_status); + zigbee_switch_init(); +} + +void zigbee_module_sniffer_enter() { + radio_selector_set_zigbee_sniffer(); + menus_module_set_app_state(true, sniffer_input_cb); + zigbee_screens_display_device_ad(); + vTaskDelay(8000 / portTICK_PERIOD_MS); + ieee_sniffer_register_cb(zigbee_module_display_records_cb); + zigbee_screens_display_zigbee_sniffer_text(); + animations_task_run(zigbee_screens_display_scanning_animation, 200, NULL); + xTaskCreate(ieee_sniffer_begin, "ieee_sniffer_task", 4096, NULL, 5, + &zigbee_task_sniffer); + led_control_run_effect(led_control_zigbee_scanning); +} + +static void switch_input_cb(uint8_t button_name, uint8_t button_event) { + ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Switch Entered"); + switch (button_name) { + case BUTTON_RIGHT: + switch (button_event) { + case BUTTON_PRESS_DOWN: + if (zigbee_switch_is_light_connected()) { + zigbee_screens_module_toogle_pressed(); } break; - case BUTTON_LEFT: - switch (button_event) { - case BUTTON_PRESS_DOWN: - screen_module_set_screen(MENU_ZIGBEE_SWITCH); - zigbee_switch_deinit(); - break; + case BUTTON_PRESS_UP: + if (zigbee_switch_is_light_connected()) { + zigbee_screens_module_toggle_released(); + zigbee_switch_toggle(); } break; - default: - break; } break; - case MENU_ZIGBEE_SNIFFER: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Sniffer Entered"); - switch (button_name) { - case BUTTON_LEFT: - if (button_event == BUTTON_SINGLE_CLICK) { - led_control_stop(); - screen_module_set_screen(MENU_ZIGBEE_SNIFFER); - esp_restart(); - } - break; - case BUTTON_RIGHT: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button right pressed - Option selected"); - break; - case BUTTON_UP: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button up pressed"); - if (button_event == BUTTON_SINGLE_CLICK) { - current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) - ? IEEE_SNIFFER_CHANNEL_MIN - : (current_channel + 1); - ieee_sniffer_set_channel(current_channel); - // zigbee_screens_display_scanning_text(0, current_channel); - } - break; - case BUTTON_DOWN: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button down pressed"); - if (button_event == BUTTON_SINGLE_CLICK) { - current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MIN) - ? IEEE_SNIFFER_CHANNEL_MAX - : (current_channel - 1); - ieee_sniffer_set_channel(current_channel); - // zigbee_screens_display_scanning_text(0, current_channel); - } - break; - case BUTTON_BOOT: - default: + case BUTTON_LEFT: + switch (button_event) { + case BUTTON_PRESS_DOWN: + menus_module_set_reset_screen(MENU_ZIGBEE_SPOOFING_2); + zigbee_switch_deinit(); break; } break; @@ -148,3 +104,42 @@ void zigbee_module_state_machine(uint8_t button_name, uint8_t button_event) { break; } } + +static void sniffer_input_cb(uint8_t button_name, uint8_t button_event) { + ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Sniffer Entered"); + switch (button_name) { + case BUTTON_LEFT: + if (button_event == BUTTON_SINGLE_CLICK) { + led_control_stop(); + menus_module_set_reset_screen(MENU_ZIGBEE_APPS_2); + esp_restart(); + } + break; + case BUTTON_RIGHT: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button right pressed - Option selected"); + break; + case BUTTON_UP: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button up pressed"); + if (button_event == BUTTON_SINGLE_CLICK) { + current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) + ? IEEE_SNIFFER_CHANNEL_MIN + : (current_channel + 1); + ieee_sniffer_set_channel(current_channel); + // zigbee_screens_display_scanning_text(0, current_channel); + } + break; + case BUTTON_DOWN: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button down pressed"); + if (button_event == BUTTON_SINGLE_CLICK) { + current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MIN) + ? IEEE_SNIFFER_CHANNEL_MAX + : (current_channel - 1); + ieee_sniffer_set_channel(current_channel); + // zigbee_screens_display_scanning_text(0, current_channel); + } + break; + case BUTTON_BOOT: + default: + break; + } +} diff --git a/firmware/main/modules/zigbee/zigbee_module.h b/firmware/main/modules/zigbee/zigbee_module.h index 6a1c2fd0..db8c07e5 100644 --- a/firmware/main/modules/zigbee/zigbee_module.h +++ b/firmware/main/modules/zigbee/zigbee_module.h @@ -7,4 +7,9 @@ * @param app_selected The selected app */ void zigbee_module_begin(int app_selected); + +void zigbee_module_switch_enter(); + +void zigbee_module_sniffer_enter(); + #endif // ZIGBEE_MODULE_H From 93ad638dfdff66231e653d59ac4ef37191c150de Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Sun, 18 Aug 2024 10:29:49 -0600 Subject: [PATCH 6/7] refactor: deauth & DOS working over new menus system --- .../main/apps/wifi/deauth/deauth_module.c | 3 +- firmware/main/modules/cat_dos/catdos_module.c | 3 +- .../main/modules/keyboard/keyboard_module.c | 16 --------- .../menu_screens/menu_screens_modules.h | 2 -- firmware/main/modules/menus_module/menus.h | 17 +++++---- firmware/main/modules/wifi/wifi_module.c | 35 ++++++++++++++++--- firmware/main/modules/wifi/wifi_module.h | 13 ++++--- 7 files changed, 48 insertions(+), 41 deletions(-) diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index 7246c718..61d965cb 100644 --- a/firmware/main/apps/wifi/deauth/deauth_module.c +++ b/firmware/main/apps/wifi/deauth/deauth_module.c @@ -208,8 +208,7 @@ static void deauth_module_cb_event(uint8_t button_name, uint8_t button_event) { case BUTTON_LEFT: wifi_scanner_clear_ap_records(); printf("Exit deauth: %d\n", current_item); - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); // led_control_stop(); break; default: diff --git a/firmware/main/modules/cat_dos/catdos_module.c b/firmware/main/modules/cat_dos/catdos_module.c index e4c2f86c..f2337741 100644 --- a/firmware/main/modules/cat_dos/catdos_module.c +++ b/firmware/main/modules/cat_dos/catdos_module.c @@ -592,8 +592,7 @@ static void catdos_module_state_machine(uint8_t button_name, case CATDOS_STATE_CONFIG_WIFI: { switch (button_name) { case BUTTON_LEFT: - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); break; case BUTTON_RIGHT: ESP_LOGI(CATDOS_TAG, "Selected item: %d", selected_item); diff --git a/firmware/main/modules/keyboard/keyboard_module.c b/firmware/main/modules/keyboard/keyboard_module.c index 82e2cea7..57b3c7d8 100644 --- a/firmware/main/modules/keyboard/keyboard_module.c +++ b/firmware/main/modules/keyboard/keyboard_module.c @@ -12,17 +12,6 @@ esp_timer_handle_t idle_timer; static bool is_idle = false; static bool lock_input = false; -void timer_callback() { - screen_module_menu_t menu = menu_screens_get_current_menu(); - if (menu == MENU_WIFI_ANALYZER_RUN || menu == MENU_WIFI_ANALYZER_SUMMARY || - menu == MENU_GPS_DATE_TIME || menu == MENU_GPS_LOCATION || - menu == MENU_GPS_SPEED) { - return; - } - - is_idle = true; - screen_saver_run(); -} void keyboard_module_reset_idle_timer() { esp_timer_stop(idle_timer); esp_timer_start_once(idle_timer, IDLE_TIMEOUT_S * 1000 * 1000); @@ -123,9 +112,4 @@ void keyboard_module_begin() { button_init(RIGHT_BUTTON_PIN, RIGHT_BUTTON_MASK); button_init(UP_BUTTON_PIN, UP_BUTTON_MASK); button_init(DOWN_BUTTON_PIN, DOWN_BUTTON_MASK); - esp_timer_create_args_t timer_args = {.callback = timer_callback, - .arg = NULL, - - .name = "one_shot_timer"}; - esp_err_t err = esp_timer_create(&timer_args, &idle_timer); } diff --git a/firmware/main/modules/menu_screens/menu_screens_modules.h b/firmware/main/modules/menu_screens/menu_screens_modules.h index 69db698c..5c2396d0 100644 --- a/firmware/main/modules/menu_screens/menu_screens_modules.h +++ b/firmware/main/modules/menu_screens/menu_screens_modules.h @@ -192,6 +192,4 @@ void menu_screens_update_options(char* options[], uint8_t selected_option); * @return void */ void screen_module_set_screen(int current_menu); - -static void screen_saver_run(); void stop_screen_saver(); \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index d5509694..d3976fb3 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -4,12 +4,15 @@ #include "apps/ble/hid_device/hid_module.h" #include "apps/ble/trackers/trackers_module.h" +#include "catdos_module.h" +#include "deauth_module.h" #include "display_settings.h" #include "file_manager_module.h" #include "open_thread_module.h" #include "ota_module.h" #include "stealth_mode.h" #include "web_file_browser_module.h" +#include "wifi_module.h" #include "zigbee_module.h" typedef enum { @@ -172,15 +175,15 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_ANALIZER_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = wifi_module_analizer_begin, + .on_exit_cb = wifi_module_analizer_exit, .is_visible = true}, {.display_name = "Start", .menu_idx = MENU_WIFI_ANALYZER_RUN_2, .parent_idx = MENU_WIFI_ANALIZER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = wifi_module_init_sniffer, + .on_exit_cb = wifi_module_analyzer_run_exit, .is_visible = true}, {.display_name = "Settings", .menu_idx = MENU_WIFI_ANALYZER_SETTINGS_2, @@ -201,7 +204,7 @@ menu_t menus[] = { ////////////////////////////////// .parent_idx = MENU_WIFI_ANALYZER_SETTINGS_2, .last_selected_submenu = 0, .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_exit_cb = wifi_module_analyzer_destination_exit, .is_visible = true}, {.display_name = "Help", .menu_idx = MENU_WIFI_ANALYZER_HELP_2, @@ -216,7 +219,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_DEAUTH_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = deauth_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -225,7 +228,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_DOS_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = catdos_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif diff --git a/firmware/main/modules/wifi/wifi_module.c b/firmware/main/modules/wifi/wifi_module.c index bbd8c9a0..56fb82a0 100644 --- a/firmware/main/modules/wifi/wifi_module.c +++ b/firmware/main/modules/wifi/wifi_module.c @@ -10,15 +10,15 @@ #include "string.h" #include "apps/wifi/deauth/include/deauth_module.h" -#include "captive_portal.h" #include "led_events.h" #include "menu_screens_modules.h" -#include "modules/wifi/wifi_module.h" +#include "menus_module.h" #include "modules/wifi/wifi_screens_module.h" #include "oled_screen.h" #include "sd_card.h" #include "wifi_attacks.h" #include "wifi_controller.h" +#include "wifi_module.h" #include "wifi_scanner.h" static const char* TAG = "wifi_module"; @@ -115,6 +115,34 @@ void wifi_module_init_sniffer() { led_control_run_effect(led_control_zigbee_scanning); } +void wifi_module_analyzer_run_exit() { + wifi_sniffer_stop(); + led_control_stop(); + wifi_sniffer_load_summary(); +} + +void wifi_module_analizer_summary_exit() { + wifi_sniffer_close_file(); +} + +void wifi_module_analizer_exit() { + menus_module_set_reset_screen(MENU_WIFI_APPS_2); + esp_restart(); +} + +void wifi_module_analyzer_destination_exit() { + if (wifi_sniffer_is_destination_sd()) { + // Verify if the SD card is inserted + sd_card_unmount(); + if (sd_card_mount() == ESP_OK) { + vTaskDelay(100 / portTICK_PERIOD_MS); + sd_card_unmount(); + } else { + wifi_sniffer_set_destination_internal(); + } + } +} + void wifi_module_exit_submenu_cb() { screen_module_menu_t current_menu = menu_screens_get_current_menu(); @@ -123,9 +151,6 @@ void wifi_module_exit_submenu_cb() { menu_screens_unregister_submenu_cbs(); break; case MENU_WIFI_ANALYZER_RUN: - wifi_sniffer_stop(); - led_control_stop(); - wifi_sniffer_load_summary(); break; case MENU_WIFI_ANALYZER_ASK_SUMMARY: oled_screen_clear(); diff --git a/firmware/main/modules/wifi/wifi_module.h b/firmware/main/modules/wifi/wifi_module.h index b74aca81..0304bc9c 100644 --- a/firmware/main/modules/wifi/wifi_module.h +++ b/firmware/main/modules/wifi/wifi_module.h @@ -11,13 +11,6 @@ */ void wifi_module_begin(); -/** - * @brief Initialize the wifi module - * - * @return void - */ -void wifi_module_deauth_begin(); - /** * @brief Initialize the wifi module * @@ -25,11 +18,17 @@ void wifi_module_deauth_begin(); */ void wifi_module_analizer_begin(); +void wifi_module_init_sniffer(); + /** * @brief Stop the wifi module * */ void wifi_module_exit(void); +void wifi_module_analyzer_run_exit(); +void wifi_module_analizer_exit(); +void wifi_module_analizer_summary_exit(); +void wifi_module_analyzer_destination_exit(); /** * @brief Callback to show the summary of the wifi analizer From 8e2c1e9c54ddaa4fb6ca79d56970a5202696ab13 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Mon, 19 Aug 2024 12:03:36 -0600 Subject: [PATCH 7/7] refactor: set reset screen function name --- firmware/main/modules/menus_module/menus_module.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/main/modules/menus_module/menus_module.c b/firmware/main/modules/menus_module/menus_module.c index 629e2f65..bc997a38 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -189,7 +189,7 @@ void menus_module_set_app_state(bool in_app, input_callback_t input_cb) { void menus_module_exit_app() { app_state2.in_app = false; app_state2.input_callback = NULL; - screen_module_set_reset_screen(menus_ctx->parent_menu_idx); + menus_module_set_reset_screen(menus_ctx->parent_menu_idx); esp_restart(); } @@ -197,7 +197,7 @@ void menus_module_exit_app_information() { app_state2.in_app = false; app_state2.input_callback = NULL; keyboard_module_set_input_callback(menus_input_cb); - screen_module_set_reset_screen(menus_ctx->parent_menu_idx); + menus_module_set_reset_screen(menus_ctx->parent_menu_idx); screen_saver_get_idle_state(); navigation_exit(); }