From 3ad40f02064f1870cdec7fe4d9ce1bd7a2ff6ec0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 14 May 2023 12:04:43 +0000 Subject: [PATCH 1/3] crashdet_cancel doesnt cleanup all variables when using Octoprint I would think that this should behave similarly as when stopping the print via the LCD. Changed UnconditionalSto()p to not close the SD card file if we're using Octoprint. Then there shouldnt be any file open. Some of the variables which were not reset: isPrintPaused pause_time saved_start_position saved_printing_type Bed heater may be left on? Change in memory: Flash: -28 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 331e4c245..b9f6ea304 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -635,16 +635,9 @@ void crashdet_recover() if (lcd_crash_detect_enabled()) tmc2130_sg_stop_on_crash = true; } -void crashdet_cancel() -{ - saved_printing = false; - tmc2130_sg_stop_on_crash = true; - if (saved_printing_type == PowerPanic::PRINT_TYPE_SD) { - print_stop(); - }else if(saved_printing_type == PowerPanic::PRINT_TYPE_USB){ - SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); //for Octoprint: works the same as clicking "Abort" button in Octoprint GUI - cmdqueue_reset(); - } +/// Crash detection cancels the print +void crashdet_cancel() { + print_stop(); } #endif //TMC2130 @@ -9693,8 +9686,10 @@ void UnconditionalStop() cmdqueue_serial_disabled = false; // Reset the sd status - card.sdprinting = false; - card.closefile(); + if (card.sdprinting) { + card.sdprinting = false; + card.closefile(); + } st_reset_timer(); CRITICAL_SECTION_END; From 30d0da469899a911e744095236eb1aff6ed0941b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 13 Aug 2023 17:37:05 +0000 Subject: [PATCH 2/3] Close SD file in print_stop instead of UnconditionalStop() Change in memory: Flash: -6 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 6 ------ Firmware/ultralcd.cpp | 6 +++++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index b9f6ea304..f7590f976 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9685,12 +9685,6 @@ void UnconditionalStop() cmdqueue_reset(); cmdqueue_serial_disabled = false; - // Reset the sd status - if (card.sdprinting) { - card.sdprinting = false; - card.closefile(); - } - st_reset_timer(); CRITICAL_SECTION_END; } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 9162a4cc4..85f76c6a7 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -5646,7 +5646,11 @@ void print_stop(bool interactive) // called by the main loop one iteration later. UnconditionalStop(); - if (!card.sdprinting) { + if (card.sdprinting) { + // Reset the sd status + card.sdprinting = false; + card.closefile(); + } else { SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint } From e1e0b0afa128f86e236140baf44d6497c4c62094 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0ni=20M=C3=A1r=20Gilbert?= Date: Sun, 13 Aug 2023 18:24:20 +0000 Subject: [PATCH 3/3] Refactor code which resets crash detection setting Add function crashdet_use_eeprom_setting Change in memory: Flash: -52 bytes SRAM: 0 bytes --- Firmware/Marlin_main.cpp | 21 +++++++++++---------- Firmware/tmc2130.cpp | 3 +++ Firmware/tmc2130.h | 3 +++ Firmware/ultralcd.cpp | 34 +++++----------------------------- Firmware/ultralcd.h | 6 ------ 5 files changed, 22 insertions(+), 45 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index f7590f976..01c423711 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -631,12 +631,16 @@ void crashdet_detected(uint8_t mask) void crashdet_recover() { - if (!print_job_timer.isPaused()) crashdet_restore_print_and_continue(); - if (lcd_crash_detect_enabled()) tmc2130_sg_stop_on_crash = true; + if (!print_job_timer.isPaused()) crashdet_restore_print_and_continue(); + crashdet_use_eeprom_setting(); } /// Crash detection cancels the print void crashdet_cancel() { + // Restore crash detection + crashdet_use_eeprom_setting(); + + // Abort the print print_stop(); } @@ -1269,14 +1273,11 @@ void setup() if (silentMode == 0xff) silentMode = 0; tmc2130_mode = TMC2130_MODE_NORMAL; - if (lcd_crash_detect_enabled() && !farm_mode) - { - lcd_crash_detect_enable(); - puts_P(_N("CrashDetect ENABLED!")); - } - else - { - lcd_crash_detect_disable(); + tmc2130_sg_stop_on_crash = eeprom_init_default_byte((uint8_t*)EEPROM_CRASH_DET, farm_mode ? false : true); + + if (tmc2130_sg_stop_on_crash) { + puts_P(_N("CrashDetect ENABLED!")); + } else { puts_P(_N("CrashDetect DISABLED")); } diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp index 1e4cce56d..d95f6dff3 100755 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -390,6 +390,9 @@ void tmc2130_st_isr() } } +void crashdet_use_eeprom_setting() { + tmc2130_sg_stop_on_crash = eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET); +} bool tmc2130_update_sg() { diff --git a/Firmware/tmc2130.h b/Firmware/tmc2130.h index 7ebc875e6..8f4b7761a 100644 --- a/Firmware/tmc2130.h +++ b/Firmware/tmc2130.h @@ -162,6 +162,9 @@ extern void tmc2130_sg_measure_start(uint8_t axis); //stop current stallguard measuring and report result extern uint16_t tmc2130_sg_measure_stop(); +// Enable or Disable crash detection according to EEPROM +void crashdet_use_eeprom_setting(); + extern void tmc2130_setup_chopper(uint8_t axis, uint8_t mres); //set holding current for any axis (M911) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 85f76c6a7..2fe0d2fbf 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3412,7 +3412,7 @@ static void lcd_silent_mode_set() { #endif //TMC2130 #ifdef TMC2130 - if (lcd_crash_detect_enabled() && (SilentModeMenu != SILENT_MODE_NORMAL)) + if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET) && (SilentModeMenu != SILENT_MODE_NORMAL)) menu_submenu(lcd_crash_mode_info2); #endif //TMC2130 } @@ -3420,8 +3420,8 @@ static void lcd_silent_mode_set() { #ifdef TMC2130 static void crash_mode_switch() { - if (lcd_crash_detect_enabled()) lcd_crash_detect_disable(); - else lcd_crash_detect_enable(); + eeprom_toggle((uint8_t*)EEPROM_CRASH_DET); + crashdet_use_eeprom_setting(); } #endif //TMC2130 @@ -4114,7 +4114,7 @@ static void SETTINGS_SILENT_MODE() { MENU_ITEM_TOGGLE_P(_T(MSG_MODE), _T(MSG_NORMAL), lcd_silent_mode_set); } - MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), lcd_crash_detect_enabled() ? _T(MSG_ON) : _T(MSG_OFF), crash_mode_switch); + MENU_ITEM_TOGGLE_P(_T(MSG_CRASHDETECT), eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET) ? _T(MSG_ON) : _T(MSG_OFF), crash_mode_switch); } else { @@ -6204,7 +6204,7 @@ static void reset_crash_det(uint8_t axis) { current_position[axis] += 10; plan_buffer_line_curposXYZE(manual_feedrate[0] / 60); st_synchronize(); - if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET)) tmc2130_sg_stop_on_crash = true; + crashdet_use_eeprom_setting(); } static bool lcd_selfcheck_axis_sg(uint8_t axis) { @@ -7348,30 +7348,6 @@ void menu_lcd_lcdupdate_func(void) if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands(); } -#ifdef TMC2130 -//! @brief Is crash detection enabled? -//! -//! @retval true crash detection enabled -//! @retval false crash detection disabled -bool lcd_crash_detect_enabled() -{ - return eeprom_read_byte((uint8_t*)EEPROM_CRASH_DET); -} - -void lcd_crash_detect_enable() -{ - tmc2130_sg_stop_on_crash = true; - eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0xFF); -} - -void lcd_crash_detect_disable() -{ - tmc2130_sg_stop_on_crash = false; - tmc2130_sg_crash = 0; - eeprom_update_byte((uint8_t*)EEPROM_CRASH_DET, 0x00); -} -#endif - #ifdef TMC2130 void UserECool_toggle(){ // this is only called when the experimental menu is visible, thus the first condition for enabling of the ECool mode is met in this place diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index e8d3bb8ab..a396af470 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -71,12 +71,6 @@ void lcd_status_screen(); // NOT static due to using ins void lcd_menu_extruder_info(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") void lcd_menu_show_sensors_state(); // NOT static due to using inside "Marlin_main" module ("manage_inactivity()") -#ifdef TMC2130 -bool lcd_crash_detect_enabled(); -void lcd_crash_detect_enable(); -void lcd_crash_detect_disable(); -#endif - enum LCDButtonChoice : uint_fast8_t { LCD_LEFT_BUTTON_CHOICE = 0, LCD_MIDDLE_BUTTON_CHOICE = 1,