diff --git a/Code/pico_multi_booter/sd_boot/main.c b/Code/pico_multi_booter/sd_boot/main.c index 8d4fe50..ea8ad44 100644 --- a/Code/pico_multi_booter/sd_boot/main.c +++ b/Code/pico_multi_booter/sd_boot/main.c @@ -203,7 +203,7 @@ static bool is_valid_application(uint32_t *app_location) int load_firmware_by_path(const char *path) { - text_directory_ui_set_status("STAT: loading app..."); + text_directory_ui_set_status("STAT: Flashing firmware..."); // Attempt to load the application from the SD card // bool load_success = load_program(FIRMWARE_PATH); @@ -222,7 +222,7 @@ int load_firmware_by_path(const char *path) if (load_success || has_valid_app) { - text_directory_ui_set_status("STAT: launching app..."); + text_directory_ui_set_status("STAT: Launching app..."); DEBUG_PRINT("launching app\n"); // Small delay to allow printf to complete sleep_ms(100); @@ -299,18 +299,25 @@ int main() keypad_init(); lcd_init(); lcd_clear(); - + text_directory_ui_pre_init(); + // Check for SD card presence DEBUG_PRINT("Checking for SD card...\n"); if (!sd_card_inserted()) { DEBUG_PRINT("SD card not detected\n"); - text_directory_ui_set_status("SD card not detected. \nPlease insert SD card."); - + text_directory_ui_set_status("SD card not detected."); + text_directory_ui_update_header(1); // Poll until SD card is inserted + text_directory_ui_draw_default_app(); + text_directory_ui_set_final_callback(final_selection_callback); while (!sd_card_inserted()) { - sleep_ms(100); + int key = keypad_get_key(); + if (key != 0) + process_key_event(key); + + sleep_ms(20); } // Card detected, wait for it to stabilize diff --git a/Code/pico_multi_booter/sd_boot/text_directory_ui.c b/Code/pico_multi_booter/sd_boot/text_directory_ui.c index ecffa02..b4e8f46 100644 --- a/Code/pico_multi_booter/sd_boot/text_directory_ui.c +++ b/Code/pico_multi_booter/sd_boot/text_directory_ui.c @@ -85,9 +85,8 @@ static uint32_t last_scrolling = 0; // for text scrolling in selected entry // Forward declarations static void ui_refresh(void); static void load_directory(const char *path); -static void process_key_event(int key); static void ui_draw_title(void); -static void ui_draw_path_header(void); +static void ui_draw_path_header(uint8_t); static void ui_draw_directory_list(void); static void ui_draw_directory_entry(int entry_idx, int posY, int font_height, int is_selected); static void ui_update_selected_entry(void); @@ -115,7 +114,10 @@ static void draw_text(int x, int y, const char *text, int foreground, int backgr */ static void format_file_size(off_t size, int is_dir, char *buf, size_t buf_size) { - if (is_dir == IS_DIR) + if(is_dir == IS_LAST_APP){ + snprintf(buf, buf_size, ""); + } + else if (is_dir == IS_DIR) { snprintf(buf, buf_size, "DIR"); } @@ -133,6 +135,13 @@ static void format_file_size(off_t size, int is_dir, char *buf, size_t buf_size) } } +static void set_default_entry(){ + entry_count = 0; + strncpy(entries[entry_count].name, "[Default app]", sizeof(entries[entry_count].name) - 1); + entries[entry_count].name[sizeof(entries[entry_count].name) - 1] = '\0'; + entries[entry_count].is_dir = IS_LAST_APP; + entries[entry_count].file_size = 0; +} /** * Create scrolling text for long filenames * Creates a continuous scroll effect for text that exceeds visible area @@ -170,11 +179,7 @@ static void load_directory(const char *path) entry_count = 0; return; } - entry_count = 0; - strncpy(entries[entry_count].name, "[Last app]", sizeof(entries[entry_count].name) - 1); - entries[entry_count].name[sizeof(entries[entry_count].name) - 1] = '\0'; - entries[0].is_dir = IS_LAST_APP; - entries[0].file_size = 0; + set_default_entry(); entry_count = 1; struct dirent *ent; @@ -232,7 +237,7 @@ static void load_directory(const char *path) static void ui_draw_title(void) { draw_rect_spi(UI_X, UI_Y, UI_X + UI_WIDTH - 1, UI_Y + HEADER_TITLE_HEIGHT, BLACK); - draw_text(UI_X + 2, UI_Y + 2, "PicoCalc SD Firmware Loader", WHITE, BLACK); + draw_text(UI_X + 2, UI_Y + 2, "PicoCalc Bootloader v1.0", WHITE, BLACK); } static void ui_draw_empty_tip(){ @@ -248,20 +253,20 @@ static void ui_draw_empty_tip(){ draw_text(UI_X + 2, y + 12+2, "Please copy .bin files to the" , COLOR_FG, COLOR_BG); draw_text(UI_X + 2, y + 24+2, "\"firmware\" folder" , COLOR_FG, COLOR_BG); - - strncpy(entries[entry_count].name, "Load default", sizeof(entries[entry_count].name) - 1); - entries[entry_count].name[sizeof(entries[entry_count].name) - 1] = '\0'; - entries[0].is_dir = IS_LAST_APP; - entries[0].file_size = 0; + set_default_entry(); // Draw the entry using the helper function ui_draw_directory_entry(0, y_start, 12, 1); } // Draw the current path header -static void ui_draw_path_header(void) +static void ui_draw_path_header(uint8_t nosd) { char path_header[300]; - snprintf(path_header, sizeof(path_header), "Path: %s", current_path); + if(nosd) { + snprintf(path_header, sizeof(path_header), "SD card not found"); + }else{ + snprintf(path_header, sizeof(path_header), "Path: SD%s", current_path); + } int y = UI_Y + HEADER_TITLE_HEIGHT; draw_rect_spi(UI_X, y, UI_X + UI_WIDTH - 1, y + PATH_HEADER_HEIGHT - 1, COLOR_BG); draw_text(UI_X + 2, y + 2, path_header, COLOR_FG, COLOR_BG); @@ -320,8 +325,8 @@ static void ui_draw_directory_entry(int entry_idx, int posY, int font_height, in size_buffer, sizeof(size_buffer)); // Draw filename and file size - draw_text(FILE_NAME_X, posY, display_buffer, is_selected?COLOR_BG:COLOR_FG , is_selected ? COLOR_HIGHLIGHT : COLOR_BG); - draw_text(FILE_SIZE_X, posY, size_buffer, is_selected?COLOR_BG:COLOR_FG, is_selected ? COLOR_HIGHLIGHT : COLOR_BG); + draw_text(FILE_NAME_X, posY, display_buffer, COLOR_FG , is_selected ? COLOR_HIGHLIGHT : COLOR_BG); + draw_text(FILE_SIZE_X, posY, size_buffer, COLOR_FG, is_selected ? COLOR_HIGHLIGHT : COLOR_BG); } /** @@ -351,6 +356,20 @@ static void ui_update_selected_entry(void) } } +static void ui_clear_directory_list(void){ + if(entry_count <1 ) return; + + for(int i=1;i