@@ -1409,6 +1409,13 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1409
1409
static float mlev_z_pos = 0 ;
1410
1410
static bool use_probe = false ;
1411
1411
1412
+ #if HAS_BED_PROBE
1413
+ constexpr float probe_x_min = _MAX (0 + corner_pos, X_MIN_POS + probe.offset .x , X_MIN_POS + PROBING_MARGIN) - probe.offset .x ,
1414
+ probe_x_max = _MIN ((X_BED_SIZE + X_MIN_POS) - corner_pos, X_MAX_POS + probe.offset .x , X_MAX_POS - PROBING_MARGIN) - probe.offset .x ,
1415
+ probe_y_min = _MAX (0 + corner_pos, Y_MIN_POS + probe.offset .y , Y_MIN_POS + PROBING_MARGIN) - probe.offset .y ,
1416
+ probe_y_max = _MIN ((Y_BED_SIZE + Y_MIN_POS) - corner_pos, Y_MAX_POS + probe.offset .y , Y_MAX_POS - PROBING_MARGIN) - probe.offset .y ;
1417
+ #endif
1418
+
1412
1419
switch (item) {
1413
1420
case MLEVEL_BACK:
1414
1421
if (draw)
@@ -1425,19 +1432,22 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1425
1432
Draw_Checkbox (row, use_probe);
1426
1433
}
1427
1434
else {
1428
- use_probe = !use_probe ;
1435
+ use_probe ^= true ;
1429
1436
Draw_Checkbox (row, use_probe);
1430
1437
if (use_probe) {
1431
1438
Popup_Handler (Level);
1439
+ constexpr struct { xy_pos_t p, ProbePtRaise r } points[] = {
1440
+ { { probe_x_min, probe_y_min }, PROBE_PT_RAISE },
1441
+ { { probe_x_min, probe_y_max }, PROBE_PT_RAISE },
1442
+ { { probe_x_max, probe_y_max }, PROBE_PT_RAISE },
1443
+ { { probe_x_max, probe_y_min }, PROBE_PT_STOW }
1444
+ };
1432
1445
corner_avg = 0 ;
1433
- #define PROBE_X_MIN _MAX (0 + corner_pos, X_MIN_POS + probe.offset.x, X_MIN_POS + PROBING_MARGIN) - probe.offset.x
1434
- #define PROBE_X_MAX _MIN ((X_BED_SIZE + X_MIN_POS) - corner_pos, X_MAX_POS + probe.offset.x, X_MAX_POS - PROBING_MARGIN) - probe.offset.x
1435
- #define PROBE_Y_MIN _MAX (0 + corner_pos, Y_MIN_POS + probe.offset.y, Y_MIN_POS + PROBING_MARGIN) - probe.offset.y
1436
- #define PROBE_Y_MAX _MIN ((Y_BED_SIZE + Y_MIN_POS) - corner_pos, Y_MAX_POS + probe.offset.y, Y_MAX_POS - PROBING_MARGIN) - probe.offset.y
1437
- corner_avg += probe.probe_at_point(PROBE_X_MIN, PROBE_Y_MIN, PROBE_PT_RAISE, 0 , false );
1438
- corner_avg += probe.probe_at_point (PROBE_X_MIN, PROBE_Y_MAX, PROBE_PT_RAISE, 0 , false );
1439
- corner_avg += probe.probe_at_point (PROBE_X_MAX, PROBE_Y_MAX, PROBE_PT_RAISE, 0 , false );
1440
- corner_avg += probe.probe_at_point (PROBE_X_MAX, PROBE_Y_MIN, PROBE_PT_STOW, 0 , false );
1446
+ for (uint8_t i = 0 ; i < COUNT (points); i++) {
1447
+ const float mz = probe.probe_at_point (points[i].p , points[i].r , 0 , false );
1448
+ if (isnan (mz)) { corner_avg = 0 ; break ; }
1449
+ corner_avg += mz;
1450
+ }
1441
1451
corner_avg /= 4 ;
1442
1452
Redraw_Menu ();
1443
1453
}
@@ -1451,7 +1461,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1451
1461
Popup_Handler (MoveWait);
1452
1462
if (use_probe) {
1453
1463
#if HAS_BED_PROBE
1454
- sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (PROBE_X_MIN , 1 , 3 , str_1), dtostrf (PROBE_Y_MIN , 1 , 3 , str_2));
1464
+ sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (probe_x_min , 1 , 3 , str_1), dtostrf (probe_y_min , 1 , 3 , str_2));
1455
1465
gcode.process_subcommands_now (cmd);
1456
1466
planner.synchronize ();
1457
1467
Popup_Handler (ManualProbing);
@@ -1472,7 +1482,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1472
1482
Popup_Handler (MoveWait);
1473
1483
if (use_probe) {
1474
1484
#if HAS_BED_PROBE
1475
- sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (PROBE_X_MIN , 1 , 3 , str_1), dtostrf (PROBE_Y_MAX , 1 , 3 , str_2));
1485
+ sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (probe_x_min , 1 , 3 , str_1), dtostrf (probe_y_max , 1 , 3 , str_2));
1476
1486
gcode.process_subcommands_now (cmd);
1477
1487
planner.synchronize ();
1478
1488
Popup_Handler (ManualProbing);
@@ -1493,7 +1503,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1493
1503
Popup_Handler (MoveWait);
1494
1504
if (use_probe) {
1495
1505
#if HAS_BED_PROBE
1496
- sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (PROBE_X_MAX , 1 , 3 , str_1), dtostrf (PROBE_Y_MAX , 1 , 3 , str_2));
1506
+ sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (probe_x_max , 1 , 3 , str_1), dtostrf (probe_y_max , 1 , 3 , str_2));
1497
1507
gcode.process_subcommands_now (cmd);
1498
1508
planner.synchronize ();
1499
1509
Popup_Handler (ManualProbing);
@@ -1514,7 +1524,7 @@ void CrealityDWINClass::Menu_Item_Handler(const uint8_t menu, const uint8_t item
1514
1524
Popup_Handler (MoveWait);
1515
1525
if (use_probe) {
1516
1526
#if HAS_BED_PROBE
1517
- sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (PROBE_X_MAX , 1 , 3 , str_1), dtostrf (PROBE_Y_MIN , 1 , 3 , str_2));
1527
+ sprintf_P (cmd, PSTR (" G0 F4000\n G0 Z10\n G0 X%s Y%s" ), dtostrf (probe_x_max , 1 , 3 , str_1), dtostrf (probe_y_min , 1 , 3 , str_2));
1518
1528
gcode.process_subcommands_now (cmd);
1519
1529
planner.synchronize ();
1520
1530
Popup_Handler (ManualProbing);
0 commit comments