Browse Source

Single user_canceled function in G26

Scott Lahteine 7 years ago
parent
commit
e271521c39
2 changed files with 30 additions and 42 deletions
  1. 27
    39
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 3
    3
      Marlin/ultralcd.cpp

+ 27
- 39
Marlin/G26_Mesh_Validation_Tool.cpp View File

@@ -187,6 +187,30 @@
187 187
   }
188 188
 
189 189
   /**
190
+   * Detect ubl_lcd_clicked, debounce it, and return true for cancel
191
+   */
192
+  bool user_canceled() {
193
+    if (!ubl_lcd_clicked()) return false;
194
+    safe_delay(10);                       // Wait for click to settle
195
+
196
+    #if ENABLED(ULTRA_LCD)
197
+      lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
198
+      lcd_quick_feedback();
199
+    #endif
200
+    lcd_reset_alert_level();
201
+
202
+    while (!ubl_lcd_clicked()) idle();    // Wait for button release
203
+
204
+    // If the button is suddenly pressed again,
205
+    // ask the user to resolve the issue
206
+    lcd_setstatuspgm(PSTR("Release button"), 99); // will never appear...
207
+    while (ubl_lcd_clicked()) idle();             // unless this loop happens
208
+    lcd_setstatuspgm(PSTR(""));
209
+
210
+    return true;
211
+  }
212
+
213
+  /**
190 214
    * G26: Mesh Validation Pattern generation.
191 215
    *
192 216
    * Used to interactively edit UBL's Mesh by placing the
@@ -300,25 +324,7 @@
300 324
 
301 325
         for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) {
302 326
 
303
-          // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
304
-          // a Press and Hold is repeated in a lot of places (including ubl_G29.cpp).   This
305
-          // should be redone and compressed.
306
-          if (ubl_lcd_clicked()) {              // Check if the user wants to stop the Mesh Validation
307
-            #if ENABLED(ULTRA_LCD)
308
-              lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
309
-              lcd_quick_feedback();
310
-            #endif
311
-            while (!ubl_lcd_clicked()) {         // Wait until the user is done pressing the
312
-              idle();                            // Encoder Wheel if that is why we are leaving
313
-              lcd_reset_alert_level();
314
-              lcd_setstatuspgm(PSTR(""));
315
-            }
316
-            while (ubl_lcd_clicked()) {          // Wait until the user is done pressing the
317
-              idle();                            // Encoder Wheel if that is why we are leaving
318
-              lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
319
-            }
320
-            goto LEAVE;
321
-          }
327
+          if (user_canceled()) goto LEAVE;              // Check if the user wants to stop the Mesh Validation
322 328
 
323 329
           int tmp_div_30 = tmp / 30.0;
324 330
           if (tmp_div_30 < 0) tmp_div_30 += 360 / 30;
@@ -436,28 +442,10 @@
436 442
     for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
437 443
       for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
438 444
 
439
-        // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is
440
-        // a Press and Hold is repeated in a lot of places (including ubl_G29.cpp).   This
441
-        // should be redone and compressed.
442
-        if (ubl_lcd_clicked()) {              // Check if the user wants to stop the Mesh Validation
443
-          #if ENABLED(ULTRA_LCD)
444
-            lcd_setstatuspgm(PSTR("Mesh Validation Stopped."), 99);
445
-            lcd_quick_feedback();
446
-          #endif
447
-          while (!ubl_lcd_clicked()) {         // Wait until the user is done pressing the
448
-            idle();                            // Encoder Wheel if that is why we are leaving
449
-            lcd_reset_alert_level();
450
-            lcd_setstatuspgm(PSTR(""));
451
-          }
452
-          while (ubl_lcd_clicked()) {          // Wait until the user is done pressing the
453
-            idle();                            // Encoder Wheel if that is why we are leaving
454
-            lcd_setstatuspgm(PSTR("Unpress Wheel"), 99);
455
-          }
456
-          return true;
457
-        }
445
+        if (user_canceled()) return true;     // Check if the user wants to stop the Mesh Validation
458 446
 
459 447
         if (i < GRID_MAX_POINTS_X) { // We can't connect to anything to the right than GRID_MAX_POINTS_X.
460
-                                         // This is already a half circle because we are at the edge of the bed.
448
+                                     // This is already a half circle because we are at the edge of the bed.
461 449
 
462 450
           if (is_bit_set(circle_flags, i, j) && is_bit_set(circle_flags, i + 1, j)) { // check if we can do a line to the left
463 451
             if (!is_bit_set(horizontal_mesh_line_flags, i, j)) {

+ 3
- 3
Marlin/ultralcd.cpp View File

@@ -1480,7 +1480,7 @@ void kill_screen(const char* lcd_msg) {
1480 1480
     void _lcd_level_bed_get_z() {
1481 1481
       ENCODER_DIRECTION_NORMAL();
1482 1482
 
1483
-      // Encoder wheel adjusts the Z position
1483
+      // Encoder knob or keypad buttons adjust the Z position
1484 1484
       if (encoderPosition) {
1485 1485
         refresh_cmd_timeout();
1486 1486
         current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
@@ -4202,9 +4202,9 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
4202 4202
       }
4203 4203
       #if ENABLED(AUTO_BED_LEVELING_UBL)
4204 4204
         if (ubl.has_control_of_lcd_panel) {
4205
-          ubl.encoder_diff = encoderDiff;    // Make the encoder's rotation available to G29's Mesh Editor
4205
+          ubl.encoder_diff = encoderDiff;   // Make the encoder's rotation available to G29's Mesh Editor
4206 4206
           encoderDiff = 0;                  // We are going to lie to the LCD Panel and claim the encoder
4207
-                                            // wheel has not turned.
4207
+                                            // knob has not turned.
4208 4208
         }
4209 4209
       #endif
4210 4210
       lastEncoderBits = enc;

Loading…
Cancel
Save