浏览代码

Move UBL Menu to its own file

Scott Lahteine 6 年前
父节点
当前提交
489017995e
共有 2 个文件被更改,包括 607 次插入578 次删除
  1. 1
    578
      Marlin/src/lcd/menu/menu.cpp
  2. 606
    0
      Marlin/src/lcd/menu/menu_ubl.cpp

+ 1
- 578
Marlin/src/lcd/menu/menu.cpp 查看文件

@@ -621,68 +621,6 @@ void line_to_z(const float &z) {
621 621
 
622 622
 #endif // BABYSTEP_ZPROBE_OFFSET
623 623
 
624
-#if ENABLED(AUTO_BED_LEVELING_UBL)
625
-
626
-  float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
627
-                                                // separate value that doesn't lose precision.
628
-  static int16_t ubl_encoderPosition = 0;
629
-
630
-  static void _lcd_mesh_fine_tune(PGM_P msg) {
631
-    defer_return_to_status = true;
632
-    if (ubl.encoder_diff) {
633
-      ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
634
-      ubl.encoder_diff = 0;
635
-
636
-      mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005f * 0.5f;
637
-      mesh_edit_value = mesh_edit_accumulator;
638
-      encoderPosition = 0;
639
-      lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
640
-
641
-      const int32_t rounded = (int32_t)(mesh_edit_value * 1000);
642
-      mesh_edit_value = float(rounded - (rounded % 5L)) / 1000;
643
-    }
644
-
645
-    if (lcdDrawUpdate) {
646
-      lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
647
-      #if ENABLED(MESH_EDIT_GFX_OVERLAY)
648
-        _lcd_zoffset_overlay_gfx(mesh_edit_value);
649
-      #endif
650
-    }
651
-  }
652
-
653
-  void _lcd_mesh_edit_NOP() {
654
-    defer_return_to_status = true;
655
-  }
656
-
657
-  float lcd_mesh_edit() {
658
-    lcd_goto_screen(_lcd_mesh_edit_NOP);
659
-    lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
660
-    _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
661
-    return mesh_edit_value;
662
-  }
663
-
664
-  void lcd_mesh_edit_setup(const float &initial) {
665
-    mesh_edit_value = mesh_edit_accumulator = initial;
666
-    lcd_goto_screen(_lcd_mesh_edit_NOP);
667
-  }
668
-
669
-  void _lcd_z_offset_edit() {
670
-    _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
671
-  }
672
-
673
-  float lcd_z_offset_edit() {
674
-    lcd_goto_screen(_lcd_z_offset_edit);
675
-    return mesh_edit_value;
676
-  }
677
-
678
-  void lcd_z_offset_edit_setup(const float &initial) {
679
-    mesh_edit_value = mesh_edit_accumulator = initial;
680
-    lcd_goto_screen(_lcd_z_offset_edit);
681
-  }
682
-
683
-#endif // AUTO_BED_LEVELING_UBL
684
-
685
-
686 624
 /**
687 625
  * Watch temperature callbacks
688 626
  */
@@ -1241,522 +1179,7 @@ void _lcd_draw_homing() {
1241 1179
     enqueue_and_echo_commands_P(PSTR("G28"));
1242 1180
   }
1243 1181
 
1244
-#elif ENABLED(AUTO_BED_LEVELING_UBL)
1245
-
1246
-  static int16_t ubl_storage_slot = 0,
1247
-             custom_hotend_temp = 190,
1248
-             side_points = 3,
1249
-             ubl_fillin_amount = 5,
1250
-             ubl_height_amount = 1,
1251
-             n_edit_pts = 1,
1252
-             x_plot = 0,
1253
-             y_plot = 0;
1254
-
1255
-  #if HAS_HEATED_BED
1256
-    static int16_t custom_bed_temp = 50;
1257
-  #endif
1258
-
1259
-  /**
1260
-   * UBL Build Custom Mesh Command
1261
-   */
1262
-  void _lcd_ubl_build_custom_mesh() {
1263
-    char UBL_LCD_GCODE[20];
1264
-    enqueue_and_echo_commands_P(PSTR("G28"));
1265
-    #if HAS_HEATED_BED
1266
-      sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
1267
-      lcd_enqueue_command(UBL_LCD_GCODE);
1268
-    #endif
1269
-    sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
1270
-    lcd_enqueue_command(UBL_LCD_GCODE);
1271
-    enqueue_and_echo_commands_P(PSTR("G29 P1"));
1272
-  }
1273
-
1274
-  /**
1275
-   * UBL Custom Mesh submenu
1276
-   *
1277
-   * << Build Mesh
1278
-   *    Hotend Temp: ---
1279
-   *    Bed Temp: ---
1280
-   *    Build Custom Mesh
1281
-   */
1282
-  void _lcd_ubl_custom_mesh() {
1283
-    START_MENU();
1284
-    MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
1285
-    MENU_ITEM_EDIT(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
1286
-    #if HAS_HEATED_BED
1287
-      MENU_ITEM_EDIT(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 15));
1288
-    #endif
1289
-    MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
1290
-    END_MENU();
1291
-  }
1292
-
1293
-  /**
1294
-   * UBL Adjust Mesh Height Command
1295
-   */
1296
-  void _lcd_ubl_adjust_height_cmd() {
1297
-    char UBL_LCD_GCODE[16];
1298
-    const int ind = ubl_height_amount > 0 ? 9 : 10;
1299
-    strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
1300
-    sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), ABS(ubl_height_amount));
1301
-    lcd_enqueue_command(UBL_LCD_GCODE);
1302
-  }
1303
-
1304
-  /**
1305
-   * UBL Adjust Mesh Height submenu
1306
-   *
1307
-   * << Edit Mesh
1308
-   *    Height Amount: ---
1309
-   *    Adjust Mesh Height
1310
-   * << Info Screen
1311
-   */
1312
-  void _menu_ubl_height_adjust() {
1313
-    START_MENU();
1314
-    MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
1315
-    MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
1316
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1317
-    END_MENU();
1318
-  }
1319
-
1320
-  /**
1321
-   * UBL Edit Mesh submenu
1322
-   *
1323
-   * << UBL Tools
1324
-   *    Fine Tune All
1325
-   *    Fine Tune Closest
1326
-   *  - Adjust Mesh Height >>
1327
-   * << Info Screen
1328
-   */
1329
-  void _lcd_ubl_edit_mesh() {
1330
-    START_MENU();
1331
-    MENU_BACK(MSG_UBL_TOOLS);
1332
-    MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
1333
-    MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
1334
-    MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _menu_ubl_height_adjust);
1335
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1336
-    END_MENU();
1337
-  }
1338
-
1339
-  /**
1340
-   * UBL Validate Custom Mesh Command
1341
-   */
1342
-  void _lcd_ubl_validate_custom_mesh() {
1343
-    char UBL_LCD_GCODE[24];
1344
-    const int temp =
1345
-      #if HAS_HEATED_BED
1346
-        custom_bed_temp
1347
-      #else
1348
-        0
1349
-      #endif
1350
-    ;
1351
-    sprintf_P(UBL_LCD_GCODE, PSTR("G26 C B%i H%i P"), temp, custom_hotend_temp);
1352
-    lcd_enqueue_commands_P(PSTR("G28"));
1353
-    lcd_enqueue_command(UBL_LCD_GCODE);
1354
-  }
1355
-
1356
-  /**
1357
-   * UBL Validate Mesh submenu
1358
-   *
1359
-   * << UBL Tools
1360
-   *    Mesh Validation with Material 1
1361
-   *    Mesh Validation with Material 2
1362
-   *    Validate Custom Mesh
1363
-   * << Info Screen
1364
-   */
1365
-  void _lcd_ubl_validate_mesh() {
1366
-    START_MENU();
1367
-    MENU_BACK(MSG_UBL_TOOLS);
1368
-    #if HAS_HEATED_BED
1369
-      MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
1370
-      MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
1371
-    #else
1372
-      MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
1373
-      MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
1374
-    #endif
1375
-    MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
1376
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1377
-    END_MENU();
1378
-  }
1379
-
1380
-  /**
1381
-   * UBL Grid Leveling Command
1382
-   */
1383
-  void _lcd_ubl_grid_level_cmd() {
1384
-    char UBL_LCD_GCODE[10];
1385
-    sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
1386
-    lcd_enqueue_command(UBL_LCD_GCODE);
1387
-  }
1388
-
1389
-  /**
1390
-   * UBL Grid Leveling submenu
1391
-   *
1392
-   * << UBL Tools
1393
-   *    Side points: ---
1394
-   *    Level Mesh
1395
-   */
1396
-  void _lcd_ubl_grid_level() {
1397
-    START_MENU();
1398
-    MENU_BACK(MSG_UBL_TOOLS);
1399
-    MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
1400
-    MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
1401
-    END_MENU();
1402
-  }
1403
-
1404
-  /**
1405
-   * UBL Mesh Leveling submenu
1406
-   *
1407
-   * << UBL Tools
1408
-   *    3-Point Mesh Leveling
1409
-   *  - Grid Mesh Leveling >>
1410
-   * << Info Screen
1411
-   */
1412
-  void _lcd_ubl_mesh_leveling() {
1413
-    START_MENU();
1414
-    MENU_BACK(MSG_UBL_TOOLS);
1415
-    MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
1416
-    MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
1417
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1418
-    END_MENU();
1419
-  }
1420
-
1421
-  /**
1422
-   * UBL Fill-in Amount Mesh Command
1423
-   */
1424
-  void _lcd_ubl_fillin_amount_cmd() {
1425
-    char UBL_LCD_GCODE[16];
1426
-    sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
1427
-    lcd_enqueue_command(UBL_LCD_GCODE);
1428
-  }
1429
-
1430
-  /**
1431
-   * UBL Fill-in Mesh submenu
1432
-   *
1433
-   * << Build Mesh
1434
-   *    Fill-in Amount: ---
1435
-   *    Fill-in Mesh
1436
-   *    Smart Fill-in
1437
-   *    Manual Fill-in
1438
-   * << Info Screen
1439
-   */
1440
-  void _menu_ubl_fillin() {
1441
-    START_MENU();
1442
-    MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
1443
-    MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
1444
-    MENU_ITEM(gcode, MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
1445
-    MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
1446
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1447
-    END_MENU();
1448
-  }
1449
-
1450
-  void _lcd_ubl_invalidate() {
1451
-    ubl.invalidate();
1452
-    SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
1453
-  }
1454
-
1455
-  /**
1456
-   * UBL Build Mesh submenu
1457
-   *
1458
-   * << UBL Tools
1459
-   *    Build Mesh with Material 1
1460
-   *    Build Mesh with Material 2
1461
-   *  - Build Custom Mesh >>
1462
-   *    Build Cold Mesh
1463
-   *  - Fill-in Mesh >>
1464
-   *    Continue Bed Mesh
1465
-   *    Invalidate All
1466
-   *    Invalidate Closest
1467
-   * << Info Screen
1468
-   */
1469
-  void _lcd_ubl_build_mesh() {
1470
-    START_MENU();
1471
-    MENU_BACK(MSG_UBL_TOOLS);
1472
-    #if HAS_HEATED_BED
1473
-      MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
1474
-        "G28\n"
1475
-        "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
1476
-        "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
1477
-        "G29 P1\n"
1478
-        "M104 S0\n"
1479
-        "M140 S0"
1480
-      ));
1481
-      MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
1482
-        "G28\n"
1483
-        "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
1484
-        "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
1485
-        "G29 P1\n"
1486
-        "M104 S0\n"
1487
-        "M140 S0"
1488
-      ));
1489
-    #else
1490
-      MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
1491
-        "G28\n"
1492
-        "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
1493
-        "G29 P1\n"
1494
-        "M104 S0"
1495
-      ));
1496
-      MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
1497
-        "G28\n"
1498
-        "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
1499
-        "G29 P1\n"
1500
-        "M104 S0"
1501
-      ));
1502
-    #endif
1503
-    MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
1504
-    MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
1505
-    MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
1506
-    MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
1507
-    MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
1508
-    MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
1509
-    MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
1510
-    END_MENU();
1511
-  }
1512
-
1513
-  /**
1514
-   * UBL Load Mesh Command
1515
-   */
1516
-  void _lcd_ubl_load_mesh_cmd() {
1517
-    char UBL_LCD_GCODE[25];
1518
-    sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
1519
-    lcd_enqueue_command(UBL_LCD_GCODE);
1520
-    sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_LOADED), ubl_storage_slot);
1521
-    lcd_enqueue_command(UBL_LCD_GCODE);
1522
-  }
1523
-
1524
-  /**
1525
-   * UBL Save Mesh Command
1526
-   */
1527
-  void _lcd_ubl_save_mesh_cmd() {
1528
-    char UBL_LCD_GCODE[25];
1529
-    sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
1530
-    lcd_enqueue_command(UBL_LCD_GCODE);
1531
-    sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_SAVED), ubl_storage_slot);
1532
-    lcd_enqueue_command(UBL_LCD_GCODE);
1533
-  }
1534
-
1535
-  /**
1536
-   * UBL Mesh Storage submenu
1537
-   *
1538
-   * << Unified Bed Leveling
1539
-   *    Memory Slot: ---
1540
-   *    Load Bed Mesh
1541
-   *    Save Bed Mesh
1542
-   */
1543
-  void _lcd_ubl_storage_mesh() {
1544
-    int16_t a = settings.calc_num_meshes();
1545
-    START_MENU();
1546
-    MENU_BACK(MSG_UBL_LEVEL_BED);
1547
-    if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
1548
-      STATIC_ITEM(MSG_NO_STORAGE);
1549
-    }
1550
-    else {
1551
-      MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
1552
-      MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
1553
-      MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
1554
-    }
1555
-    END_MENU();
1556
-  }
1557
-
1558
-  /**
1559
-   * UBL LCD "radar" map homing
1560
-   */
1561
-  void _lcd_ubl_output_map_lcd();
1562
-
1563
-  void _lcd_ubl_map_homing() {
1564
-    defer_return_to_status = true;
1565
-    _lcd_draw_homing();
1566
-    if (all_axes_homed()) {
1567
-      ubl.lcd_map_control = true; // Return to the map screen
1568
-      lcd_goto_screen(_lcd_ubl_output_map_lcd);
1569
-    }
1570
-  }
1571
-
1572
-  /**
1573
-   * UBL LCD "radar" map point editing
1574
-   */
1575
-  void _lcd_ubl_map_lcd_edit_cmd() {
1576
-    char UBL_LCD_GCODE[50], str[10], str2[10];
1577
-    dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
1578
-    dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
1579
-    snprintf_P(UBL_LCD_GCODE, sizeof(UBL_LCD_GCODE), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
1580
-    lcd_enqueue_command(UBL_LCD_GCODE);
1581
-  }
1582
-
1583
-  /**
1584
-   * UBL LCD Map Movement
1585
-   */
1586
-  void ubl_map_move_to_xy() {
1587
-    current_position[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
1588
-    current_position[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
1589
-    planner.buffer_line(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
1590
-  }
1591
-
1592
-  /**
1593
-   * UBL LCD "radar" map
1594
-   */
1595
-  void set_current_from_steppers_for_axis(const AxisEnum axis);
1596
-  void sync_plan_position();
1597
-
1598
-  void _lcd_do_nothing() {}
1599
-  void _lcd_hard_stop() {
1600
-    const screenFunc_t old_screen = currentScreen;
1601
-    currentScreen = _lcd_do_nothing;
1602
-    planner.quick_stop();
1603
-    currentScreen = old_screen;
1604
-    set_current_from_steppers_for_axis(ALL_AXES);
1605
-    sync_plan_position();
1606
-  }
1607
-
1608
-  void _lcd_ubl_output_map_lcd() {
1609
-    static int16_t step_scaler = 0;
1610
-
1611
-    if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
1612
-    ENCODER_DIRECTION_NORMAL();
1613
-
1614
-    if (encoderPosition) {
1615
-      step_scaler += (int32_t)encoderPosition;
1616
-      x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
1617
-      if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
1618
-      encoderPosition = 0;
1619
-      lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
1620
-    }
1621
-
1622
-    // Encoder to the right (++)
1623
-    if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
1624
-    if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
1625
-
1626
-    // Encoder to the left (--)
1627
-    if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
1628
-    if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
1629
-
1630
-    // Prevent underrun/overrun of plot numbers
1631
-    x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
1632
-    y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
1633
-
1634
-    // Determine number of points to edit
1635
-    #if IS_KINEMATIC
1636
-      n_edit_pts = 9; //TODO: Delta accessible edit points
1637
-    #else
1638
-      const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
1639
-                 yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
1640
-      n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
1641
-    #endif
1642
-
1643
-    if (lcdDrawUpdate) {
1644
-      lcd_implementation_ubl_plot(x_plot, y_plot);
1645
-
1646
-      if (planner.movesplanned()) // If the nozzle is already moving, cancel the move.
1647
-        _lcd_hard_stop();
1648
-
1649
-      ubl_map_move_to_xy();       // Move to new location
1650
-    }
1651
-  }
1652
-
1653
-  /**
1654
-   * UBL Homing before LCD map
1655
-   */
1656
-  void _lcd_ubl_output_map_lcd_cmd() {
1657
-    if (!all_axes_known()) {
1658
-      axis_homed = 0;
1659
-      enqueue_and_echo_commands_P(PSTR("G28"));
1660
-    }
1661
-    lcd_goto_screen(_lcd_ubl_map_homing);
1662
-  }
1663
-
1664
-  /**
1665
-   * UBL Output map submenu
1666
-   *
1667
-   * << Unified Bed Leveling
1668
-   *  Output for Host
1669
-   *  Output for CSV
1670
-   *  Off Printer Backup
1671
-   *  Output Mesh Map
1672
-   */
1673
-  void _lcd_ubl_output_map() {
1674
-    START_MENU();
1675
-    MENU_BACK(MSG_UBL_LEVEL_BED);
1676
-    MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
1677
-    MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
1678
-    MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
1679
-    MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
1680
-    END_MENU();
1681
-  }
1682
-
1683
-  /**
1684
-   * UBL Tools submenu
1685
-   *
1686
-   * << Unified Bed Leveling
1687
-   *  - Build Mesh >>
1688
-   *  - Validate Mesh >>
1689
-   *  - Edit Mesh >>
1690
-   *  - Mesh Leveling >>
1691
-   */
1692
-  void _menu_ubl_tools() {
1693
-    START_MENU();
1694
-    MENU_BACK(MSG_UBL_LEVEL_BED);
1695
-    MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
1696
-    MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
1697
-    MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
1698
-    MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
1699
-    MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
1700
-    END_MENU();
1701
-  }
1702
-
1703
-  /**
1704
-   * UBL Step-By-Step submenu
1705
-   *
1706
-   * << Unified Bed Leveling
1707
-   *    1 Build Cold Mesh
1708
-   *    2 Smart Fill-in
1709
-   *  - 3 Validate Mesh >>
1710
-   *    4 Fine Tune All
1711
-   *  - 5 Validate Mesh >>
1712
-   *    6 Fine Tune All
1713
-   *    7 Save Bed Mesh
1714
-   */
1715
-  void _lcd_ubl_step_by_step() {
1716
-    START_MENU();
1717
-    MENU_BACK(MSG_UBL_LEVEL_BED);
1718
-    MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
1719
-    MENU_ITEM(gcode, "2 " MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
1720
-    MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
1721
-    MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
1722
-    MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
1723
-    MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
1724
-    MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
1725
-    END_MENU();
1726
-  }
1727
-
1728
-  /**
1729
-   * UBL System submenu
1730
-   *
1731
-   * << Motion
1732
-   *  - Manually Build Mesh >>
1733
-   *  - Activate UBL >>
1734
-   *  - Deactivate UBL >>
1735
-   *  - Step-By-Step UBL >>
1736
-   *  - Mesh Storage >>
1737
-   *  - Output Map >>
1738
-   *  - UBL Tools >>
1739
-   *  - Output UBL Info >>
1740
-   */
1741
-
1742
-  void _lcd_ubl_level_bed() {
1743
-    START_MENU();
1744
-    MENU_BACK(MSG_MOTION);
1745
-    MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
1746
-    MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
1747
-    MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
1748
-    MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
1749
-    MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
1750
-    MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
1751
-    MENU_ITEM(submenu, MSG_UBL_TOOLS, _menu_ubl_tools);
1752
-    MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
1753
-    #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1754
-      MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &lcd_z_fade_height, 0, 100, _lcd_set_z_fade_height);
1755
-    #endif
1756
-    END_MENU();
1757
-  }
1758
-
1759
-#endif // AUTO_BED_LEVELING_UBL
1182
+#endif // LCD_BED_LEVELING && (PROBE_MANUALLY || MESH_BED_LEVELING)
1760 1183
 
1761 1184
 #if ENABLED(LCD_BED_LEVELING) || (HAS_LEVELING && DISABLED(SLIM_LCD_MENUS))
1762 1185
   void _lcd_toggle_bed_leveling() { set_bed_leveling_enabled(!planner.leveling_active); }

+ 606
- 0
Marlin/src/lcd/menu/menu_ubl.cpp 查看文件

@@ -0,0 +1,606 @@
1
+/**
2
+ * Marlin 3D Printer Firmware
3
+ * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
4
+ *
5
+ * Based on Sprinter and grbl.
6
+ * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
7
+ *
8
+ * This program is free software: you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation, either version 3 of the License, or
11
+ * (at your option) any later version.
12
+ *
13
+ * This program is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
+ *
21
+ */
22
+
23
+//
24
+// Unified Bed Leveling Menus
25
+//
26
+
27
+#include "../../inc/MarlinConfigPre.h"
28
+
29
+#if HAS_LCD_MENU && ENABLED(AUTO_BED_LEVELING_UBL)
30
+
31
+#include "menu.h"
32
+#include "../../module/planner.h"
33
+#include "../../module/configuration_store.h"
34
+#include "../../feature/bedlevel/bedlevel.h"
35
+
36
+static int16_t ubl_storage_slot = 0,
37
+               custom_hotend_temp = 190,
38
+               side_points = 3,
39
+               ubl_fillin_amount = 5,
40
+               ubl_height_amount = 1,
41
+               n_edit_pts = 1,
42
+               x_plot = 0,
43
+               y_plot = 0;
44
+
45
+#if HAS_HEATED_BED
46
+  static int16_t custom_bed_temp = 50;
47
+#endif
48
+
49
+float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
50
+                                              // separate value that doesn't lose precision.
51
+static int16_t ubl_encoderPosition = 0;
52
+
53
+static void _lcd_mesh_fine_tune(PGM_P msg) {
54
+  defer_return_to_status = true;
55
+  if (ubl.encoder_diff) {
56
+    ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
57
+    ubl.encoder_diff = 0;
58
+
59
+    mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005f * 0.5f;
60
+    mesh_edit_value = mesh_edit_accumulator;
61
+    encoderPosition = 0;
62
+    lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
63
+
64
+    const int32_t rounded = (int32_t)(mesh_edit_value * 1000);
65
+    mesh_edit_value = float(rounded - (rounded % 5L)) / 1000;
66
+  }
67
+
68
+  if (lcdDrawUpdate) {
69
+    lcd_implementation_drawedit(msg, ftostr43sign(mesh_edit_value));
70
+    #if ENABLED(MESH_EDIT_GFX_OVERLAY)
71
+      _lcd_zoffset_overlay_gfx(mesh_edit_value);
72
+    #endif
73
+  }
74
+}
75
+
76
+void _lcd_mesh_edit_NOP() {
77
+  defer_return_to_status = true;
78
+}
79
+
80
+float lcd_mesh_edit() {
81
+  lcd_goto_screen(_lcd_mesh_edit_NOP);
82
+  lcdDrawUpdate = LCDVIEW_CALL_REDRAW_NEXT;
83
+  _lcd_mesh_fine_tune(PSTR("Mesh Editor"));
84
+  return mesh_edit_value;
85
+}
86
+
87
+void lcd_mesh_edit_setup(const float &initial) {
88
+  mesh_edit_value = mesh_edit_accumulator = initial;
89
+  lcd_goto_screen(_lcd_mesh_edit_NOP);
90
+}
91
+
92
+void _lcd_z_offset_edit() {
93
+  _lcd_mesh_fine_tune(PSTR("Z-Offset: "));
94
+}
95
+
96
+float lcd_z_offset_edit() {
97
+  lcd_goto_screen(_lcd_z_offset_edit);
98
+  return mesh_edit_value;
99
+}
100
+
101
+void lcd_z_offset_edit_setup(const float &initial) {
102
+  mesh_edit_value = mesh_edit_accumulator = initial;
103
+  lcd_goto_screen(_lcd_z_offset_edit);
104
+}
105
+
106
+/**
107
+ * UBL Build Custom Mesh Command
108
+ */
109
+void _lcd_ubl_build_custom_mesh() {
110
+  char UBL_LCD_GCODE[20];
111
+  enqueue_and_echo_commands_P(PSTR("G28"));
112
+  #if HAS_HEATED_BED
113
+    sprintf_P(UBL_LCD_GCODE, PSTR("M190 S%i"), custom_bed_temp);
114
+    lcd_enqueue_command(UBL_LCD_GCODE);
115
+  #endif
116
+  sprintf_P(UBL_LCD_GCODE, PSTR("M109 S%i"), custom_hotend_temp);
117
+  lcd_enqueue_command(UBL_LCD_GCODE);
118
+  enqueue_and_echo_commands_P(PSTR("G29 P1"));
119
+}
120
+
121
+/**
122
+ * UBL Custom Mesh submenu
123
+ *
124
+ * << Build Mesh
125
+ *    Hotend Temp: ---
126
+ *    Bed Temp: ---
127
+ *    Build Custom Mesh
128
+ */
129
+void _lcd_ubl_custom_mesh() {
130
+  START_MENU();
131
+  MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
132
+  MENU_ITEM_EDIT(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, (HEATER_0_MAXTEMP - 10));
133
+  #if HAS_HEATED_BED
134
+    MENU_ITEM_EDIT(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, (BED_MAXTEMP - 15));
135
+  #endif
136
+  MENU_ITEM(function, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
137
+  END_MENU();
138
+}
139
+
140
+/**
141
+ * UBL Adjust Mesh Height Command
142
+ */
143
+void _lcd_ubl_adjust_height_cmd() {
144
+  char UBL_LCD_GCODE[16];
145
+  const int ind = ubl_height_amount > 0 ? 9 : 10;
146
+  strcpy_P(UBL_LCD_GCODE, PSTR("G29 P6 C -"));
147
+  sprintf_P(&UBL_LCD_GCODE[ind], PSTR(".%i"), ABS(ubl_height_amount));
148
+  lcd_enqueue_command(UBL_LCD_GCODE);
149
+}
150
+
151
+/**
152
+ * UBL Adjust Mesh Height submenu
153
+ *
154
+ * << Edit Mesh
155
+ *    Height Amount: ---
156
+ *    Adjust Mesh Height
157
+ * << Info Screen
158
+ */
159
+void _menu_ubl_height_adjust() {
160
+  START_MENU();
161
+  MENU_BACK(MSG_UBL_EDIT_MESH_MENU);
162
+  MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
163
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
164
+  END_MENU();
165
+}
166
+
167
+/**
168
+ * UBL Edit Mesh submenu
169
+ *
170
+ * << UBL Tools
171
+ *    Fine Tune All
172
+ *    Fine Tune Closest
173
+ *  - Adjust Mesh Height >>
174
+ * << Info Screen
175
+ */
176
+void _lcd_ubl_edit_mesh() {
177
+  START_MENU();
178
+  MENU_BACK(MSG_UBL_TOOLS);
179
+  MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
180
+  MENU_ITEM(gcode, MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29 P4 T"));
181
+  MENU_ITEM(submenu, MSG_UBL_MESH_HEIGHT_ADJUST, _menu_ubl_height_adjust);
182
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
183
+  END_MENU();
184
+}
185
+
186
+/**
187
+ * UBL Validate Custom Mesh Command
188
+ */
189
+void _lcd_ubl_validate_custom_mesh() {
190
+  char UBL_LCD_GCODE[24];
191
+  const int temp =
192
+    #if HAS_HEATED_BED
193
+      custom_bed_temp
194
+    #else
195
+      0
196
+    #endif
197
+  ;
198
+  sprintf_P(UBL_LCD_GCODE, PSTR("G26 C B%i H%i P"), temp, custom_hotend_temp);
199
+  lcd_enqueue_commands_P(PSTR("G28"));
200
+  lcd_enqueue_command(UBL_LCD_GCODE);
201
+}
202
+
203
+/**
204
+ * UBL Validate Mesh submenu
205
+ *
206
+ * << UBL Tools
207
+ *    Mesh Validation with Material 1
208
+ *    Mesh Validation with Material 2
209
+ *    Validate Custom Mesh
210
+ * << Info Screen
211
+ */
212
+void _lcd_ubl_validate_mesh() {
213
+  START_MENU();
214
+  MENU_BACK(MSG_UBL_TOOLS);
215
+  #if HAS_HEATED_BED
216
+    MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_1_TEMP_BED) " H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
217
+    MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B" STRINGIFY(PREHEAT_2_TEMP_BED) " H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
218
+  #else
219
+    MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M1, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_1_TEMP_HOTEND) " P"));
220
+    MENU_ITEM(gcode, MSG_UBL_VALIDATE_MESH_M2, PSTR("G28\nG26 C B0 H" STRINGIFY(PREHEAT_2_TEMP_HOTEND) " P"));
221
+  #endif
222
+  MENU_ITEM(function, MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
223
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
224
+  END_MENU();
225
+}
226
+
227
+/**
228
+ * UBL Grid Leveling Command
229
+ */
230
+void _lcd_ubl_grid_level_cmd() {
231
+  char UBL_LCD_GCODE[10];
232
+  sprintf_P(UBL_LCD_GCODE, PSTR("G29 J%i"), side_points);
233
+  lcd_enqueue_command(UBL_LCD_GCODE);
234
+}
235
+
236
+/**
237
+ * UBL Grid Leveling submenu
238
+ *
239
+ * << UBL Tools
240
+ *    Side points: ---
241
+ *    Level Mesh
242
+ */
243
+void _lcd_ubl_grid_level() {
244
+  START_MENU();
245
+  MENU_BACK(MSG_UBL_TOOLS);
246
+  MENU_ITEM_EDIT(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
247
+  MENU_ITEM(function, MSG_UBL_MESH_LEVEL, _lcd_ubl_grid_level_cmd);
248
+  END_MENU();
249
+}
250
+
251
+/**
252
+ * UBL Mesh Leveling submenu
253
+ *
254
+ * << UBL Tools
255
+ *    3-Point Mesh Leveling
256
+ *  - Grid Mesh Leveling >>
257
+ * << Info Screen
258
+ */
259
+void _lcd_ubl_mesh_leveling() {
260
+  START_MENU();
261
+  MENU_BACK(MSG_UBL_TOOLS);
262
+  MENU_ITEM(gcode, MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29 J0"));
263
+  MENU_ITEM(submenu, MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
264
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
265
+  END_MENU();
266
+}
267
+
268
+/**
269
+ * UBL Fill-in Amount Mesh Command
270
+ */
271
+void _lcd_ubl_fillin_amount_cmd() {
272
+  char UBL_LCD_GCODE[16];
273
+  sprintf_P(UBL_LCD_GCODE, PSTR("G29 P3 R C.%i"), ubl_fillin_amount);
274
+  lcd_enqueue_command(UBL_LCD_GCODE);
275
+}
276
+
277
+/**
278
+ * UBL Fill-in Mesh submenu
279
+ *
280
+ * << Build Mesh
281
+ *    Fill-in Amount: ---
282
+ *    Fill-in Mesh
283
+ *    Smart Fill-in
284
+ *    Manual Fill-in
285
+ * << Info Screen
286
+ */
287
+void _menu_ubl_fillin() {
288
+  START_MENU();
289
+  MENU_BACK(MSG_UBL_BUILD_MESH_MENU);
290
+  MENU_ITEM_EDIT_CALLBACK(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
291
+  MENU_ITEM(gcode, MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
292
+  MENU_ITEM(gcode, MSG_UBL_MANUAL_FILLIN, PSTR("G29 P2 B T0"));
293
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
294
+  END_MENU();
295
+}
296
+
297
+void _lcd_ubl_invalidate() {
298
+  ubl.invalidate();
299
+  SERIAL_PROTOCOLLNPGM("Mesh invalidated.");
300
+}
301
+
302
+/**
303
+ * UBL Build Mesh submenu
304
+ *
305
+ * << UBL Tools
306
+ *    Build Mesh with Material 1
307
+ *    Build Mesh with Material 2
308
+ *  - Build Custom Mesh >>
309
+ *    Build Cold Mesh
310
+ *  - Fill-in Mesh >>
311
+ *    Continue Bed Mesh
312
+ *    Invalidate All
313
+ *    Invalidate Closest
314
+ * << Info Screen
315
+ */
316
+void _lcd_ubl_build_mesh() {
317
+  START_MENU();
318
+  MENU_BACK(MSG_UBL_TOOLS);
319
+  #if HAS_HEATED_BED
320
+    MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
321
+      "G28\n"
322
+      "M190 S" STRINGIFY(PREHEAT_1_TEMP_BED) "\n"
323
+      "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
324
+      "G29 P1\n"
325
+      "M104 S0\n"
326
+      "M140 S0"
327
+    ));
328
+    MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
329
+      "G28\n"
330
+      "M190 S" STRINGIFY(PREHEAT_2_TEMP_BED) "\n"
331
+      "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
332
+      "G29 P1\n"
333
+      "M104 S0\n"
334
+      "M140 S0"
335
+    ));
336
+  #else
337
+    MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M1, PSTR(
338
+      "G28\n"
339
+      "M109 S" STRINGIFY(PREHEAT_1_TEMP_HOTEND) "\n"
340
+      "G29 P1\n"
341
+      "M104 S0"
342
+    ));
343
+    MENU_ITEM(gcode, MSG_UBL_BUILD_MESH_M2, PSTR(
344
+      "G28\n"
345
+      "M109 S" STRINGIFY(PREHEAT_2_TEMP_HOTEND) "\n"
346
+      "G29 P1\n"
347
+      "M104 S0"
348
+    ));
349
+  #endif
350
+  MENU_ITEM(submenu, MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
351
+  MENU_ITEM(gcode, MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
352
+  MENU_ITEM(submenu, MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
353
+  MENU_ITEM(gcode, MSG_UBL_CONTINUE_MESH, PSTR("G29 P1 C"));
354
+  MENU_ITEM(function, MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
355
+  MENU_ITEM(gcode, MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29 I"));
356
+  MENU_ITEM(function, MSG_WATCH, lcd_return_to_status);
357
+  END_MENU();
358
+}
359
+
360
+/**
361
+ * UBL Load Mesh Command
362
+ */
363
+void _lcd_ubl_load_mesh_cmd() {
364
+  char UBL_LCD_GCODE[25];
365
+  sprintf_P(UBL_LCD_GCODE, PSTR("G29 L%i"), ubl_storage_slot);
366
+  lcd_enqueue_command(UBL_LCD_GCODE);
367
+  sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_LOADED), ubl_storage_slot);
368
+  lcd_enqueue_command(UBL_LCD_GCODE);
369
+}
370
+
371
+/**
372
+ * UBL Save Mesh Command
373
+ */
374
+void _lcd_ubl_save_mesh_cmd() {
375
+  char UBL_LCD_GCODE[25];
376
+  sprintf_P(UBL_LCD_GCODE, PSTR("G29 S%i"), ubl_storage_slot);
377
+  lcd_enqueue_command(UBL_LCD_GCODE);
378
+  sprintf_P(UBL_LCD_GCODE, PSTR("M117 " MSG_MESH_SAVED), ubl_storage_slot);
379
+  lcd_enqueue_command(UBL_LCD_GCODE);
380
+}
381
+
382
+/**
383
+ * UBL Mesh Storage submenu
384
+ *
385
+ * << Unified Bed Leveling
386
+ *    Memory Slot: ---
387
+ *    Load Bed Mesh
388
+ *    Save Bed Mesh
389
+ */
390
+void _lcd_ubl_storage_mesh() {
391
+  int16_t a = settings.calc_num_meshes();
392
+  START_MENU();
393
+  MENU_BACK(MSG_UBL_LEVEL_BED);
394
+  if (!WITHIN(ubl_storage_slot, 0, a - 1)) {
395
+    STATIC_ITEM(MSG_NO_STORAGE);
396
+  }
397
+  else {
398
+    MENU_ITEM_EDIT(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
399
+    MENU_ITEM(function, MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
400
+    MENU_ITEM(function, MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
401
+  }
402
+  END_MENU();
403
+}
404
+
405
+/**
406
+ * UBL LCD "radar" map homing
407
+ */
408
+void _lcd_ubl_output_map_lcd();
409
+
410
+void _lcd_ubl_map_homing() {
411
+  defer_return_to_status = true;
412
+  _lcd_draw_homing();
413
+  if (all_axes_homed()) {
414
+    ubl.lcd_map_control = true; // Return to the map screen
415
+    lcd_goto_screen(_lcd_ubl_output_map_lcd);
416
+  }
417
+}
418
+
419
+/**
420
+ * UBL LCD "radar" map point editing
421
+ */
422
+void _lcd_ubl_map_lcd_edit_cmd() {
423
+  char UBL_LCD_GCODE[50], str[10], str2[10];
424
+  dtostrf(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]), 0, 2, str);
425
+  dtostrf(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]), 0, 2, str2);
426
+  snprintf_P(UBL_LCD_GCODE, sizeof(UBL_LCD_GCODE), PSTR("G29 P4 X%s Y%s R%i"), str, str2, n_edit_pts);
427
+  lcd_enqueue_command(UBL_LCD_GCODE);
428
+}
429
+
430
+/**
431
+ * UBL LCD Map Movement
432
+ */
433
+void ubl_map_move_to_xy() {
434
+  current_position[X_AXIS] = pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]);
435
+  current_position[Y_AXIS] = pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]);
436
+  planner.buffer_line(current_position, MMM_TO_MMS(XY_PROBE_SPEED), active_extruder);
437
+}
438
+
439
+/**
440
+ * UBL LCD "radar" map
441
+ */
442
+void set_current_from_steppers_for_axis(const AxisEnum axis);
443
+void sync_plan_position();
444
+
445
+void _lcd_do_nothing() {}
446
+void _lcd_hard_stop() {
447
+  const screenFunc_t old_screen = currentScreen;
448
+  currentScreen = _lcd_do_nothing;
449
+  planner.quick_stop();
450
+  currentScreen = old_screen;
451
+  set_current_from_steppers_for_axis(ALL_AXES);
452
+  sync_plan_position();
453
+}
454
+
455
+void _lcd_ubl_output_map_lcd() {
456
+  static int16_t step_scaler = 0;
457
+
458
+  if (use_click()) return _lcd_ubl_map_lcd_edit_cmd();
459
+  ENCODER_DIRECTION_NORMAL();
460
+
461
+  if (encoderPosition) {
462
+    step_scaler += (int32_t)encoderPosition;
463
+    x_plot += step_scaler / (ENCODER_STEPS_PER_MENU_ITEM);
464
+    if (ABS(step_scaler) >= ENCODER_STEPS_PER_MENU_ITEM) step_scaler = 0;
465
+    encoderPosition = 0;
466
+    lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
467
+  }
468
+
469
+  // Encoder to the right (++)
470
+  if (x_plot >= GRID_MAX_POINTS_X) { x_plot = 0; y_plot++; }
471
+  if (y_plot >= GRID_MAX_POINTS_Y) y_plot = 0;
472
+
473
+  // Encoder to the left (--)
474
+  if (x_plot <= GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1)) { x_plot = GRID_MAX_POINTS_X - 1; y_plot--; }
475
+  if (y_plot <= GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1)) y_plot = GRID_MAX_POINTS_Y - 1;
476
+
477
+  // Prevent underrun/overrun of plot numbers
478
+  x_plot = constrain(x_plot, GRID_MAX_POINTS_X - (GRID_MAX_POINTS_X + 1), GRID_MAX_POINTS_X + 1);
479
+  y_plot = constrain(y_plot, GRID_MAX_POINTS_Y - (GRID_MAX_POINTS_Y + 1), GRID_MAX_POINTS_Y + 1);
480
+
481
+  // Determine number of points to edit
482
+  #if IS_KINEMATIC
483
+    n_edit_pts = 9; //TODO: Delta accessible edit points
484
+  #else
485
+    const bool xc = WITHIN(x_plot, 1, GRID_MAX_POINTS_X - 2),
486
+               yc = WITHIN(y_plot, 1, GRID_MAX_POINTS_Y - 2);
487
+    n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
488
+  #endif
489
+
490
+  if (lcdDrawUpdate) {
491
+    lcd_implementation_ubl_plot(x_plot, y_plot);
492
+
493
+    if (planner.movesplanned()) // If the nozzle is already moving, cancel the move.
494
+      _lcd_hard_stop();
495
+
496
+    ubl_map_move_to_xy();       // Move to new location
497
+  }
498
+}
499
+
500
+/**
501
+ * UBL Homing before LCD map
502
+ */
503
+void _lcd_ubl_output_map_lcd_cmd() {
504
+  if (!all_axes_known()) {
505
+    axis_homed = 0;
506
+    enqueue_and_echo_commands_P(PSTR("G28"));
507
+  }
508
+  lcd_goto_screen(_lcd_ubl_map_homing);
509
+}
510
+
511
+/**
512
+ * UBL Output map submenu
513
+ *
514
+ * << Unified Bed Leveling
515
+ *  Output for Host
516
+ *  Output for CSV
517
+ *  Off Printer Backup
518
+ *  Output Mesh Map
519
+ */
520
+void _lcd_ubl_output_map() {
521
+  START_MENU();
522
+  MENU_BACK(MSG_UBL_LEVEL_BED);
523
+  MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29 T0"));
524
+  MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29 T1"));
525
+  MENU_ITEM(gcode, MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29 S-1"));
526
+  MENU_ITEM(function, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map_lcd_cmd);
527
+  END_MENU();
528
+}
529
+
530
+/**
531
+ * UBL Tools submenu
532
+ *
533
+ * << Unified Bed Leveling
534
+ *  - Build Mesh >>
535
+ *  - Validate Mesh >>
536
+ *  - Edit Mesh >>
537
+ *  - Mesh Leveling >>
538
+ */
539
+void _menu_ubl_tools() {
540
+  START_MENU();
541
+  MENU_BACK(MSG_UBL_LEVEL_BED);
542
+  MENU_ITEM(submenu, MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
543
+  MENU_ITEM(gcode, MSG_UBL_MANUAL_MESH, PSTR("G29 I999\nG29 P2 B T0"));
544
+  MENU_ITEM(submenu, MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
545
+  MENU_ITEM(submenu, MSG_UBL_EDIT_MESH_MENU, _lcd_ubl_edit_mesh);
546
+  MENU_ITEM(submenu, MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
547
+  END_MENU();
548
+}
549
+
550
+/**
551
+ * UBL Step-By-Step submenu
552
+ *
553
+ * << Unified Bed Leveling
554
+ *    1 Build Cold Mesh
555
+ *    2 Smart Fill-in
556
+ *  - 3 Validate Mesh >>
557
+ *    4 Fine Tune All
558
+ *  - 5 Validate Mesh >>
559
+ *    6 Fine Tune All
560
+ *    7 Save Bed Mesh
561
+ */
562
+void _lcd_ubl_step_by_step() {
563
+  START_MENU();
564
+  MENU_BACK(MSG_UBL_LEVEL_BED);
565
+  MENU_ITEM(gcode, "1 " MSG_UBL_BUILD_COLD_MESH, PSTR("G28\nG29 P1"));
566
+  MENU_ITEM(gcode, "2 " MSG_UBL_SMART_FILLIN, PSTR("G29 P3 T0"));
567
+  MENU_ITEM(submenu, "3 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
568
+  MENU_ITEM(gcode, "4 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
569
+  MENU_ITEM(submenu, "5 " MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
570
+  MENU_ITEM(gcode, "6 " MSG_UBL_FINE_TUNE_ALL, PSTR("G29 P4 R999 T"));
571
+  MENU_ITEM(function, "7 " MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
572
+  END_MENU();
573
+}
574
+
575
+/**
576
+ * UBL System submenu
577
+ *
578
+ * << Motion
579
+ *  - Manually Build Mesh >>
580
+ *  - Activate UBL >>
581
+ *  - Deactivate UBL >>
582
+ *  - Step-By-Step UBL >>
583
+ *  - Mesh Storage >>
584
+ *  - Output Map >>
585
+ *  - UBL Tools >>
586
+ *  - Output UBL Info >>
587
+ */
588
+
589
+void _lcd_ubl_level_bed() {
590
+  START_MENU();
591
+  MENU_BACK(MSG_MOTION);
592
+  MENU_ITEM(gcode, MSG_UBL_ACTIVATE_MESH, PSTR("G29 A"));
593
+  MENU_ITEM(gcode, MSG_UBL_DEACTIVATE_MESH, PSTR("G29 D"));
594
+  MENU_ITEM(submenu, MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
595
+  MENU_ITEM(function, MSG_UBL_MESH_EDIT, _lcd_ubl_output_map_lcd_cmd);
596
+  MENU_ITEM(submenu, MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
597
+  MENU_ITEM(submenu, MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
598
+  MENU_ITEM(submenu, MSG_UBL_TOOLS, _menu_ubl_tools);
599
+  MENU_ITEM(gcode, MSG_UBL_INFO_UBL, PSTR("G29 W"));
600
+  #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
601
+    MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(float3, MSG_Z_FADE_HEIGHT, &lcd_z_fade_height, 0, 100, _lcd_set_z_fade_height);
602
+  #endif
603
+  END_MENU();
604
+}
605
+
606
+#endif // HAS_LCD_MENU && AUTO_BED_LEVELING_UBL

正在加载...
取消
保存