Pārlūkot izejas kodu

Standardize LCD interface code for UBL a little

Scott Lahteine 6 gadus atpakaļ
vecāks
revīzija
ff26b7446c
5 mainītis faili ar 84 papildinājumiem un 70 dzēšanām
  1. 3
    4
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 8
    4
      Marlin/ubl.h
  3. 68
    62
      Marlin/ubl_G29.cpp
  4. 4
    0
      Marlin/ultralcd.cpp
  5. 1
    0
      Marlin/ultralcd.h

+ 3
- 4
Marlin/G26_Mesh_Validation_Tool.cpp Parādīt failu

@@ -181,9 +181,8 @@
181 181
       // If the button is suddenly pressed again,
182 182
       // ask the user to resolve the issue
183 183
       lcd_setstatusPGM(PSTR("Release button"), 99); // will never appear...
184
-      while (is_lcd_clicked()) idle();             // unless this loop happens
184
+      wait_for_release();
185 185
       lcd_reset_status();
186
-
187 186
       return true;
188 187
     }
189 188
   #endif
@@ -191,7 +190,7 @@
191 190
   #if ENABLED(NEWPANEL)
192 191
     bool exit_from_g26() {
193 192
       lcd_setstatusPGM(PSTR("Leaving G26"), -1);
194
-      while (is_lcd_clicked()) idle();
193
+      wait_for_release();
195 194
       return G26_ERR;
196 195
     }
197 196
   #endif
@@ -291,7 +290,7 @@
291 290
           idle();
292 291
         }
293 292
 
294
-        while (is_lcd_clicked()) idle();           // Debounce Encoder Wheel
293
+        wait_for_release();
295 294
 
296 295
         #if ENABLED(ULTRA_LCD)
297 296
           strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue;

+ 8
- 4
Marlin/ubl.h Parādīt failu

@@ -81,19 +81,23 @@
81 81
         static int  g29_grid_size;
82 82
       #endif
83 83
 
84
-      static float measure_point_with_encoder();
85
-      static float measure_business_card_thickness(float);
84
+      #if ENABLED(NEWPANEL)
85
+        static void move_z_with_encoder(const float &multiplier);
86
+        static float measure_point_with_encoder();
87
+        static float measure_business_card_thickness(float);
88
+        static void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
89
+        static void fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map);
90
+      #endif
91
+
86 92
       static bool g29_parameter_parsing();
87 93
       static void find_mean_mesh_height();
88 94
       static void shift_mesh_height();
89 95
       static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest);
90
-      static void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
91 96
       static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
92 97
       static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
93 98
       static void g29_what_command();
94 99
       static void g29_eeprom_dump();
95 100
       static void g29_compare_current_mesh_to_stored_mesh();
96
-      static void fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map);
97 101
       static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir);
98 102
       static void smart_fill_mesh();
99 103
 

+ 68
- 62
Marlin/ubl_G29.cpp Parādīt failu

@@ -730,6 +730,30 @@
730 730
           z_values[x][y] += g29_constant;
731 731
   }
732 732
 
733
+  #if ENABLED(NEWPANEL)
734
+
735
+    typedef void (*clickFunc_t)();
736
+
737
+    bool click_and_hold(const clickFunc_t func=NULL) {
738
+      if (is_lcd_clicked()) {
739
+        lcd_quick_feedback();
740
+        const millis_t nxt = millis() + 1500UL;
741
+        while (is_lcd_clicked()) {                // Loop while the encoder is pressed. Uses hardware flag!
742
+          idle();                                 // idle, of course
743
+          if (ELAPSED(millis(), nxt)) {           // After 1.5 seconds
744
+            lcd_quick_feedback();
745
+            if (func) (*func)();
746
+            wait_for_release();
747
+            safe_delay(50);                       // Debounce the Encoder wheel
748
+            return true;
749
+          }
750
+        }
751
+      }
752
+      return false;
753
+    }
754
+
755
+  #endif // NEWPANEL
756
+
733 757
   #if HAS_BED_PROBE
734 758
     /**
735 759
      * Probe all invalidated locations of the mesh that can be reached by the probe.
@@ -755,10 +779,9 @@
755 779
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
756 780
             lcd_quick_feedback();
757 781
             STOW_PROBE();
758
-            while (is_lcd_clicked()) idle();
782
+            wait_for_release();
759 783
             lcd_external_control = false;
760 784
             restore_ubl_active_state_and_leave();
761
-            safe_delay(50);  // Debounce the Encoder wheel
762 785
             return;
763 786
           }
764 787
         #endif
@@ -895,19 +918,20 @@
895 918
 
896 919
   #if ENABLED(NEWPANEL)
897 920
 
898
-    float unified_bed_leveling::measure_point_with_encoder() {
899
-
900
-      while (is_lcd_clicked()) delay(50);  // wait for user to release encoder wheel
901
-      delay(50);  // debounce
902
-
903
-      KEEPALIVE_STATE(PAUSED_FOR_USER);
904
-      while (!is_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
921
+    void unified_bed_leveling::move_z_with_encoder(const float &multiplier) {
922
+      wait_for_release();
923
+      while (!is_lcd_clicked()) {
905 924
         idle();
906 925
         if (encoder_diff) {
907
-          do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(encoder_diff));
926
+          do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier);
908 927
           encoder_diff = 0;
909 928
         }
910 929
       }
930
+    }
931
+
932
+    float unified_bed_leveling::measure_point_with_encoder() {
933
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
934
+      move_z_with_encoder(0.01);
911 935
       KEEPALIVE_STATE(IN_HANDLER);
912 936
       return current_position[Z_AXIS];
913 937
     }
@@ -956,6 +980,14 @@
956 980
       return thickness;
957 981
     }
958 982
 
983
+    void abort_manual_probe_remaining_mesh() {
984
+      SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
985
+      do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
986
+      lcd_external_control = false;
987
+      KEEPALIVE_STATE(IN_HANDLER);
988
+      ubl.restore_ubl_active_state_and_leave();
989
+    }
990
+
959 991
     void unified_bed_leveling::manually_probe_remaining_mesh(const float &rx, const float &ry, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) {
960 992
 
961 993
       lcd_external_control = true;
@@ -991,36 +1023,15 @@
991 1023
         const float z_step = 0.01;                                        // existing behavior: 0.01mm per click, occasionally step
992 1024
         //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS];   // approx one step each click
993 1025
 
994
-        while (is_lcd_clicked()) delay(50);             // wait for user to release encoder wheel
995
-        delay(50);                                       // debounce
996
-        while (!is_lcd_clicked()) {                     // we need the loop to move the nozzle based on the encoder wheel here!
997
-          idle();
998
-          if (encoder_diff) {
999
-            do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * z_step);
1000
-            encoder_diff = 0;
1001
-          }
1002
-        }
1026
+        move_z_with_encoder(z_step);
1003 1027
 
1004
-        // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1005
-        // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1006
-        // should be redone and compressed.
1007
-        const millis_t nxt = millis() + 1500L;
1008
-        while (is_lcd_clicked()) {     // debounce and watch for abort
1009
-          idle();
1010
-          if (ELAPSED(millis(), nxt)) {
1011
-            SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
1012
-            do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1013
-
1014
-            #if ENABLED(NEWPANEL)
1015
-              lcd_quick_feedback();
1016
-              while (is_lcd_clicked()) idle();
1017
-              lcd_external_control = false;
1018
-            #endif
1019
-
1020
-            KEEPALIVE_STATE(IN_HANDLER);
1021
-            restore_ubl_active_state_and_leave();
1022
-            return;
1023
-          }
1028
+        if (click_and_hold()) {
1029
+          SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
1030
+          do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1031
+          lcd_external_control = false;
1032
+          KEEPALIVE_STATE(IN_HANDLER);
1033
+          restore_ubl_active_state_and_leave();
1034
+          return;
1024 1035
         }
1025 1036
 
1026 1037
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
@@ -1177,16 +1188,16 @@
1177 1188
   }
1178 1189
 
1179 1190
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1180
-    if (--ubl_state_recursion_chk) {
1181
-      SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1182
-
1183
-      #if ENABLED(NEWPANEL)
1184
-        LCD_MESSAGEPGM(MSG_UBL_RESTORE_ERROR);
1185
-        lcd_quick_feedback();
1186
-      #endif
1187
-
1188
-      return;
1189
-    }
1191
+    #ifdef UBL_DEVEL_DEBUGGING
1192
+      if (--ubl_state_recursion_chk) {
1193
+        SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1194
+        #if ENABLED(NEWPANEL)
1195
+          LCD_MESSAGEPGM(MSG_UBL_RESTORE_ERROR);
1196
+          lcd_quick_feedback();
1197
+        #endif
1198
+        return;
1199
+      }
1200
+    #endif
1190 1201
     set_bed_leveling_enabled(ubl_state_at_invocation);
1191 1202
   }
1192 1203
 
@@ -1468,6 +1479,12 @@
1468 1479
 
1469 1480
   #if ENABLED(NEWPANEL)
1470 1481
 
1482
+    void abort_fine_tune() {
1483
+      lcd_return_to_status();
1484
+      do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1485
+      LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1486
+    }
1487
+
1471 1488
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1472 1489
       if (!parser.seen('R'))    // fine_tune_mesh() is special. If no repetition count flag is specified
1473 1490
         g29_repetition_cnt = 1;   // do exactly one mesh location. Otherwise use what the parser decided.
@@ -1543,19 +1560,8 @@
1543 1560
         // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1544 1561
         // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1545 1562
         // should be redone and compressed.
1546
-        const millis_t nxt = millis() + 1500UL;
1547
-        while (is_lcd_clicked()) { // debounce and watch for abort
1548
-          idle();
1549
-          if (ELAPSED(millis(), nxt)) {
1550
-            lcd_return_to_status();
1551
-            do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1552
-            LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1553
-
1554
-            while (is_lcd_clicked()) idle();
1555
-
1556
-            goto FINE_TUNE_EXIT;
1557
-          }
1558
-        }
1563
+        if (click_and_hold(abort_fine_tune))
1564
+          goto FINE_TUNE_EXIT;
1559 1565
 
1560 1566
         safe_delay(20);                       // We don't want any switch noise.
1561 1567
 

+ 4
- 0
Marlin/ultralcd.cpp Parādīt failu

@@ -5112,6 +5112,10 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
5112 5112
 
5113 5113
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
5114 5114
     bool is_lcd_clicked() { return LCD_CLICKED; }
5115
+    void wait_for_release() {
5116
+      while (is_lcd_clicked()) safe_delay(50);
5117
+      safe_delay(50);
5118
+    }
5115 5119
   #endif
5116 5120
 
5117 5121
 #endif // ULTIPANEL

+ 1
- 0
Marlin/ultralcd.h Parādīt failu

@@ -176,6 +176,7 @@
176 176
 
177 177
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
178 178
     bool is_lcd_clicked();
179
+    void wait_for_release();
179 180
   #endif
180 181
 
181 182
   #if ENABLED(LCD_SET_PROGRESS_MANUALLY) && (ENABLED(LCD_PROGRESS_BAR) || ENABLED(DOGLCD))

Notiek ielāde…
Atcelt
Saglabāt