Browse Source

A single generate_click lambda

Scott Lahteine 6 years ago
parent
commit
1eeef30097
1 changed files with 20 additions and 18 deletions
  1. 20
    18
      Marlin/src/lcd/ultralcd.cpp

+ 20
- 18
Marlin/src/lcd/ultralcd.cpp View File

@@ -765,14 +765,19 @@ void MarlinUI::update() {
765 765
 
766 766
     // If the action button is pressed...
767 767
     static bool wait_for_unclick; // = 0
768
+    auto generate_click = [&]() {
769
+      if (!wait_for_unclick) {                        // If not waiting for a debounce release:
770
+        wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
771
+        lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
772
+        wait_for_user = false;                        //  - Any click clears wait for user
773
+        quick_feedback();                             //  - Always make a click sound
774
+      }
775
+    };
776
+
768 777
     #if ENABLED(TOUCH_BUTTONS)
769 778
       if (touch_buttons) {
770
-        if (!wait_for_unclick && (buttons & EN_C)) {    // If not waiting for a debounce release:
771
-          wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
772
-          lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
773
-          wait_for_user = false;                        //  - Any click clears wait for user
774
-          quick_feedback();                             //  - Always make a click sound
775
-        }
779
+        if (buttons & EN_C)
780
+          generate_click();
776 781
         else if (buttons & (EN_A | EN_B)) {             // Ignore the encoder if clicked, to prevent "slippage"
777 782
           const millis_t ms = millis();
778 783
           if (ELAPSED(ms, next_button_update_ms)) {
@@ -790,19 +795,16 @@ void MarlinUI::update() {
790 795
         }
791 796
       }
792 797
       else
793
-    #endif //TOUCH_BUTTONS
794
-    //
795
-    // Integrated LCD click handling via button_pressed()
796
-    //
797
-    if (!external_control && button_pressed()) {
798
-      if (!wait_for_unclick) {                        // If not waiting for a debounce release:
799
-        wait_for_unclick = true;                      //  - Set debounce flag to ignore continous clicks
800
-        lcd_clicked = !wait_for_user && !no_reentry;  //  - Keep the click if not waiting for a user-click
801
-        wait_for_user = false;                        //  - Any click clears wait for user
802
-        quick_feedback();                             //  - Always make a click sound
798
+    #endif // TOUCH_BUTTONS
799
+      {
800
+        //
801
+        // Integrated LCD click handling via button_pressed()
802
+        //
803
+        if (!external_control && button_pressed())
804
+          generate_click();
805
+        else
806
+          wait_for_unclick = false;
803 807
       }
804
-    }
805
-    else wait_for_unclick = false;
806 808
 
807 809
     #if HAS_DIGITAL_BUTTONS && (BUTTON_EXISTS(BACK) || ENABLED(TOUCH_BUTTONS))
808 810
       if (LCD_BACK_CLICKED()) {

Loading…
Cancel
Save