Browse Source

Merge pull request #8695 from thinkyhead/bf2_fixes_DEC6

[2.0.x] Cleanup, bugfixes, parity with 1.1.x
Scott Lahteine 7 years ago
parent
commit
d163c4b530
No account linked to committer's email address

+ 8
- 8
Marlin/src/HAL/HAL_LPC1768/spi_pins.h View File

26
 #include "../../inc/MarlinConfig.h"
26
 #include "../../inc/MarlinConfig.h"
27
 
27
 
28
 #if MB(MKS_SBASE)
28
 #if MB(MKS_SBASE)
29
-  
30
-#define LPC_SOFTWARE_SPI  // MKS_SBASE needs a software SPI because the 
29
+
30
+#define LPC_SOFTWARE_SPI  // MKS_SBASE needs a software SPI because the
31
                           // selected pins are not on a hardware SPI controller
31
                           // selected pins are not on a hardware SPI controller
32
 
32
 
33
-// A custom cable is needed. See the README file in the 
33
+// A custom cable is needed. See the README file in the
34
 // Marlin\src\config\examples\Mks\Sbase directory
34
 // Marlin\src\config\examples\Mks\Sbase directory
35
 
35
 
36
 #define SCK_PIN           P1_22  // J8-2 (moved from EXP2 P0.7)
36
 #define SCK_PIN           P1_22  // J8-2 (moved from EXP2 P0.7)
37
-#define MISO_PIN          P1_23  // J8-3 (moved from EXP2 P0.8)  
38
-#define MOSI_PIN          P2_12  // J8-4 (moved from EXP2 P0.5)  
39
-#define SS_PIN            P0_28  
37
+#define MISO_PIN          P1_23  // J8-3 (moved from EXP2 P0.8)
38
+#define MOSI_PIN          P2_12  // J8-4 (moved from EXP2 P0.5)
39
+#define SS_PIN            P0_28
40
 
40
 
41
 #else
41
 #else
42
 
42
 
43
-#define LPC_SOFTWARE_SPI  // Re-ARM board needs a software SPI because using the 
44
-                          // standard LCD adapter results in the LCD and the 
43
+#define LPC_SOFTWARE_SPI  // Re-ARM board needs a software SPI because using the
44
+                          // standard LCD adapter results in the LCD and the
45
                           // SD card sharing a single SPI when the RepRap Full
45
                           // SD card sharing a single SPI when the RepRap Full
46
                           // Graphic Smart Controller is selected
46
                           // Graphic Smart Controller is selected
47
 
47
 

+ 1
- 1
Marlin/src/feature/bedlevel/ubl/ubl.cpp View File

64
   constexpr float unified_bed_leveling::_mesh_index_to_xpos[16],
64
   constexpr float unified_bed_leveling::_mesh_index_to_xpos[16],
65
                   unified_bed_leveling::_mesh_index_to_ypos[16];
65
                   unified_bed_leveling::_mesh_index_to_ypos[16];
66
 
66
 
67
-  #if ENABLED(ULTRA_LCD)
67
+  #if ENABLED(ULTIPANEL)
68
     bool unified_bed_leveling::lcd_map_control = false;
68
     bool unified_bed_leveling::lcd_map_control = false;
69
   #endif
69
   #endif
70
 
70
 

+ 9
- 5
Marlin/src/feature/bedlevel/ubl/ubl.h View File

76
       static int  g29_grid_size;
76
       static int  g29_grid_size;
77
     #endif
77
     #endif
78
 
78
 
79
-    static float measure_point_with_encoder();
80
-    static float measure_business_card_thickness(float);
79
+    #if ENABLED(NEWPANEL)
80
+      static void move_z_with_encoder(const float &multiplier);
81
+      static float measure_point_with_encoder();
82
+      static float measure_business_card_thickness(const float&);
83
+      static void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
84
+      static void fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map);
85
+    #endif
86
+
81
     static bool g29_parameter_parsing();
87
     static bool g29_parameter_parsing();
82
     static void find_mean_mesh_height();
88
     static void find_mean_mesh_height();
83
     static void shift_mesh_height();
89
     static void shift_mesh_height();
84
     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 probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest);
85
-    static void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
86
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
91
     static void tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3);
87
     static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
92
     static void tilt_mesh_based_on_probed_grid(const bool do_ubl_mesh_map);
88
     static void g29_what_command();
93
     static void g29_what_command();
89
     static void g29_eeprom_dump();
94
     static void g29_eeprom_dump();
90
     static void g29_compare_current_mesh_to_stored_mesh();
95
     static void g29_compare_current_mesh_to_stored_mesh();
91
-    static void fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map);
92
     static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir);
96
     static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir);
93
     static void smart_fill_mesh();
97
     static void smart_fill_mesh();
94
 
98
 
137
                               MESH_MIN_Y + 14 * (MESH_Y_DIST), MESH_MIN_Y + 15 * (MESH_Y_DIST)
141
                               MESH_MIN_Y + 14 * (MESH_Y_DIST), MESH_MIN_Y + 15 * (MESH_Y_DIST)
138
                             };
142
                             };
139
 
143
 
140
-    #if ENABLED(ULTRA_LCD)
144
+    #if ENABLED(ULTIPANEL)
141
       static bool lcd_map_control;
145
       static bool lcd_map_control;
142
     #endif
146
     #endif
143
 
147
 

+ 125
- 117
Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp View File

24
 
24
 
25
 #if ENABLED(AUTO_BED_LEVELING_UBL)
25
 #if ENABLED(AUTO_BED_LEVELING_UBL)
26
 
26
 
27
+  //#define UBL_DEVEL_DEBUGGING
28
+
27
   #include "ubl.h"
29
   #include "ubl.h"
28
 
30
 
29
   #include "../../../Marlin.h"
31
   #include "../../../Marlin.h"
308
   void unified_bed_leveling::G29() {
310
   void unified_bed_leveling::G29() {
309
 
311
 
310
     if (!settings.calc_num_meshes()) {
312
     if (!settings.calc_num_meshes()) {
311
-      SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
312
-      SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
313
+      SERIAL_PROTOCOLLNPGM("?Enable EEPROM and init with M502, M500.\n");
313
       return;
314
       return;
314
     }
315
     }
315
 
316
 
458
                               parser.seen('T'), parser.seen('E'), parser.seen('U'));
459
                               parser.seen('T'), parser.seen('E'), parser.seen('U'));
459
             break;
460
             break;
460
 
461
 
461
-        #endif
462
+        #endif // HAS_BED_PROBE
462
 
463
 
463
         case 2: {
464
         case 2: {
464
           #if ENABLED(NEWPANEL)
465
           #if ENABLED(NEWPANEL)
728
           z_values[x][y] += g29_constant;
729
           z_values[x][y] += g29_constant;
729
   }
730
   }
730
 
731
 
731
-  #if HAS_BED_PROBE
732
+  #if ENABLED(NEWPANEL)
733
+
734
+    typedef void (*clickFunc_t)();
735
+
736
+    bool click_and_hold(const clickFunc_t func=NULL) {
737
+      if (is_lcd_clicked()) {
738
+        lcd_quick_feedback();
739
+        const millis_t nxt = millis() + 1500UL;
740
+        while (is_lcd_clicked()) {                // Loop while the encoder is pressed. Uses hardware flag!
741
+          idle();                                 // idle, of course
742
+          if (ELAPSED(millis(), nxt)) {           // After 1.5 seconds
743
+            lcd_quick_feedback();
744
+            if (func) (*func)();
745
+            wait_for_release();
746
+            safe_delay(50);                       // Debounce the Encoder wheel
747
+            return true;
748
+          }
749
+        }
750
+      }
751
+      return false;
752
+    }
753
+
754
+  #endif // NEWPANEL
732
 
755
 
756
+  #if HAS_BED_PROBE
733
     /**
757
     /**
734
      * Probe all invalidated locations of the mesh that can be reached by the probe.
758
      * Probe all invalidated locations of the mesh that can be reached by the probe.
735
      * This attempts to fill in locations closest to the nozzle's start location first.
759
      * This attempts to fill in locations closest to the nozzle's start location first.
754
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
778
             SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n");
755
             lcd_quick_feedback();
779
             lcd_quick_feedback();
756
             STOW_PROBE();
780
             STOW_PROBE();
757
-            while (is_lcd_clicked()) idle();
781
+            wait_for_release();
758
             lcd_external_control = false;
782
             lcd_external_control = false;
759
             restore_ubl_active_state_and_leave();
783
             restore_ubl_active_state_and_leave();
760
-            safe_delay(50);  // Debounce the Encoder wheel
761
             return;
784
             return;
762
           }
785
           }
763
         #endif
786
         #endif
894
 
917
 
895
   #if ENABLED(NEWPANEL)
918
   #if ENABLED(NEWPANEL)
896
 
919
 
897
-    float unified_bed_leveling::measure_point_with_encoder() {
898
-
899
-      while (is_lcd_clicked()) delay(50);  // wait for user to release encoder wheel
900
-      delay(50);  // debounce
901
-
902
-      KEEPALIVE_STATE(PAUSED_FOR_USER);
903
-      while (!is_lcd_clicked()) {     // we need the loop to move the nozzle based on the encoder wheel here!
920
+    void unified_bed_leveling::move_z_with_encoder(const float &multiplier) {
921
+      wait_for_release();
922
+      while (!is_lcd_clicked()) {
904
         idle();
923
         idle();
905
         if (encoder_diff) {
924
         if (encoder_diff) {
906
-          do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(encoder_diff));
925
+          do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * multiplier);
907
           encoder_diff = 0;
926
           encoder_diff = 0;
908
         }
927
         }
909
       }
928
       }
929
+    }
930
+
931
+    float unified_bed_leveling::measure_point_with_encoder() {
932
+      KEEPALIVE_STATE(PAUSED_FOR_USER);
933
+      move_z_with_encoder(0.01);
910
       KEEPALIVE_STATE(IN_HANDLER);
934
       KEEPALIVE_STATE(IN_HANDLER);
911
       return current_position[Z_AXIS];
935
       return current_position[Z_AXIS];
912
     }
936
     }
913
 
937
 
914
     static void echo_and_take_a_measurement() { SERIAL_PROTOCOLLNPGM(" and take a measurement."); }
938
     static void echo_and_take_a_measurement() { SERIAL_PROTOCOLLNPGM(" and take a measurement."); }
915
 
939
 
916
-    float unified_bed_leveling::measure_business_card_thickness(const float in_height) {
940
+    float unified_bed_leveling::measure_business_card_thickness(const float &in_height) {
917
       lcd_external_control = true;
941
       lcd_external_control = true;
918
       save_ubl_active_state_and_disable();   // Disable bed level correction for probing
942
       save_ubl_active_state_and_disable();   // Disable bed level correction for probing
919
 
943
 
953
       return thickness;
977
       return thickness;
954
     }
978
     }
955
 
979
 
980
+    void abort_manual_probe_remaining_mesh() {
981
+      SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
982
+      do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
983
+      lcd_external_control = false;
984
+      KEEPALIVE_STATE(IN_HANDLER);
985
+      ubl.restore_ubl_active_state_and_leave();
986
+    }
987
+
956
     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) {
988
     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) {
957
 
989
 
958
       lcd_external_control = true;
990
       lcd_external_control = true;
959
 
991
 
960
       save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
992
       save_ubl_active_state_and_disable();   // we don't do bed level correction because we want the raw data when we probe
961
-
962
       do_blocking_move_to(rx, ry, Z_CLEARANCE_BETWEEN_PROBES);
993
       do_blocking_move_to(rx, ry, Z_CLEARANCE_BETWEEN_PROBES);
963
 
994
 
964
       lcd_return_to_status();
995
       lcd_return_to_status();
989
         const float z_step = 0.01;                                        // existing behavior: 0.01mm per click, occasionally step
1020
         const float z_step = 0.01;                                        // existing behavior: 0.01mm per click, occasionally step
990
         //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS];   // approx one step each click
1021
         //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS];   // approx one step each click
991
 
1022
 
992
-        while (is_lcd_clicked()) delay(50);             // wait for user to release encoder wheel
993
-        delay(50);                                       // debounce
994
-        while (!is_lcd_clicked()) {                     // we need the loop to move the nozzle based on the encoder wheel here!
995
-          idle();
996
-          if (encoder_diff) {
997
-            do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * z_step);
998
-            encoder_diff = 0;
999
-          }
1000
-        }
1001
-
1002
-        // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1003
-        // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1004
-        // should be redone and compressed.
1005
-        const millis_t nxt = millis() + 1500L;
1006
-        while (is_lcd_clicked()) {     // debounce and watch for abort
1007
-          idle();
1008
-          if (ELAPSED(millis(), nxt)) {
1009
-            SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
1010
-            do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1011
-
1012
-            lcd_quick_feedback();
1013
-            while (is_lcd_clicked()) idle();
1014
-            lcd_external_control = false;
1023
+        move_z_with_encoder(z_step);
1015
 
1024
 
1016
-            KEEPALIVE_STATE(IN_HANDLER);
1017
-            restore_ubl_active_state_and_leave();
1018
-            return;
1019
-          }
1025
+        if (click_and_hold()) {
1026
+          SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.");
1027
+          do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
1028
+          lcd_external_control = false;
1029
+          KEEPALIVE_STATE(IN_HANDLER);
1030
+          restore_ubl_active_state_and_leave();
1031
+          return;
1020
         }
1032
         }
1021
 
1033
 
1022
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
1034
         z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - thick;
1033
       KEEPALIVE_STATE(IN_HANDLER);
1045
       KEEPALIVE_STATE(IN_HANDLER);
1034
       do_blocking_move_to(rx, ry, Z_CLEARANCE_DEPLOY_PROBE);
1046
       do_blocking_move_to(rx, ry, Z_CLEARANCE_DEPLOY_PROBE);
1035
     }
1047
     }
1036
-
1037
   #endif // NEWPANEL
1048
   #endif // NEWPANEL
1038
 
1049
 
1039
   bool unified_bed_leveling::g29_parameter_parsing() {
1050
   bool unified_bed_leveling::g29_parameter_parsing() {
1078
       #endif
1089
       #endif
1079
         {
1090
         {
1080
           g29_phase_value = pv;
1091
           g29_phase_value = pv;
1081
-           if (!WITHIN(g29_phase_value, 0, 6)) {
1082
-             SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
1083
-             err_flag = true;
1084
-           }
1085
-         }
1092
+          if (!WITHIN(g29_phase_value, 0, 6)) {
1093
+            SERIAL_PROTOCOLLNPGM("?(P)hase value invalid (0-6).\n");
1094
+            err_flag = true;
1095
+          }
1096
+        }
1086
     }
1097
     }
1087
 
1098
 
1088
     if (parser.seen('J')) {
1099
     if (parser.seen('J')) {
1151
     return UBL_OK;
1162
     return UBL_OK;
1152
   }
1163
   }
1153
 
1164
 
1154
-  static int ubl_state_at_invocation = 0,
1155
-             ubl_state_recursion_chk = 0;
1165
+  static uint8_t ubl_state_at_invocation = 0;
1156
 
1166
 
1157
-  void unified_bed_leveling::save_ubl_active_state_and_disable() {
1158
-    ubl_state_recursion_chk++;
1159
-    if (ubl_state_recursion_chk != 1) {
1160
-      SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1161
-
1162
-      #if ENABLED(NEWPANEL)
1163
-        LCD_MESSAGEPGM(MSG_UBL_SAVE_ERROR);
1164
-        lcd_quick_feedback();
1165
-      #endif
1167
+  #ifdef UBL_DEVEL_DEBUGGING
1168
+    static uint8_t ubl_state_recursion_chk = 0;
1169
+  #endif
1166
 
1170
 
1167
-      return;
1168
-    }
1171
+  void unified_bed_leveling::save_ubl_active_state_and_disable() {
1172
+    #ifdef UBL_DEVEL_DEBUGGING
1173
+      ubl_state_recursion_chk++;
1174
+      if (ubl_state_recursion_chk != 1) {
1175
+        SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1176
+        #if ENABLED(NEWPANEL)
1177
+          LCD_MESSAGEPGM(MSG_UBL_SAVE_ERROR);
1178
+          lcd_quick_feedback();
1179
+        #endif
1180
+        return;
1181
+      }
1182
+    #endif
1169
     ubl_state_at_invocation = planner.leveling_active;
1183
     ubl_state_at_invocation = planner.leveling_active;
1170
     set_bed_leveling_enabled(false);
1184
     set_bed_leveling_enabled(false);
1171
   }
1185
   }
1172
 
1186
 
1173
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1187
   void unified_bed_leveling::restore_ubl_active_state_and_leave() {
1174
-    if (--ubl_state_recursion_chk) {
1175
-      SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1176
-
1177
-      #if ENABLED(NEWPANEL)
1178
-        LCD_MESSAGEPGM(MSG_UBL_RESTORE_ERROR);
1179
-        lcd_quick_feedback();
1180
-      #endif
1181
-
1182
-      return;
1183
-    }
1188
+    #ifdef UBL_DEVEL_DEBUGGING
1189
+      if (--ubl_state_recursion_chk) {
1190
+        SERIAL_ECHOLNPGM("restore_ubl_active_state_and_leave() called too many times.");
1191
+        #if ENABLED(NEWPANEL)
1192
+          LCD_MESSAGEPGM(MSG_UBL_RESTORE_ERROR);
1193
+          lcd_quick_feedback();
1194
+        #endif
1195
+        return;
1196
+      }
1197
+    #endif
1184
     set_bed_leveling_enabled(ubl_state_at_invocation);
1198
     set_bed_leveling_enabled(ubl_state_at_invocation);
1185
   }
1199
   }
1186
 
1200
 
1250
     SERIAL_EOL();
1264
     SERIAL_EOL();
1251
     safe_delay(50);
1265
     safe_delay(50);
1252
 
1266
 
1253
-    SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1254
-    SERIAL_EOL();
1255
-    SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1256
-    SERIAL_EOL();
1257
-    safe_delay(50);
1267
+    #ifdef UBL_DEVEL_DEBUGGING
1268
+      SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1269
+      SERIAL_EOL();
1270
+      SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1271
+      SERIAL_EOL();
1272
+      safe_delay(50);
1258
 
1273
 
1259
-    SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.get_start_of_meshes()));
1260
-    SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.get_end_of_meshes()));
1261
-    safe_delay(50);
1274
+      SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.get_start_of_meshes()));
1275
+      SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.get_end_of_meshes()));
1276
+      safe_delay(50);
1262
 
1277
 
1263
-    SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1264
-    SERIAL_EOL();
1265
-    SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
1266
-    SERIAL_EOL();
1267
-    safe_delay(25);
1278
+      SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1279
+      SERIAL_EOL();
1280
+      SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
1281
+      SERIAL_EOL();
1282
+      safe_delay(25);
1268
 
1283
 
1269
-    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.get_end_of_meshes() - settings.get_start_of_meshes())));
1270
-    safe_delay(50);
1284
+      SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.get_end_of_meshes() - settings.get_start_of_meshes())));
1285
+      safe_delay(50);
1271
 
1286
 
1272
-    SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());
1273
-    SERIAL_PROTOCOLLNPGM(" meshes.\n");
1274
-    safe_delay(25);
1287
+      SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());
1288
+      SERIAL_PROTOCOLLNPGM(" meshes.\n");
1289
+      safe_delay(25);
1290
+    #endif // UBL_DEVEL_DEBUGGING
1275
 
1291
 
1276
     if (!sanity_check()) {
1292
     if (!sanity_check()) {
1277
       echo_name();
1293
       echo_name();
1341
         z_values[x][y] -= tmp_z_values[x][y];
1357
         z_values[x][y] -= tmp_z_values[x][y];
1342
   }
1358
   }
1343
 
1359
 
1344
-
1345
   mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1360
   mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1346
 
1361
 
1347
-    bool found_a_NAN  = false;
1348
-    bool found_a_real = false;
1362
+    bool found_a_NAN  = false, found_a_real = false;
1363
+
1349
     mesh_index_pair out_mesh;
1364
     mesh_index_pair out_mesh;
1350
     out_mesh.x_index = out_mesh.y_index = -1;
1365
     out_mesh.x_index = out_mesh.y_index = -1;
1351
     out_mesh.distance = -99999.99;
1366
     out_mesh.distance = -99999.99;
1353
     for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1368
     for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1354
       for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1369
       for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1355
 
1370
 
1356
-        if ( isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
1371
+        if (isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
1357
 
1372
 
1358
           const float mx = mesh_index_to_xpos(i),
1373
           const float mx = mesh_index_to_xpos(i),
1359
                       my = mesh_index_to_ypos(j);
1374
                       my = mesh_index_to_ypos(j);
1360
 
1375
 
1361
-          if ( !position_is_reachable_by_probe(mx, my))  // make sure the probe can get to the mesh point
1376
+          if (!position_is_reachable_by_probe(mx, my))  // make sure the probe can get to the mesh point
1362
             continue;
1377
             continue;
1363
 
1378
 
1364
           found_a_NAN = true;
1379
           found_a_NAN = true;
1452
         }
1467
         }
1453
       } // for j
1468
       } // for j
1454
     } // for i
1469
     } // for i
1470
+
1455
     return out_mesh;
1471
     return out_mesh;
1456
   }
1472
   }
1457
 
1473
 
1458
   #if ENABLED(NEWPANEL)
1474
   #if ENABLED(NEWPANEL)
1459
 
1475
 
1476
+    void abort_fine_tune() {
1477
+      lcd_return_to_status();
1478
+      do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1479
+      LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1480
+    }
1481
+
1460
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1482
     void unified_bed_leveling::fine_tune_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map) {
1461
       if (!parser.seen('R'))    // fine_tune_mesh() is special. If no repetition count flag is specified
1483
       if (!parser.seen('R'))    // fine_tune_mesh() is special. If no repetition count flag is specified
1462
         g29_repetition_cnt = 1;   // do exactly one mesh location. Otherwise use what the parser decided.
1484
         g29_repetition_cnt = 1;   // do exactly one mesh location. Otherwise use what the parser decided.
1499
         if (!position_is_reachable(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
1521
         if (!position_is_reachable(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
1500
           break;
1522
           break;
1501
 
1523
 
1502
-        float new_z = z_values[location.x_index][location.y_index];
1503
-
1504
-        if (isnan(new_z)) // if the mesh point is invalid, set it to 0.0 so it can be edited
1505
-          new_z = 0.0;
1506
-
1507
         do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point
1524
         do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point
1508
 
1525
 
1509
-        new_z = FLOOR(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
1510
-
1511
         KEEPALIVE_STATE(PAUSED_FOR_USER);
1526
         KEEPALIVE_STATE(PAUSED_FOR_USER);
1512
         lcd_external_control = true;
1527
         lcd_external_control = true;
1513
 
1528
 
1515
 
1530
 
1516
         lcd_refresh();
1531
         lcd_refresh();
1517
 
1532
 
1533
+        float new_z = z_values[location.x_index][location.y_index];
1534
+        if (isnan(new_z)) new_z = 0.0;          // Set invalid mesh points to 0.0 so they can be edited
1535
+        new_z = FLOOR(new_z * 1000.0) * 0.001;  // Chop off digits after the 1000ths place
1536
+
1518
         lcd_mesh_edit_setup(new_z);
1537
         lcd_mesh_edit_setup(new_z);
1519
 
1538
 
1520
-        do {
1539
+        while (!is_lcd_clicked()) {
1521
           new_z = lcd_mesh_edit();
1540
           new_z = lcd_mesh_edit();
1522
           #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
1541
           #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
1523
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1542
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1524
           #endif
1543
           #endif
1525
           idle();
1544
           idle();
1526
-        } while (!is_lcd_clicked());
1545
+        }
1527
 
1546
 
1528
         if (!lcd_map_control) lcd_return_to_status();
1547
         if (!lcd_map_control) lcd_return_to_status();
1529
 
1548
 
1535
         // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1554
         // this sequence to detect an is_lcd_clicked() debounce it and leave if it is
1536
         // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1555
         // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp).   This
1537
         // should be redone and compressed.
1556
         // should be redone and compressed.
1538
-        const millis_t nxt = millis() + 1500UL;
1539
-        while (is_lcd_clicked()) { // debounce and watch for abort
1540
-          idle();
1541
-          if (ELAPSED(millis(), nxt)) {
1542
-            lcd_return_to_status();
1543
-            do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
1544
-            LCD_MESSAGEPGM(MSG_EDITING_STOPPED);
1545
-
1546
-            while (is_lcd_clicked()) idle();
1547
-
1548
-            goto FINE_TUNE_EXIT;
1549
-          }
1550
-        }
1557
+        if (click_and_hold(abort_fine_tune))
1558
+          goto FINE_TUNE_EXIT;
1551
 
1559
 
1552
         safe_delay(20);                       // We don't want any switch noise.
1560
         safe_delay(20);                       // We don't want any switch noise.
1553
 
1561
 

+ 19
- 30
Marlin/src/gcode/bedlevel/G26.cpp View File

53
   #error "SIZE_OF_CROSSHAIRS must be less than SIZE_OF_INTERSECTION_CIRCLES."
53
   #error "SIZE_OF_CROSSHAIRS must be less than SIZE_OF_INTERSECTION_CIRCLES."
54
 #endif
54
 #endif
55
 
55
 
56
+#define G26_OK false
57
+#define G26_ERR true
58
+
56
 /**
59
 /**
57
  *   G26 Mesh Validation Tool
60
  *   G26 Mesh Validation Tool
58
  *
61
  *
156
 #if ENABLED(NEWPANEL)
159
 #if ENABLED(NEWPANEL)
157
 
160
 
158
   /**
161
   /**
159
-   * Detect is_lcd_clicked, debounce it, and return true for cancel
162
+   * If the LCD is clicked, cancel, wait for release, return true
160
    */
163
    */
161
   bool user_canceled() {
164
   bool user_canceled() {
162
-    if (!is_lcd_clicked()) return false;
163
-    safe_delay(10);                       // Wait for click to settle
164
-
165
-    #if ENABLED(ULTRA_LCD)
166
-      lcd_setstatusPGM(PSTR("Mesh Validation Stopped."), 99);
165
+    if (!is_lcd_clicked()) return false; // Return if the button isn't pressed
166
+    lcd_setstatusPGM(PSTR("Mesh Validation Stopped."), 99);
167
+    #if ENABLED(ULTIPANEL)
167
       lcd_quick_feedback();
168
       lcd_quick_feedback();
168
     #endif
169
     #endif
169
-
170
-    while (!is_lcd_clicked()) idle();    // Wait for button release
171
-
172
-    // If the button is suddenly pressed again,
173
-    // ask the user to resolve the issue
174
-    lcd_setstatusPGM(PSTR("Release button"), 99); // will never appear...
175
-    while (is_lcd_clicked()) idle();             // unless this loop happens
176
-    lcd_reset_status();
177
-
170
+    wait_for_release();
178
     return true;
171
     return true;
179
   }
172
   }
180
 
173
 
181
   bool exit_from_g26() {
174
   bool exit_from_g26() {
182
     lcd_setstatusPGM(PSTR("Leaving G26"), -1);
175
     lcd_setstatusPGM(PSTR("Leaving G26"), -1);
183
-    while (is_lcd_clicked()) idle();
176
+    wait_for_release();
184
     return G26_ERR;
177
     return G26_ERR;
185
   }
178
   }
186
 
179
 
268
   set_destination_from_current();
261
   set_destination_from_current();
269
 }
262
 }
270
 
263
 
271
-FORCE_INLINE void move_to(const float where[XYZE], const float &de) {
272
-  move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de);
273
-}
264
+FORCE_INLINE void move_to(const float where[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); }
274
 
265
 
275
 void retract_filament(const float where[XYZE]) {
266
 void retract_filament(const float where[XYZE]) {
276
   if (!g26_retracted) { // Only retract if we are not already retracted!
267
   if (!g26_retracted) { // Only retract if we are not already retracted!
314
 
305
 
315
   // If the end point of the line is closer to the nozzle, flip the direction,
306
   // If the end point of the line is closer to the nozzle, flip the direction,
316
   // moving from the end to the start. On very small lines the optimization isn't worth it.
307
   // moving from the end to the start. On very small lines the optimization isn't worth it.
317
-  if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < FABS(line_length)) {
308
+  if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < FABS(line_length))
318
     return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
309
     return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
319
-  }
320
 
310
 
321
   // Decide whether to retract & bump
311
   // Decide whether to retract & bump
322
 
312
 
373
                 SERIAL_EOL();
363
                 SERIAL_EOL();
374
                 //debug_current_and_destination(PSTR("Connecting horizontal line."));
364
                 //debug_current_and_destination(PSTR("Connecting horizontal line."));
375
               }
365
               }
376
-
377
               print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
366
               print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height);
378
             }
367
             }
379
             bitmap_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again, even if we skipped it
368
             bitmap_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again, even if we skipped it
405
                   SERIAL_ECHOPAIR(", ey=", ey);
394
                   SERIAL_ECHOPAIR(", ey=", ey);
406
                   SERIAL_CHAR(')');
395
                   SERIAL_CHAR(')');
407
                   SERIAL_EOL();
396
                   SERIAL_EOL();
397
+
408
                   #if ENABLED(AUTO_BED_LEVELING_UBL)
398
                   #if ENABLED(AUTO_BED_LEVELING_UBL)
409
-                    void debug_current_and_destination(const char *title);
410
                     debug_current_and_destination(PSTR("Connecting vertical line."));
399
                     debug_current_and_destination(PSTR("Connecting vertical line."));
411
                   #endif
400
                   #endif
412
                 }
401
                 }
515
         idle();
504
         idle();
516
       }
505
       }
517
 
506
 
518
-      while (is_lcd_clicked()) idle();           // Debounce Encoder Wheel
507
+      wait_for_release();
519
 
508
 
520
       strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue;
509
       strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue;
521
                                                           // So... We cheat to get a message up.
510
                                                           // So... We cheat to get a message up.
678
     return;
667
     return;
679
   }
668
   }
680
 
669
 
681
-  g26_x_pos = parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position[X_AXIS],
670
+  g26_x_pos = parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position[X_AXIS];
682
   g26_y_pos = parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position[Y_AXIS];
671
   g26_y_pos = parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position[Y_AXIS];
683
-
684
   if (!position_is_reachable(g26_x_pos, g26_y_pos)) {
672
   if (!position_is_reachable(g26_x_pos, g26_y_pos)) {
685
     SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds.");
673
     SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds.");
686
     return;
674
     return;
727
   #if ENABLED(ULTRA_LCD)
715
   #if ENABLED(ULTRA_LCD)
728
     lcd_external_control = true;
716
     lcd_external_control = true;
729
   #endif
717
   #endif
718
+
730
   //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern."));
719
   //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern."));
731
 
720
 
732
   /**
721
   /**
806
         #if IS_KINEMATIC
795
         #if IS_KINEMATIC
807
           // Check to make sure this segment is entirely on the bed, skip if not.
796
           // Check to make sure this segment is entirely on the bed, skip if not.
808
           if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
797
           if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue;
809
-        #else                                              // not, we need to skip
798
+        #else                                               // not, we need to skip
810
           rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
799
           rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops
811
           ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
800
           ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1);
812
           xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1);
801
           xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1);
842
   move_to(destination, 0); // Raise the nozzle
831
   move_to(destination, 0); // Raise the nozzle
843
   //debug_current_and_destination(PSTR("done doing Z-Raise."));
832
   //debug_current_and_destination(PSTR("done doing Z-Raise."));
844
 
833
 
845
-  destination[X_AXIS] = g26_x_pos;                                               // Move back to the starting position
834
+  destination[X_AXIS] = g26_x_pos;                               // Move back to the starting position
846
   destination[Y_AXIS] = g26_y_pos;
835
   destination[Y_AXIS] = g26_y_pos;
847
-  //destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;                        // Keep the nozzle where it is
836
+  //destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;            // Keep the nozzle where it is
848
 
837
 
849
   move_to(destination, 0); // Move back to the starting position
838
   move_to(destination, 0); // Move back to the starting position
850
   //debug_current_and_destination(PSTR("done doing X/Y move."));
839
   //debug_current_and_destination(PSTR("done doing X/Y move."));
851
 
840
 
852
   #if ENABLED(ULTRA_LCD)
841
   #if ENABLED(ULTRA_LCD)
853
-    lcd_external_control = false;   // Give back control of the LCD Panel!
842
+    lcd_external_control = false;     // Give back control of the LCD Panel!
854
   #endif
843
   #endif
855
 
844
 
856
   if (!g26_keep_heaters_on) {
845
   if (!g26_keep_heaters_on) {

+ 1
- 1
Marlin/src/gcode/eeprom/M500-M503.cpp View File

51
    * M503: print settings currently in memory
51
    * M503: print settings currently in memory
52
    */
52
    */
53
   void GcodeSuite::M503() {
53
   void GcodeSuite::M503() {
54
-    (void)settings.report(parser.boolval('S'));
54
+    (void)settings.report(parser.seen('S') && !parser.value_bool());
55
   }
55
   }
56
 
56
 
57
 #endif // !DISABLE_M503
57
 #endif // !DISABLE_M503

+ 4
- 0
Marlin/src/inc/SanityCheck.h View File

313
 #if ENABLED(LCD_PROGRESS_BAR)
313
 #if ENABLED(LCD_PROGRESS_BAR)
314
   #if DISABLED(SDSUPPORT)
314
   #if DISABLED(SDSUPPORT)
315
     #error "LCD_PROGRESS_BAR requires SDSUPPORT."
315
     #error "LCD_PROGRESS_BAR requires SDSUPPORT."
316
+  #elif DISABLED(ULTRA_LCD)
317
+    #error "LCD_PROGRESS_BAR requires a character LCD."
316
   #elif ENABLED(DOGLCD)
318
   #elif ENABLED(DOGLCD)
317
     #error "LCD_PROGRESS_BAR does not apply to graphical displays."
319
     #error "LCD_PROGRESS_BAR does not apply to graphical displays."
318
   #elif ENABLED(FILAMENT_LCD_DISPLAY)
320
   #elif ENABLED(FILAMENT_LCD_DISPLAY)
319
     #error "LCD_PROGRESS_BAR and FILAMENT_LCD_DISPLAY are not fully compatible. Comment out this line to use both."
321
     #error "LCD_PROGRESS_BAR and FILAMENT_LCD_DISPLAY are not fully compatible. Comment out this line to use both."
320
   #endif
322
   #endif
323
+#elif ENABLED(LCD_SET_PROGRESS_MANUALLY) && DISABLED(DOGLCD)
324
+  #error "LCD_SET_PROGRESS_MANUALLY requires LCD_PROGRESS_BAR or Graphical LCD."
321
 #endif
325
 #endif
322
 
326
 
323
 /**
327
 /**

+ 55
- 53
Marlin/src/lcd/ultralcd.cpp View File

85
 #endif
85
 #endif
86
 
86
 
87
 uint8_t lcd_status_update_delay = 1, // First update one loop delayed
87
 uint8_t lcd_status_update_delay = 1, // First update one loop delayed
88
-        lcd_status_message_level;    // Higher level overrides lower
88
+        lcd_status_message_level;    // Higher level blocks lower level
89
 char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
89
 char lcd_status_message[3 * (LCD_WIDTH) + 1] = WELCOME_MSG; // worst case is kana with up to 3*LCD_WIDTH+1
90
 
90
 
91
 #if ENABLED(STATUS_MESSAGE_SCROLLING)
91
 #if ENABLED(STATUS_MESSAGE_SCROLLING)
92
   uint8_t status_scroll_pos = 0;
92
   uint8_t status_scroll_pos = 0;
93
 #endif
93
 #endif
94
+
94
 #if ENABLED(SCROLL_LONG_FILENAMES)
95
 #if ENABLED(SCROLL_LONG_FILENAMES)
95
   uint8_t filename_scroll_pos, filename_scroll_max, filename_scroll_hash;
96
   uint8_t filename_scroll_pos, filename_scroll_max, filename_scroll_hash;
96
 #endif
97
 #endif
163
     extern bool powersupply_on;
164
     extern bool powersupply_on;
164
   #endif
165
   #endif
165
 
166
 
166
-  float move_menu_scale;
167
-
168
   ////////////////////////////////////////////
167
   ////////////////////////////////////////////
169
   ///////////////// Menu Tree ////////////////
168
   ///////////////// Menu Tree ////////////////
170
   ////////////////////////////////////////////
169
   ////////////////////////////////////////////
244
     void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
243
     void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
245
     typedef void _name##_void
244
     typedef void _name##_void
246
 
245
 
247
-  DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
248
   DECLARE_MENU_EDIT_TYPE(int16_t, int3);
246
   DECLARE_MENU_EDIT_TYPE(int16_t, int3);
249
   DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
247
   DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
250
   DECLARE_MENU_EDIT_TYPE(float, float3);
248
   DECLARE_MENU_EDIT_TYPE(float, float3);
254
   DECLARE_MENU_EDIT_TYPE(float, float51);
252
   DECLARE_MENU_EDIT_TYPE(float, float51);
255
   DECLARE_MENU_EDIT_TYPE(float, float52);
253
   DECLARE_MENU_EDIT_TYPE(float, float52);
256
   DECLARE_MENU_EDIT_TYPE(float, float62);
254
   DECLARE_MENU_EDIT_TYPE(float, float62);
255
+  DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
257
 
256
 
258
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
257
   void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
259
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
258
   void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
566
     static bool no_reentry = false;
565
     static bool no_reentry = false;
567
     if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
566
     if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, sync_message);
568
     if (no_reentry) return;
567
     if (no_reentry) return;
569
-
570
     // Make this the current handler till all moves are done
568
     // Make this the current handler till all moves are done
571
     no_reentry = true;
569
     no_reentry = true;
572
-    screenFunc_t old_screen = currentScreen;
570
+    const screenFunc_t old_screen = currentScreen;
573
     lcd_goto_screen(_lcd_synchronize);
571
     lcd_goto_screen(_lcd_synchronize);
574
     stepper.synchronize();
572
     stepper.synchronize();
575
     no_reentry = false;
573
     no_reentry = false;
997
     #if ENABLED(SDSUPPORT)
995
     #if ENABLED(SDSUPPORT)
998
       if (card.cardOK) {
996
       if (card.cardOK) {
999
         if (card.isFileOpen()) {
997
         if (card.isFileOpen()) {
1000
-          if (IS_SD_PRINTING)
998
+          if (card.sdprinting)
1001
             MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
999
             MENU_ITEM(function, MSG_PAUSE_PRINT, lcd_sdcard_pause);
1002
           else
1000
           else
1003
             MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
1001
             MENU_ITEM(function, MSG_RESUME_PRINT, lcd_sdcard_resume);
1074
       if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20, 3, 1, offset_bedline_bmp);
1072
       if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20, 3, 1, offset_bedline_bmp);
1075
 
1073
 
1076
       // Draw cw/ccw indicator and up/down arrows.
1074
       // Draw cw/ccw indicator and up/down arrows.
1077
-      if (PAGE_CONTAINS(47,62)) {
1075
+      if (PAGE_CONTAINS(47, 62)) {
1078
         u8g.drawBitmapP(left  + 0, 47, 3, 16, rot_down);
1076
         u8g.drawBitmapP(left  + 0, 47, 3, 16, rot_down);
1079
         u8g.drawBitmapP(right + 0, 47, 3, 16, rot_up);
1077
         u8g.drawBitmapP(right + 0, 47, 3, 16, rot_up);
1080
         u8g.drawBitmapP(right + 20, 48 - dir, 2, 13, up_arrow_bmp);
1078
         u8g.drawBitmapP(right + 20, 48 - dir, 2, 13, up_arrow_bmp);
1115
         ENCODER_DIRECTION_NORMAL();
1113
         ENCODER_DIRECTION_NORMAL();
1116
         if (encoderPosition) {
1114
         if (encoderPosition) {
1117
           const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
1115
           const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
1116
+          encoderPosition = 0;
1117
+
1118
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1118
           const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
1119
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
1119
           if (WITHIN(new_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
1120
 
1120
 
1124
             zprobe_zoffset = new_zoffset;
1124
             zprobe_zoffset = new_zoffset;
1125
             lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
1125
             lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
1126
           }
1126
           }
1127
-          encoderPosition = 0;
1128
         }
1127
         }
1129
         if (lcdDrawUpdate) {
1128
         if (lcdDrawUpdate) {
1130
           lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
1129
           lcd_implementation_drawedit(PSTR(MSG_ZPROBE_ZOFFSET), ftostr43sign(zprobe_zoffset));
1164
         mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
1163
         mesh_edit_value = float(rounded - (rounded % 5L)) / 1000.0;
1165
       }
1164
       }
1166
 
1165
 
1167
-      if (lcdDrawUpdate)
1166
+      if (lcdDrawUpdate) {
1168
         lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
1167
         lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
1169
         #if ENABLED(MESH_EDIT_GFX_OVERLAY)
1168
         #if ENABLED(MESH_EDIT_GFX_OVERLAY)
1170
           _lcd_zoffset_overlay_gfx(mesh_edit_value);
1169
           _lcd_zoffset_overlay_gfx(mesh_edit_value);
1171
         #endif
1170
         #endif
1171
+      }
1172
     }
1172
     }
1173
 
1173
 
1174
     void _lcd_mesh_edit_NOP() {
1174
     void _lcd_mesh_edit_NOP() {
1182
       return mesh_edit_value;
1182
       return mesh_edit_value;
1183
     }
1183
     }
1184
 
1184
 
1185
-    void lcd_mesh_edit_setup(float initial) {
1185
+    void lcd_mesh_edit_setup(const float initial) {
1186
       mesh_edit_value = mesh_edit_accumulator = initial;
1186
       mesh_edit_value = mesh_edit_accumulator = initial;
1187
       lcd_goto_screen(_lcd_mesh_edit_NOP);
1187
       lcd_goto_screen(_lcd_mesh_edit_NOP);
1188
     }
1188
     }
1203
 
1203
 
1204
   #endif // AUTO_BED_LEVELING_UBL
1204
   #endif // AUTO_BED_LEVELING_UBL
1205
 
1205
 
1206
+
1206
   /**
1207
   /**
1207
    * Watch temperature callbacks
1208
    * Watch temperature callbacks
1208
    */
1209
    */
2030
      */
2031
      */
2031
     void _lcd_ubl_adjust_height_cmd() {
2032
     void _lcd_ubl_adjust_height_cmd() {
2032
       char UBL_LCD_GCODE[16];
2033
       char UBL_LCD_GCODE[16];
2033
-      const int ind = ubl_height_amount < 0 ? 6 : 7;
2034
-      strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6-"));
2034
+      const int ind = ubl_height_amount > 0 ? 9 : 10;
2035
+      strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
2035
       sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
2036
       sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), abs(ubl_height_amount));
2036
       enqueue_and_echo_command(UBL_LCD_GCODE);
2037
       enqueue_and_echo_command(UBL_LCD_GCODE);
2037
     }
2038
     }
2047
     void _lcd_ubl_height_adjust_menu() {
2048
     void _lcd_ubl_height_adjust_menu() {
2048
       START_MENU();
2049
       START_MENU();
2049
       MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
2050
       MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
2050
-      MENU_ITEM_EDIT(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9);
2051
-      MENU_ITEM(function, MSG_UBL_MESH_HEIGHT_ADJUST, _lcd_ubl_adjust_height_cmd);
2051
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
2052
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2052
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2053
       END_MENU();
2053
       END_MENU();
2054
     }
2054
     }
2184
     void _lcd_ubl_fillin_menu() {
2184
     void _lcd_ubl_fillin_menu() {
2185
       START_MENU();
2185
       START_MENU();
2186
       MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
2186
       MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
2187
-      MENU_ITEM_EDIT(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9);
2188
-      MENU_ITEM(function, MSG_UBL_FILLIN_MESH, _lcd_ubl_fillin_amount_cmd);
2187
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
2189
       MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
2188
       MENU_ITEM(function, MSG_UBL_SMART_FILLIN, _lcd_ubl_smart_fillin_cmd);
2190
       MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
2189
       MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
2191
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2190
       MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
2644
     END_MENU();
2643
     END_MENU();
2645
   }
2644
   }
2646
 
2645
 
2646
+  float move_menu_scale;
2647
+
2647
   #if ENABLED(DELTA_CALIBRATION_MENU) || (ENABLED(DELTA_AUTO_CALIBRATION) && !HAS_BED_PROBE)
2648
   #if ENABLED(DELTA_CALIBRATION_MENU) || (ENABLED(DELTA_AUTO_CALIBRATION) && !HAS_BED_PROBE)
2648
 
2649
 
2649
     void lcd_move_z();
2650
     void lcd_move_z();
2653
         reset_bed_level(); // After calibration bed-level data is no longer valid
2654
         reset_bed_level(); // After calibration bed-level data is no longer valid
2654
       #endif
2655
       #endif
2655
 
2656
 
2656
-      float z_dest = (Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5;
2657
-      line_to_z(z_dest);
2657
+      line_to_z((Z_CLEARANCE_BETWEEN_PROBES) + (DELTA_PRINTABLE_RADIUS) / 5);
2658
       current_position[X_AXIS] = rx;
2658
       current_position[X_AXIS] = rx;
2659
       current_position[Y_AXIS] = ry;
2659
       current_position[Y_AXIS] = ry;
2660
       line_to_current_z();
2660
       line_to_current_z();
2661
-      z_dest = Z_CLEARANCE_BETWEEN_PROBES;
2662
-      line_to_z(z_dest);
2661
+      line_to_z(Z_CLEARANCE_BETWEEN_PROBES);
2663
 
2662
 
2664
       lcd_synchronize();
2663
       lcd_synchronize();
2665
       move_menu_scale = PROBE_MANUALLY_STEP;
2664
       move_menu_scale = PROBE_MANUALLY_STEP;
2813
       #endif
2812
       #endif
2814
           manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
2813
           manual_move_e_index = eindex >= 0 ? eindex : active_extruder;
2815
     #endif
2814
     #endif
2816
-
2817
     manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
2815
     manual_move_start_time = millis() + (move_menu_scale < 0.99 ? 0UL : 250UL); // delay for bigger moves
2818
     manual_move_axis = (int8_t)axis;
2816
     manual_move_axis = (int8_t)axis;
2819
   }
2817
   }
2830
     if (encoderPosition && !processing_manual_move) {
2828
     if (encoderPosition && !processing_manual_move) {
2831
       gcode.refresh_cmd_timeout();
2829
       gcode.refresh_cmd_timeout();
2832
 
2830
 
2831
+      // Start with no limits to movement
2833
       float min = current_position[axis] - 1000,
2832
       float min = current_position[axis] - 1000,
2834
             max = current_position[axis] + 1000;
2833
             max = current_position[axis] + 1000;
2835
 
2834
 
2867
       // This assumes the center is 0,0
2866
       // This assumes the center is 0,0
2868
       #if ENABLED(DELTA)
2867
       #if ENABLED(DELTA)
2869
         if (axis != Z_AXIS) {
2868
         if (axis != Z_AXIS) {
2870
-          max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
2869
+          max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); // (Y_AXIS - axis) == the other axis
2871
           min = -max;
2870
           min = -max;
2872
         }
2871
         }
2873
       #endif
2872
       #endif
3131
     MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
3130
     MENU_ITEM(submenu, MSG_FILAMENT, lcd_control_filament_menu);
3132
 
3131
 
3133
     #if HAS_LCD_CONTRAST
3132
     #if HAS_LCD_CONTRAST
3134
-      MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, (int16_t*)&lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
3133
+      MENU_ITEM_EDIT_CALLBACK(int3, MSG_CONTRAST, &lcd_contrast, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX, lcd_callback_set_contrast, true);
3135
     #endif
3134
     #endif
3136
     #if ENABLED(FWRETRACT)
3135
     #if ENABLED(FWRETRACT)
3137
       MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
3136
       MENU_ITEM(submenu, MSG_RETRACT, lcd_control_retract_menu);
3724
 
3723
 
3725
         lcd_goto_screen(lcd_sdcard_menu, last_sdfile_encoderPosition);
3724
         lcd_goto_screen(lcd_sdcard_menu, last_sdfile_encoderPosition);
3726
         defer_return_to_status = true;
3725
         defer_return_to_status = true;
3727
-        last_sdfile_encoderPosition == 0xFFFF;
3726
+        last_sdfile_encoderPosition = 0xFFFF;
3728
 
3727
 
3729
         #if ENABLED(DOGLCD)
3728
         #if ENABLED(DOGLCD)
3730
           lcd_update();
3729
           lcd_update();
3749
         MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
3748
         MENU_ITEM(function, LCD_STR_FOLDER "..", lcd_sd_updir);
3750
       }
3749
       }
3751
 
3750
 
3752
-      if (fileCnt) {
3753
-        for (uint16_t i = 0; i < fileCnt; i++) {
3754
-          if (_menuLineNr == _thisItemNr) {
3755
-            const uint16_t nr =
3756
-              #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
3757
-                fileCnt - 1 -
3758
-              #endif
3759
-            i;
3760
-
3761
-            #if ENABLED(SDCARD_SORT_ALPHA)
3762
-              card.getfilename_sorted(nr);
3763
-            #else
3764
-              card.getfilename(nr);
3751
+      for (uint16_t i = 0; i < fileCnt; i++) {
3752
+        if (_menuLineNr == _thisItemNr) {
3753
+          const uint16_t nr =
3754
+            #if ENABLED(SDCARD_RATHERRECENTFIRST) && DISABLED(SDCARD_SORT_ALPHA)
3755
+              fileCnt - 1 -
3765
             #endif
3756
             #endif
3757
+          i;
3766
 
3758
 
3767
-            if (card.filenameIsDir)
3768
-              MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
3769
-            else
3770
-              MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
3771
-          }
3772
-          else {
3773
-            MENU_ITEM_DUMMY();
3774
-          }
3759
+          #if ENABLED(SDCARD_SORT_ALPHA)
3760
+            card.getfilename_sorted(nr);
3761
+          #else
3762
+            card.getfilename(nr);
3763
+          #endif
3764
+
3765
+          if (card.filenameIsDir)
3766
+            MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename);
3767
+          else
3768
+            MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename);
3769
+        }
3770
+        else {
3771
+          MENU_ITEM_DUMMY();
3775
         }
3772
         }
3776
       }
3773
       }
3777
       END_MENU();
3774
       END_MENU();
4476
   lcd_implementation_init();
4473
   lcd_implementation_init();
4477
 
4474
 
4478
   #if ENABLED(NEWPANEL)
4475
   #if ENABLED(NEWPANEL)
4479
-
4480
     #if BUTTON_EXISTS(EN1)
4476
     #if BUTTON_EXISTS(EN1)
4481
       SET_INPUT_PULLUP(BTN_EN1);
4477
       SET_INPUT_PULLUP(BTN_EN1);
4482
     #endif
4478
     #endif
4479
+
4483
     #if BUTTON_EXISTS(EN2)
4480
     #if BUTTON_EXISTS(EN2)
4484
       SET_INPUT_PULLUP(BTN_EN2);
4481
       SET_INPUT_PULLUP(BTN_EN2);
4485
     #endif
4482
     #endif
4483
+
4486
     #if BUTTON_EXISTS(ENC)
4484
     #if BUTTON_EXISTS(ENC)
4487
       SET_INPUT_PULLUP(BTN_ENC);
4485
       SET_INPUT_PULLUP(BTN_ENC);
4488
     #endif
4486
     #endif
4684
 
4682
 
4685
       #endif
4683
       #endif
4686
 
4684
 
4687
-      bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
4685
+      const bool encoderPastThreshold = (abs(encoderDiff) >= ENCODER_PULSES_PER_STEP);
4688
       if (encoderPastThreshold || lcd_clicked) {
4686
       if (encoderPastThreshold || lcd_clicked) {
4689
         if (encoderPastThreshold) {
4687
         if (encoderPastThreshold) {
4690
           int32_t encoderMultiplier = 1;
4688
           int32_t encoderMultiplier = 1;
4979
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
4977
           if (BUTTON_PRESSED(ENC)) newbutton |= EN_C;
4980
         #endif
4978
         #endif
4981
 
4979
 
4982
-        buttons = newbutton;
4983
-        #if ENABLED(LCD_HAS_SLOW_BUTTONS)
4984
-          buttons |= slow_buttons;
4985
-        #endif
4986
-
4987
         //
4980
         //
4988
         // Directional buttons
4981
         // Directional buttons
4989
         //
4982
         //
5032
 
5025
 
5033
         #endif // LCD_HAS_DIRECTIONAL_BUTTONS
5026
         #endif // LCD_HAS_DIRECTIONAL_BUTTONS
5034
 
5027
 
5028
+        buttons = newbutton;
5029
+        #if ENABLED(LCD_HAS_SLOW_BUTTONS)
5030
+          buttons |= slow_buttons;
5031
+        #endif
5032
+
5035
         #if ENABLED(ADC_KEYPAD)
5033
         #if ENABLED(ADC_KEYPAD)
5036
 
5034
 
5037
           uint8_t newbutton_reprapworld_keypad = 0;
5035
           uint8_t newbutton_reprapworld_keypad = 0;
5107
 
5105
 
5108
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
5106
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
5109
     bool is_lcd_clicked() { return LCD_CLICKED; }
5107
     bool is_lcd_clicked() { return LCD_CLICKED; }
5108
+    void wait_for_release() {
5109
+      while (is_lcd_clicked()) safe_delay(50);
5110
+      safe_delay(50);
5111
+    }
5110
   #endif
5112
   #endif
5111
 
5113
 
5112
 #endif // ULTIPANEL
5114
 #endif // ULTIPANEL

+ 1
- 0
Marlin/src/lcd/ultralcd.h View File

222
 
222
 
223
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
223
   #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION)
224
     bool is_lcd_clicked();
224
     bool is_lcd_clicked();
225
+    void wait_for_release();
225
   #endif
226
   #endif
226
 
227
 
227
 #else // no LCD
228
 #else // no LCD

+ 1
- 1
Marlin/src/module/configuration_store.cpp View File

1527
    *
1527
    *
1528
    * Unless specifically disabled, M503 is available even without EEPROM
1528
    * Unless specifically disabled, M503 is available even without EEPROM
1529
    */
1529
    */
1530
-  void MarlinSettings::report(bool forReplay) {
1530
+  void MarlinSettings::report(const bool forReplay) {
1531
 
1531
 
1532
     /**
1532
     /**
1533
      * Announce current units, in case inches are being displayed
1533
      * Announce current units, in case inches are being displayed

+ 2
- 2
Marlin/src/module/configuration_store.h View File

52
     #endif
52
     #endif
53
 
53
 
54
     #if DISABLED(DISABLE_M503)
54
     #if DISABLED(DISABLE_M503)
55
-      static void report(bool forReplay=false);
55
+      static void report(const bool forReplay=false);
56
     #else
56
     #else
57
       FORCE_INLINE
57
       FORCE_INLINE
58
-      static void report(bool forReplay=false) { UNUSED(forReplay); }
58
+      static void report(const bool forReplay=false) { UNUSED(forReplay); }
59
     #endif
59
     #endif
60
 
60
 
61
   private:
61
   private:

+ 9
- 4
Marlin/src/module/planner.cpp View File

135
           Planner::inverse_z_fade_height,
135
           Planner::inverse_z_fade_height,
136
           Planner::last_fade_z;
136
           Planner::last_fade_z;
137
   #endif
137
   #endif
138
+#else
139
+  constexpr bool Planner::leveling_active;
138
 #endif
140
 #endif
139
 
141
 
140
 #if ENABLED(SKEW_CORRECTION)
142
 #if ENABLED(SKEW_CORRECTION)
141
   #if ENABLED(SKEW_CORRECTION_GCODE)
143
   #if ENABLED(SKEW_CORRECTION_GCODE)
142
-    // Initialized by settings.load()
143
     float Planner::xy_skew_factor;
144
     float Planner::xy_skew_factor;
144
-    #if ENABLED(SKEW_CORRECTION_FOR_Z)
145
-      float Planner::xz_skew_factor, Planner::yz_skew_factor;
146
-    #endif
145
+  #else
146
+    constexpr float Planner::xy_skew_factor;
147
+  #endif
148
+  #if ENABLED(SKEW_CORRECTION_FOR_Z) && ENABLED(SKEW_CORRECTION_GCODE)
149
+    float Planner::xz_skew_factor, Planner::yz_skew_factor;
150
+  #else
151
+    constexpr float Planner::xz_skew_factor, Planner::yz_skew_factor;
147
   #endif
152
   #endif
148
 #endif
153
 #endif
149
 
154
 

+ 34
- 37
Marlin/src/module/stepper.cpp View File

94
 // private:
94
 // private:
95
 
95
 
96
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
96
 uint8_t Stepper::last_direction_bits = 0;        // The next stepping-bits to be output
97
-uint16_t Stepper::cleaning_buffer_counter = 0;
97
+int16_t Stepper::cleaning_buffer_counter = 0;
98
 
98
 
99
 #if ENABLED(X_DUAL_ENDSTOPS)
99
 #if ENABLED(X_DUAL_ENDSTOPS)
100
-  bool Stepper::locked_x_motor = false;
101
-  bool Stepper::locked_x2_motor = false;
100
+  bool Stepper::locked_x_motor = false, Stepper::locked_x2_motor = false;
102
 #endif
101
 #endif
103
-
104
 #if ENABLED(Y_DUAL_ENDSTOPS)
102
 #if ENABLED(Y_DUAL_ENDSTOPS)
105
-  bool Stepper::locked_y_motor = false;
106
-  bool Stepper::locked_y2_motor = false;
103
+  bool Stepper::locked_y_motor = false, Stepper::locked_y2_motor = false;
107
 #endif
104
 #endif
108
-
109
 #if ENABLED(Z_DUAL_ENDSTOPS)
105
 #if ENABLED(Z_DUAL_ENDSTOPS)
110
-  bool Stepper::locked_z_motor = false;
111
-  bool Stepper::locked_z2_motor = false;
106
+  bool Stepper::locked_z_motor = false, Stepper::locked_z2_motor = false;
112
 #endif
107
 #endif
113
 
108
 
114
 long Stepper::counter_X = 0,
109
 long Stepper::counter_X = 0,
341
 
336
 
342
 void Stepper::isr() {
337
 void Stepper::isr() {
343
 
338
 
344
-  hal_timer_t ocr_val;
345
-
346
-  #define ENDSTOP_NOMINAL_OCR_VAL 1500 * HAL_TICKS_PER_US    // check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
347
-  #define OCR_VAL_TOLERANCE 500 * HAL_TICKS_PER_US           // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
339
+  #define ENDSTOP_NOMINAL_OCR_VAL 1500 * HAL_TICKS_PER_US // Check endstops every 1.5ms to guarantee two stepper ISRs within 5ms for BLTouch
340
+  #define OCR_VAL_TOLERANCE        500 * HAL_TICKS_PER_US // First max delay is 2.0ms, last min delay is 0.5ms, all others 1.5ms
348
 
341
 
349
   #if DISABLED(LIN_ADVANCE)
342
   #if DISABLED(LIN_ADVANCE)
350
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
343
     // Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
355
     #endif
348
     #endif
356
   #endif
349
   #endif
357
 
350
 
351
+  hal_timer_t ocr_val;
358
   static uint32_t step_remaining = 0;  // SPLIT function always runs.  This allows 16 bit timers to be
352
   static uint32_t step_remaining = 0;  // SPLIT function always runs.  This allows 16 bit timers to be
359
                                        // used to generate the stepper ISR.
353
                                        // used to generate the stepper ISR.
360
   #define SPLIT(L) do { \
354
   #define SPLIT(L) do { \
367
       ocr_val = L;\
361
       ocr_val = L;\
368
   }while(0)
362
   }while(0)
369
 
363
 
364
+  // Time remaining before the next step?
370
   if (step_remaining) {
365
   if (step_remaining) {
371
-    if (ENDSTOPS_ENABLED)
372
-      endstops.update();
373
-    if (step_remaining > ENDSTOP_NOMINAL_OCR_VAL) {
374
-      step_remaining -= ENDSTOP_NOMINAL_OCR_VAL;
375
-      ocr_val = ENDSTOP_NOMINAL_OCR_VAL;
376
-    }
377
-    else {
378
-      ocr_val = step_remaining;
379
-      step_remaining = 0;  //  last one before the ISR that does the step
380
-    }
381
 
366
 
367
+    // Make sure endstops are updated
368
+    if (ENDSTOPS_ENABLED) endstops.update();
369
+
370
+    // Next ISR either for endstops or stepping
371
+    ocr_val = step_remaining <= ENDSTOP_NOMINAL_OCR_VAL ? step_remaining : ENDSTOP_NOMINAL_OCR_VAL;
372
+    step_remaining -= ocr_val;
382
     _NEXT_ISR(ocr_val);
373
     _NEXT_ISR(ocr_val);
383
 
374
 
384
-  #if DISABLED(LIN_ADVANCE)
385
-    #ifdef CPU_32_BIT
386
-      HAL_timer_set_count(STEP_TIMER_NUM, ocr_val);
387
-    #else
388
-      NOLESS(OCR1A, TCNT1 + 16);
375
+    #if DISABLED(LIN_ADVANCE)
376
+      #ifdef CPU_32_BIT
377
+        HAL_timer_set_count(STEP_TIMER_NUM, ocr_val);
378
+      #else
379
+        NOLESS(OCR1A, TCNT1 + 16);
380
+      #endif
381
+      HAL_ENABLE_ISRs(); // re-enable ISRs
389
     #endif
382
     #endif
390
-    HAL_ENABLE_ISRs(); // re-enable ISRs
391
-  #endif
392
 
383
 
393
     return;
384
     return;
394
   }
385
   }
395
 
386
 
396
-
387
+  //
388
+  // When cleaning, discard the current block and run fast
389
+  //
397
   if (cleaning_buffer_counter) {
390
   if (cleaning_buffer_counter) {
398
-    --cleaning_buffer_counter;
391
+    if (cleaning_buffer_counter < 0)
392
+      ++cleaning_buffer_counter;                // Count up for endstop hit
393
+    else {
394
+      --cleaning_buffer_counter;                // Count down for abort print
395
+      #ifdef SD_FINISHED_RELEASECOMMAND
396
+        if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
397
+      #endif
398
+    }
399
     current_block = NULL;
399
     current_block = NULL;
400
     planner.discard_current_block();
400
     planner.discard_current_block();
401
-    #ifdef SD_FINISHED_RELEASECOMMAND
402
-      if (!cleaning_buffer_counter && (SD_FINISHED_STEPPERRELEASE)) enqueue_and_echo_commands_P(PSTR(SD_FINISHED_RELEASECOMMAND));
403
-    #endif
404
-    _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 10000); // Run at max speed - 10 KHz
405
-    HAL_ENABLE_ISRs(); // re-enable ISRs
401
+    _NEXT_ISR(HAL_STEPPER_TIMER_RATE / 10000);  // Run at max speed - 10 KHz
402
+    HAL_ENABLE_ISRs();                          // Re-enable ISRs
406
     return;
403
     return;
407
   }
404
   }
408
 
405
 

+ 1
- 1
Marlin/src/module/stepper.h View File

80
   private:
80
   private:
81
 
81
 
82
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
82
     static uint8_t last_direction_bits;        // The next stepping-bits to be output
83
-    static uint16_t cleaning_buffer_counter;
83
+    static int16_t cleaning_buffer_counter;
84
 
84
 
85
     #if ENABLED(X_DUAL_ENDSTOPS)
85
     #if ENABLED(X_DUAL_ENDSTOPS)
86
       static bool locked_x_motor, locked_x2_motor;
86
       static bool locked_x_motor, locked_x2_motor;

+ 1
- 1
Marlin/src/pins/pins_MELZI_CREALITY.h View File

60
 #define ST7920_DELAY_3 DELAY_2_NOP
60
 #define ST7920_DELAY_3 DELAY_2_NOP
61
 
61
 
62
 #if ENABLED(MINIPANEL)
62
 #if ENABLED(MINIPANEL)
63
-  #undef DOGLCD_CS    
63
+  #undef DOGLCD_CS
64
   #define DOGLCD_CS        LCD_PINS_RS
64
   #define DOGLCD_CS        LCD_PINS_RS
65
 #endif
65
 #endif
66
 
66
 

Loading…
Cancel
Save