From 539e0c2f31f7a98f09e7bd42721d322315125409 Mon Sep 17 00:00:00 2001 From: Pablo Ventura Date: Wed, 10 May 2017 13:07:58 -0300 Subject: [PATCH] "M80 S" to report the state of the PSU pin --- Marlin/Marlin_main.cpp | 30 ++++++++++++++++++++---------- Marlin/ultralcd.cpp | 4 ++-- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 4047adb52b..4f227afb81 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -559,8 +559,8 @@ static uint8_t target_extruder; #endif // FWRETRACT -#if ENABLED(ULTIPANEL) && HAS_POWER_SWITCH - bool powersupply = +#if HAS_POWER_SWITCH + bool powersupply_on = #if ENABLED(PS_DEFAULT_OFF) false #else @@ -7093,10 +7093,18 @@ inline void gcode_M140() { #if HAS_POWER_SWITCH /** - * M80: Turn on Power Supply + * M80 : Turn on the Power Supply + * M80 S : Report the current state and exit */ inline void gcode_M80() { - OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); //GND + + // S: Report the current power supply state and exit + if (code_seen('S')) { + serialprintPGM(powersupply_on ? PSTR("PS:1\n") : PSTR("PS:0\n")); + return; + } + + OUT_WRITE(PS_ON_PIN, PS_ON_AWAKE); // GND /** * If you have a switch on suicide pin, this is useful @@ -7112,8 +7120,9 @@ inline void gcode_M140() { tmc2130_init(); // Settings only stick when the driver has power #endif + powersupply_on = true; + #if ENABLED(ULTIPANEL) - powersupply = true; LCD_MESSAGEPGM(WELCOME_MSG); #endif } @@ -7128,25 +7137,26 @@ inline void gcode_M140() { inline void gcode_M81() { thermalManager.disable_all_heaters(); stepper.finish_and_disable(); + #if FAN_COUNT > 0 for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0; - #if ENABLED(PROBING_FANS_OFF) fans_paused = false; ZERO(paused_fanSpeeds); #endif #endif + safe_delay(1000); // Wait 1 second before switching off + #if HAS_SUICIDE stepper.synchronize(); suicide(); #elif HAS_POWER_SWITCH OUT_WRITE(PS_ON_PIN, PS_ON_ASLEEP); + powersupply_on = false; #endif + #if ENABLED(ULTIPANEL) - #if HAS_POWER_SWITCH - powersupply = false; - #endif LCD_MESSAGEPGM(MACHINE_NAME " " MSG_OFF "."); #endif } @@ -10119,7 +10129,7 @@ void process_next_command() { gcode_M81(); break; - case 82: // M83: Set E axis normal mode (same as other axes) + case 82: // M82: Set E axis normal mode (same as other axes) gcode_M82(); break; case 83: // M83: Set E axis relative mode diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 29eb269bdc..f563c09ccc 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -98,7 +98,7 @@ uint16_t max_display_update_time = 0; typedef void (*screenFunc_t)(); #if HAS_POWER_SWITCH - extern bool powersupply; + extern bool powersupply_on; #endif #if ENABLED(AUTO_BED_LEVELING_UBL) @@ -2129,7 +2129,7 @@ void kill_screen(const char* lcd_msg) { // Switch power on/off // #if HAS_POWER_SWITCH - if (powersupply) + if (powersupply_on) MENU_ITEM(gcode, MSG_SWITCH_PS_OFF, PSTR("M81")); else MENU_ITEM(gcode, MSG_SWITCH_PS_ON, PSTR("M80"));