adding flasher

This commit is contained in:
Brent Perteet
2025-10-12 13:40:31 -05:00
parent a89fdc6843
commit 04d2c71d01
18 changed files with 1034 additions and 194 deletions

View File

@@ -72,6 +72,13 @@ static lv_obj_t* create_volume_page(void);
static void update_volume_display(int volume);
static void ensure_menu_styles(void);
// Menu stack management functions
static void menu_stack_push(lv_obj_t *page);
static lv_obj_t* menu_stack_pop(void);
static void menu_stack_clear(void);
static bool menu_stack_is_empty(void);
static void menu_go_back(void);
#define MAX_ITEMS 10
#define VISIBLE_ITEMS 3
#define MENU_MAX_STRING_LENGTH 30
@@ -91,6 +98,15 @@ static lv_obj_t *_currentPage = NULL;
static GuiMode_t _mode = GUI_BUBBLE;
// Menu navigation stack
#define MAX_MENU_STACK_SIZE 8
typedef struct {
lv_obj_t *pages[MAX_MENU_STACK_SIZE];
int count;
} menu_stack_t;
static menu_stack_t _menuStack = {0};
/* 1. Prepare a default (unfocused) style */
static lv_style_t _styleUnfocusedBtn;
@@ -135,6 +151,9 @@ static void show_menu(void) {
lv_obj_t* menu = create_menu_container();
lv_obj_t* main_page = create_main_page();
// Clear the menu stack when starting fresh menu navigation
menu_stack_clear();
lv_menu_set_page(menu, main_page);
_currentPage = main_page;
@@ -180,7 +199,8 @@ static void lcd_init(void)
.miso_io_num = -1,
.quadwp_io_num = -1,
.quadhd_io_num = -1,
.max_transfer_sz = LCD_H_RES * LCD_V_RES * 2
//.max_transfer_sz = LCD_H_RES * LCD_V_RES * 2
.max_transfer_sz = LCD_H_RES * 25 * (LCD_BITS_PER_PIXEL/8),
};
ESP_ERROR_CHECK(spi_bus_initialize(LCD_SPI_HOST, &buscfg, SPI_DMA_CH_AUTO));
@@ -236,7 +256,8 @@ static void lvgl_init(void)
const lvgl_port_display_cfg_t disp_cfg = {
.io_handle = io_handle,
.panel_handle = panel_handle,
.buffer_size = LCD_H_RES * LCD_V_RES * 2,
// .buffer_size = LCD_H_RES * LCD_V_RES * 2,
.buffer_size = LCD_H_RES * 25 * (LCD_BITS_PER_PIXEL/8), // was full screen
.double_buffer = false,
.hres = LCD_H_RES,
.vres = LCD_V_RES,
@@ -347,12 +368,20 @@ static void btn_click_cb(lv_event_t * e) {
// Handle specific menu items
if (strcmp(txt, "Bluetooth") == 0) {
LOCK();
// Push current page onto stack before navigating
menu_stack_push(_currentPage);
show_bt_device_list();
UNLOCK();
} else if (strcmp(txt, "Volume") == 0) {
LOCK();
// Push current page onto stack before navigating
menu_stack_push(_currentPage);
show_volume_control();
UNLOCK();
} else if (strcmp(txt, "Back") == 0) {
LOCK();
menu_go_back();
UNLOCK();
} else if (strcmp(txt, "Exit") == 0) {
LOCK();
_mode = GUI_BUBBLE;
@@ -609,8 +638,7 @@ static void bt_device_click_cb(lv_event_t * e) {
if (strcmp(txt, "Back") == 0) {
LOCK();
bt_stop_discovery();
_mode = GUI_MENU;
show_menu();
menu_go_back();
UNLOCK();
return;
} else if (strcmp(txt, "Refresh") == 0) {
@@ -803,6 +831,10 @@ static lv_obj_t* create_volume_page(void) {
lv_obj_align(instr2, LV_ALIGN_BOTTOM_MID, 0, -10);
#endif
// Add Back button
lv_obj_t* back_btn = addMenuItem(_volume_page, "Back");
lv_obj_add_event_cb(back_btn, btn_click_cb, LV_EVENT_CLICKED, NULL);
return _volume_page;
}
@@ -831,6 +863,64 @@ static void show_volume_control(void) {
ESP_LOGI(TAG, "Volume control displayed");
}
// Menu stack management functions
static void menu_stack_push(lv_obj_t *page) {
if (_menuStack.count < MAX_MENU_STACK_SIZE && page != NULL) {
_menuStack.pages[_menuStack.count++] = page;
ESP_LOGI(TAG, "Menu stack push: page=%p, count=%d", page, _menuStack.count);
} else if (_menuStack.count >= MAX_MENU_STACK_SIZE) {
ESP_LOGW(TAG, "Menu stack overflow, cannot push more pages");
}
}
static lv_obj_t* menu_stack_pop(void) {
if (_menuStack.count > 0) {
lv_obj_t *page = _menuStack.pages[--_menuStack.count];
ESP_LOGI(TAG, "Menu stack pop: page=%p, count=%d", page, _menuStack.count);
return page;
}
ESP_LOGI(TAG, "Menu stack is empty, cannot pop");
return NULL;
}
static void menu_stack_clear(void) {
_menuStack.count = 0;
ESP_LOGI(TAG, "Menu stack cleared");
}
static bool menu_stack_is_empty(void) {
return (_menuStack.count == 0);
}
static void menu_go_back(void) {
ESP_LOGI(TAG, "Menu go back requested");
if (menu_stack_is_empty()) {
ESP_LOGI(TAG, "Menu stack empty, returning to bubble mode");
_mode = GUI_BUBBLE;
show_bubble();
return;
}
lv_obj_t *previous_page = menu_stack_pop();
if (previous_page != NULL) {
ESP_LOGI(TAG, "Returning to previous menu page");
lv_obj_t* menu = create_menu_container();
if (menu) {
lv_menu_set_page(menu, previous_page);
_currentPage = previous_page;
_mode = GUI_MENU;
lv_obj_remove_flag(menu, LV_OBJ_FLAG_HIDDEN);
lv_obj_add_flag(_bubble, LV_OBJ_FLAG_HIDDEN);
}
} else {
ESP_LOGI(TAG, "No previous page found, returning to bubble mode");
_mode = GUI_BUBBLE;
show_bubble();
}
}
static void update_volume_display(int volume) {
if (_volume_bar && _volume_label) {
LOCK();
@@ -1029,8 +1119,7 @@ static void gui_task(void *pvParameters)
LOCK();
if (_mode == GUI_MENU)
{
_mode = GUI_BUBBLE;
show_bubble(); // Cleanup menu and show bubble
menu_go_back(); // Use menu stack navigation
}
else
{