From 9cd54712021568fc3dbb1dc49388b912a88116c5 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 27 Oct 2018 22:48:28 -0500 Subject: [PATCH] Move Job Recovery Menu to its own file --- Marlin/src/feature/power_loss_recovery.h | 6 +- Marlin/src/lcd/menu/menu.cpp | 87 +----------------- Marlin/src/lcd/menu/menu_job_recovery.cpp | 106 ++++++++++++++++++++++ 3 files changed, 111 insertions(+), 88 deletions(-) create mode 100644 Marlin/src/lcd/menu/menu_job_recovery.cpp diff --git a/Marlin/src/feature/power_loss_recovery.h b/Marlin/src/feature/power_loss_recovery.h index d173b87c54..d5a0aea69d 100644 --- a/Marlin/src/feature/power_loss_recovery.h +++ b/Marlin/src/feature/power_loss_recovery.h @@ -19,14 +19,12 @@ * along with this program. If not, see . * */ +#pragma once /** * power_loss_recovery.h - Resume an SD print after power-loss */ -#ifndef _POWER_LOSS_RECOVERY_H_ -#define _POWER_LOSS_RECOVERY_H_ - #include "../sd/cardreader.h" #include "../core/millis_t.h" #include "../inc/MarlinConfigPre.h" @@ -99,5 +97,3 @@ extern uint8_t job_recovery_commands_count; void check_print_job_recovery(); void save_job_recovery_info(); - -#endif // _POWER_LOSS_RECOVERY_H_ diff --git a/Marlin/src/lcd/menu/menu.cpp b/Marlin/src/lcd/menu/menu.cpp index ff449d6f39..a65d9020b4 100644 --- a/Marlin/src/lcd/menu/menu.cpp +++ b/Marlin/src/lcd/menu/menu.cpp @@ -27,7 +27,6 @@ #include "menu.h" #include "../ultralcd.h" -#include "../../sd/cardreader.h" #include "../../module/planner.h" #include "../../module/motion.h" #include "../../module/probe.h" @@ -40,16 +39,12 @@ #include -#if ENABLED(ADVANCED_PAUSE_FEATURE) - #include "../../feature/pause.h" -#endif - -#if ENABLED(POWER_LOSS_RECOVERY) - #include "../../feature/power_loss_recovery.h" +#if ENABLED(SDSUPPORT) + #include "../../sd/cardreader.h" #endif -#if ENABLED(PRINTCOUNTER) && ENABLED(LCD_INFO_MENU) - #include "../../libs/duration_t.h" +#if ENABLED(ADVANCED_PAUSE_FEATURE) + #include "../../feature/pause.h" #endif #if HAS_LEVELING @@ -405,80 +400,6 @@ void line_to_z(const float &z) { line_to_current_z(); } -#if ENABLED(POWER_LOSS_RECOVERY) - - static void lcd_power_loss_recovery_resume() { - char cmd[20]; - - // Return to status now - lcd_return_to_status(); - - // Turn leveling off and home - enqueue_and_echo_commands_P(PSTR("M420 S0\nG28 R0" - #if ENABLED(MARLIN_DEV_MODE) - " S" - #elif !IS_KINEMATIC - " X Y" - #endif - )); - - #if HAS_HEATED_BED - const int16_t bt = job_recovery_info.target_temperature_bed; - if (bt) { - // Restore the bed temperature - sprintf_P(cmd, PSTR("M190 S%i"), bt); - enqueue_and_echo_command(cmd); - } - #endif - - // Restore all hotend temperatures - HOTEND_LOOP() { - const int16_t et = job_recovery_info.target_temperature[e]; - if (et) { - #if HOTENDS > 1 - sprintf_P(cmd, PSTR("T%i"), e); - enqueue_and_echo_command(cmd); - #endif - sprintf_P(cmd, PSTR("M109 S%i"), et); - enqueue_and_echo_command(cmd); - } - } - - #if HOTENDS > 1 - sprintf_P(cmd, PSTR("T%i"), job_recovery_info.active_hotend); - enqueue_and_echo_command(cmd); - #endif - - // Restore print cooling fan speeds - for (uint8_t i = 0; i < FAN_COUNT; i++) { - uint8_t f = job_recovery_info.fan_speed[i]; - if (f) { - sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f); - enqueue_and_echo_command(cmd); - } - } - - // Start draining the job recovery command queue - job_recovery_phase = JOB_RECOVERY_YES; - } - - static void lcd_power_loss_recovery_cancel() { - card.removeJobRecoveryFile(); - card.autostart_index = 0; - lcd_return_to_status(); - } - - void menu_job_recovery() { - defer_return_to_status = true; - START_MENU(); - STATIC_ITEM(MSG_POWER_LOSS_RECOVERY); - MENU_ITEM(function, MSG_RESUME_PRINT, lcd_power_loss_recovery_resume); - MENU_ITEM(function, MSG_STOP_PRINT, lcd_power_loss_recovery_cancel); - END_MENU(); - } - -#endif // POWER_LOSS_RECOVERY - #if ENABLED(CUSTOM_USER_MENUS) #ifdef USER_SCRIPT_DONE diff --git a/Marlin/src/lcd/menu/menu_job_recovery.cpp b/Marlin/src/lcd/menu/menu_job_recovery.cpp new file mode 100644 index 0000000000..51adcaf0d2 --- /dev/null +++ b/Marlin/src/lcd/menu/menu_job_recovery.cpp @@ -0,0 +1,106 @@ +/** + * Marlin 3D Printer Firmware + * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] + * + * Based on Sprinter and grbl. + * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +// +// Job Recovery Menu +// + +#include "../../inc/MarlinConfigPre.h" + +#if HAS_LCD_MENU && ENABLED(POWER_LOSS_RECOVERY) + +#include "menu.h" +#include "../../gcode/queue.h" +#include "../../sd/cardreader.h" +#include "../../feature/power_loss_recovery.h" + +static void lcd_power_loss_recovery_resume() { + char cmd[20]; + + // Return to status now + lcd_return_to_status(); + + // Turn leveling off and home + enqueue_and_echo_commands_P(PSTR("M420 S0\nG28 R0" + #if ENABLED(MARLIN_DEV_MODE) + " S" + #elif !IS_KINEMATIC + " X Y" + #endif + )); + + #if HAS_HEATED_BED + const int16_t bt = job_recovery_info.target_temperature_bed; + if (bt) { + // Restore the bed temperature + sprintf_P(cmd, PSTR("M190 S%i"), bt); + enqueue_and_echo_command(cmd); + } + #endif + + // Restore all hotend temperatures + HOTEND_LOOP() { + const int16_t et = job_recovery_info.target_temperature[e]; + if (et) { + #if HOTENDS > 1 + sprintf_P(cmd, PSTR("T%i"), e); + enqueue_and_echo_command(cmd); + #endif + sprintf_P(cmd, PSTR("M109 S%i"), et); + enqueue_and_echo_command(cmd); + } + } + + #if HOTENDS > 1 + sprintf_P(cmd, PSTR("T%i"), job_recovery_info.active_hotend); + enqueue_and_echo_command(cmd); + #endif + + // Restore print cooling fan speeds + for (uint8_t i = 0; i < FAN_COUNT; i++) { + uint8_t f = job_recovery_info.fan_speed[i]; + if (f) { + sprintf_P(cmd, PSTR("M106 P%i S%i"), i, f); + enqueue_and_echo_command(cmd); + } + } + + // Start draining the job recovery command queue + job_recovery_phase = JOB_RECOVERY_YES; +} + +static void lcd_power_loss_recovery_cancel() { + card.removeJobRecoveryFile(); + card.autostart_index = 0; + lcd_return_to_status(); +} + +void menu_job_recovery() { + defer_return_to_status = true; + START_MENU(); + STATIC_ITEM(MSG_POWER_LOSS_RECOVERY); + MENU_ITEM(function, MSG_RESUME_PRINT, lcd_power_loss_recovery_resume); + MENU_ITEM(function, MSG_STOP_PRINT, lcd_power_loss_recovery_cancel); + END_MENU(); +} + +#endif // HAS_LCD_MENU && POWER_LOSS_RECOVERY