Skip to content

Commit

Permalink
refactor: thread apps working over new menus system
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Aug 18, 2024
1 parent 7bc4308 commit 85d9ef7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 52 deletions.
11 changes: 6 additions & 5 deletions firmware/main/modules/menus_module/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -318,23 +319,23 @@ 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
{.display_name = "Sniffer",
.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
Expand Down
71 changes: 29 additions & 42 deletions firmware/main/modules/open_thread/open_thread_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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:
Expand All @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions firmware/main/modules/open_thread/open_thread_module.h
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit 85d9ef7

Please sign in to comment.