From d292c9e9ea04d9a1847fc0281d9fe993106985b3 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 16:05:21 +0200 Subject: [PATCH] avoid while printing --- Marlin/Configuration_adv.h | 5 +++++ Marlin/src/MarlinCore.cpp | 24 +++++++++++++----------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 276e668094..5e3fa419d1 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3205,6 +3205,7 @@ //#define USER_GCODE_PIN_1 -1 // PIN assigned to trigger USER_GCODE_1 execution #ifdef USER_GCODE_PIN_1 #define USER_GCODE_PIN_STATE_1 LOW // What state should trigger USER_GCODE_1 execution (LOW or HIGH) + #define USER_GCODE_PIN_TRIGGER_ALWAYS_1 false // PIN can trigger USER_GCODE_5 even if print job timer is running #endif #define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL @@ -3212,6 +3213,7 @@ //#define USER_GCODE_PIN_2 -1 // PIN assigned to trigger USER_GCODE_2 execution #ifdef USER_GCODE_PIN_2 #define USER_GCODE_PIN_STATE_2 LOW // What state should trigger USER_GCODE_2 execution (LOW or HIGH) + #define USER_GCODE_PIN_TRIGGER_ALWAYS_2 false // PIN can trigger USER_GCODE_5 even if print job timer is running #endif #define USER_DESC_3 "Preheat for " PREHEAT_2_LABEL @@ -3219,6 +3221,7 @@ //#define USER_GCODE_PIN_3 -1 // PIN assigned to trigger USER_GCODE_3 execution #ifdef USER_GCODE_PIN_3 #define USER_GCODE_PIN_STATE_3 LOW // What state should trigger USER_GCODE_3 execution (LOW or HIGH) + #define USER_GCODE_PIN_TRIGGER_ALWAYS_3 false // PIN can trigger USER_GCODE_5 even if print job timer is running #endif #define USER_DESC_4 "Heat Bed/Home/Level" @@ -3226,6 +3229,7 @@ //#define USER_GCODE_PIN_4 -1 // PIN assigned to trigger USER_GCODE_4 execution #ifdef USER_GCODE_PIN_4 #define USER_GCODE_PIN_STATE_4 LOW // What state should trigger USER_GCODE_4 execution (LOW or HIGH) + #define USER_GCODE_PIN_TRIGGER_ALWAYS_4 false // PIN can trigger USER_GCODE_5 even if print job timer is running #endif #define USER_DESC_5 "Home & Info" @@ -3233,6 +3237,7 @@ //#define USER_GCODE_PIN_5 -1 // PIN assigned to trigger USER_GCODE_5 execution #ifdef USER_GCODE_PIN_5 #define USER_GCODE_PIN_STATE_5 LOW // What state should trigger USER_GCODE_5 execution (LOW or HIGH) + #define USER_GCODE_PIN_TRIGGER_ALWAYS_5 false // PIN can trigger USER_GCODE_5 even if print job timer is running #endif #endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index c902eb15c3..5a9e4141d7 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -576,18 +576,20 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { #if HAS_CUSTOM_USER_BUTTONS // Handle a custom user button if defined as part of a user-defined menu item + const bool printer_not_busy = !printingIsActive(); #define HAS_CUSTOM_USER_BUTTON(N) ((defined(USER_GCODE_PIN_##N) && USER_GCODE_PIN_##N >= 0) && defined(USER_GCODE_PIN_STATE_##N) && defined(USER_GCODE_##N) && defined(USER_DESC_##N)) - #define CHECK_CUSTOM_USER_BUTTON(N) do{ \ - constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 2000UL; \ - static millis_t next_cub_ms_##N; \ - if (USER_GCODE_PIN_STATE_##N == READ(USER_GCODE_PIN_##N)) { \ - const millis_t ms = millis(); \ - if (ELAPSED(ms, next_cub_ms_##N)) { \ - next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \ - LCD_MESSAGEPGM_P(USER_DESC_##N); \ - queue.inject_P(USER_GCODE_##N); \ - } \ - } \ + #define CHECK_CUSTOM_USER_BUTTON(N) do{ \ + constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 2000UL; \ + static millis_t next_cub_ms_##N; \ + if ((USER_GCODE_PIN_STATE_##N == READ(USER_GCODE_PIN_##N)) \ + && (USER_GCODE_PIN_TRIGGER_ALWAYS_##N || printer_not_busy)) { \ + const millis_t ms = millis(); \ + if (ELAPSED(ms, next_cub_ms_##N)) { \ + next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \ + LCD_MESSAGEPGM_P(USER_DESC_##N); \ + queue.inject_P(USER_GCODE_##N); \ + } \ + } \ }while(0) #if HAS_CUSTOM_USER_BUTTON(1)