From 30d9faef9d797adfd6ff2e66d47093a3cf23d4e3 Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Sun, 20 Jun 2021 22:30:47 -0700 Subject: [PATCH] Minor fixes to SD presence handling (#3139) * Remove forgotten function protorypes * Fix code indentation * Fix double sorting if SD card is inserted during setup() * Correctly handle SD removal during sorting --- Firmware/cardreader.cpp | 5 +++-- Firmware/cardreader.h | 2 +- Firmware/ultralcd.cpp | 21 ++++++++++++--------- Firmware/ultralcd.h | 6 ------ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index a86c49e1..b0c972fc 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -196,7 +196,7 @@ void CardReader::ls(ls_param params) } -void CardReader::initsd() +void CardReader::initsd(bool doPresort/* = true*/) { cardOK = false; if(root.isOpen()) @@ -240,7 +240,8 @@ void CardReader::initsd() workDirDepth = 0; #ifdef SDCARD_SORT_ALPHA - presort(); + if (doPresort) + presort(); #endif /* diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index c6e55428..f7e3acc9 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -27,7 +27,7 @@ public: inline ls_param(bool LFN, bool timestamp):LFN(LFN), timestamp(timestamp) { } } __attribute__((packed)); - void initsd(); + void initsd(bool doPresort = true); void write_command(char *buf); void write_command_no_newline(char *buf); //files auto[0-9].g on the sd card are performed in a row diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 01968364..b1d13b8f 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -8866,25 +8866,28 @@ void menu_lcd_lcdupdate_func(void) lcd_draw_update = 2; lcd_oldcardstatus = IS_SD_INSERTED; lcd_refresh(); // to maybe revive the LCD if static electricity killed it. - backlight_wake(); + backlight_wake(); if (lcd_oldcardstatus) { - card.initsd(); - LCD_MESSAGERPGM(_T(WELCOME_MSG)); - bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function - menu_submenu(lcd_sdcard_menu); - //get_description(); + if (!card.cardOK) + { + card.initsd(false); //delay the sorting to the sd menu. Otherwise, removing the SD card while sorting will not menu_back() + card.presort_flag = true; //force sorting of the SD menu + } + LCD_MESSAGERPGM(_T(WELCOME_MSG)); + bMain=false; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function + menu_submenu(lcd_sdcard_menu); } else { - if(menu_menu==lcd_sdcard_menu) - menu_back(); + if(menu_menu==lcd_sdcard_menu) + menu_back(); card.release(); LCD_MESSAGERPGM(_i("Card removed"));////MSG_SD_REMOVED c=20 } } #endif//CARDINSERTED - backlight_update(); + backlight_update(); if (lcd_next_update_millis < _millis()) { if (abs(lcd_encoder_diff) >= ENCODER_PULSES_PER_STEP) diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 3aab932d..a58d48ee 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -205,12 +205,6 @@ void lcd_printer_connected(); void lcd_ping(); void lcd_calibrate_extruder(); -void lcd_farm_sdcard_menu(); - -//void getFileDescription(char *name, char *description); - -void lcd_farm_sdcard_menu_w(); -//void get_description(); void lcd_wait_for_heater(); void lcd_wait_for_cool_down();