From 4448422913d4e92f90e277cb855378e84b666245 Mon Sep 17 00:00:00 2001 From: lwtnb-wrk Date: Mon, 2 Nov 2020 19:40:33 -0300 Subject: [PATCH] Add external pin to control PSU state M80/M81 --- Marlin/src/MarlinCore.cpp | 29 +++++++++++++++++++++++++++++ Marlin/src/MarlinCore.h | 6 ++++++ Marlin/src/pins/ramps/pins_RAMPS.h | 5 +++++ 3 files changed, 40 insertions(+) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index e395bdccb8..fbfd30255c 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -231,6 +231,8 @@ PGMSTR(G28_STR, "G28"); PGMSTR(M21_STR, "M21"); PGMSTR(M23_STR, "M23 %s"); PGMSTR(M24_STR, "M24"); +PGMSTR(M80_STR, "M80"); +PGMSTR(M81_STR, "M81"); PGMSTR(SP_P_STR, " P"); PGMSTR(SP_T_STR, " T"); PGMSTR(X_STR, "X"); PGMSTR(Y_STR, "Y"); PGMSTR(Z_STR, "Z"); PGMSTR(E_STR, "E"); PGMSTR(X_LBL, "X:"); PGMSTR(Y_LBL, "Y:"); PGMSTR(Z_LBL, "Z:"); PGMSTR(E_LBL, "E:"); @@ -288,6 +290,13 @@ void setup_powerhold() { OUT_WRITE(SUICIDE_PIN, !SUICIDE_PIN_INVERTING); #endif #if ENABLED(PSU_CONTROL) + #if PSU_EXT_PIN + #if PSU_EXT_PIN_STATE + SET_INPUT_PULLDOWN(PSU_EXT_PIN); + #else + SET_INPUT_PULLUP(PSU_EXT_PIN); + #endif + #endif powersupply_on = ENABLED(PSU_DEFAULT_OFF); if (ENABLED(PSU_DEFAULT_OFF)) PSU_OFF(); else PSU_ON(); #endif @@ -563,6 +572,21 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { } #endif + #if ENABLED(PSU_CONTROL) + #if PSU_EXT_PIN + // Handle a standalone PSU_EXT button + constexpr millis_t PSU_EXT_DEBOUNCE_DELAY = 750UL; + static millis_t next_psu_ext_key_ms; // = 0 + if (!IS_SD_PRINTING() && psu_ext_state()) { + const millis_t ms = millis(); + if (ELAPSED(ms, next_psu_ext_key_ms)) { + next_psu_ext_key_ms = ms + PSU_EXT_DEBOUNCE_DELAY; + powersupply_on ? queue.enqueue_now_P(M81_STR) : queue.enqueue_now_P(M80_STR); + } + } + #endif + #endif + #if HAS_HOME // Handle a standalone HOME button constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL; @@ -1295,6 +1319,11 @@ void setup() { SETUP_RUN(tft_lvgl_init()); #endif + #if ENABLED(PSU_CONTROL) + if (!powersupply_on) + LCD_MESSAGEPGM_P(PSTR(MACHINE_NAME " " STR_OFF ".")); + #endif + #if ENABLED(PASSWORD_ON_STARTUP) SETUP_RUN(password.lock_machine()); // Will not proceed until correct password provided #endif diff --git a/Marlin/src/MarlinCore.h b/Marlin/src/MarlinCore.h index 69afc7f30e..fc0c89dce3 100644 --- a/Marlin/src/MarlinCore.h +++ b/Marlin/src/MarlinCore.h @@ -98,6 +98,12 @@ extern bool wait_for_heatup; #define PSU_ON() PSU_PIN_ON() #define PSU_OFF() PSU_PIN_OFF() #endif + #if PSU_EXT_PIN + #ifndef PSU_EXT_PIN_STATE + #define PSU_EXT_PIN_STATE LOW + #endif + inline bool psu_ext_state() { return READ(PSU_EXT_PIN) == PSU_EXT_PIN_STATE; } + #endif #endif bool pin_is_protected(const pin_t pin); diff --git a/Marlin/src/pins/ramps/pins_RAMPS.h b/Marlin/src/pins/ramps/pins_RAMPS.h index 69a80d6b27..5d5b915d5d 100644 --- a/Marlin/src/pins/ramps/pins_RAMPS.h +++ b/Marlin/src/pins/ramps/pins_RAMPS.h @@ -261,6 +261,11 @@ #define PS_ON_PIN 12 #endif +// External pin to control PSU state +#ifndef PSU_EXT_PIN + #define PSU_EXT_PIN 58 +#endif + #if ENABLED(CASE_LIGHT_ENABLE) && !defined(CASE_LIGHT_PIN) && !defined(SPINDLE_LASER_ENA_PIN) #if NUM_SERVOS <= 1 // Prefer the servo connector #define CASE_LIGHT_PIN 6 // Hardware PWM