From 665ac1e4d0d5d7ec5b194375d1ae3bcaf0268f46 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Wed, 18 Jul 2018 19:50:42 -0500 Subject: [PATCH] Add POWER_LOSS_PIN support --- Marlin/Configuration_adv.h | 4 ++++ Marlin/src/config/default/Configuration_adv.h | 4 ++++ Marlin/src/feature/power_loss_recovery.cpp | 18 +++++++++++++++--- buildroot/share/tests/megaatmega2560_tests | 2 +- 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 964a2c104..e5cfce17f 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -589,6 +589,10 @@ * point in the file. */ //#define POWER_LOSS_RECOVERY + #if ENABLED(POWER_LOSS_RECOVERY) + //#define POWER_LOSS_PIN 44 // Pin to detect power loss + //#define POWER_LOSS_STATE HIGH // State of pin indicating power loss + #endif /** * Sort SD file listings in alphabetical order. diff --git a/Marlin/src/config/default/Configuration_adv.h b/Marlin/src/config/default/Configuration_adv.h index 964a2c104..e5cfce17f 100644 --- a/Marlin/src/config/default/Configuration_adv.h +++ b/Marlin/src/config/default/Configuration_adv.h @@ -589,6 +589,10 @@ * point in the file. */ //#define POWER_LOSS_RECOVERY + #if ENABLED(POWER_LOSS_RECOVERY) + //#define POWER_LOSS_PIN 44 // Pin to detect power loss + //#define POWER_LOSS_STATE HIGH // State of pin indicating power loss + #endif /** * Sort SD file listings in alphabetical order. diff --git a/Marlin/src/feature/power_loss_recovery.cpp b/Marlin/src/feature/power_loss_recovery.cpp index eace4f7df..095858837 100644 --- a/Marlin/src/feature/power_loss_recovery.cpp +++ b/Marlin/src/feature/power_loss_recovery.cpp @@ -202,12 +202,19 @@ void save_job_recovery_info() { millis_t ms = millis(); #endif if ( - #if SAVE_INFO_INTERVAL_MS > 0 - ELAPSED(ms, next_save_ms) || - #endif + // Save on every command #if ENABLED(SAVE_EACH_CMD_MODE) true #else + // Save if power loss pin is triggered + #if PIN_EXISTS(POWER_LOSS) + READ(POWER_LOSS_PIN) == POWER_LOSS_STATE || + #endif + // Save if interval is elapsed + #if SAVE_INFO_INTERVAL_MS > 0 + ELAPSED(ms, next_save_ms) || + #endif + // Save on every new Z height (current_position[Z_AXIS] > 0 && current_position[Z_AXIS] > job_recovery_info.current_position[Z_AXIS]) #endif ) { @@ -267,6 +274,11 @@ void save_job_recovery_info() { card.openJobRecoveryFile(false); (void)card.saveJobRecoveryInfo(); + + // If power-loss pin was triggered, write just once then kill + #if PIN_EXISTS(POWER_LOSS) + if (READ(POWER_LOSS_PIN) == POWER_LOSS_STATE) kill(MSG_POWER_LOSS_RECOVERY); + #endif } } diff --git a/buildroot/share/tests/megaatmega2560_tests b/buildroot/share/tests/megaatmega2560_tests index 2a62447f9..e13085594 100755 --- a/buildroot/share/tests/megaatmega2560_tests +++ b/buildroot/share/tests/megaatmega2560_tests @@ -27,7 +27,7 @@ opt_enable PIDTEMPBED FIX_MOUNTED_PROBE Z_SAFE_HOMING opt_enable REPRAP_DISCOUNT_SMART_CONTROLLER SDSUPPORT EEPROM_SETTINGS PINS_DEBUGGING opt_enable BLINKM PCA9632 RGB_LED NEOPIXEL_LED AUTO_POWER_CONTROL NOZZLE_PARK_FEATURE FILAMENT_RUNOUT_SENSOR opt_enable AUTO_BED_LEVELING_LINEAR Z_MIN_PROBE_REPEATABILITY_TEST DEBUG_LEVELING_FEATURE SKEW_CORRECTION SKEW_CORRECTION_FOR_Z SKEW_CORRECTION_GCODE -opt_enable_adv ARC_P_CIRCLES ADVANCED_PAUSE_FEATURE CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS POWER_LOSS_RECOVERY +opt_enable_adv ARC_P_CIRCLES ADVANCED_PAUSE_FEATURE CNC_WORKSPACE_PLANES CNC_COORDINATE_SYSTEMS POWER_LOSS_RECOVERY POWER_LOSS_PIN POWER_LOSS_STATE opt_enable_adv FWRETRACT MAX7219_DEBUG LED_CONTROL_MENU CASE_LIGHT_ENABLE CASE_LIGHT_USE_NEOPIXEL CODEPENDENT_XY_HOMING opt_set GRID_MAX_POINTS_X 16 opt_set_adv FANMUX0_PIN 53