From f798343b0f6d3409e055553bca433b80feea54aa Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 20 Jun 2020 21:01:16 +0200 Subject: [PATCH 1/9] add PIN to trigger G-CODE macro feature --- Marlin/Configuration_adv.h | 7 +- Marlin/src/MarlinCore.cpp | 178 ++++++++++++++++++++++++++++- Marlin/src/inc/Conditionals_post.h | 3 + 3 files changed, 186 insertions(+), 2 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index c5f56f18d0..ee6223ab39 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3191,7 +3191,7 @@ #endif /** - * User-defined menu items that execute custom GCode + * User-defined menu items (up to 25 may be used) that execute custom GCode */ //#define CUSTOM_USER_MENUS #if ENABLED(CUSTOM_USER_MENUS) @@ -3202,6 +3202,11 @@ #define USER_DESC_1 "Home & UBL Info" #define USER_GCODE_1 "G28\nG29 W" + //#define USER_GCODE_PIN_1 -1 // PIN assigned to trigger USER_GCODE_1 execution + #ifdef USER_GCODE_PIN_1 + #define USER_GCODE_PIN_INIT_1 // Init the PIN state at reboot + #define USER_GCODE_PIN_STATE_1 LOW // What state should trigger USER_GCODE_1 execution (LOW or HIGH) + #endif #define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index c6c6ef9b0d..716de5fbd0 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -481,6 +481,7 @@ void startOrResumeJob() { * - Check if CHDK_PIN needs to go LOW * - Check for KILL button held down * - Check for HOME button held down + * - Check for CUSTOM USER button held down * - Check if cooling fan needs to be switched on * - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT) * - Pulse FET_SAFETY_PIN if it exists @@ -573,6 +574,100 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { } #endif + #if HAS_CUSTOM_USER_BUTTONS + // Handle a custom user button if defined as part of a user-defined menu item + // Debug macro on https://godbolt.org/z/SJDZmp + #define HAS_CUSTOM_USER_BUTTON(N) (defined(USER_GCODE_PIN_##N) && 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 = 1000UL; \ + 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); \ + } \ + } \ + }while(0) + + #if HAS_CUSTOM_USER_BUTTON(1) + CHECK_CUSTOM_USER_BUTTON(1); + #endif + #if HAS_CUSTOM_USER_BUTTON(2) + CHECK_CUSTOM_USER_BUTTON(2); + #endif + #if HAS_CUSTOM_USER_BUTTON(3) + CHECK_CUSTOM_USER_BUTTON(3); + #endif + #if HAS_CUSTOM_USER_BUTTON(4) + CHECK_CUSTOM_USER_BUTTON(4); + #endif + #if HAS_CUSTOM_USER_BUTTON(5) + CHECK_CUSTOM_USER_BUTTON(5); + #endif + #if HAS_CUSTOM_USER_BUTTON(6) + CHECK_CUSTOM_USER_BUTTON(6); + #endif + #if HAS_CUSTOM_USER_BUTTON(7) + CHECK_CUSTOM_USER_BUTTON(7); + #endif + #if HAS_CUSTOM_USER_BUTTON(8) + CHECK_CUSTOM_USER_BUTTON(8); + #endif + #if HAS_CUSTOM_USER_BUTTON(9) + CHECK_CUSTOM_USER_BUTTON(9); + #endif + #if HAS_CUSTOM_USER_BUTTON(10) + CHECK_CUSTOM_USER_BUTTON(10); + #endif + #if HAS_CUSTOM_USER_BUTTON(11) + CHECK_CUSTOM_USER_BUTTON(11); + #endif + #if HAS_CUSTOM_USER_BUTTON(12) + CHECK_CUSTOM_USER_BUTTON(12); + #endif + #if HAS_CUSTOM_USER_BUTTON(13) + CHECK_CUSTOM_USER_BUTTON(13); + #endif + #if HAS_CUSTOM_USER_BUTTON(14) + CHECK_CUSTOM_USER_BUTTON(14); + #endif + #if HAS_CUSTOM_USER_BUTTON(15) + CHECK_CUSTOM_USER_BUTTON(15); + #endif + #if HAS_CUSTOM_USER_BUTTON(16) + CHECK_CUSTOM_USER_BUTTON(16); + #endif + #if HAS_CUSTOM_USER_BUTTON(17) + CHECK_CUSTOM_USER_BUTTON(17); + #endif + #if HAS_CUSTOM_USER_BUTTON(18) + CHECK_CUSTOM_USER_BUTTON(18); + #endif + #if HAS_CUSTOM_USER_BUTTON(19) + CHECK_CUSTOM_USER_BUTTON(19); + #endif + #if HAS_CUSTOM_USER_BUTTON(20) + CHECK_CUSTOM_USER_BUTTON(20); + #endif + #if HAS_CUSTOM_USER_BUTTON(21) + CHECK_CUSTOM_USER_BUTTON(21); + #endif + #if HAS_CUSTOM_USER_BUTTON(22) + CHECK_CUSTOM_USER_BUTTON(22); + #endif + #if HAS_CUSTOM_USER_BUTTON(23) + CHECK_CUSTOM_USER_BUTTON(23); + #endif + #if HAS_CUSTOM_USER_BUTTON(24) + CHECK_CUSTOM_USER_BUTTON(24); + #endif + #if HAS_CUSTOM_USER_BUTTON(25) + CHECK_CUSTOM_USER_BUTTON(25); + #endif + #endif + TERN_(USE_CONTROLLER_FAN, controllerFan.update()); // Check if fan should be turned on to cool stepper drivers down TERN_(AUTO_POWER_CONTROL, powerManager.check()); @@ -920,7 +1015,7 @@ inline void tmc_standby_setup() { /** * Marlin entry-point: Set up before the program loop - * - Set up the kill pin, filament runout, power hold + * - Set up the kill pin, filament runout, power hold, custom user buttons * - Start the serial port * - Print startup messages and diagnostics * - Get EEPROM or default settings @@ -1148,6 +1243,87 @@ void setup() { SET_INPUT_PULLUP(HOME_PIN); #endif + #if HAS_CUSTOM_USER_BUTTONS + #define INIT_CUSTOM_USER_BUTTON_PINS(N) (ENABLED(USER_GCODE_PIN_INIT_##N) && defined(USER_GCODE_PIN_##N) && defined(USER_GCODE_PIN_STATE_##N)) + #define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(USER_GCODE_PIN_##N); WRITE(USER_GCODE_PIN_##N, !USER_GCODE_PIN_STATE_##N); }while(0) + + #if INIT_CUSTOM_USER_BUTTON_PINS(1) + INIT_CUSTOM_USER_BUTTON_PIN(1); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(2) + INIT_CUSTOM_USER_BUTTON_PIN(2); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(3) + INIT_CUSTOM_USER_BUTTON_PIN(3); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(4) + INIT_CUSTOM_USER_BUTTON_PIN(4); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(5) + INIT_CUSTOM_USER_BUTTON_PIN(5); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(6) + INIT_CUSTOM_USER_BUTTON_PIN(6); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(7) + INIT_CUSTOM_USER_BUTTON_PIN(7); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(8) + INIT_CUSTOM_USER_BUTTON_PIN(8); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(9) + INIT_CUSTOM_USER_BUTTON_PIN(9); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(10) + INIT_CUSTOM_USER_BUTTON_PIN(10); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(11) + INIT_CUSTOM_USER_BUTTON_PIN(11); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(12) + INIT_CUSTOM_USER_BUTTON_PIN(12); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(13) + INIT_CUSTOM_USER_BUTTON_PIN(13); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(14) + INIT_CUSTOM_USER_BUTTON_PIN(14); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(15) + INIT_CUSTOM_USER_BUTTON_PIN(15); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(16) + INIT_CUSTOM_USER_BUTTON_PIN(16); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(17) + INIT_CUSTOM_USER_BUTTON_PIN(17); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(18) + INIT_CUSTOM_USER_BUTTON_PIN(18); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(19) + INIT_CUSTOM_USER_BUTTON_PIN(19); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(20) + INIT_CUSTOM_USER_BUTTON_PIN(20); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(21) + INIT_CUSTOM_USER_BUTTON_PIN(21); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(22) + INIT_CUSTOM_USER_BUTTON_PIN(22); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(23) + INIT_CUSTOM_USER_BUTTON_PIN(23); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(24) + INIT_CUSTOM_USER_BUTTON_PIN(24); + #endif + #if INIT_CUSTOM_USER_BUTTON_PINS(25) + INIT_CUSTOM_USER_BUTTON_PIN(25); + #endif + #endif + #if PIN_EXISTS(STAT_LED_RED) OUT_WRITE(STAT_LED_RED_PIN, LOW); // OFF #endif diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index c9a29b351c..e0901fc620 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -1966,6 +1966,9 @@ #if PIN_EXISTS(PHOTOGRAPH) #define HAS_PHOTOGRAPH 1 #endif +#if ENABLED(CUSTOM_USER_MENUS) + #define HAS_CUSTOM_USER_BUTTONS 1 +#endif // Digital control #if PIN_EXISTS(STEPPER_RESET) From 311ad9454bd3ac0f3e5252394c60ff23423aaf2e Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Mon, 22 Jun 2020 21:36:57 +0200 Subject: [PATCH 2/9] ensure PIN_EXISTS --- Marlin/src/MarlinCore.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 716de5fbd0..74e6c4241c 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -577,7 +577,7 @@ 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 // Debug macro on https://godbolt.org/z/SJDZmp - #define HAS_CUSTOM_USER_BUTTON(N) (defined(USER_GCODE_PIN_##N) && defined(USER_GCODE_PIN_STATE_##N) && defined(USER_GCODE_##N) && defined(USER_DESC_##N)) + #define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(USER_GCODE_PIN_##N) && 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 = 1000UL; \ static millis_t next_cub_ms_##N; \ @@ -1244,7 +1244,7 @@ void setup() { #endif #if HAS_CUSTOM_USER_BUTTONS - #define INIT_CUSTOM_USER_BUTTON_PINS(N) (ENABLED(USER_GCODE_PIN_INIT_##N) && defined(USER_GCODE_PIN_##N) && defined(USER_GCODE_PIN_STATE_##N)) + #define INIT_CUSTOM_USER_BUTTON_PINS(N) (PIN_EXISTS(USER_GCODE_PIN_##N) && ENABLED(USER_GCODE_PIN_INIT_##N) && defined(USER_GCODE_PIN_STATE_##N)) #define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(USER_GCODE_PIN_##N); WRITE(USER_GCODE_PIN_##N, !USER_GCODE_PIN_STATE_##N); }while(0) #if INIT_CUSTOM_USER_BUTTON_PINS(1) From bbd5f47187be48d0f41aff705971e4f72cdb0ea8 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Mon, 22 Jun 2020 21:42:42 +0200 Subject: [PATCH 3/9] update configuration.h --- Marlin/Configuration_adv.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index ee6223ab39..2ff73a28ab 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3210,15 +3210,35 @@ #define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) + //#define USER_GCODE_PIN_2 -1 // PIN assigned to trigger USER_GCODE_2 execution + #ifdef USER_GCODE_PIN_2 + #define USER_GCODE_PIN_INIT_2 // Init the PIN state at reboot + #define USER_GCODE_PIN_STATE_2 LOW // What state should trigger USER_GCODE_2 execution (LOW or HIGH) + #endif #define USER_DESC_3 "Preheat for " PREHEAT_2_LABEL #define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) + //#define USER_GCODE_PIN_3 -1 // PIN assigned to trigger USER_GCODE_3 execution + #ifdef USER_GCODE_PIN_3 + #define USER_GCODE_PIN_INIT_3 // Init the PIN state at reboot + #define USER_GCODE_PIN_STATE_3 LOW // What state should trigger USER_GCODE_3 execution (LOW or HIGH) + #endif #define USER_DESC_4 "Heat Bed/Home/Level" #define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29" + //#define USER_GCODE_PIN_4 -1 // PIN assigned to trigger USER_GCODE_4 execution + #ifdef USER_GCODE_PIN_4 + #define USER_GCODE_PIN_INIT_4 // Init the PIN state at reboot + #define USER_GCODE_PIN_STATE_4 LOW // What state should trigger USER_GCODE_4 execution (LOW or HIGH) + #endif #define USER_DESC_5 "Home & Info" #define USER_GCODE_5 "G28\nM503" + //#define USER_GCODE_PIN_5 -1 // PIN assigned to trigger USER_GCODE_5 execution + #ifdef USER_GCODE_PIN_5 + #define USER_GCODE_PIN_INIT_5 // Init the PIN state at reboot + #define USER_GCODE_PIN_STATE_5 LOW // What state should trigger USER_GCODE_5 execution (LOW or HIGH) + #endif #endif /** From d5899a21abd9924905d62d5f867dc2408eb8aa51 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Mon, 22 Jun 2020 15:22:45 -0500 Subject: [PATCH 4/9] Update MarlinCore.cpp --- Marlin/src/MarlinCore.cpp | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 74e6c4241c..afd561703b 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -1247,79 +1247,79 @@ void setup() { #define INIT_CUSTOM_USER_BUTTON_PINS(N) (PIN_EXISTS(USER_GCODE_PIN_##N) && ENABLED(USER_GCODE_PIN_INIT_##N) && defined(USER_GCODE_PIN_STATE_##N)) #define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(USER_GCODE_PIN_##N); WRITE(USER_GCODE_PIN_##N, !USER_GCODE_PIN_STATE_##N); }while(0) - #if INIT_CUSTOM_USER_BUTTON_PINS(1) + #if HAS_CUSTOM_USER_BUTTON(1) INIT_CUSTOM_USER_BUTTON_PIN(1); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(2) + #if HAS_CUSTOM_USER_BUTTON(2) INIT_CUSTOM_USER_BUTTON_PIN(2); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(3) + #if HAS_CUSTOM_USER_BUTTON(3) INIT_CUSTOM_USER_BUTTON_PIN(3); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(4) + #if HAS_CUSTOM_USER_BUTTON(4) INIT_CUSTOM_USER_BUTTON_PIN(4); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(5) + #if HAS_CUSTOM_USER_BUTTON(5) INIT_CUSTOM_USER_BUTTON_PIN(5); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(6) + #if HAS_CUSTOM_USER_BUTTON(6) INIT_CUSTOM_USER_BUTTON_PIN(6); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(7) + #if HAS_CUSTOM_USER_BUTTON(7) INIT_CUSTOM_USER_BUTTON_PIN(7); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(8) + #if HAS_CUSTOM_USER_BUTTON(8) INIT_CUSTOM_USER_BUTTON_PIN(8); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(9) + #if HAS_CUSTOM_USER_BUTTON(9) INIT_CUSTOM_USER_BUTTON_PIN(9); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(10) + #if HAS_CUSTOM_USER_BUTTON(10) INIT_CUSTOM_USER_BUTTON_PIN(10); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(11) + #if HAS_CUSTOM_USER_BUTTON(11) INIT_CUSTOM_USER_BUTTON_PIN(11); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(12) + #if HAS_CUSTOM_USER_BUTTON(12) INIT_CUSTOM_USER_BUTTON_PIN(12); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(13) + #if HAS_CUSTOM_USER_BUTTON(13) INIT_CUSTOM_USER_BUTTON_PIN(13); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(14) + #if HAS_CUSTOM_USER_BUTTON(14) INIT_CUSTOM_USER_BUTTON_PIN(14); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(15) + #if HAS_CUSTOM_USER_BUTTON(15) INIT_CUSTOM_USER_BUTTON_PIN(15); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(16) + #if HAS_CUSTOM_USER_BUTTON(16) INIT_CUSTOM_USER_BUTTON_PIN(16); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(17) + #if HAS_CUSTOM_USER_BUTTON(17) INIT_CUSTOM_USER_BUTTON_PIN(17); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(18) + #if HAS_CUSTOM_USER_BUTTON(18) INIT_CUSTOM_USER_BUTTON_PIN(18); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(19) + #if HAS_CUSTOM_USER_BUTTON(19) INIT_CUSTOM_USER_BUTTON_PIN(19); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(20) + #if HAS_CUSTOM_USER_BUTTON(20) INIT_CUSTOM_USER_BUTTON_PIN(20); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(21) + #if HAS_CUSTOM_USER_BUTTON(21) INIT_CUSTOM_USER_BUTTON_PIN(21); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(22) + #if HAS_CUSTOM_USER_BUTTON(22) INIT_CUSTOM_USER_BUTTON_PIN(22); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(23) + #if HAS_CUSTOM_USER_BUTTON(23) INIT_CUSTOM_USER_BUTTON_PIN(23); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(24) + #if HAS_CUSTOM_USER_BUTTON(24) INIT_CUSTOM_USER_BUTTON_PIN(24); #endif - #if INIT_CUSTOM_USER_BUTTON_PINS(25) + #if HAS_CUSTOM_USER_BUTTON(25) INIT_CUSTOM_USER_BUTTON_PIN(25); #endif #endif From 3652f24350b5feb63deddc06ffc91c57083bb03d Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 10:10:30 +0200 Subject: [PATCH 5/9] INIT_CUSTOM_USER_BUTTON_PINS(N) macro and USER_GCODE_PIN_INIT_n removed; USER_GCODE_PIN_n will always be initiated --- Marlin/Configuration_adv.h | 5 ----- Marlin/src/MarlinCore.cpp | 1 - 2 files changed, 6 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 2ff73a28ab..276e668094 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3204,7 +3204,6 @@ #define USER_GCODE_1 "G28\nG29 W" //#define USER_GCODE_PIN_1 -1 // PIN assigned to trigger USER_GCODE_1 execution #ifdef USER_GCODE_PIN_1 - #define USER_GCODE_PIN_INIT_1 // Init the PIN state at reboot #define USER_GCODE_PIN_STATE_1 LOW // What state should trigger USER_GCODE_1 execution (LOW or HIGH) #endif @@ -3212,7 +3211,6 @@ #define USER_GCODE_2 "M140 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) //#define USER_GCODE_PIN_2 -1 // PIN assigned to trigger USER_GCODE_2 execution #ifdef USER_GCODE_PIN_2 - #define USER_GCODE_PIN_INIT_2 // Init the PIN state at reboot #define USER_GCODE_PIN_STATE_2 LOW // What state should trigger USER_GCODE_2 execution (LOW or HIGH) #endif @@ -3220,7 +3218,6 @@ #define USER_GCODE_3 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nM104 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) //#define USER_GCODE_PIN_3 -1 // PIN assigned to trigger USER_GCODE_3 execution #ifdef USER_GCODE_PIN_3 - #define USER_GCODE_PIN_INIT_3 // Init the PIN state at reboot #define USER_GCODE_PIN_STATE_3 LOW // What state should trigger USER_GCODE_3 execution (LOW or HIGH) #endif @@ -3228,7 +3225,6 @@ #define USER_GCODE_4 "M140 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\nG28\nG29" //#define USER_GCODE_PIN_4 -1 // PIN assigned to trigger USER_GCODE_4 execution #ifdef USER_GCODE_PIN_4 - #define USER_GCODE_PIN_INIT_4 // Init the PIN state at reboot #define USER_GCODE_PIN_STATE_4 LOW // What state should trigger USER_GCODE_4 execution (LOW or HIGH) #endif @@ -3236,7 +3232,6 @@ #define USER_GCODE_5 "G28\nM503" //#define USER_GCODE_PIN_5 -1 // PIN assigned to trigger USER_GCODE_5 execution #ifdef USER_GCODE_PIN_5 - #define USER_GCODE_PIN_INIT_5 // Init the PIN state at reboot #define USER_GCODE_PIN_STATE_5 LOW // What state should trigger USER_GCODE_5 execution (LOW or HIGH) #endif #endif diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index afd561703b..c2c766c494 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -1244,7 +1244,6 @@ void setup() { #endif #if HAS_CUSTOM_USER_BUTTONS - #define INIT_CUSTOM_USER_BUTTON_PINS(N) (PIN_EXISTS(USER_GCODE_PIN_##N) && ENABLED(USER_GCODE_PIN_INIT_##N) && defined(USER_GCODE_PIN_STATE_##N)) #define INIT_CUSTOM_USER_BUTTON_PIN(N) do{ SET_INPUT(USER_GCODE_PIN_##N); WRITE(USER_GCODE_PIN_##N, !USER_GCODE_PIN_STATE_##N); }while(0) #if HAS_CUSTOM_USER_BUTTON(1) From 7d7f33cfa71cf703af1b788e3550cf878e222830 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 15:21:27 +0200 Subject: [PATCH 6/9] fix PIN_EXISTS was ignored --- Marlin/src/MarlinCore.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index c2c766c494..16e0ce2698 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -576,8 +576,7 @@ 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 - // Debug macro on https://godbolt.org/z/SJDZmp - #define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(USER_GCODE_PIN_##N) && defined(USER_GCODE_PIN_STATE_##N) && defined(USER_GCODE_##N) && defined(USER_DESC_##N)) + #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 = 1000UL; \ static millis_t next_cub_ms_##N; \ From ed6e0ba36724b2da389a5f8f88f09c47fc94f61c Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 15:22:05 +0200 Subject: [PATCH 7/9] make pin a bit less bouncy --- Marlin/src/MarlinCore.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/src/MarlinCore.cpp b/Marlin/src/MarlinCore.cpp index 16e0ce2698..c902eb15c3 100644 --- a/Marlin/src/MarlinCore.cpp +++ b/Marlin/src/MarlinCore.cpp @@ -578,7 +578,7 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) { // Handle a custom user button if defined as part of a user-defined menu item #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 = 1000UL; \ + 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(); \ From d292c9e9ea04d9a1847fc0281d9fe993106985b3 Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 16:05:21 +0200 Subject: [PATCH 8/9] 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) From a02d19421a7f8c8710f9b0ce5d9270c52170c90b Mon Sep 17 00:00:00 2001 From: Dirk Moeller Date: Sat, 26 Sep 2020 16:18:32 +0200 Subject: [PATCH 9/9] fix typo --- Marlin/Configuration_adv.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 5e3fa419d1..be88feb8e9 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -3205,7 +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 + #define USER_GCODE_PIN_TRIGGER_ALWAYS_1 false // PIN can trigger USER_GCODE_1 even if print job timer is running #endif #define USER_DESC_2 "Preheat for " PREHEAT_1_LABEL @@ -3213,7 +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 + #define USER_GCODE_PIN_TRIGGER_ALWAYS_2 false // PIN can trigger USER_GCODE_2 even if print job timer is running #endif #define USER_DESC_3 "Preheat for " PREHEAT_2_LABEL @@ -3221,7 +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 + #define USER_GCODE_PIN_TRIGGER_ALWAYS_3 false // PIN can trigger USER_GCODE_3 even if print job timer is running #endif #define USER_DESC_4 "Heat Bed/Home/Level" @@ -3229,7 +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 + #define USER_GCODE_PIN_TRIGGER_ALWAYS_4 false // PIN can trigger USER_GCODE_4 even if print job timer is running #endif #define USER_DESC_5 "Home & Info"