Merge pull request #4207 from gudnimg/crashdet_cancel-fixup

`crashdet_cancel()` doesnt cleanup all variables when USB printing
This commit is contained in:
3d-gussner 2023-12-01 17:41:33 +01:00 committed by GitHub
commit 4dfc484265
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 30 additions and 60 deletions

View File

@ -631,20 +631,17 @@ void crashdet_detected(uint8_t mask)
void crashdet_recover() void crashdet_recover()
{ {
if (!print_job_timer.isPaused()) crashdet_restore_print_and_continue(); if (!print_job_timer.isPaused()) crashdet_restore_print_and_continue();
if (lcd_crash_detect_enabled()) tmc2130_sg_stop_on_crash = true; crashdet_use_eeprom_setting();
} }
void crashdet_cancel() /// Crash detection cancels the print
{ void crashdet_cancel() {
saved_printing = false; // Restore crash detection
tmc2130_sg_stop_on_crash = true; crashdet_use_eeprom_setting();
if (saved_printing_type == PowerPanic::PRINT_TYPE_SD) {
print_stop(); // Abort the print
}else if(saved_printing_type == PowerPanic::PRINT_TYPE_USB){ print_stop();
SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); //for Octoprint: works the same as clicking "Abort" button in Octoprint GUI
cmdqueue_reset();
}
} }
#endif //TMC2130 #endif //TMC2130
@ -1276,14 +1273,11 @@ void setup()
if (silentMode == 0xff) silentMode = 0; if (silentMode == 0xff) silentMode = 0;
tmc2130_mode = TMC2130_MODE_NORMAL; tmc2130_mode = TMC2130_MODE_NORMAL;
if (lcd_crash_detect_enabled() && !farm_mode) tmc2130_sg_stop_on_crash = eeprom_init_default_byte((uint8_t*)EEPROM_CRASH_DET, farm_mode ? false : true);
{
lcd_crash_detect_enable(); if (tmc2130_sg_stop_on_crash) {
puts_P(_N("CrashDetect ENABLED!")); puts_P(_N("CrashDetect ENABLED!"));
} } else {
else
{
lcd_crash_detect_disable();
puts_P(_N("CrashDetect DISABLED")); puts_P(_N("CrashDetect DISABLED"));
} }
@ -9715,10 +9709,6 @@ void UnconditionalStop()
cmdqueue_reset(); cmdqueue_reset();
cmdqueue_serial_disabled = false; cmdqueue_serial_disabled = false;
// Reset the sd status
card.sdprinting = false;
card.closefile();
st_reset_timer(); st_reset_timer();
CRITICAL_SECTION_END; CRITICAL_SECTION_END;
} }

View File

@ -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() bool tmc2130_update_sg()
{ {

View File

@ -162,6 +162,9 @@ extern void tmc2130_sg_measure_start(uint8_t axis);
//stop current stallguard measuring and report result //stop current stallguard measuring and report result
extern uint16_t tmc2130_sg_measure_stop(); 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); extern void tmc2130_setup_chopper(uint8_t axis, uint8_t mres);
//set holding current for any axis (M911) //set holding current for any axis (M911)

View File

@ -3412,7 +3412,7 @@ static void lcd_silent_mode_set() {
#endif //TMC2130 #endif //TMC2130
#ifdef 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); menu_submenu(lcd_crash_mode_info2);
#endif //TMC2130 #endif //TMC2130
} }
@ -3420,8 +3420,8 @@ static void lcd_silent_mode_set() {
#ifdef TMC2130 #ifdef TMC2130
static void crash_mode_switch() static void crash_mode_switch()
{ {
if (lcd_crash_detect_enabled()) lcd_crash_detect_disable(); eeprom_toggle((uint8_t*)EEPROM_CRASH_DET);
else lcd_crash_detect_enable(); crashdet_use_eeprom_setting();
} }
#endif //TMC2130 #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_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 else
{ {
@ -5655,7 +5655,11 @@ void print_stop(bool interactive)
// called by the main loop one iteration later. // called by the main loop one iteration later.
UnconditionalStop(); UnconditionalStop();
if (!card.sdprinting) { if (card.sdprinting) {
// Reset the sd status
card.sdprinting = false;
card.closefile();
} else {
SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint SERIAL_ECHOLNRPGM(MSG_OCTOPRINT_CANCEL); // for Octoprint
} }
@ -6209,7 +6213,7 @@ static void reset_crash_det(uint8_t axis) {
current_position[axis] += 10; current_position[axis] += 10;
plan_buffer_line_curposXYZE(manual_feedrate[0] / 60); plan_buffer_line_curposXYZE(manual_feedrate[0] / 60);
st_synchronize(); 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) { static bool lcd_selfcheck_axis_sg(uint8_t axis) {
@ -7353,30 +7357,6 @@ void menu_lcd_lcdupdate_func(void)
if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands(); 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 #ifdef TMC2130
void UserECool_toggle(){ 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 // 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

View File

@ -75,12 +75,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_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()") 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 { enum LCDButtonChoice : uint_fast8_t {
LCD_LEFT_BUTTON_CHOICE = 0, LCD_LEFT_BUTTON_CHOICE = 0,
LCD_MIDDLE_BUTTON_CHOICE = 1, LCD_MIDDLE_BUTTON_CHOICE = 1,