Browse Source

Merge pull request #8512 from thinkyhead/bf2_debouncer

[2.0.x] General code clean/comment
Scott Lahteine 7 years ago
parent
commit
8d0a45f5d4
No account linked to committer's email address

+ 3
- 3
Marlin/src/gcode/control/M42.cpp View File

@@ -37,10 +37,10 @@ void GcodeSuite::M42() {
37 37
   if (!parser.seenval('S')) return;
38 38
   const byte pin_status = parser.value_byte();
39 39
 
40
-  int pin_number = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
41
-  if (pin_number < 0) return;
40
+  const int pin_index = PARSED_PIN_INDEX('P', GET_PIN_MAP_INDEX(LED_PIN));
41
+  if (pin_index < 0) return;
42 42
 
43
-  const pin_t pin = GET_PIN_MAP_PIN(pin_number);
43
+  const pin_t pin = GET_PIN_MAP_PIN(pin_index);
44 44
   if (pin_is_protected(pin)) {
45 45
     SERIAL_ERROR_START();
46 46
     SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);

+ 24
- 14
Marlin/src/lcd/ultralcd.cpp View File

@@ -4590,14 +4590,20 @@ void lcd_update() {
4590 4590
 
4591 4591
   #if ENABLED(ULTIPANEL)
4592 4592
     static millis_t return_to_status_ms = 0;
4593
+
4594
+    // Handle any queued Move Axis motion
4593 4595
     manage_manual_move();
4594 4596
 
4597
+    // Update button states for LCD_CLICKED, etc.
4598
+    // After state changes the next button update
4599
+    // may be delayed 300-500ms.
4595 4600
     lcd_buttons_update();
4596 4601
 
4597 4602
     #if ENABLED(AUTO_BED_LEVELING_UBL)
4598
-      const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
4603
+      // Don't run the debouncer if UBL owns the display
4604
+      #define UBL_CONDITION !ubl.has_control_of_lcd_panel
4599 4605
     #else
4600
-      constexpr bool UBL_CONDITION = true;
4606
+      #define UBL_CONDITION true
4601 4607
     #endif
4602 4608
 
4603 4609
     // If the action button is pressed...
@@ -4925,7 +4931,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
4925 4931
     #define encrot3 1
4926 4932
   #endif
4927 4933
 
4928
-  #define GET_BUTTON_STATES(DST) \
4934
+  #define GET_SHIFT_BUTTON_STATES(DST) \
4929 4935
     uint8_t new_##DST = 0; \
4930 4936
     WRITE(SHIFT_LD, LOW); \
4931 4937
     WRITE(SHIFT_LD, HIGH); \
@@ -4944,7 +4950,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
4944 4950
    */
4945 4951
   void lcd_buttons_update() {
4946 4952
     static uint8_t lastEncoderBits;
4947
-    millis_t now = millis();
4953
+    const millis_t now = millis();
4948 4954
     if (ELAPSED(now, next_button_update_ms)) {
4949 4955
 
4950 4956
       #if ENABLED(NEWPANEL)
@@ -4962,9 +4968,16 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
4962 4968
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
4963 4969
         #endif
4964 4970
 
4971
+        buttons = newbutton;
4972
+        #if ENABLED(LCD_HAS_SLOW_BUTTONS)
4973
+          buttons |= slow_buttons;
4974
+        #endif
4975
+
4976
+        //
4977
+        // Directional buttons
4978
+        //
4965 4979
         #if LCD_HAS_DIRECTIONAL_BUTTONS
4966 4980
 
4967
-          // Manage directional buttons
4968 4981
           #if ENABLED(REVERSE_MENU_DIRECTION)
4969 4982
             #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
4970 4983
           #else
@@ -5008,11 +5021,6 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
5008 5021
 
5009 5022
         #endif // LCD_HAS_DIRECTIONAL_BUTTONS
5010 5023
 
5011
-        buttons = newbutton;
5012
-        #if ENABLED(LCD_HAS_SLOW_BUTTONS)
5013
-          buttons |= slow_buttons;
5014
-        #endif
5015
-
5016 5024
         #if ENABLED(ADC_KEYPAD)
5017 5025
 
5018 5026
           uint8_t newbutton_reprapworld_keypad = 0;
@@ -5025,13 +5033,15 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
5025 5033
 
5026 5034
         #elif ENABLED(REPRAPWORLD_KEYPAD)
5027 5035
 
5028
-          GET_BUTTON_STATES(buttons_reprapworld_keypad);
5036
+          GET_SHIFT_BUTTON_STATES(buttons_reprapworld_keypad);
5029 5037
 
5030 5038
         #endif
5031 5039
 
5032
-      #else
5033
-        GET_BUTTON_STATES(buttons);
5034
-      #endif // !NEWPANEL
5040
+      #else // !NEWPANEL
5041
+
5042
+        GET_SHIFT_BUTTON_STATES(buttons);
5043
+
5044
+      #endif
5035 5045
 
5036 5046
     } // next_button_update_ms
5037 5047
 

+ 4
- 4
Marlin/src/lcd/ultralcd_impl_HD44780.h View File

@@ -78,12 +78,12 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
78 78
 
79 79
     #if BUTTON_EXISTS(ENC)
80 80
       // the pause/stop/restart button is connected to BTN_ENC when used
81
-      #define B_ST (EN_C)                            // Map the pause/stop/resume button into its normalized functional name
81
+      #define B_ST (EN_C)                              // Map the pause/stop/resume button into its normalized functional name
82 82
       #undef LCD_CLICKED
83
-      #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
83
+      #define LCD_CLICKED (buttons & (B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
84 84
     #else
85 85
       #undef LCD_CLICKED
86
-      #define LCD_CLICKED (buttons&(B_MI|B_RI))
86
+      #define LCD_CLICKED (buttons & (B_MI|B_RI))
87 87
     #endif
88 88
 
89 89
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
@@ -119,7 +119,7 @@ extern volatile uint8_t buttons;  //an extended version of the last checked butt
119 119
     #define B_DW (_BV(BL_DW))
120 120
     #define B_RI (_BV(BL_RI))
121 121
     #define B_ST (_BV(BL_ST))
122
-    #define LCD_CLICKED ((buttons & B_MI) || (buttons & B_ST))
122
+    #define LCD_CLICKED (buttons & (B_MI|B_ST))
123 123
   #endif
124 124
 
125 125
 #endif // ULTIPANEL

+ 13
- 13
Marlin/src/module/endstops.cpp View File

@@ -609,43 +609,43 @@ void Endstops::update() {
609 609
 
610 610
     if (endstop_change) {
611 611
       #if HAS_X_MIN
612
-        if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR("  X_MIN:", !!TEST(current_endstop_bits_local, X_MIN));
612
+        if (TEST(endstop_change, X_MIN)) SERIAL_PROTOCOLPAIR("  X_MIN:", TEST(current_endstop_bits_local, X_MIN));
613 613
       #endif
614 614
       #if HAS_X_MAX
615
-        if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR("  X_MAX:", !!TEST(current_endstop_bits_local, X_MAX));
615
+        if (TEST(endstop_change, X_MAX)) SERIAL_PROTOCOLPAIR("  X_MAX:", TEST(current_endstop_bits_local, X_MAX));
616 616
       #endif
617 617
       #if HAS_Y_MIN
618
-        if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR("  Y_MIN:", !!TEST(current_endstop_bits_local, Y_MIN));
618
+        if (TEST(endstop_change, Y_MIN)) SERIAL_PROTOCOLPAIR("  Y_MIN:", TEST(current_endstop_bits_local, Y_MIN));
619 619
       #endif
620 620
       #if HAS_Y_MAX
621
-        if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR("  Y_MAX:", !!TEST(current_endstop_bits_local, Y_MAX));
621
+        if (TEST(endstop_change, Y_MAX)) SERIAL_PROTOCOLPAIR("  Y_MAX:", TEST(current_endstop_bits_local, Y_MAX));
622 622
       #endif
623 623
       #if HAS_Z_MIN
624
-        if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR("  Z_MIN:", !!TEST(current_endstop_bits_local, Z_MIN));
624
+        if (TEST(endstop_change, Z_MIN)) SERIAL_PROTOCOLPAIR("  Z_MIN:", TEST(current_endstop_bits_local, Z_MIN));
625 625
       #endif
626 626
       #if HAS_Z_MAX
627
-        if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR("  Z_MAX:", !!TEST(current_endstop_bits_local, Z_MAX));
627
+        if (TEST(endstop_change, Z_MAX)) SERIAL_PROTOCOLPAIR("  Z_MAX:", TEST(current_endstop_bits_local, Z_MAX));
628 628
       #endif
629 629
       #if HAS_Z_MIN_PROBE_PIN
630
-        if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR("  PROBE:", !!TEST(current_endstop_bits_local, Z_MIN_PROBE));
630
+        if (TEST(endstop_change, Z_MIN_PROBE)) SERIAL_PROTOCOLPAIR("  PROBE:", TEST(current_endstop_bits_local, Z_MIN_PROBE));
631 631
       #endif
632 632
       #if HAS_X2_MIN
633
-        if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR("  X2_MIN:", !!TEST(current_endstop_bits_local, X2_MIN));
633
+        if (TEST(endstop_change, X2_MIN)) SERIAL_PROTOCOLPAIR("  X2_MIN:", TEST(current_endstop_bits_local, X2_MIN));
634 634
       #endif
635 635
       #if HAS_X2_MAX
636
-        if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR("  X2_MAX:", !!TEST(current_endstop_bits_local, X2_MAX));
636
+        if (TEST(endstop_change, X2_MAX)) SERIAL_PROTOCOLPAIR("  X2_MAX:", TEST(current_endstop_bits_local, X2_MAX));
637 637
       #endif
638 638
       #if HAS_Y2_MIN
639
-        if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR("  Y2_MIN:", !!TEST(current_endstop_bits_local, Y2_MIN));
639
+        if (TEST(endstop_change, Y2_MIN)) SERIAL_PROTOCOLPAIR("  Y2_MIN:", TEST(current_endstop_bits_local, Y2_MIN));
640 640
       #endif
641 641
       #if HAS_Y2_MAX
642
-        if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR("  Y2_MAX:", !!TEST(current_endstop_bits_local, Y2_MAX));
642
+        if (TEST(endstop_change, Y2_MAX)) SERIAL_PROTOCOLPAIR("  Y2_MAX:", TEST(current_endstop_bits_local, Y2_MAX));
643 643
       #endif
644 644
       #if HAS_Z2_MIN
645
-        if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR("  Z2_MIN:", !!TEST(current_endstop_bits_local, Z2_MIN));
645
+        if (TEST(endstop_change, Z2_MIN)) SERIAL_PROTOCOLPAIR("  Z2_MIN:", TEST(current_endstop_bits_local, Z2_MIN));
646 646
       #endif
647 647
       #if HAS_Z2_MAX
648
-        if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR("  Z2_MAX:", !!TEST(current_endstop_bits_local, Z2_MAX));
648
+        if (TEST(endstop_change, Z2_MAX)) SERIAL_PROTOCOLPAIR("  Z2_MAX:", TEST(current_endstop_bits_local, Z2_MAX));
649 649
       #endif
650 650
       SERIAL_PROTOCOLPGM("\n\n");
651 651
       analogWrite(LED_PIN, local_LED_status);

Loading…
Cancel
Save