Pārlūkot izejas kodu

Implement LCD_BED_LEVELING for PROBE_MANUALLY

Scott Lahteine 7 gadus atpakaļ
vecāks
revīzija
73e193da1d
3 mainītis faili ar 175 papildinājumiem un 67 dzēšanām
  1. 2
    2
      .travis.yml
  2. 1
    1
      Marlin/Marlin_main.cpp
  3. 172
    64
      Marlin/ultralcd.cpp

+ 2
- 2
.travis.yml Parādīt failu

@@ -145,10 +145,10 @@ script:
145 145
   - opt_enable MESH_BED_LEVELING MESH_G28_REST_ORIGIN LCD_BED_LEVELING ULTIMAKERCONTROLLER
146 146
   - build_marlin
147 147
   #
148
-  # Test PROBE_MANUALLY feature
148
+  # Test PROBE_MANUALLY feature, with LCD support
149 149
   #
150 150
   - restore_configs
151
-  - opt_enable PROBE_MANUALLY AUTO_BED_LEVELING_BILINEAR
151
+  - opt_enable PROBE_MANUALLY AUTO_BED_LEVELING_BILINEAR LCD_BED_LEVELING ULTIMAKERCONTROLLER
152 152
   - build_marlin
153 153
   #
154 154
   # Test EEPROM_SETTINGS, EEPROM_CHITCHAT, M100_FREE_MEMORY_WATCHER,

+ 1
- 1
Marlin/Marlin_main.cpp Parādīt failu

@@ -3503,7 +3503,7 @@ inline void gcode_G4() {
3503 3503
 #endif // Z_SAFE_HOMING
3504 3504
 
3505 3505
 #if ENABLED(PROBE_MANUALLY)
3506
-  static bool g29_in_progress = false;
3506
+  bool g29_in_progress = false;
3507 3507
 #else
3508 3508
   constexpr bool g29_in_progress = false;
3509 3509
 #endif

+ 172
- 64
Marlin/ultralcd.cpp Parādīt failu

@@ -457,13 +457,18 @@ uint16_t max_display_update_time = 0;
457 457
    * Synchronize safely while holding the current screen
458 458
    * This blocks all further screen or stripe updates once called
459 459
    */
460
+  extern uint8_t commands_in_queue;
461
+
460 462
   inline void lcd_synchronize() {
461 463
     lcd_implementation_drawmenu_static(LCD_HEIGHT >= 4 ? 1 : 0, PSTR(MSG_MOVING));
462 464
     if (no_reentrance) return;
463 465
     no_reentrance = true;
464 466
     screenFunc_t old_screen = currentScreen;
465 467
     lcd_goto_screen(lcd_synchronize);
466
-    stepper.synchronize();
468
+    while (commands_in_queue) {
469
+      idle();
470
+      stepper.synchronize();
471
+    }
467 472
     no_reentrance = false;
468 473
     lcd_goto_screen(old_screen);
469 474
   }
@@ -982,7 +987,7 @@ void kill_screen(const char* lcd_msg) {
982 987
     MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999);
983 988
 
984 989
     // Manual bed leveling, Bed Z:
985
-    #if ENABLED(LCD_BED_LEVELING)
990
+    #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
986 991
       MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
987 992
     #endif
988 993
 
@@ -1325,30 +1330,53 @@ void kill_screen(const char* lcd_msg) {
1325 1330
 
1326 1331
     /**
1327 1332
      *
1328
-     * "Prepare" > "Bed Leveling" handlers
1333
+     * "Prepare" > "Level Bed" handlers
1329 1334
      *
1330 1335
      */
1331 1336
 
1332 1337
     static uint8_t manual_probe_index;
1333 1338
 
1334
-    // Utility to go to the next mesh point
1335
-    inline void _manual_probe_xy(float x, float y) {
1336
-      if (no_reentrance) return;
1337
-      #if MANUAL_PROBE_HEIGHT > 0
1338
-        current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
1339
-        line_to_current(Z_AXIS);
1340
-      #endif
1341
-      current_position[X_AXIS] = LOGICAL_X_POSITION(x);
1342
-      current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
1343
-      planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
1344
-      #if MANUAL_PROBE_HEIGHT > 0
1345
-        current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
1346
-        line_to_current(Z_AXIS);
1339
+    #if ENABLED(PROBE_MANUALLY)
1340
+      extern bool g29_in_progress;
1341
+    #endif
1342
+
1343
+    // LCD probed points are from defaults
1344
+    constexpr uint8_t total_probe_points =
1345
+      #if ABL_GRID
1346
+        (ABL_GRID_MAX_POINTS_X) * (ABL_GRID_MAX_POINTS_Y)
1347
+      #elif ENABLED(AUTO_BED_LEVELING_3POINT)
1348
+        int(3)
1349
+      #elif ENABLED(AUTO_BED_LEVELING_UBL)
1350
+        (UBL_MESH_NUM_X_POINTS) * (UBL_MESH_NUM_Y_POINTS)
1351
+      #elif ENABLED(MESH_BED_LEVELING)
1352
+        (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)
1347 1353
       #endif
1348
-      lcd_synchronize();
1349
-    }
1354
+    ;
1350 1355
 
1351
-    void _lcd_level_goto_next_point();
1356
+    #if ENABLED(MESH_BED_LEVELING)
1357
+
1358
+      // Utility to go to the next mesh point
1359
+      inline void _manual_probe_goto_xy(float x, float y) {
1360
+        if (no_reentrance) return;
1361
+        #if MANUAL_PROBE_HEIGHT > 0
1362
+          current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
1363
+          line_to_current(Z_AXIS);
1364
+        #endif
1365
+        current_position[X_AXIS] = LOGICAL_X_POSITION(x);
1366
+        current_position[Y_AXIS] = LOGICAL_Y_POSITION(y);
1367
+        planner.buffer_line_kinematic(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
1368
+        #if MANUAL_PROBE_HEIGHT > 0
1369
+          current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + 0.2;
1370
+          line_to_current(Z_AXIS);
1371
+        #endif
1372
+        lcd_synchronize();
1373
+      }
1374
+
1375
+    #endif // MESH_BED_LEVELING
1376
+
1377
+    #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
1378
+      void _lcd_level_goto_next_point();
1379
+    #endif
1352 1380
 
1353 1381
     void _lcd_level_bed_done() {
1354 1382
       if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_DONE));
@@ -1356,7 +1384,19 @@ void kill_screen(const char* lcd_msg) {
1356 1384
     }
1357 1385
 
1358 1386
     /**
1359
-     * Step 7: Get the Z coordinate, then goto next point or exit
1387
+     * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
1388
+     */
1389
+    void _lcd_level_bed_moving() {
1390
+      if (lcdDrawUpdate) {
1391
+        char msg[10];
1392
+        sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), total_probe_points);
1393
+        lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
1394
+      }
1395
+      lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
1396
+    }
1397
+
1398
+    /**
1399
+     * Step 7: Get the Z coordinate, click goes to the next point or exits
1360 1400
      */
1361 1401
     void _lcd_level_bed_get_z() {
1362 1402
       ENCODER_DIRECTION_NORMAL();
@@ -1368,77 +1408,129 @@ void kill_screen(const char* lcd_msg) {
1368 1408
         refresh_cmd_timeout();
1369 1409
         current_position[Z_AXIS] += float((int32_t)encoderPosition) * (MBL_Z_STEP);
1370 1410
         NOLESS(current_position[Z_AXIS], -(LCD_PROBE_Z_RANGE) * 0.5);
1371
-        NOMORE(current_position[Z_AXIS], (LCD_PROBE_Z_RANGE) * 0.5);
1411
+        NOMORE(current_position[Z_AXIS],  (LCD_PROBE_Z_RANGE) * 0.5);
1372 1412
         line_to_current(Z_AXIS);
1373 1413
         lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
1374 1414
         encoderPosition = 0;
1375 1415
       }
1376 1416
 
1377 1417
       if (lcd_clicked) {
1378
-        mbl.set_zigzag_z(manual_probe_index++, current_position[Z_AXIS]);
1379
-        if (manual_probe_index == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
1418
+
1419
+        // Use a hook to set the probe point z
1420
+        // (zigzag arranges in XY order)
1421
+        #if ENABLED(AUTO_BED_LEVELING_UBL)
1422
+
1423
+          // UBL set-z handling goes here
1424
+
1425
+        #elif ENABLED(PROBE_MANUALLY)
1426
+
1427
+          // G29 helpfully records Z and goes to the next
1428
+          // point (or beeps if done)
1429
+          enqueue_and_echo_commands_P(PSTR("G29"));
1430
+          manual_probe_index++;
1431
+
1432
+        #elif ENABLED(MESH_BED_LEVELING)
1433
+
1434
+          mbl.set_zigzag_z(manual_probe_index++, current_position[Z_AXIS]);
1435
+
1436
+        #endif
1437
+
1438
+        // If done...
1439
+        if (manual_probe_index == total_probe_points) {
1440
+
1441
+          // Say "Done!"
1380 1442
           lcd_goto_screen(_lcd_level_bed_done);
1381 1443
 
1444
+          // Raise Z to the "manual probe height"
1382 1445
           #if MANUAL_PROBE_HEIGHT > 0
1383 1446
             current_position[Z_AXIS] = LOGICAL_Z_POSITION(Z_MIN_POS) + MANUAL_PROBE_HEIGHT;
1384 1447
             line_to_current(Z_AXIS);
1385 1448
             lcd_synchronize();
1386 1449
           #endif
1387 1450
 
1388
-          mbl.set_has_mesh(true);
1389
-          mbl.set_reactivate(true);
1390
-          enqueue_and_echo_commands_P(PSTR("G28"));
1451
+          // Enable leveling, if needed
1452
+          #if ENABLED(MESH_BED_LEVELING)
1453
+
1454
+            mbl.set_has_mesh(true);
1455
+            mbl.set_reactivate(true);
1456
+            enqueue_and_echo_commands_P(PSTR("G28"));
1457
+
1458
+          #elif ENABLED(AUTO_BED_LEVELING_UBL)
1459
+
1460
+            // UBL enable goes here
1461
+
1462
+          #elif ENABLED(PROBE_MANUALLY)
1463
+
1464
+            // ABL will be enabled due to "G29".
1465
+
1466
+          #endif
1467
+
1391 1468
           lcd_return_to_status();
1392 1469
           //LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);
1393 1470
           lcd_completion_feedback();
1394 1471
         }
1395 1472
         else {
1396
-          lcd_goto_screen(_lcd_level_goto_next_point);
1473
+
1474
+          // Move to the next probe point, if needed
1475
+          #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
1476
+
1477
+            _lcd_level_goto_next_point();
1478
+
1479
+          #elif ENABLED(AUTO_BED_LEVELING_UBL)
1480
+
1481
+            // UBL goto-next-point goes here
1482
+
1483
+          #endif
1397 1484
         }
1398 1485
       }
1399 1486
 
1400
-KeepDrawing:
1487
+      KeepDrawing:
1488
+
1401 1489
       // Update on first display, then only on updates to Z position
1402 1490
       // Show message above on clicks instead
1403 1491
       if (lcdDrawUpdate) {
1404 1492
         const float v = current_position[Z_AXIS];
1405 1493
         lcd_implementation_drawedit(PSTR(MSG_MOVE_Z), ftostr43sign(v + (v < 0 ? -0.0001 : 0.0001), '+'));
1406 1494
       }
1407
-
1408 1495
     }
1409 1496
 
1410
-    /**
1411
-     * Step 6: Display "Next point: 1 / 9" while waiting for move to finish
1412
-     */
1413
-    void _lcd_level_bed_moving() {
1414
-      if (lcdDrawUpdate) {
1415
-        char msg[10];
1497
+    #if ENABLED(MESH_BED_LEVELING) || ENABLED(PROBE_MANUALLY)
1498
+
1499
+      /**
1500
+       * Step 5: Initiate a move to the next point
1501
+       */
1502
+      void _lcd_level_goto_next_point() {
1503
+
1504
+        // Set the menu to display ahead of blocking call
1505
+        lcd_goto_screen(_lcd_level_bed_moving);
1506
+
1416 1507
         #if ENABLED(MESH_BED_LEVELING)
1417
-          sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS));
1508
+
1509
+          int8_t px, py;
1510
+          mbl.zigzag(manual_probe_index, px, py);
1511
+
1512
+          // Controls the loop until the move is done
1513
+          _manual_probe_goto_xy(
1514
+            LOGICAL_X_POSITION(mbl.index_to_xpos[px]),
1515
+            LOGICAL_Y_POSITION(mbl.index_to_ypos[py])
1516
+          );
1517
+
1418 1518
         #elif ENABLED(AUTO_BED_LEVELING_UBL)
1419
-          sprintf_P(msg, PSTR("%i / %u"), (int)(manual_probe_index + 1), (UBL_MESH_NUM_X_POINTS) * (UBL_MESH_NUM_Y_POINTS));
1420
-        #endif
1421
-        lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_NEXT_POINT), msg);
1422
-      }
1423 1519
 
1424
-      lcdDrawUpdate = LCDVIEW_KEEP_REDRAWING;
1425
-    }
1520
+          // UBL may have its own methodology
1426 1521
 
1427
-    /**
1428
-     * Step 5: Initiate a move to the next point
1429
-     */
1430
-    void _lcd_level_goto_next_point() {
1431
-      // Set the menu to display ahead of blocking call
1432
-      lcd_goto_screen(_lcd_level_bed_moving);
1522
+        #elif ENABLED(PROBE_MANUALLY)
1523
+
1524
+          // Just wait for the G29 move to complete
1525
+          lcd_synchronize();
1433 1526
 
1434
-      // _manual_probe_xy runs the menu loop until the move is done
1435
-      int8_t px, py;
1436
-      mbl.zigzag(manual_probe_index, px, py);
1437
-      _manual_probe_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
1527
+        #endif
1438 1528
 
1439
-      // After the blocking function returns, change menus
1440
-      lcd_goto_screen(_lcd_level_bed_get_z);
1441
-    }
1529
+        // After the blocking function returns, change menus
1530
+        lcd_goto_screen(_lcd_level_bed_get_z);
1531
+      }
1532
+
1533
+    #endif // MESH_BED_LEVELING
1442 1534
 
1443 1535
     /**
1444 1536
      * Step 4: Display "Click to Begin", wait for click
@@ -1448,7 +1540,14 @@ KeepDrawing:
1448 1540
       if (lcdDrawUpdate) lcd_implementation_drawedit(PSTR(MSG_LEVEL_BED_WAITING));
1449 1541
       if (lcd_clicked) {
1450 1542
         manual_probe_index = 0;
1451
-        lcd_goto_screen(_lcd_level_goto_next_point);
1543
+        #if ENABLED(MESH_BED_LEVELING)
1544
+          _lcd_level_goto_next_point();
1545
+        #elif ENABLED(AUTO_BED_LEVELING_UBL)
1546
+          // UBL click handling should go here
1547
+        #elif ENABLED(PROBE_MANUALLY)
1548
+          enqueue_and_echo_commands_P(PSTR("G29"));
1549
+          _lcd_level_goto_next_point();
1550
+        #endif
1452 1551
       }
1453 1552
     }
1454 1553
 
@@ -1466,15 +1565,17 @@ KeepDrawing:
1466 1565
      * Step 2: Continue Bed Leveling...
1467 1566
      */
1468 1567
     void _lcd_level_bed_continue() {
1568
+      #if PLANNER_LEVELING && DISABLED(AUTO_BED_LEVELING_UBL)
1569
+        reset_bed_level();
1570
+      #endif
1469 1571
       defer_return_to_status = true;
1470 1572
       axis_homed[X_AXIS] = axis_homed[Y_AXIS] = axis_homed[Z_AXIS] = false;
1471
-      mbl.reset();
1472
-      enqueue_and_echo_commands_P(PSTR("G28"));
1473 1573
       lcd_goto_screen(_lcd_level_bed_homing);
1574
+      enqueue_and_echo_commands_P(PSTR("G28"));
1474 1575
     }
1475 1576
 
1476 1577
     /**
1477
-     * Step 1: MBL entry-point: "Cancel" or "Level Bed"
1578
+     * Step 1: Bed Level entry-point: "Cancel" or "Level Bed"
1478 1579
      */
1479 1580
     void lcd_level_bed() {
1480 1581
       START_MENU();
@@ -1483,7 +1584,7 @@ KeepDrawing:
1483 1584
       END_MENU();
1484 1585
     }
1485 1586
 
1486
-  #endif  // LCD_BED_LEVELING
1587
+  #endif // LCD_BED_LEVELING
1487 1588
 
1488 1589
   /**
1489 1590
    *
@@ -1520,12 +1621,19 @@ KeepDrawing:
1520 1621
     //
1521 1622
     // Level Bed
1522 1623
     //
1523
-    #if HAS_ABL
1624
+    #if ENABLED(LCD_BED_LEVELING)
1625
+
1626
+      #if ENABLED(PROBE_MANUALLY)
1627
+        if (!g29_in_progress)
1628
+      #endif
1629
+          MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
1630
+
1631
+    #elif HAS_ABL
1632
+
1524 1633
       MENU_ITEM(gcode, MSG_LEVEL_BED,
1525 1634
         axis_homed[X_AXIS] && axis_homed[Y_AXIS] ? PSTR("G29") : PSTR("G28\nG29")
1526 1635
       );
1527
-    #elif ENABLED(LCD_BED_LEVELING)
1528
-      MENU_ITEM(submenu, MSG_LEVEL_BED, lcd_level_bed);
1636
+
1529 1637
     #endif
1530 1638
 
1531 1639
     #if DISABLED(NO_WORKSPACE_OFFSETS)
@@ -2253,7 +2361,7 @@ KeepDrawing:
2253 2361
       MENU_ITEM_EDIT(float32, MSG_ZPROBE_ZOFFSET, &zprobe_zoffset, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX);
2254 2362
     #endif
2255 2363
     // Manual bed leveling, Bed Z:
2256
-    #if ENABLED(LCD_BED_LEVELING)
2364
+    #if ENABLED(MESH_BED_LEVELING) && ENABLED(LCD_BED_LEVELING)
2257 2365
       MENU_ITEM_EDIT(float43, MSG_BED_Z, &mbl.z_offset, -1, 1);
2258 2366
     #endif
2259 2367
     MENU_ITEM_EDIT(float5, MSG_ACC, &planner.acceleration, 10, 99000);

Notiek ielāde…
Atcelt
Saglabāt