From 3c2bfa5e533b9f1d659baec30770f6e274cb539e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Thu, 8 Mar 2018 18:56:47 -0600 Subject: [PATCH] Update powersupply_on in power_on/off (#10015) Fix #10004 --- Marlin/src/Marlin.h | 22 +++++++++++++--------- Marlin/src/feature/power.cpp | 4 ++-- Marlin/src/gcode/control/M80_M81.cpp | 3 --- Marlin/src/lcd/ultralcd.cpp | 4 ---- Marlin/src/module/planner.cpp | 2 +- 5 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Marlin/src/Marlin.h b/Marlin/src/Marlin.h index f5b14a97fe..5a554b2580 100644 --- a/Marlin/src/Marlin.h +++ b/Marlin/src/Marlin.h @@ -42,15 +42,6 @@ void idle( void manage_inactivity(bool ignore_stepper_queue = false); -// Auto Power Control -#if ENABLED(AUTO_POWER_CONTROL) - #define PSU_ON() powerManager.power_on() - #define PSU_OFF() powerManager.power_off() -#else - #define PSU_ON() OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE) - #define PSU_OFF() OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP) -#endif - #if HAS_X2_ENABLE #define enable_X() do{ X_ENABLE_WRITE( X_ENABLE_ON); X2_ENABLE_WRITE( X_ENABLE_ON); }while(0) #define disable_X() do{ X_ENABLE_WRITE(!X_ENABLE_ON); X2_ENABLE_WRITE(!X_ENABLE_ON); axis_known_position[X_AXIS] = false; }while(0) @@ -220,6 +211,19 @@ extern millis_t max_inactive_time, stepper_inactive_time; extern int lpq_len; #endif +#if HAS_POWER_SWITCH + extern bool powersupply_on; + #define PSU_PIN_ON() do{ OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); powersupply_on = true; }while(0) + #define PSU_PIN_OFF() do{ OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); powersupply_on = false; }while(0) + #if ENABLED(AUTO_POWER_CONTROL) + #define PSU_ON() powerManager.power_on() + #define PSU_OFF() powerManager.power_off() + #else + #define PSU_ON() PSU_PIN_ON() + #define PSU_OFF() PSU_PIN_OFF() + #endif +#endif + bool pin_is_protected(const pin_t pin); #if HAS_SUICIDE diff --git a/Marlin/src/feature/power.cpp b/Marlin/src/feature/power.cpp index d4bda257f6..6e5ba9d43f 100644 --- a/Marlin/src/feature/power.cpp +++ b/Marlin/src/feature/power.cpp @@ -87,11 +87,11 @@ void Power::check() { void Power::power_on() { lastPowerOn = millis(); - OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); + PSU_PIN_ON(); } void Power::power_off() { - OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); + PSU_PIN_OFF(); } #endif // AUTO_POWER_CONTROL diff --git a/Marlin/src/gcode/control/M80_M81.cpp b/Marlin/src/gcode/control/M80_M81.cpp index 10846fc097..eee197dbbd 100644 --- a/Marlin/src/gcode/control/M80_M81.cpp +++ b/Marlin/src/gcode/control/M80_M81.cpp @@ -86,8 +86,6 @@ tmc2208_init(); #endif - powersupply_on = true; - #if ENABLED(ULTIPANEL) LCD_MESSAGEPGM(WELCOME_MSG); #endif @@ -119,7 +117,6 @@ void GcodeSuite::M81() { suicide(); #elif HAS_POWER_SWITCH PSU_OFF(); - powersupply_on = false; #endif #if ENABLED(ULTIPANEL) diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index 40c1339d4c..a5137c0094 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -175,10 +175,6 @@ uint16_t max_display_update_time = 0; #define TALL_FONT_CORRECTION 0 #endif - #if HAS_POWER_SWITCH - extern bool powersupply_on; - #endif - bool no_reentry = false; constexpr int8_t menu_bottom = LCD_HEIGHT - (TALL_FONT_CORRECTION); diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index fdee276d3f..602e4691d1 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -894,7 +894,7 @@ void Planner::_buffer_steps(const int32_t (&target)[XYZE] #if ENABLED(AUTO_POWER_CONTROL) if (block->steps[X_AXIS] || block->steps[Y_AXIS] || block->steps[Z_AXIS]) - powerManager.power_on(); + powerManager.power_on(); #endif //enable active axes