diff --git a/Firmware/Configuration_prusa.h b/Firmware/Configuration_prusa.h index fad1ecff..a40a9af6 100644 --- a/Firmware/Configuration_prusa.h +++ b/Firmware/Configuration_prusa.h @@ -512,6 +512,8 @@ const bool Z_MIN_ENDSTOP_INVERTING = false; // set to true to invert the logic o #define DEFAULT_RETRACTION 1 //used for PINDA temp calibration and pause print #endif +#define END_FILE_SECTION 10000 //number of bytes from end of file used for checking if file is complete + // How much shall the print head be lifted on power panic? // Ideally the Z axis will reach a zero phase of the stepper driver on power outage. To simplify this, // UVLO_Z_AXIS_SHIFT shall be an integer multiply of the stepper driver cycle, that is 4x full step. diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index f2f1e9bc..74455a38 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -379,6 +379,7 @@ float temp_compensation_pinda_thermistor_offset(float temperature_pinda); void wait_for_heater(long codenum); void serialecho_temperatures(); +bool check_commands(); void uvlo_(); void recover_print(uint8_t automatic); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 549862fd..99328679 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1602,6 +1602,20 @@ inline void gcode_M900() { } #endif // LIN_ADVANCE +bool check_commands() { + bool end_command_found = false; + + while (buflen) + { + if ((code_seen("M84")) || (code_seen("M 84"))) end_command_found = true; + if (!cmdbuffer_front_already_processed) + cmdqueue_pop_front(); + cmdbuffer_front_already_processed = false; + } + return end_command_found; + +} + #ifdef TMC2130 bool calibrate_z_auto() { diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 5426eb0f..ed78ea23 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -468,6 +468,11 @@ void CardReader::removeFile(char* name) } +uint32_t CardReader::getFileSize() +{ + return filesize; +} + void CardReader::getStatus() { if(sdprinting){ @@ -669,8 +674,8 @@ void CardReader::printingHasFinished() sdprinting = false; if(SD_FINISHED_STEPPERRELEASE) { - //finishAndDisableSteppers(); - enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); + finishAndDisableSteppers(); + //enquecommand_P(PSTR(SD_FINISHED_RELEASECOMMAND)); } autotempShutdown(); } diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index 11768621..fa2bec75 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -26,6 +26,7 @@ public: void release(); void startFileprint(); void pauseSDPrint(); + uint32_t getFileSize(); void getStatus(); void printingHasFinished(); diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index ce2831aa..c437e1f6 100644 --- a/Firmware/language_all.cpp +++ b/Firmware/language_all.cpp @@ -621,6 +621,13 @@ const char * const MSG_FILAMENT_LOADING_T3_LANG_TABLE[LANG_NUM] PROGMEM = { MSG_FILAMENT_LOADING_T3_CZ }; +const char MSG_FILE_INCOMPLETE_EN[] PROGMEM = "File incomplete. Continue anyway?"; +const char MSG_FILE_INCOMPLETE_CZ[] PROGMEM = "Soubor nekompletni. Pokracovat?"; +const char * const MSG_FILE_INCOMPLETE_LANG_TABLE[LANG_NUM] PROGMEM = { + MSG_FILE_INCOMPLETE_EN, + MSG_FILE_INCOMPLETE_CZ +}; + const char MSG_FILE_PRINTED_EN[] PROGMEM = "Done printing file"; const char * const MSG_FILE_PRINTED_LANG_TABLE[1] PROGMEM = { MSG_FILE_PRINTED_EN diff --git a/Firmware/language_all.h b/Firmware/language_all.h index f46f025e..6fb1275a 100644 --- a/Firmware/language_all.h +++ b/Firmware/language_all.h @@ -222,6 +222,8 @@ extern const char* const MSG_FILAMENT_LOADING_T2_LANG_TABLE[LANG_NUM]; #define MSG_FILAMENT_LOADING_T2 LANG_TABLE_SELECT(MSG_FILAMENT_LOADING_T2_LANG_TABLE) extern const char* const MSG_FILAMENT_LOADING_T3_LANG_TABLE[LANG_NUM]; #define MSG_FILAMENT_LOADING_T3 LANG_TABLE_SELECT(MSG_FILAMENT_LOADING_T3_LANG_TABLE) +extern const char* const MSG_FILE_INCOMPLETE_LANG_TABLE[LANG_NUM]; +#define MSG_FILE_INCOMPLETE LANG_TABLE_SELECT(MSG_FILE_INCOMPLETE_LANG_TABLE) extern const char* const MSG_FILE_PRINTED_LANG_TABLE[1]; #define MSG_FILE_PRINTED LANG_TABLE_SELECT_EXPLICIT(MSG_FILE_PRINTED_LANG_TABLE, 0) extern const char* const MSG_FILE_SAVED_LANG_TABLE[1]; diff --git a/Firmware/language_cz.h b/Firmware/language_cz.h index c4989d57..708cdff5 100644 --- a/Firmware/language_cz.h +++ b/Firmware/language_cz.h @@ -351,4 +351,5 @@ #define MSG_PLACE_STEEL_SHEET "Umistete prosim tiskovy plat na heatbed" #define MSG_RECOVER_PRINT "Detekovan vypadek proudu.Obnovit tisk?" #define MSG_PRESS_TO_UNLOAD "Pro vysunuti filamentu stisknete prosim tlacitko" -#define MSG_UNLOAD_SUCCESSFULL "Opakovat vysunuti filamentu?" \ No newline at end of file +#define MSG_UNLOAD_SUCCESSFULL "Opakovat vysunuti filamentu?" +#define MSG_FILE_INCOMPLETE "Soubor nekompletni. Pokracovat?" \ No newline at end of file diff --git a/Firmware/language_en.h b/Firmware/language_en.h index e596b35b..e011e12c 100644 --- a/Firmware/language_en.h +++ b/Firmware/language_en.h @@ -368,3 +368,5 @@ #define(length=17, lines=1) MSG_FANS_CHECK_OFF "Fans check [off]" #define(length=20, lines=4) MSG_PRESS_TO_UNLOAD "Please press the knob to unload filament" #define(length=20, lines=2) MSG_UNLOAD_SUCCESSFULL "Repeat unloading filament?" +#define(length=20, lines=2) MSG_FILE_INCOMPLETE "File incomplete. Continue anyway?" + diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index a568d669..a6b9fbc2 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6156,37 +6156,59 @@ static void menu_action_setlang(unsigned char lang) { static void menu_action_function(menuFunc_t data) { (*data)(); } + +static bool check_file(const char* filename) { + bool result = false; + uint32_t filesize; + card.openFile(filename, true); + filesize = card.getFileSize(); + if (filesize > END_FILE_SECTION) { + card.setIndex(filesize - END_FILE_SECTION); + + } + + while (!card.eof() && !result) { + card.sdprinting = true; + get_command(); + result = check_commands(); + + } + card.printingHasFinished(); + strncpy_P(lcd_status_message, WELCOME_MSG, LCD_WIDTH); + return result; + +} + static void menu_action_sdfile(const char* filename, char* longFilename) { loading_flag = false; char cmd[30]; char* c; + bool result = true; sprintf_P(cmd, PSTR("M23 %s"), filename); for (c = &cmd[4]; *c; c++) *c = tolower(*c); - enquecommand(cmd); - for (int i = 0; i < 8; i++) { - eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, filename[i]); + + if (!check_file(filename)) { + result = lcd_show_fullscreen_message_yes_no_and_wait_P(MSG_FILE_INCOMPLETE, false, false); + lcd_update_enable(true); } + if (result) { - uint8_t depth = (uint8_t)card.getWorkDirDepth(); + uint8_t depth = (uint8_t)card.getWorkDirDepth(); - //char dir_name[9]; + for (uint8_t i = 0; i < depth; i++) { + for (int j = 0; j < 8; j++) { + eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]); + } - for (uint8_t i = 0; i < depth; i++) { - //card.getDirName(dir_name, i + 1); - //dir_name[8] = '\0'; - //MYSERIAL.println(dir_name); - for (int j = 0; j < 8; j++) { - eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8*i, dir_names[i][j]); - //eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_name[j]); } + eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth); + enquecommand(cmd); + enquecommand_P(PSTR("M24")); } - //MYSERIAL.println(int(depth)); - eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth); - enquecommand_P(PSTR("M24")); lcd_return_to_status(); } static void menu_action_sddirectory(const char* filename, char* longFilename)