@@ -406,6 +406,7 @@ void startOrResumeJob() {
406406 * - Check if CHDK_PIN needs to go LOW
407407 * - Check for KILL button held down
408408 * - Check for HOME button held down
409+ * - Check for CUSTOM USER button held down
409410 * - Check if cooling fan needs to be switched on
410411 * - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT)
411412 * - Pulse FET_SAFETY_PIN if it exists
@@ -498,6 +499,102 @@ inline void manage_inactivity(const bool ignore_stepper_queue=false) {
498499 }
499500 #endif
500501
502+ #if ENABLED(CUSTOM_USER_BUTTONS)
503+ // Handle a custom user button if defined
504+ const bool printer_not_busy = !printingIsActive ();
505+ #define HAS_CUSTOM_USER_BUTTON (N ) (PIN_EXISTS(BUTTON##N) && defined (BUTTON##N##_HIT_STATE) && defined (BUTTON##N##_GCODE) && defined (BUTTON##N##_DESC))
506+ #define CHECK_CUSTOM_USER_BUTTON (N ) do { \
507+ constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 250UL ; \
508+ static millis_t next_cub_ms_##N; \
509+ if (BUTTON##N##_HIT_STATE == READ (BUTTON##N##_PIN) \
510+ && (ENABLED (BUTTON##N##_WHEN_PRINTING) || printer_not_busy)) { \
511+ const millis_t ms = millis (); \
512+ if (ELAPSED (ms, next_cub_ms_##N)) { \
513+ next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N; \
514+ if (strlen (BUTTON##N##_DESC)) \
515+ LCD_MESSAGEPGM_P (PSTR (BUTTON##N##_DESC)); \
516+ queue.inject_P (PSTR (BUTTON##N##_GCODE)); \
517+ } \
518+ } \
519+ }while (0 )
520+
521+ #if HAS_CUSTOM_USER_BUTTON(1)
522+ CHECK_CUSTOM_USER_BUTTON (1 );
523+ #endif
524+ #if HAS_CUSTOM_USER_BUTTON(2)
525+ CHECK_CUSTOM_USER_BUTTON (2 );
526+ #endif
527+ #if HAS_CUSTOM_USER_BUTTON(3)
528+ CHECK_CUSTOM_USER_BUTTON (3 );
529+ #endif
530+ #if HAS_CUSTOM_USER_BUTTON(4)
531+ CHECK_CUSTOM_USER_BUTTON (4 );
532+ #endif
533+ #if HAS_CUSTOM_USER_BUTTON(5)
534+ CHECK_CUSTOM_USER_BUTTON (5 );
535+ #endif
536+ #if HAS_CUSTOM_USER_BUTTON(6)
537+ CHECK_CUSTOM_USER_BUTTON (6 );
538+ #endif
539+ #if HAS_CUSTOM_USER_BUTTON(7)
540+ CHECK_CUSTOM_USER_BUTTON (7 );
541+ #endif
542+ #if HAS_CUSTOM_USER_BUTTON(8)
543+ CHECK_CUSTOM_USER_BUTTON (8 );
544+ #endif
545+ #if HAS_CUSTOM_USER_BUTTON(9)
546+ CHECK_CUSTOM_USER_BUTTON (9 );
547+ #endif
548+ #if HAS_CUSTOM_USER_BUTTON(10)
549+ CHECK_CUSTOM_USER_BUTTON (10 );
550+ #endif
551+ #if HAS_CUSTOM_USER_BUTTON(11)
552+ CHECK_CUSTOM_USER_BUTTON (11 );
553+ #endif
554+ #if HAS_CUSTOM_USER_BUTTON(12)
555+ CHECK_CUSTOM_USER_BUTTON (12 );
556+ #endif
557+ #if HAS_CUSTOM_USER_BUTTON(13)
558+ CHECK_CUSTOM_USER_BUTTON (13 );
559+ #endif
560+ #if HAS_CUSTOM_USER_BUTTON(14)
561+ CHECK_CUSTOM_USER_BUTTON (14 );
562+ #endif
563+ #if HAS_CUSTOM_USER_BUTTON(15)
564+ CHECK_CUSTOM_USER_BUTTON (15 );
565+ #endif
566+ #if HAS_CUSTOM_USER_BUTTON(16)
567+ CHECK_CUSTOM_USER_BUTTON (16 );
568+ #endif
569+ #if HAS_CUSTOM_USER_BUTTON(17)
570+ CHECK_CUSTOM_USER_BUTTON (17 );
571+ #endif
572+ #if HAS_CUSTOM_USER_BUTTON(18)
573+ CHECK_CUSTOM_USER_BUTTON (18 );
574+ #endif
575+ #if HAS_CUSTOM_USER_BUTTON(19)
576+ CHECK_CUSTOM_USER_BUTTON (19 );
577+ #endif
578+ #if HAS_CUSTOM_USER_BUTTON(20)
579+ CHECK_CUSTOM_USER_BUTTON (20 );
580+ #endif
581+ #if HAS_CUSTOM_USER_BUTTON(21)
582+ CHECK_CUSTOM_USER_BUTTON (21 );
583+ #endif
584+ #if HAS_CUSTOM_USER_BUTTON(22)
585+ CHECK_CUSTOM_USER_BUTTON (22 );
586+ #endif
587+ #if HAS_CUSTOM_USER_BUTTON(23)
588+ CHECK_CUSTOM_USER_BUTTON (23 );
589+ #endif
590+ #if HAS_CUSTOM_USER_BUTTON(24)
591+ CHECK_CUSTOM_USER_BUTTON (24 );
592+ #endif
593+ #if HAS_CUSTOM_USER_BUTTON(25)
594+ CHECK_CUSTOM_USER_BUTTON (25 );
595+ #endif
596+ #endif
597+
501598 TERN_ (USE_CONTROLLER_FAN, controllerFan.update ()); // Check if fan should be turned on to cool stepper drivers down
502599
503600 TERN_ (AUTO_POWER_CONTROL, powerManager.check ());
@@ -857,7 +954,7 @@ inline void tmc_standby_setup() {
857954
858955/* *
859956 * Marlin entry-point: Set up before the program loop
860- * - Set up the kill pin, filament runout, power hold
957+ * - Set up the kill pin, filament runout, power hold, custom user buttons
861958 * - Start the serial port
862959 * - Print startup messages and diagnostics
863960 * - Get EEPROM or default settings
@@ -1131,6 +1228,86 @@ void setup() {
11311228 SET_INPUT_PULLUP (HOME_PIN);
11321229 #endif
11331230
1231+ #if ENABLED(CUSTOM_USER_BUTTONS)
1232+ #define INIT_CUSTOM_USER_BUTTON_PIN (N ) do { SET_INPUT (BUTTON##N##_PIN); WRITE (BUTTON##N##_PIN, !BUTTON##N##_HIT_STATE); }while (0 )
1233+
1234+ #if HAS_CUSTOM_USER_BUTTON(1)
1235+ INIT_CUSTOM_USER_BUTTON_PIN (1 );
1236+ #endif
1237+ #if HAS_CUSTOM_USER_BUTTON(2)
1238+ INIT_CUSTOM_USER_BUTTON_PIN (2 );
1239+ #endif
1240+ #if HAS_CUSTOM_USER_BUTTON(3)
1241+ INIT_CUSTOM_USER_BUTTON_PIN (3 );
1242+ #endif
1243+ #if HAS_CUSTOM_USER_BUTTON(4)
1244+ INIT_CUSTOM_USER_BUTTON_PIN (4 );
1245+ #endif
1246+ #if HAS_CUSTOM_USER_BUTTON(5)
1247+ INIT_CUSTOM_USER_BUTTON_PIN (5 );
1248+ #endif
1249+ #if HAS_CUSTOM_USER_BUTTON(6)
1250+ INIT_CUSTOM_USER_BUTTON_PIN (6 );
1251+ #endif
1252+ #if HAS_CUSTOM_USER_BUTTON(7)
1253+ INIT_CUSTOM_USER_BUTTON_PIN (7 );
1254+ #endif
1255+ #if HAS_CUSTOM_USER_BUTTON(8)
1256+ INIT_CUSTOM_USER_BUTTON_PIN (8 );
1257+ #endif
1258+ #if HAS_CUSTOM_USER_BUTTON(9)
1259+ INIT_CUSTOM_USER_BUTTON_PIN (9 );
1260+ #endif
1261+ #if HAS_CUSTOM_USER_BUTTON(10)
1262+ INIT_CUSTOM_USER_BUTTON_PIN (10 );
1263+ #endif
1264+ #if HAS_CUSTOM_USER_BUTTON(11)
1265+ INIT_CUSTOM_USER_BUTTON_PIN (11 );
1266+ #endif
1267+ #if HAS_CUSTOM_USER_BUTTON(12)
1268+ INIT_CUSTOM_USER_BUTTON_PIN (12 );
1269+ #endif
1270+ #if HAS_CUSTOM_USER_BUTTON(13)
1271+ INIT_CUSTOM_USER_BUTTON_PIN (13 );
1272+ #endif
1273+ #if HAS_CUSTOM_USER_BUTTON(14)
1274+ INIT_CUSTOM_USER_BUTTON_PIN (14 );
1275+ #endif
1276+ #if HAS_CUSTOM_USER_BUTTON(15)
1277+ INIT_CUSTOM_USER_BUTTON_PIN (15 );
1278+ #endif
1279+ #if HAS_CUSTOM_USER_BUTTON(16)
1280+ INIT_CUSTOM_USER_BUTTON_PIN (16 );
1281+ #endif
1282+ #if HAS_CUSTOM_USER_BUTTON(17)
1283+ INIT_CUSTOM_USER_BUTTON_PIN (17 );
1284+ #endif
1285+ #if HAS_CUSTOM_USER_BUTTON(18)
1286+ INIT_CUSTOM_USER_BUTTON_PIN (18 );
1287+ #endif
1288+ #if HAS_CUSTOM_USER_BUTTON(19)
1289+ INIT_CUSTOM_USER_BUTTON_PIN (19 );
1290+ #endif
1291+ #if HAS_CUSTOM_USER_BUTTON(20)
1292+ INIT_CUSTOM_USER_BUTTON_PIN (20 );
1293+ #endif
1294+ #if HAS_CUSTOM_USER_BUTTON(21)
1295+ INIT_CUSTOM_USER_BUTTON_PIN (21 );
1296+ #endif
1297+ #if HAS_CUSTOM_USER_BUTTON(22)
1298+ INIT_CUSTOM_USER_BUTTON_PIN (22 );
1299+ #endif
1300+ #if HAS_CUSTOM_USER_BUTTON(23)
1301+ INIT_CUSTOM_USER_BUTTON_PIN (23 );
1302+ #endif
1303+ #if HAS_CUSTOM_USER_BUTTON(24)
1304+ INIT_CUSTOM_USER_BUTTON_PIN (24 );
1305+ #endif
1306+ #if HAS_CUSTOM_USER_BUTTON(25)
1307+ INIT_CUSTOM_USER_BUTTON_PIN (25 );
1308+ #endif
1309+ #endif
1310+
11341311 #if PIN_EXISTS(STAT_LED_RED)
11351312 OUT_WRITE (STAT_LED_RED_PIN, LOW); // OFF
11361313 #endif
0 commit comments