Browse Source

General UBL/G26 code cleanup

Scott Lahteine 7 years ago
parent
commit
7b6ad28a5d
3 changed files with 54 additions and 50 deletions
  1. 3
    3
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 48
    45
      Marlin/ubl_G29.cpp
  3. 3
    2
      Marlin/ultralcd.cpp

+ 3
- 3
Marlin/G26_Mesh_Validation_Tool.cpp View File

168
      * Detect is_lcd_clicked, debounce it, and return true for cancel
168
      * Detect is_lcd_clicked, debounce it, and return true for cancel
169
      */
169
      */
170
     bool user_canceled() {
170
     bool user_canceled() {
171
-      if (!is_lcd_clicked()) return false;
172
-      safe_delay(10);                       // Wait for click to settle
171
+      if (!is_lcd_clicked()) return false; // Return if the button isn't pressed
173
 
172
 
174
       #if ENABLED(ULTRA_LCD)
173
       #if ENABLED(ULTRA_LCD)
175
         lcd_setstatusPGM(PSTR("Mesh Validation Stopped."), 99);
174
         lcd_setstatusPGM(PSTR("Mesh Validation Stopped."), 99);
176
         lcd_quick_feedback();
175
         lcd_quick_feedback();
177
       #endif
176
       #endif
178
 
177
 
179
-      while (!is_lcd_clicked()) idle();    // Wait for button release
178
+      safe_delay(10);                      // Wait for click to settle
179
+      while (!is_lcd_clicked()) idle();    // Wait for button press again?
180
 
180
 
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

+ 48
- 45
Marlin/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
   #include "Marlin.h"
30
   #include "Marlin.h"
29
   #include "hex_print_routines.h"
31
   #include "hex_print_routines.h"
1152
     return UBL_OK;
1154
     return UBL_OK;
1153
   }
1155
   }
1154
 
1156
 
1155
-  static int ubl_state_at_invocation = 0,
1156
-             ubl_state_recursion_chk = 0;
1157
-
1158
-  void unified_bed_leveling::save_ubl_active_state_and_disable() {
1159
-    ubl_state_recursion_chk++;
1160
-    if (ubl_state_recursion_chk != 1) {
1161
-      SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1157
+  static uint8_t ubl_state_at_invocation = 0;
1162
 
1158
 
1163
-      #if ENABLED(NEWPANEL)
1164
-        LCD_MESSAGEPGM(MSG_UBL_SAVE_ERROR);
1165
-        lcd_quick_feedback();
1166
-      #endif
1159
+  #ifdef UBL_DEVEL_DEBUGGING
1160
+    static uint8_t ubl_state_recursion_chk = 0;
1161
+  #endif
1167
 
1162
 
1168
-      return;
1169
-    }
1163
+  void unified_bed_leveling::save_ubl_active_state_and_disable() {
1164
+    #ifdef UBL_DEVEL_DEBUGGING
1165
+      ubl_state_recursion_chk++;
1166
+      if (ubl_state_recursion_chk != 1) {
1167
+        SERIAL_ECHOLNPGM("save_ubl_active_state_and_disabled() called multiple times in a row.");
1168
+        #if ENABLED(NEWPANEL)
1169
+          LCD_MESSAGEPGM(MSG_UBL_SAVE_ERROR);
1170
+          lcd_quick_feedback();
1171
+        #endif
1172
+        return;
1173
+      }
1174
+    #endif
1170
     ubl_state_at_invocation = planner.leveling_active;
1175
     ubl_state_at_invocation = planner.leveling_active;
1171
     set_bed_leveling_enabled(false);
1176
     set_bed_leveling_enabled(false);
1172
   }
1177
   }
1253
     SERIAL_EOL();
1258
     SERIAL_EOL();
1254
     safe_delay(50);
1259
     safe_delay(50);
1255
 
1260
 
1256
-    SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1257
-    SERIAL_EOL();
1258
-    SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1259
-    SERIAL_EOL();
1260
-    safe_delay(50);
1261
+    #ifdef UBL_DEVEL_DEBUGGING
1262
+      SERIAL_PROTOCOLLNPAIR("ubl_state_at_invocation :", ubl_state_at_invocation);
1263
+      SERIAL_EOL();
1264
+      SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
1265
+      SERIAL_EOL();
1266
+      safe_delay(50);
1261
 
1267
 
1262
-    SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.get_start_of_meshes()));
1263
-    SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.get_end_of_meshes()));
1264
-    safe_delay(50);
1268
+      SERIAL_PROTOCOLPAIR("Meshes go from ", hex_address((void*)settings.get_start_of_meshes()));
1269
+      SERIAL_PROTOCOLLNPAIR(" to ", hex_address((void*)settings.get_end_of_meshes()));
1270
+      safe_delay(50);
1265
 
1271
 
1266
-    SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1267
-    SERIAL_EOL();
1268
-    SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
1269
-    SERIAL_EOL();
1270
-    safe_delay(25);
1272
+      SERIAL_PROTOCOLLNPAIR("sizeof(ubl) :  ", (int)sizeof(ubl));
1273
+      SERIAL_EOL();
1274
+      SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
1275
+      SERIAL_EOL();
1276
+      safe_delay(25);
1271
 
1277
 
1272
-    SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.get_end_of_meshes() - settings.get_start_of_meshes())));
1273
-    safe_delay(50);
1278
+      SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: ", hex_address((void*)(settings.get_end_of_meshes() - settings.get_start_of_meshes())));
1279
+      safe_delay(50);
1274
 
1280
 
1275
-    SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());
1276
-    SERIAL_PROTOCOLLNPGM(" meshes.\n");
1277
-    safe_delay(25);
1281
+      SERIAL_PROTOCOLPAIR("EEPROM can hold ", settings.calc_num_meshes());
1282
+      SERIAL_PROTOCOLLNPGM(" meshes.\n");
1283
+      safe_delay(25);
1284
+    #endif // UBL_DEVEL_DEBUGGING
1278
 
1285
 
1279
     if (!sanity_check()) {
1286
     if (!sanity_check()) {
1280
       echo_name();
1287
       echo_name();
1344
         z_values[x][y] -= tmp_z_values[x][y];
1351
         z_values[x][y] -= tmp_z_values[x][y];
1345
   }
1352
   }
1346
 
1353
 
1347
-
1348
   mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1354
   mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
1349
 
1355
 
1350
-    bool found_a_NAN  = false;
1351
-    bool found_a_real = false;
1356
+    bool found_a_NAN  = false, found_a_real = false;
1357
+
1352
     mesh_index_pair out_mesh;
1358
     mesh_index_pair out_mesh;
1353
     out_mesh.x_index = out_mesh.y_index = -1;
1359
     out_mesh.x_index = out_mesh.y_index = -1;
1354
     out_mesh.distance = -99999.99;
1360
     out_mesh.distance = -99999.99;
1356
     for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1362
     for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
1357
       for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1363
       for (int8_t j = 0; j < GRID_MAX_POINTS_Y; j++) {
1358
 
1364
 
1359
-        if ( isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
1365
+        if (isnan(z_values[i][j])) { // Check to see if this location holds an invalid mesh point
1360
 
1366
 
1361
           const float mx = mesh_index_to_xpos(i),
1367
           const float mx = mesh_index_to_xpos(i),
1362
                       my = mesh_index_to_ypos(j);
1368
                       my = mesh_index_to_ypos(j);
1363
 
1369
 
1364
-          if ( !position_is_reachable_by_probe(mx, my))  // make sure the probe can get to the mesh point
1370
+          if (!position_is_reachable_by_probe(mx, my))  // make sure the probe can get to the mesh point
1365
             continue;
1371
             continue;
1366
 
1372
 
1367
           found_a_NAN = true;
1373
           found_a_NAN = true;
1504
         if (!position_is_reachable(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
1510
         if (!position_is_reachable(rawx, rawy)) // SHOULD NOT OCCUR because find_closest_mesh_point_of_type will only return reachable
1505
           break;
1511
           break;
1506
 
1512
 
1507
-        float new_z = z_values[location.x_index][location.y_index];
1508
-
1509
-        if (isnan(new_z)) // if the mesh point is invalid, set it to 0.0 so it can be edited
1510
-          new_z = 0.0;
1511
-
1512
         do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point
1513
         do_blocking_move_to(rawx, rawy, Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to the edit point
1513
 
1514
 
1514
-        new_z = FLOOR(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
1515
-
1516
         KEEPALIVE_STATE(PAUSED_FOR_USER);
1515
         KEEPALIVE_STATE(PAUSED_FOR_USER);
1517
         lcd_external_control = true;
1516
         lcd_external_control = true;
1518
 
1517
 
1520
 
1519
 
1521
         lcd_refresh();
1520
         lcd_refresh();
1522
 
1521
 
1522
+        float new_z = z_values[location.x_index][location.y_index];
1523
+        if (isnan(new_z)) new_z = 0.0;          // Set invalid mesh points to 0.0 so they can be edited
1524
+        new_z = FLOOR(new_z * 1000.0) * 0.001;  // Chop off digits after the 1000ths place
1525
+
1523
         lcd_mesh_edit_setup(new_z);
1526
         lcd_mesh_edit_setup(new_z);
1524
 
1527
 
1525
-        do {
1528
+        while (!is_lcd_clicked()) {
1526
           new_z = lcd_mesh_edit();
1529
           new_z = lcd_mesh_edit();
1527
           #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
1530
           #if ENABLED(UBL_MESH_EDIT_MOVES_Z)
1528
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1531
             do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited
1529
           #endif
1532
           #endif
1530
           idle();
1533
           idle();
1531
-        } while (!is_lcd_clicked());
1534
+        }
1532
 
1535
 
1533
         if (!lcd_map_control) lcd_return_to_status();
1536
         if (!lcd_map_control) lcd_return_to_status();
1534
 
1537
 

+ 3
- 2
Marlin/ultralcd.cpp View File

2306
 
2306
 
2307
     void _lcd_ubl_map_homing() {
2307
     void _lcd_ubl_map_homing() {
2308
       defer_return_to_status = true;
2308
       defer_return_to_status = true;
2309
-      ubl.lcd_map_control = true; // Return to the map screen
2310
       if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
2309
       if (lcdDrawUpdate) lcd_implementation_drawmenu_static(LCD_HEIGHT < 3 ? 0 : (LCD_HEIGHT > 4 ? 2 : 1), PSTR(MSG_LEVEL_BED_HOMING));
2311
       lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
2310
       lcdDrawUpdate = LCDVIEW_CALL_NO_REDRAW;
2312
-      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS])
2311
+      if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
2312
+        ubl.lcd_map_control = true; // Return to the map screen
2313
         lcd_goto_screen(_lcd_ubl_output_map_lcd);
2313
         lcd_goto_screen(_lcd_ubl_output_map_lcd);
2314
+      }
2314
     }
2315
     }
2315
 
2316
 
2316
     /**
2317
     /**

Loading…
Cancel
Save