Browse Source

Standardize LCD interface code for UBL a little

Scott Lahteine 7 years ago
parent
commit
ff26b7446c
5 changed files with 84 additions and 70 deletions
  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 View File

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

+ 8
- 4
Marlin/ubl.h View File

81
         static int  g29_grid_size;
81
         static int  g29_grid_size;
82
       #endif
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
       static bool g29_parameter_parsing();
92
       static bool g29_parameter_parsing();
87
       static void find_mean_mesh_height();
93
       static void find_mean_mesh_height();
88
       static void shift_mesh_height();
94
       static void shift_mesh_height();
89
       static void probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest);
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
       static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
96
       static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
92
       static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
97
       static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
93
       static void g29_what_command();
98
       static void g29_what_command();
94
       static void g29_eeprom_dump();
99
       static void g29_eeprom_dump();
95
       static void g29_compare_current_mesh_to_stored_mesh();
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
       static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir);
101
       static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir);
98
       static void smart_fill_mesh();
102
       static void smart_fill_mesh();
99
 
103
 

+ 68
- 62
Marlin/ubl_G29.cpp View File

730
           z_values[x][y] += g29_constant;
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
   #if HAS_BED_PROBE
757
   #if HAS_BED_PROBE
734
     /**
758
     /**
735
      * Probe all invalidated locations of the mesh that can be reached by the probe.
759
      * Probe all invalidated locations of the mesh that can be reached by the probe.
755
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
779
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
756
             lcd_quick_feedback();
780
             lcd_quick_feedback();
757
             STOW_PROBE();
781
             STOW_PROBE();
758
-            while (is_lcd_clicked()) idle();
782
+            wait_for_release();
759
             lcd_external_control = false;
783
             lcd_external_control = false;
760
             restore_ubl_active_state_and_leave();
784
             restore_ubl_active_state_and_leave();
761
-            safe_delay(50);  // Debounce the Encoder wheel
762
             return;
785
             return;
763
           }
786
           }
764
         #endif
787
         #endif
895
 
918
 
896
   #if ENABLED(NEWPANEL)
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
         idle();
924
         idle();
906
         if (encoder_diff) {
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
           encoder_diff = 0;
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
       KEEPALIVE_STATE(IN_HANDLER);
935
       KEEPALIVE_STATE(IN_HANDLER);
912
       return current_position[Z_AXIS];
936
       return current_position[Z_AXIS];
913
     }
937
     }
956
       return thickness;
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
     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) {
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
       lcd_external_control = true;
993
       lcd_external_control = true;
991
         const float z_step = 0.01;                                        // existing behavior: 0.01mm per click, occasionally step
1023
         const float z_step = 0.01;                                        // existing behavior: 0.01mm per click, occasionally step
992
         //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS];   // approx one step each click
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
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
1037
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
1177
   }
1188
   }
1178
 
1189
 
1179
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
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
     set_bed_leveling_enabled(ubl_state_at_invocation);
1201
     set_bed_leveling_enabled(ubl_state_at_invocation);
1191
   }
1202
   }
1192
 
1203
 
1468
 
1479
 
1469
   #if ENABLED(NEWPANEL)
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
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1488
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1472
       if (!parser.seen('R'))    // fine_tune_mesh() is special. If no repetition count flag is specified
1489
       if (!parser.seen('R'))    // fine_tune_mesh() is special. If no repetition count flag is specified
1473
         g29_repetition_cnt = 1;   // do exactly one mesh location. Otherwise use what the parser decided.
1490
         g29_repetition_cnt = 1;   // do exactly one mesh location. Otherwise use what the parser decided.
1543
         // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1560
         // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1544
         // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1561
         // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1545
         // should be redone and compressed.
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
         safe_delay(20);                       // We don't want any switch noise.
1566
         safe_delay(20);                       // We don't want any switch noise.
1561
 
1567
 

+ 4
- 0
Marlin/ultralcd.cpp View File

5112
 
5112
 
5113
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
5113
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
5114
     bool is_lcd_clicked() { return LCD_CLICKED; }
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
   #endif
5119
   #endif
5116
 
5120
 
5117
 #endif // ULTIPANEL
5121
 #endif // ULTIPANEL

+ 1
- 0
Marlin/ultralcd.h View File

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

Loading…
Cancel
Save