Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add external pin to control PSU state M80/M81 #20006

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:");
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions Marlin/src/MarlinCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions Marlin/src/pins/ramps/pins_RAMPS.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down