Browse Source

🎨 Optional Custom Button description (#22336)

ellensp 3 years ago
parent
commit
2c6a053ce1
No account linked to committer's email address
1 changed files with 83 additions and 30 deletions
  1. 83
    30
      Marlin/src/MarlinCore.cpp

+ 83
- 30
Marlin/src/MarlinCore.cpp View File

526
   #if ENABLED(CUSTOM_USER_BUTTONS)
526
   #if ENABLED(CUSTOM_USER_BUTTONS)
527
     // Handle a custom user button if defined
527
     // Handle a custom user button if defined
528
     const bool printer_not_busy = !printingIsActive();
528
     const bool printer_not_busy = !printingIsActive();
529
-    #define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(BUTTON##N) && defined(BUTTON##N##_HIT_STATE) && defined(BUTTON##N##_GCODE) && defined(BUTTON##N##_DESC))
530
-    #define CHECK_CUSTOM_USER_BUTTON(N) do{                            \
529
+    const millis_t ms = millis();
530
+    #define HAS_CUSTOM_USER_BUTTON(N) (PIN_EXISTS(BUTTON##N) && defined(BUTTON##N##_HIT_STATE) && defined(BUTTON##N##_GCODE))
531
+    #define HAS_BETTER_USER_BUTTON(N) HAS_CUSTOM_USER_BUTTON(N) && defined(BUTTON##N##_DESC)
532
+    #define _CHECK_CUSTOM_USER_BUTTON(N, CODE) do{                     \
531
       constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 250UL;               \
533
       constexpr millis_t CUB_DEBOUNCE_DELAY_##N = 250UL;               \
532
       static millis_t next_cub_ms_##N;                                 \
534
       static millis_t next_cub_ms_##N;                                 \
533
       if (BUTTON##N##_HIT_STATE == READ(BUTTON##N##_PIN)               \
535
       if (BUTTON##N##_HIT_STATE == READ(BUTTON##N##_PIN)               \
534
         && (ENABLED(BUTTON##N##_WHEN_PRINTING) || printer_not_busy)) { \
536
         && (ENABLED(BUTTON##N##_WHEN_PRINTING) || printer_not_busy)) { \
535
-        const millis_t ms = millis();                                  \
536
         if (ELAPSED(ms, next_cub_ms_##N)) {                            \
537
         if (ELAPSED(ms, next_cub_ms_##N)) {                            \
537
           next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N;               \
538
           next_cub_ms_##N = ms + CUB_DEBOUNCE_DELAY_##N;               \
538
-          if (strlen(BUTTON##N##_DESC))                                \
539
-            LCD_MESSAGEPGM_P(PSTR(BUTTON##N##_DESC));                  \
539
+          CODE;                                                        \
540
           queue.inject_P(PSTR(BUTTON##N##_GCODE));                     \
540
           queue.inject_P(PSTR(BUTTON##N##_GCODE));                     \
541
         }                                                              \
541
         }                                                              \
542
       }                                                                \
542
       }                                                                \
543
     }while(0)
543
     }while(0)
544
 
544
 
545
-    #if HAS_CUSTOM_USER_BUTTON(1)
545
+    #define CHECK_CUSTOM_USER_BUTTON(N)     _CHECK_CUSTOM_USER_BUTTON(N, NOOP)
546
+    #define CHECK_BETTER_USER_BUTTON(N) _CHECK_CUSTOM_USER_BUTTON(N, if (strlen(BUTTON##N##_DESC)) LCD_MESSAGEPGM_P(PSTR(BUTTON##N##_DESC)))
547
+
548
+    #if HAS_BETTER_USER_BUTTON(1)
549
+      CHECK_BETTER_USER_BUTTON(1);
550
+    #elif HAS_CUSTOM_USER_BUTTON(1)
546
       CHECK_CUSTOM_USER_BUTTON(1);
551
       CHECK_CUSTOM_USER_BUTTON(1);
547
     #endif
552
     #endif
548
-    #if HAS_CUSTOM_USER_BUTTON(2)
553
+    #if HAS_BETTER_USER_BUTTON(2)
554
+      CHECK_BETTER_USER_BUTTON(2);
555
+    #elif HAS_CUSTOM_USER_BUTTON(2)
549
       CHECK_CUSTOM_USER_BUTTON(2);
556
       CHECK_CUSTOM_USER_BUTTON(2);
550
     #endif
557
     #endif
551
-    #if HAS_CUSTOM_USER_BUTTON(3)
558
+    #if HAS_BETTER_USER_BUTTON(3)
559
+      CHECK_BETTER_USER_BUTTON(3);
560
+    #elif HAS_CUSTOM_USER_BUTTON(3)
552
       CHECK_CUSTOM_USER_BUTTON(3);
561
       CHECK_CUSTOM_USER_BUTTON(3);
553
     #endif
562
     #endif
554
-    #if HAS_CUSTOM_USER_BUTTON(4)
563
+    #if HAS_BETTER_USER_BUTTON(4)
564
+      CHECK_BETTER_USER_BUTTON(4);
565
+    #elif HAS_CUSTOM_USER_BUTTON(4)
555
       CHECK_CUSTOM_USER_BUTTON(4);
566
       CHECK_CUSTOM_USER_BUTTON(4);
556
     #endif
567
     #endif
557
-    #if HAS_CUSTOM_USER_BUTTON(5)
568
+    #if HAS_BETTER_USER_BUTTON(5)
569
+      CHECK_BETTER_USER_BUTTON(5);
570
+    #elif HAS_CUSTOM_USER_BUTTON(5)
558
       CHECK_CUSTOM_USER_BUTTON(5);
571
       CHECK_CUSTOM_USER_BUTTON(5);
559
     #endif
572
     #endif
560
-    #if HAS_CUSTOM_USER_BUTTON(6)
573
+    #if HAS_BETTER_USER_BUTTON(6)
574
+      CHECK_BETTER_USER_BUTTON(6);
575
+    #elif HAS_CUSTOM_USER_BUTTON(6)
561
       CHECK_CUSTOM_USER_BUTTON(6);
576
       CHECK_CUSTOM_USER_BUTTON(6);
562
     #endif
577
     #endif
563
-    #if HAS_CUSTOM_USER_BUTTON(7)
578
+    #if HAS_BETTER_USER_BUTTON(7)
579
+      CHECK_BETTER_USER_BUTTON(7);
580
+    #elif HAS_CUSTOM_USER_BUTTON(7)
564
       CHECK_CUSTOM_USER_BUTTON(7);
581
       CHECK_CUSTOM_USER_BUTTON(7);
565
     #endif
582
     #endif
566
-    #if HAS_CUSTOM_USER_BUTTON(8)
583
+    #if HAS_BETTER_USER_BUTTON(8)
584
+      CHECK_BETTER_USER_BUTTON(8);
585
+    #elif HAS_CUSTOM_USER_BUTTON(8)
567
       CHECK_CUSTOM_USER_BUTTON(8);
586
       CHECK_CUSTOM_USER_BUTTON(8);
568
     #endif
587
     #endif
569
-    #if HAS_CUSTOM_USER_BUTTON(9)
588
+    #if HAS_BETTER_USER_BUTTON(9)
589
+      CHECK_BETTER_USER_BUTTON(9);
590
+    #elif HAS_CUSTOM_USER_BUTTON(9)
570
       CHECK_CUSTOM_USER_BUTTON(9);
591
       CHECK_CUSTOM_USER_BUTTON(9);
571
     #endif
592
     #endif
572
-    #if HAS_CUSTOM_USER_BUTTON(10)
593
+    #if HAS_BETTER_USER_BUTTON(10)
594
+      CHECK_BETTER_USER_BUTTON(10);
595
+    #elif HAS_CUSTOM_USER_BUTTON(10)
573
       CHECK_CUSTOM_USER_BUTTON(10);
596
       CHECK_CUSTOM_USER_BUTTON(10);
574
     #endif
597
     #endif
575
-    #if HAS_CUSTOM_USER_BUTTON(11)
598
+    #if HAS_BETTER_USER_BUTTON(11)
599
+      CHECK_BETTER_USER_BUTTON(11);
600
+    #elif HAS_CUSTOM_USER_BUTTON(11)
576
       CHECK_CUSTOM_USER_BUTTON(11);
601
       CHECK_CUSTOM_USER_BUTTON(11);
577
     #endif
602
     #endif
578
-    #if HAS_CUSTOM_USER_BUTTON(12)
603
+    #if HAS_BETTER_USER_BUTTON(12)
604
+      CHECK_BETTER_USER_BUTTON(12);
605
+    #elif HAS_CUSTOM_USER_BUTTON(12)
579
       CHECK_CUSTOM_USER_BUTTON(12);
606
       CHECK_CUSTOM_USER_BUTTON(12);
580
     #endif
607
     #endif
581
-    #if HAS_CUSTOM_USER_BUTTON(13)
608
+    #if HAS_BETTER_USER_BUTTON(13)
609
+      CHECK_BETTER_USER_BUTTON(13);
610
+    #elif HAS_CUSTOM_USER_BUTTON(13)
582
       CHECK_CUSTOM_USER_BUTTON(13);
611
       CHECK_CUSTOM_USER_BUTTON(13);
583
     #endif
612
     #endif
584
-    #if HAS_CUSTOM_USER_BUTTON(14)
613
+    #if HAS_BETTER_USER_BUTTON(14)
614
+      CHECK_BETTER_USER_BUTTON(14);
615
+    #elif HAS_CUSTOM_USER_BUTTON(14)
585
       CHECK_CUSTOM_USER_BUTTON(14);
616
       CHECK_CUSTOM_USER_BUTTON(14);
586
     #endif
617
     #endif
587
-    #if HAS_CUSTOM_USER_BUTTON(15)
618
+    #if HAS_BETTER_USER_BUTTON(15)
619
+      CHECK_BETTER_USER_BUTTON(15);
620
+    #elif HAS_CUSTOM_USER_BUTTON(15)
588
       CHECK_CUSTOM_USER_BUTTON(15);
621
       CHECK_CUSTOM_USER_BUTTON(15);
589
     #endif
622
     #endif
590
-    #if HAS_CUSTOM_USER_BUTTON(16)
623
+    #if HAS_BETTER_USER_BUTTON(16)
624
+      CHECK_BETTER_USER_BUTTON(16);
625
+    #elif HAS_CUSTOM_USER_BUTTON(16)
591
       CHECK_CUSTOM_USER_BUTTON(16);
626
       CHECK_CUSTOM_USER_BUTTON(16);
592
     #endif
627
     #endif
593
-    #if HAS_CUSTOM_USER_BUTTON(17)
628
+    #if HAS_BETTER_USER_BUTTON(17)
629
+      CHECK_BETTER_USER_BUTTON(17);
630
+    #elif HAS_CUSTOM_USER_BUTTON(17)
594
       CHECK_CUSTOM_USER_BUTTON(17);
631
       CHECK_CUSTOM_USER_BUTTON(17);
595
     #endif
632
     #endif
596
-    #if HAS_CUSTOM_USER_BUTTON(18)
633
+    #if HAS_BETTER_USER_BUTTON(18)
634
+      CHECK_BETTER_USER_BUTTON(18);
635
+    #elif HAS_CUSTOM_USER_BUTTON(18)
597
       CHECK_CUSTOM_USER_BUTTON(18);
636
       CHECK_CUSTOM_USER_BUTTON(18);
598
     #endif
637
     #endif
599
-    #if HAS_CUSTOM_USER_BUTTON(19)
638
+    #if HAS_BETTER_USER_BUTTON(19)
639
+      CHECK_BETTER_USER_BUTTON(19);
640
+    #elif HAS_CUSTOM_USER_BUTTON(19)
600
       CHECK_CUSTOM_USER_BUTTON(19);
641
       CHECK_CUSTOM_USER_BUTTON(19);
601
     #endif
642
     #endif
602
-    #if HAS_CUSTOM_USER_BUTTON(20)
643
+    #if HAS_BETTER_USER_BUTTON(20)
644
+      CHECK_BETTER_USER_BUTTON(20);
645
+    #elif HAS_CUSTOM_USER_BUTTON(20)
603
       CHECK_CUSTOM_USER_BUTTON(20);
646
       CHECK_CUSTOM_USER_BUTTON(20);
604
     #endif
647
     #endif
605
-    #if HAS_CUSTOM_USER_BUTTON(21)
648
+    #if HAS_BETTER_USER_BUTTON(21)
649
+      CHECK_BETTER_USER_BUTTON(21);
650
+    #elif HAS_CUSTOM_USER_BUTTON(21)
606
       CHECK_CUSTOM_USER_BUTTON(21);
651
       CHECK_CUSTOM_USER_BUTTON(21);
607
     #endif
652
     #endif
608
-    #if HAS_CUSTOM_USER_BUTTON(22)
653
+    #if HAS_BETTER_USER_BUTTON(22)
654
+      CHECK_BETTER_USER_BUTTON(22);
655
+    #elif HAS_CUSTOM_USER_BUTTON(22)
609
       CHECK_CUSTOM_USER_BUTTON(22);
656
       CHECK_CUSTOM_USER_BUTTON(22);
610
     #endif
657
     #endif
611
-    #if HAS_CUSTOM_USER_BUTTON(23)
658
+    #if HAS_BETTER_USER_BUTTON(23)
659
+      CHECK_BETTER_USER_BUTTON(23);
660
+    #elif HAS_CUSTOM_USER_BUTTON(23)
612
       CHECK_CUSTOM_USER_BUTTON(23);
661
       CHECK_CUSTOM_USER_BUTTON(23);
613
     #endif
662
     #endif
614
-    #if HAS_CUSTOM_USER_BUTTON(24)
663
+    #if HAS_BETTER_USER_BUTTON(24)
664
+      CHECK_BETTER_USER_BUTTON(24);
665
+    #elif HAS_CUSTOM_USER_BUTTON(24)
615
       CHECK_CUSTOM_USER_BUTTON(24);
666
       CHECK_CUSTOM_USER_BUTTON(24);
616
     #endif
667
     #endif
617
-    #if HAS_CUSTOM_USER_BUTTON(25)
668
+    #if HAS_BETTER_USER_BUTTON(25)
669
+      CHECK_BETTER_USER_BUTTON(25);
670
+    #elif HAS_CUSTOM_USER_BUTTON(25)
618
       CHECK_CUSTOM_USER_BUTTON(25);
671
       CHECK_CUSTOM_USER_BUTTON(25);
619
     #endif
672
     #endif
620
   #endif
673
   #endif

Loading…
Cancel
Save