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
   if (!parser.seenval('S')) return;
37
   if (!parser.seenval('S')) return;
38
   const byte pin_status = parser.value_byte();
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
   if (pin_is_protected(pin)) {
44
   if (pin_is_protected(pin)) {
45
     SERIAL_ERROR_START();
45
     SERIAL_ERROR_START();
46
     SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);
46
     SERIAL_ERRORLNPGM(MSG_ERR_PROTECTED_PIN);

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

4590
 
4590
 
4591
   #if ENABLED(ULTIPANEL)
4591
   #if ENABLED(ULTIPANEL)
4592
     static millis_t return_to_status_ms = 0;
4592
     static millis_t return_to_status_ms = 0;
4593
+
4594
+    // Handle any queued Move Axis motion
4593
     manage_manual_move();
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
     lcd_buttons_update();
4600
     lcd_buttons_update();
4596
 
4601
 
4597
     #if ENABLED(AUTO_BED_LEVELING_UBL)
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
     #else
4605
     #else
4600
-      constexpr bool UBL_CONDITION = true;
4606
+      #define UBL_CONDITION true
4601
     #endif
4607
     #endif
4602
 
4608
 
4603
     // If the action button is pressed...
4609
     // If the action button is pressed...
4925
     #define encrot3 1
4931
     #define encrot3 1
4926
   #endif
4932
   #endif
4927
 
4933
 
4928
-  #define GET_BUTTON_STATES(DST) \
4934
+  #define GET_SHIFT_BUTTON_STATES(DST) \
4929
     uint8_t new_##DST = 0; \
4935
     uint8_t new_##DST = 0; \
4930
     WRITE(SHIFT_LD, LOW); \
4936
     WRITE(SHIFT_LD, LOW); \
4931
     WRITE(SHIFT_LD, HIGH); \
4937
     WRITE(SHIFT_LD, HIGH); \
4944
    */
4950
    */
4945
   void lcd_buttons_update() {
4951
   void lcd_buttons_update() {
4946
     static uint8_t lastEncoderBits;
4952
     static uint8_t lastEncoderBits;
4947
-    millis_t now = millis();
4953
+    const millis_t now = millis();
4948
     if (ELAPSED(now, next_button_update_ms)) {
4954
     if (ELAPSED(now, next_button_update_ms)) {
4949
 
4955
 
4950
       #if ENABLED(NEWPANEL)
4956
       #if ENABLED(NEWPANEL)
4962
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
4968
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
4963
         #endif
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
         #if LCD_HAS_DIRECTIONAL_BUTTONS
4979
         #if LCD_HAS_DIRECTIONAL_BUTTONS
4966
 
4980
 
4967
-          // Manage directional buttons
4968
           #if ENABLED(REVERSE_MENU_DIRECTION)
4981
           #if ENABLED(REVERSE_MENU_DIRECTION)
4969
             #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
4982
             #define _ENCODER_UD_STEPS (ENCODER_STEPS_PER_MENU_ITEM * encoderDirection)
4970
           #else
4983
           #else
5008
 
5021
 
5009
         #endif // LCD_HAS_DIRECTIONAL_BUTTONS
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
         #if ENABLED(ADC_KEYPAD)
5024
         #if ENABLED(ADC_KEYPAD)
5017
 
5025
 
5018
           uint8_t newbutton_reprapworld_keypad = 0;
5026
           uint8_t newbutton_reprapworld_keypad = 0;
5025
 
5033
 
5026
         #elif ENABLED(REPRAPWORLD_KEYPAD)
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
         #endif
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
     } // next_button_update_ms
5046
     } // next_button_update_ms
5037
 
5047
 

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

78
 
78
 
79
     #if BUTTON_EXISTS(ENC)
79
     #if BUTTON_EXISTS(ENC)
80
       // the pause/stop/restart button is connected to BTN_ENC when used
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
       #undef LCD_CLICKED
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
     #else
84
     #else
85
       #undef LCD_CLICKED
85
       #undef LCD_CLICKED
86
-      #define LCD_CLICKED (buttons&(B_MI|B_RI))
86
+      #define LCD_CLICKED (buttons & (B_MI|B_RI))
87
     #endif
87
     #endif
88
 
88
 
89
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
89
     // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
119
     #define B_DW (_BV(BL_DW))
119
     #define B_DW (_BV(BL_DW))
120
     #define B_RI (_BV(BL_RI))
120
     #define B_RI (_BV(BL_RI))
121
     #define B_ST (_BV(BL_ST))
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
   #endif
123
   #endif
124
 
124
 
125
 #endif // ULTIPANEL
125
 #endif // ULTIPANEL

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

609
 
609
 
610
     if (endstop_change) {
610
     if (endstop_change) {
611
       #if HAS_X_MIN
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
       #endif
613
       #endif
614
       #if HAS_X_MAX
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
       #endif
616
       #endif
617
       #if HAS_Y_MIN
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
       #endif
619
       #endif
620
       #if HAS_Y_MAX
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
       #endif
622
       #endif
623
       #if HAS_Z_MIN
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
       #endif
625
       #endif
626
       #if HAS_Z_MAX
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
       #endif
628
       #endif
629
       #if HAS_Z_MIN_PROBE_PIN
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
       #endif
631
       #endif
632
       #if HAS_X2_MIN
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
       #endif
634
       #endif
635
       #if HAS_X2_MAX
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
       #endif
637
       #endif
638
       #if HAS_Y2_MIN
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
       #endif
640
       #endif
641
       #if HAS_Y2_MAX
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
       #endif
643
       #endif
644
       #if HAS_Z2_MIN
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
       #endif
646
       #endif
647
       #if HAS_Z2_MAX
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
       #endif
649
       #endif
650
       SERIAL_PROTOCOLPGM("\n\n");
650
       SERIAL_PROTOCOLPGM("\n\n");
651
       analogWrite(LED_PIN, local_LED_status);
651
       analogWrite(LED_PIN, local_LED_status);

Loading…
Cancel
Save