Merge pull request #10437 from thinkyhead/bf1_creality_power_loss_resume

[1.1.x] Creality3D Power-Loss Recovery
This commit is contained in:
Scott Lahteine 2018-04-22 00:17:27 -05:00 committed by GitHub
commit 58bd2a5e81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
53 changed files with 956 additions and 43 deletions

View file

@ -65,6 +65,10 @@
bool lcd_external_control; // = false
#endif
#if ENABLED(POWER_LOSS_RECOVERY)
#include "power_loss_recovery.h"
#endif
// Initialized by settings.load()
int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
@ -851,10 +855,70 @@ void kill_screen(const char* lcd_msg) {
abort_sd_printing = true;
lcd_setstatusPGM(PSTR(MSG_PRINT_ABORTED), -1);
lcd_return_to_status();
#if ENABLED(POWER_LOSS_RECOVERY)
card.openJobRecoveryFile(false);
job_recovery_info.valid_head = job_recovery_info.valid_foot = 0;
(void)card.saveJobRecoveryInfo();
card.closeJobRecoveryFile();
job_recovery_commands_count = 0;
#endif
}
#endif // SDSUPPORT
#if ENABLED(POWER_LOSS_RECOVERY)
static void lcd_sdcard_recover_job() {
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"
#if !IS_KINEMATIC
" X Y"
#endif
));
// Restore the bed temperature
sprintf_P(cmd, PSTR("M190 S%i"), job_recovery_info.target_temperature_bed);
enqueue_and_echo_command(cmd);
// Restore all hotend temperatures
HOTEND_LOOP() {
sprintf_P(cmd, PSTR("M109 S%i"), job_recovery_info.target_temperature[e]);
enqueue_and_echo_command(cmd);
}
// Restore print cooling fan speeds
for (uint8_t i = 0; i < FAN_COUNT; i++) {
sprintf_P(cmd, PSTR("M106 P%i S%i"), i, job_recovery_info.fanSpeeds[i]);
enqueue_and_echo_command(cmd);
}
// Start draining the job recovery command queue
job_recovery_phase = JOB_RECOVERY_YES;
// Resume the print job timer
if (job_recovery_info.print_job_elapsed)
print_job_timer.resume(job_recovery_info.print_job_elapsed);
// Start getting commands from SD
card.startFileprint();
}
static void lcd_job_recovery_menu() {
defer_return_to_status = true;
START_MENU();
MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_recover_job);
MENU_ITEM(function, MSG_STOP_PRINT, lcd_sdcard_stop);
END_MENU();
}
#endif
#if ENABLED(MENU_ITEM_CASE_LIGHT)
extern uint8_t case_light_brightness;
@ -5045,7 +5109,7 @@ void lcd_update() {
}
#endif
#endif
#endif // ULTIPANEL
#if ENABLED(SDSUPPORT) && PIN_EXISTS(SD_DETECT)
@ -5075,6 +5139,13 @@ void lcd_update() {
#endif // SDSUPPORT && SD_DETECT_PIN
#if ENABLED(POWER_LOSS_RECOVERY)
if (job_recovery_commands_count && job_recovery_phase == JOB_RECOVERY_IDLE) {
lcd_goto_screen(lcd_job_recovery_menu);
job_recovery_phase = JOB_RECOVERY_MAYBE; // Waiting for a response
}
#endif
const millis_t ms = millis();
if (ELAPSED(ms, next_lcd_update_ms)
#if ENABLED(DOGLCD)