Bladeren bron

Merge remote-tracking branch 'MarlinFirmware/Development' into Merge_cleanup

Conflicts:
	Marlin/Marlin_main.cpp
Chris Roadfeldt 9 jaren geleden
bovenliggende
commit
745d9fe1a4
5 gewijzigde bestanden met toevoegingen van 383 en 317 verwijderingen
  1. 5
    1
      Marlin/Conditionals.h
  2. 2
    0
      Marlin/Marlin.h
  3. 304
    314
      Marlin/Marlin_main.cpp
  4. 70
    1
      Marlin/Sd2PinMap.h
  5. 2
    1
      Marlin/ultralcd.h

+ 5
- 1
Marlin/Conditionals.h Bestand weergeven

@@ -4,6 +4,10 @@
4 4
  */
5 5
 #ifndef CONDITIONALS_H
6 6
 
7
+#ifndef M_PI
8
+  #define M_PI 3.1415926536
9
+#endif
10
+
7 11
 #ifndef CONFIGURATION_LCD // Get the LCD defines which are needed first
8 12
 
9 13
   #define CONFIGURATION_LCD
@@ -255,7 +259,7 @@
255 259
    * Advance calculated values
256 260
    */
257 261
   #ifdef ADVANCE
258
-    #define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * 3.14159)
262
+    #define EXTRUSION_AREA (0.25 * D_FILAMENT * D_FILAMENT * M_PI)
259 263
     #define STEPS_PER_CUBIC_MM_E (axis_steps_per_unit[E_AXIS] / EXTRUSION_AREA)
260 264
   #endif
261 265
 

+ 2
- 0
Marlin/Marlin.h Bestand weergeven

@@ -29,6 +29,8 @@
29 29
 
30 30
 #define BIT(b) (1<<(b))
31 31
 #define TEST(n,b) (((n)&BIT(b))!=0)
32
+#define RADIANS(d) ((d)*M_PI/180.0)
33
+#define DEGREES(r) ((d)*180.0/M_PI)
32 34
 
33 35
 // Arduino < 1.0.0 does not define this, so we need to do it ourselves
34 36
 #ifndef analogInputToDigitalPin

+ 304
- 314
Marlin/Marlin_main.cpp Bestand weergeven

@@ -1034,6 +1034,12 @@ inline void line_to_destination() {
1034 1034
 inline void sync_plan_position() {
1035 1035
   plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
1036 1036
 }
1037
+#if defined(DELTA) || defined(SCARA)
1038
+  inline void sync_plan_position_delta() {
1039
+    calculate_delta(current_position);
1040
+    plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1041
+  }
1042
+#endif
1037 1043
 
1038 1044
 #ifdef ENABLE_AUTO_BED_LEVELING
1039 1045
 
@@ -1103,15 +1109,14 @@ inline void sync_plan_position() {
1103 1109
       destination[Z_AXIS] = -10;
1104 1110
       prepare_move_raw();
1105 1111
       st_synchronize();
1106
-      endstops_hit_on_purpose();
1107
-
1112
+      endstops_hit_on_purpose(); // clear endstop hit flags
1113
+      
1108 1114
       // we have to let the planner know where we are right now as it is not where we said to go.
1109 1115
       long stop_steps = st_get_position(Z_AXIS);
1110 1116
       float mm = start_z - float(start_steps - stop_steps) / axis_steps_per_unit[Z_AXIS];
1111 1117
       current_position[Z_AXIS] = mm;
1112
-      calculate_delta(current_position);
1113
-      plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1114
-
1118
+      sync_plan_position_delta();
1119
+      
1115 1120
     #else // !DELTA
1116 1121
 
1117 1122
       plan_bed_level_matrix.set_to_identity();
@@ -1130,7 +1135,7 @@ inline void sync_plan_position() {
1130 1135
       zPosition += home_retract_mm(Z_AXIS);
1131 1136
       line_to_z(zPosition);
1132 1137
       st_synchronize();
1133
-      endstops_hit_on_purpose();
1138
+      endstops_hit_on_purpose(); // clear endstop hit flags
1134 1139
 
1135 1140
       // move back down slowly to find bed
1136 1141
       if (homing_bump_divisor[Z_AXIS] >= 1)
@@ -1143,7 +1148,7 @@ inline void sync_plan_position() {
1143 1148
       zPosition -= home_retract_mm(Z_AXIS) * 2;
1144 1149
       line_to_z(zPosition);
1145 1150
       st_synchronize();
1146
-      endstops_hit_on_purpose();
1151
+      endstops_hit_on_purpose(); // clear endstop hit flags
1147 1152
 
1148 1153
       current_position[Z_AXIS] = st_get_position_mm(Z_AXIS);
1149 1154
       // make sure the planner knows where we are as it may be a bit different than we last said to move to
@@ -1267,7 +1272,7 @@ inline void sync_plan_position() {
1267 1272
       if (servo_endstops[Z_AXIS] >= 0) {
1268 1273
 
1269 1274
         #if Z_RAISE_AFTER_PROBING > 0
1270
-          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_AFTER_PROBING);
1275
+          do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_AFTER_PROBING);
1271 1276
           st_synchronize();
1272 1277
         #endif
1273 1278
 
@@ -1355,7 +1360,7 @@ inline void sync_plan_position() {
1355 1360
 
1356 1361
     #if Z_RAISE_BETWEEN_PROBINGS > 0
1357 1362
       if (retract_action == ProbeStay) {
1358
-        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], Z_RAISE_BETWEEN_PROBINGS);
1363
+        do_blocking_move_to(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS] + Z_RAISE_BETWEEN_PROBINGS);
1359 1364
         st_synchronize();
1360 1365
       }
1361 1366
     #endif
@@ -1440,13 +1445,17 @@ inline void sync_plan_position() {
1440 1445
 
1441 1446
 #endif // ENABLE_AUTO_BED_LEVELING
1442 1447
 
1448
+/**
1449
+ * Home an individual axis
1450
+ */
1451
+
1452
+#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1453
+
1443 1454
 static void homeaxis(int axis) {
1444 1455
   #define HOMEAXIS_DO(LETTER) \
1445 1456
     ((LETTER##_MIN_PIN > -1 && LETTER##_HOME_DIR==-1) || (LETTER##_MAX_PIN > -1 && LETTER##_HOME_DIR==1))
1446 1457
 
1447
-  if (axis == X_AXIS ? HOMEAXIS_DO(X) :
1448
-      axis == Y_AXIS ? HOMEAXIS_DO(Y) :
1449
-      axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) {
1458
+  if (axis == X_AXIS ? HOMEAXIS_DO(X) : axis == Y_AXIS ? HOMEAXIS_DO(Y) : axis == Z_AXIS ? HOMEAXIS_DO(Z) : 0) {
1450 1459
 
1451 1460
     int axis_home_dir;
1452 1461
 
@@ -1456,166 +1465,165 @@ static void homeaxis(int axis) {
1456 1465
       axis_home_dir = home_dir(axis);
1457 1466
     #endif
1458 1467
 
1468
+    // Set the axis position as setup for the move
1459 1469
     current_position[axis] = 0;
1460 1470
     sync_plan_position();
1461 1471
 
1462
-    #ifndef Z_PROBE_SLED
1463
-      // Engage Servo endstop if enabled
1464
-      #ifdef SERVO_ENDSTOPS
1465
-        #if SERVO_LEVELING
1466
-          if (axis == Z_AXIS) {
1467
-            engage_z_probe();
1468
-          }
1469
-          else
1470
-        #endif // SERVO_LEVELING
1471
-
1472
-        if (servo_endstops[axis] > -1)
1473
-          servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1472
+    // Engage Servo endstop if enabled
1473
+    #ifdef SERVO_ENDSTOPS && !defined(Z_PROBE_SLED)
1474 1474
 
1475
-      #endif // SERVO_ENDSTOPS
1475
+      #if SERVO_LEVELING
1476
+        if (axis == Z_AXIS) engage_z_probe(); else
1477
+      #endif
1478
+        {
1479
+          if (servo_endstops[axis] > -1)
1480
+            servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2]);
1481
+        }
1476 1482
 
1477
-    #endif // Z_PROBE_SLED
1483
+    #endif // SERVO_ENDSTOPS && !Z_PROBE_SLED
1478 1484
 
1479 1485
     #ifdef Z_DUAL_ENDSTOPS
1480 1486
       if (axis == Z_AXIS) In_Homing_Process(true);
1481 1487
     #endif
1482 1488
 
1489
+    // Move towards the endstop until an endstop is triggered
1483 1490
     destination[axis] = 1.5 * max_length(axis) * axis_home_dir;
1484 1491
     feedrate = homing_feedrate[axis];
1485 1492
     line_to_destination();
1486 1493
     st_synchronize();
1487 1494
 
1495
+    // Set the axis position as setup for the move
1488 1496
     current_position[axis] = 0;
1489 1497
     sync_plan_position();
1498
+
1499
+    // Move away from the endstop by the axis HOME_RETRACT_MM
1490 1500
     destination[axis] = -home_retract_mm(axis) * axis_home_dir;
1491 1501
     line_to_destination();
1492 1502
     st_synchronize();
1493 1503
 
1494
-    destination[axis] = 2 * home_retract_mm(axis) * axis_home_dir;
1495
-
1504
+    // Slow down the feedrate for the next move
1496 1505
     if (homing_bump_divisor[axis] >= 1)
1497 1506
       feedrate = homing_feedrate[axis] / homing_bump_divisor[axis];
1498 1507
     else {
1499 1508
       feedrate = homing_feedrate[axis] / 10;
1500
-      SERIAL_ECHOLN("Warning: The Homing Bump Feedrate Divisor cannot be less than 1");
1509
+      SERIAL_ECHOLNPGM("Warning: The Homing Bump Feedrate Divisor cannot be less than 1");
1501 1510
     }
1502 1511
 
1512
+    // Move slowly towards the endstop until triggered
1513
+    destination[axis] = 2 * home_retract_mm(axis) * axis_home_dir;
1503 1514
     line_to_destination();
1504 1515
     st_synchronize();
1516
+
1505 1517
     #ifdef Z_DUAL_ENDSTOPS
1506
-      if (axis==Z_AXIS)
1507
-      {
1508
-        feedrate = homing_feedrate[axis];
1509
-        sync_plan_position();
1510
-        if (axis_home_dir > 0)
1511
-        {
1512
-          destination[axis] = (-1) * fabs(z_endstop_adj);
1513
-          if (z_endstop_adj > 0) Lock_z_motor(true); else Lock_z2_motor(true);
1514
-        } else {
1515
-          destination[axis] = fabs(z_endstop_adj);
1516
-          if (z_endstop_adj < 0) Lock_z_motor(true); else Lock_z2_motor(true);        
1518
+      if (axis == Z_AXIS) {
1519
+        float adj = fabs(z_endstop_adj);
1520
+        bool lockZ1;
1521
+        if (axis_home_dir > 0) {
1522
+          adj = -adj;
1523
+          lockZ1 = (z_endstop_adj > 0);
1517 1524
         }
1525
+        else
1526
+          lockZ1 = (z_endstop_adj < 0);
1527
+
1528
+        if (lockZ1) Lock_z_motor(true); else Lock_z2_motor(true);
1529
+        sync_plan_position();
1530
+
1531
+        // Move to the adjusted endstop height
1532
+        feedrate = homing_feedrate[axis];
1533
+        destination[Z_AXIS] = adj;
1518 1534
         line_to_destination();
1519 1535
         st_synchronize();
1520
-        Lock_z_motor(false);
1521
-        Lock_z2_motor(false);
1536
+
1537
+        if (lockZ1) Lock_z_motor(false); else Lock_z2_motor(false);
1522 1538
         In_Homing_Process(false);
1539
+      } // Z_AXIS
1540
+    #endif
1541
+
1542
+    #ifdef DELTA
1543
+      // retrace by the amount specified in endstop_adj
1544
+      if (endstop_adj[axis] * axis_home_dir < 0) {
1545
+        sync_plan_position();
1546
+        destination[axis] = endstop_adj[axis];
1547
+        line_to_destination();
1548
+        st_synchronize();
1523 1549
       }
1524 1550
     #endif
1525 1551
 
1526
-#ifdef DELTA
1527
-    // retrace by the amount specified in endstop_adj
1528
-    if (endstop_adj[axis] * axis_home_dir < 0) {
1529
-      sync_plan_position();
1530
-      destination[axis] = endstop_adj[axis];
1531
-      line_to_destination();
1532
-      st_synchronize();
1533
-    }
1534
-#endif
1552
+    // Set the axis position to its home position (plus home offsets)
1535 1553
     axis_is_at_home(axis);
1554
+
1536 1555
     destination[axis] = current_position[axis];
1537 1556
     feedrate = 0.0;
1538
-    endstops_hit_on_purpose();
1557
+    endstops_hit_on_purpose(); // clear endstop hit flags
1539 1558
     axis_known_position[axis] = true;
1540 1559
 
1541 1560
     // Retract Servo endstop if enabled
1542 1561
     #ifdef SERVO_ENDSTOPS
1543
-      if (servo_endstops[axis] > -1) {
1562
+      if (servo_endstops[axis] > -1)
1544 1563
         servos[servo_endstops[axis]].write(servo_endstop_angles[axis * 2 + 1]);
1545
-      }
1546 1564
     #endif
1547
-#if SERVO_LEVELING
1548
-  #ifndef Z_PROBE_SLED
1549
-    if (axis==Z_AXIS) retract_z_probe();
1550
-  #endif
1551
-#endif
1565
+
1566
+    #if SERVO_LEVELING && !defined(Z_PROBE_SLED)
1567
+      if (axis == Z_AXIS) retract_z_probe();
1568
+    #endif
1552 1569
 
1553 1570
   }
1554 1571
 }
1555
-#define HOMEAXIS(LETTER) homeaxis(LETTER##_AXIS)
1556 1572
 
1557
-void refresh_cmd_timeout(void)
1558
-{
1559
-  previous_millis_cmd = millis();
1560
-}
1573
+void refresh_cmd_timeout(void) { previous_millis_cmd = millis(); }
1561 1574
 
1562 1575
 #ifdef FWRETRACT
1576
+
1563 1577
   void retract(bool retracting, bool swapretract = false) {
1564
-    if(retracting && !retracted[active_extruder]) {
1565
-      destination[X_AXIS]=current_position[X_AXIS];
1566
-      destination[Y_AXIS]=current_position[Y_AXIS];
1567
-      destination[Z_AXIS]=current_position[Z_AXIS];
1568
-      destination[E_AXIS]=current_position[E_AXIS];
1569
-      if (swapretract) {
1570
-        current_position[E_AXIS]+=retract_length_swap/volumetric_multiplier[active_extruder];
1571
-      } else {
1572
-        current_position[E_AXIS]+=retract_length/volumetric_multiplier[active_extruder];
1573
-      }
1574
-      plan_set_e_position(current_position[E_AXIS]);
1575
-      float oldFeedrate = feedrate;
1578
+
1579
+    if (retracting == retracted[active_extruder]) return;
1580
+
1581
+    float oldFeedrate = feedrate;
1582
+
1583
+    for (int i = 0; i < NUM_AXIS; i++) destination[i] = current_position[i];
1584
+
1585
+    if (retracting) {
1586
+
1576 1587
       feedrate = retract_feedrate * 60;
1577
-      retracted[active_extruder]=true;
1588
+      current_position[E_AXIS] += (swapretract ? retract_length_swap : retract_length) / volumetric_multiplier[active_extruder];
1589
+      plan_set_e_position(current_position[E_AXIS]);
1578 1590
       prepare_move();
1579
-      if(retract_zlift > 0.01) {
1580
-         current_position[Z_AXIS]-=retract_zlift;
1581
-#ifdef DELTA
1582
-         calculate_delta(current_position); // change cartesian kinematic to  delta kinematic;
1583
-         plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1584
-#else
1585
-         sync_plan_position();
1586
-#endif
1587
-         prepare_move();
1588
-      }
1589
-      feedrate = oldFeedrate;
1590
-    } else if(!retracting && retracted[active_extruder]) {
1591
-      destination[X_AXIS]=current_position[X_AXIS];
1592
-      destination[Y_AXIS]=current_position[Y_AXIS];
1593
-      destination[Z_AXIS]=current_position[Z_AXIS];
1594
-      destination[E_AXIS]=current_position[E_AXIS];
1595
-      if(retract_zlift > 0.01) {
1596
-         current_position[Z_AXIS]+=retract_zlift;
1597
-#ifdef DELTA
1598
-         calculate_delta(current_position); // change cartesian kinematic  to  delta kinematic;
1599
-         plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1600
-#else
1601
-         sync_plan_position();
1602
-#endif
1603
-         //prepare_move();
1591
+
1592
+      if (retract_zlift > 0.01) {
1593
+        current_position[Z_AXIS] -= retract_zlift;
1594
+        #ifdef DELTA
1595
+          sync_plan_position_delta();
1596
+        #else
1597
+          sync_plan_position();
1598
+        #endif
1599
+        prepare_move();
1604 1600
       }
1605
-      if (swapretract) {
1606
-        current_position[E_AXIS]-=(retract_length_swap+retract_recover_length_swap)/volumetric_multiplier[active_extruder]; 
1607
-      } else {
1608
-        current_position[E_AXIS]-=(retract_length+retract_recover_length)/volumetric_multiplier[active_extruder]; 
1601
+    }
1602
+    else {
1603
+
1604
+      if (retract_zlift > 0.01) {
1605
+        current_position[Z_AXIS] + =retract_zlift;
1606
+        #ifdef DELTA
1607
+          sync_plan_position_delta();
1608
+        #else
1609
+          sync_plan_position();
1610
+        #endif
1611
+        //prepare_move();
1609 1612
       }
1610
-      plan_set_e_position(current_position[E_AXIS]);
1611
-      float oldFeedrate = feedrate;
1613
+
1612 1614
       feedrate = retract_recover_feedrate * 60;
1613
-      retracted[active_extruder] = false;
1615
+      float move_e = swapretract ? retract_length_swap + retract_recover_length_swap : retract_length + retract_recover_length;
1616
+      current_position[E_AXIS] -= move_e / volumetric_multiplier[active_extruder];
1617
+      plan_set_e_position(current_position[E_AXIS]);
1614 1618
       prepare_move();
1615
-      feedrate = oldFeedrate;
1616 1619
     }
1617
-  } //retract
1618
-#endif //FWRETRACT
1620
+
1621
+    feedrate = oldFeedrate;
1622
+    retracted[active_extruder] = retract;
1623
+
1624
+  } // retract()
1625
+
1626
+#endif // FWRETRACT
1619 1627
 
1620 1628
 #ifdef Z_PROBE_SLED
1621 1629
 
@@ -1623,40 +1631,32 @@ void refresh_cmd_timeout(void)
1623 1631
     #define SLED_DOCKING_OFFSET 0
1624 1632
   #endif
1625 1633
 
1626
-//
1627
-// Method to dock/undock a sled designed by Charles Bell.
1628
-//
1629
-// dock[in]     If true, move to MAX_X and engage the electromagnet
1630
-// offset[in]   The additional distance to move to adjust docking location
1631
-//
1632
-static void dock_sled(bool dock, int offset=0) {
1633
- int z_loc;
1634
- 
1635
- if (!((axis_known_position[X_AXIS]) && (axis_known_position[Y_AXIS]))) {
1636
-   LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1637
-   SERIAL_ECHO_START;
1638
-   SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1639
-   return;
1640
- }
1641
-
1642
- if (dock) {
1643
-   do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset,
1644
-                       current_position[Y_AXIS],
1645
-                       current_position[Z_AXIS]);
1646
-   // turn off magnet
1647
-   digitalWrite(SERVO0_PIN, LOW);
1648
- } else {
1649
-   if (current_position[Z_AXIS] < (Z_RAISE_BEFORE_PROBING + 5))
1650
-     z_loc = Z_RAISE_BEFORE_PROBING;
1651
-   else
1652
-     z_loc = current_position[Z_AXIS];
1653
-   do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset,
1654
-                       Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
1655
-   // turn on magnet
1656
-   digitalWrite(SERVO0_PIN, HIGH);
1657
- }
1658
-}
1659
-#endif
1634
+  //
1635
+  // Method to dock/undock a sled designed by Charles Bell.
1636
+  //
1637
+  // dock[in]     If true, move to MAX_X and engage the electromagnet
1638
+  // offset[in]   The additional distance to move to adjust docking location
1639
+  //
1640
+  static void dock_sled(bool dock, int offset=0) {
1641
+    if (!axis_known_position[X_AXIS] || !axis_known_position[Y_AXIS]) {
1642
+      LCD_MESSAGEPGM(MSG_POSITION_UNKNOWN);
1643
+      SERIAL_ECHO_START;
1644
+      SERIAL_ECHOLNPGM(MSG_POSITION_UNKNOWN);
1645
+      return;
1646
+    }
1647
+
1648
+    if (dock) {
1649
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, current_position[Y_AXIS], current_position[Z_AXIS]);
1650
+      digitalWrite(SERVO0_PIN, LOW); // turn off magnet
1651
+    } else {
1652
+      float z_loc = current_position[Z_AXIS];
1653
+      if (z_loc < Z_RAISE_BEFORE_PROBING + 5) z_loc = Z_RAISE_BEFORE_PROBING;
1654
+      do_blocking_move_to(X_MAX_POS + SLED_DOCKING_OFFSET + offset, Y_PROBE_OFFSET_FROM_EXTRUDER, z_loc);
1655
+      digitalWrite(SERVO0_PIN, HIGH); // turn on magnet
1656
+    }
1657
+  }
1658
+
1659
+#endif // Z_PROBE_SLED
1660 1660
 
1661 1661
 /**
1662 1662
  *
@@ -1798,7 +1798,7 @@ inline void gcode_G28() {
1798 1798
     feedrate = 1.732 * homing_feedrate[X_AXIS];
1799 1799
     line_to_destination();
1800 1800
     st_synchronize();
1801
-    endstops_hit_on_purpose();
1801
+    endstops_hit_on_purpose(); // clear endstop hit flags
1802 1802
 
1803 1803
     // Destination reached
1804 1804
     for (int i = X_AXIS; i <= Z_AXIS; i++) current_position[i] = destination[i];
@@ -1808,8 +1808,7 @@ inline void gcode_G28() {
1808 1808
     HOMEAXIS(Y);
1809 1809
     HOMEAXIS(Z);
1810 1810
 
1811
-    calculate_delta(current_position);
1812
-    plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
1811
+    sync_plan_position_delta();
1813 1812
 
1814 1813
   #else // NOT DELTA
1815 1814
 
@@ -1817,7 +1816,7 @@ inline void gcode_G28() {
1817 1816
           homeY = code_seen(axis_codes[Y_AXIS]),
1818 1817
           homeZ = code_seen(axis_codes[Z_AXIS]);
1819 1818
 
1820
-    home_all_axis = !homeX && !homeY && !homeZ; // No parameters means home all axes
1819
+    home_all_axis = !(homeX || homeY || homeZ) || (homeX && homeY && homeZ);
1821 1820
 
1822 1821
     #if Z_HOME_DIR > 0                      // If homing away from BED do Z first
1823 1822
 
@@ -1836,7 +1835,9 @@ inline void gcode_G28() {
1836 1835
     #endif
1837 1836
 
1838 1837
     #ifdef QUICK_HOME
1839
-      if (home_all_axis || (homeX && homeY)) {  //first diagonal move
1838
+
1839
+      if (home_all_axis || (homeX && homeY)) {  // First diagonal move
1840
+
1840 1841
         current_position[X_AXIS] = current_position[Y_AXIS] = 0;
1841 1842
 
1842 1843
         #ifdef DUAL_X_CARRIAGE
@@ -1847,27 +1848,26 @@ inline void gcode_G28() {
1847 1848
         #endif
1848 1849
 
1849 1850
         sync_plan_position();
1850
-        destination[X_AXIS] = 1.5 * max_length(X_AXIS) * x_axis_home_dir;
1851
-        destination[Y_AXIS] = 1.5 * max_length(Y_AXIS) * home_dir(Y_AXIS);
1852
-        feedrate = homing_feedrate[X_AXIS];
1853
-        if (homing_feedrate[Y_AXIS] < feedrate) feedrate = homing_feedrate[Y_AXIS];
1854
-        if (max_length(X_AXIS) > max_length(Y_AXIS)) {
1855
-          feedrate *= sqrt(pow(max_length(Y_AXIS) / max_length(X_AXIS), 2) + 1);
1856
-        } else {
1857
-          feedrate *= sqrt(pow(max_length(X_AXIS) / max_length(Y_AXIS), 2) + 1);
1858
-        }
1851
+
1852
+        float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS),
1853
+              mlratio = mlx>mly ? mly/mlx : mlx/mly;
1854
+
1855
+        destination[X_AXIS] = 1.5 * mlx * x_axis_home_dir;
1856
+        destination[Y_AXIS] = 1.5 * mly * home_dir(Y_AXIS);
1857
+        feedrate = min(homing_feedrate[X_AXIS], homing_feedrate[Y_AXIS]) * sqrt(mlratio * mlratio + 1);
1859 1858
         line_to_destination();
1860 1859
         st_synchronize();
1861 1860
 
1862 1861
         axis_is_at_home(X_AXIS);
1863 1862
         axis_is_at_home(Y_AXIS);
1864 1863
         sync_plan_position();
1864
+
1865 1865
         destination[X_AXIS] = current_position[X_AXIS];
1866 1866
         destination[Y_AXIS] = current_position[Y_AXIS];
1867 1867
         line_to_destination();
1868 1868
         feedrate = 0.0;
1869 1869
         st_synchronize();
1870
-        endstops_hit_on_purpose();
1870
+        endstops_hit_on_purpose(); // clear endstop hit flags
1871 1871
 
1872 1872
         current_position[X_AXIS] = destination[X_AXIS];
1873 1873
         current_position[Y_AXIS] = destination[Y_AXIS];
@@ -1875,7 +1875,8 @@ inline void gcode_G28() {
1875 1875
           current_position[Z_AXIS] = destination[Z_AXIS];
1876 1876
         #endif
1877 1877
       }
1878
-    #endif //QUICK_HOME
1878
+
1879
+    #endif // QUICK_HOME
1879 1880
 
1880 1881
     // Home X
1881 1882
     if (home_all_axis || homeX) {
@@ -1957,7 +1958,7 @@ inline void gcode_G28() {
1957 1958
                 && cpy >= Y_MIN_POS - Y_PROBE_OFFSET_FROM_EXTRUDER
1958 1959
                 && cpy <= Y_MAX_POS - Y_PROBE_OFFSET_FROM_EXTRUDER) {
1959 1960
               current_position[Z_AXIS] = 0;
1960
-              plan_set_position(cpx, cpy, current_position[Z_AXIS], current_position[E_AXIS]);
1961
+              plan_set_position(cpx, cpy, 0, current_position[E_AXIS]);
1961 1962
               destination[Z_AXIS] = -Z_RAISE_BEFORE_HOMING * home_dir(Z_AXIS);    // Set destination away from bed
1962 1963
               feedrate = max_feedrate[Z_AXIS];
1963 1964
               line_to_destination();
@@ -1996,8 +1997,7 @@ inline void gcode_G28() {
1996 1997
   #endif // else DELTA
1997 1998
 
1998 1999
   #ifdef SCARA
1999
-    calculate_delta(current_position);
2000
-    plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], current_position[E_AXIS]);
2000
+    sync_plan_position_delta();
2001 2001
   #endif
2002 2002
 
2003 2003
   #ifdef ENDSTOPS_ONLY_FOR_HOMING
@@ -2024,7 +2024,7 @@ inline void gcode_G28() {
2024 2024
   feedrate = saved_feedrate;
2025 2025
   feedmultiply = saved_feedmultiply;
2026 2026
   previous_millis_cmd = millis();
2027
-  endstops_hit_on_purpose();
2027
+  endstops_hit_on_purpose(); // clear endstop hit flags
2028 2028
 }
2029 2029
 
2030 2030
 #if defined(MESH_BED_LEVELING) || defined(ENABLE_AUTO_BED_LEVELING)
@@ -2196,8 +2196,7 @@ inline void gcode_G28() {
2196 2196
         bool do_topography_map = verbose_level > 2 || code_seen('T') || code_seen('t');
2197 2197
       #endif
2198 2198
 
2199
-      if (verbose_level > 0)
2200
-      {
2199
+      if (verbose_level > 0) {
2201 2200
         SERIAL_PROTOCOLPGM("G29 Auto Bed Leveling\n");
2202 2201
         if (dryrun) SERIAL_ECHOLN("Running in DRY-RUN mode");
2203 2202
       }
@@ -2272,10 +2271,9 @@ inline void gcode_G28() {
2272 2271
         current_position[Y_AXIS] = uncorrected_position.y;
2273 2272
         current_position[Z_AXIS] = uncorrected_position.z;
2274 2273
         sync_plan_position();
2275
-
2276 2274
       #endif // !DELTA
2277 2275
     }
2278
-    
2276
+
2279 2277
     setup_for_endstop_move();
2280 2278
 
2281 2279
     feedrate = homing_feedrate[Z_AXIS];
@@ -2283,8 +2281,8 @@ inline void gcode_G28() {
2283 2281
     #ifdef AUTO_BED_LEVELING_GRID
2284 2282
 
2285 2283
       // probe at the points of a lattice grid
2286
-      const int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points-1);
2287
-      const int yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points-1);
2284
+      const int xGridSpacing = (right_probe_bed_position - left_probe_bed_position) / (auto_bed_leveling_grid_points - 1),
2285
+                yGridSpacing = (back_probe_bed_position - front_probe_bed_position) / (auto_bed_leveling_grid_points - 1);
2288 2286
 
2289 2287
       #ifdef DELTA
2290 2288
         delta_grid_spacing[0] = xGridSpacing;
@@ -2842,9 +2840,7 @@ inline void gcode_M42() {
2842 2840
   inline void gcode_M48() {
2843 2841
 
2844 2842
     double sum = 0.0, mean = 0.0, sigma = 0.0, sample_set[50];
2845
-    int verbose_level = 1, n = 0, j, n_samples = 10, n_legs = 0, engage_probe_for_each_reading = 0;
2846
-    double X_current, Y_current, Z_current;
2847
-    double X_probe_location, Y_probe_location, Z_start_location, ext_position;
2843
+    int verbose_level = 1, n_samples = 10, n_legs = 0;
2848 2844
     
2849 2845
     if (code_seen('V') || code_seen('v')) {
2850 2846
       verbose_level = code_value();
@@ -2865,14 +2861,14 @@ inline void gcode_M42() {
2865 2861
       }
2866 2862
     }
2867 2863
 
2868
-    X_current = X_probe_location = st_get_position_mm(X_AXIS);
2869
-    Y_current = Y_probe_location = st_get_position_mm(Y_AXIS);
2870
-    Z_current = st_get_position_mm(Z_AXIS);
2871
-    Z_start_location = st_get_position_mm(Z_AXIS) + Z_RAISE_BEFORE_PROBING;
2872
-    ext_position = st_get_position_mm(E_AXIS);
2864
+    double X_probe_location, Y_probe_location,
2865
+           X_current = X_probe_location = st_get_position_mm(X_AXIS),
2866
+           Y_current = Y_probe_location = st_get_position_mm(Y_AXIS),
2867
+           Z_current = st_get_position_mm(Z_AXIS),
2868
+           Z_start_location = Z_current + Z_RAISE_BEFORE_PROBING,
2869
+           ext_position = st_get_position_mm(E_AXIS);
2873 2870
 
2874
-    if (code_seen('E') || code_seen('e'))
2875
-      engage_probe_for_each_reading++;
2871
+    bool engage_probe_for_each_reading = code_seen('E') || code_seen('e');
2876 2872
 
2877 2873
     if (code_seen('X') || code_seen('x')) {
2878 2874
       X_probe_location = code_value() - X_PROBE_OFFSET_FROM_EXTRUDER;
@@ -2952,33 +2948,29 @@ inline void gcode_M42() {
2952 2948
 
2953 2949
     if (engage_probe_for_each_reading) retract_z_probe();
2954 2950
 
2955
-    for (n=0; n < n_samples; n++) {
2951
+    for (uint16_t n=0; n < n_samples; n++) {
2956 2952
 
2957
-      do_blocking_move_to( X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location
2953
+      do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Make sure we are at the probe location
2958 2954
 
2959 2955
       if (n_legs) {
2960
-        double radius=0.0, theta=0.0;
2961
-        int l;
2962
-        int rotational_direction = (unsigned long) millis() & 0x0001;     // clockwise or counter clockwise
2963
-        radius = (unsigned long)millis() % (long)(X_MAX_LENGTH / 4);      // limit how far out to go
2964
-        theta = (float)((unsigned long)millis() % 360L) / (360. / (2 * 3.1415926)); // turn into radians
2956
+        unsigned long ms = millis();
2957
+        double radius = ms % (X_MAX_LENGTH / 4),       // limit how far out to go
2958
+               theta = RADIANS(ms % 360L);
2959
+        float dir = (ms & 0x0001) ? 1 : -1;            // clockwise or counter clockwise
2965 2960
 
2966 2961
         //SERIAL_ECHOPAIR("starting radius: ",radius);
2967 2962
         //SERIAL_ECHOPAIR("   theta: ",theta);
2968
-        //SERIAL_ECHOPAIR("   direction: ",rotational_direction);
2963
+        //SERIAL_ECHOPAIR("   direction: ",dir);
2969 2964
         //SERIAL_EOL;
2970 2965
 
2971
-        float dir = rotational_direction ? 1 : -1;
2972
-        for (l = 0; l < n_legs - 1; l++) {
2973
-          theta += dir * (float)((unsigned long)millis() % 20L) / (360.0/(2*3.1415926)); // turn into radians
2974
-
2975
-          radius += (float)(((long)((unsigned long) millis() % 10L)) - 5L);
2966
+        for (int l = 0; l < n_legs - 1; l++) {
2967
+          ms = millis();
2968
+          theta += RADIANS(dir * (ms % 20L));
2969
+          radius += (ms % 10L) - 5L;
2976 2970
           if (radius < 0.0) radius = -radius;
2977 2971
 
2978 2972
           X_current = X_probe_location + cos(theta) * radius;
2979 2973
           Y_current = Y_probe_location + sin(theta) * radius;
2980
-
2981
-          // Make sure our X & Y are sane
2982 2974
           X_current = constrain(X_current, X_MIN_POS, X_MAX_POS);
2983 2975
           Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS);
2984 2976
 
@@ -2988,10 +2980,13 @@ inline void gcode_M42() {
2988 2980
             SERIAL_EOL;
2989 2981
           }
2990 2982
 
2991
-          do_blocking_move_to( X_current, Y_current, Z_current );
2992
-        }
2993
-        do_blocking_move_to( X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location
2994
-      }
2983
+          do_blocking_move_to(X_current, Y_current, Z_current);
2984
+
2985
+        } // n_legs loop
2986
+
2987
+        do_blocking_move_to(X_probe_location, Y_probe_location, Z_start_location); // Go back to the probe location
2988
+
2989
+      } // n_legs
2995 2990
 
2996 2991
       if (engage_probe_for_each_reading)  {
2997 2992
         engage_z_probe(); 
@@ -3007,46 +3002,49 @@ inline void gcode_M42() {
3007 3002
       // Get the current mean for the data points we have so far
3008 3003
       //
3009 3004
       sum = 0.0;
3010
-      for (j=0; j<=n; j++) sum += sample_set[j];
3011
-      mean = sum / (double (n+1));
3005
+      for (int j = 0; j <= n; j++) sum += sample_set[j];
3006
+      mean = sum / (n + 1);
3012 3007
 
3013 3008
       //
3014 3009
       // Now, use that mean to calculate the standard deviation for the
3015 3010
       // data points we have so far
3016 3011
       //
3017 3012
       sum = 0.0;
3018
-      for (j=0; j<=n; j++) sum += (sample_set[j]-mean) * (sample_set[j]-mean);
3019
-      sigma = sqrt( sum / (double (n+1)) );
3013
+      for (int j = 0; j <= n; j++) {
3014
+        float ss = sample_set[j] - mean;
3015
+        sum += ss * ss;
3016
+      }
3017
+      sigma = sqrt(sum / (n + 1));
3020 3018
 
3021 3019
       if (verbose_level > 1) {
3022 3020
         SERIAL_PROTOCOL(n+1);
3023
-        SERIAL_PROTOCOL(" of ");
3021
+        SERIAL_PROTOCOLPGM(" of ");
3024 3022
         SERIAL_PROTOCOL(n_samples);
3025 3023
         SERIAL_PROTOCOLPGM("   z: ");
3026 3024
         SERIAL_PROTOCOL_F(current_position[Z_AXIS], 6);
3027
-      }
3028
-
3029
-      if (verbose_level > 2) {
3030
-        SERIAL_PROTOCOL(" mean: ");
3031
-        SERIAL_PROTOCOL_F(mean,6);
3032
-        SERIAL_PROTOCOL("   sigma: ");
3033
-        SERIAL_PROTOCOL_F(sigma,6);
3025
+        if (verbose_level > 2) {
3026
+          SERIAL_PROTOCOLPGM(" mean: ");
3027
+          SERIAL_PROTOCOL_F(mean,6);
3028
+          SERIAL_PROTOCOLPGM("   sigma: ");
3029
+          SERIAL_PROTOCOL_F(sigma,6);
3030
+        }
3034 3031
       }
3035 3032
 
3036 3033
       if (verbose_level > 0) SERIAL_EOL;
3037 3034
 
3038
-      plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location,
3039
-          current_position[E_AXIS], homing_feedrate[Z_AXIS]/60, active_extruder);
3035
+      plan_buffer_line(X_probe_location, Y_probe_location, Z_start_location, current_position[E_AXIS], homing_feedrate[Z_AXIS]/60, active_extruder);
3040 3036
       st_synchronize();
3041 3037
 
3042 3038
       if (engage_probe_for_each_reading) {
3043
-        retract_z_probe();  
3039
+        retract_z_probe();
3044 3040
         delay(1000);
3045 3041
       }
3046 3042
     }
3047 3043
 
3048
-    retract_z_probe();
3049
-    delay(1000);
3044
+    if (!engage_probe_for_each_reading) {
3045
+      retract_z_probe();
3046
+      delay(1000);
3047
+    }
3050 3048
 
3051 3049
     clean_up_after_endstop_move();
3052 3050
 
@@ -4688,9 +4686,7 @@ inline void gcode_T() {
4688 4686
           active_extruder = tmp_extruder;
4689 4687
         #endif // !DUAL_X_CARRIAGE
4690 4688
         #ifdef DELTA
4691
-          calculate_delta(current_position); // change cartesian kinematic  to  delta kinematic;
4692
-          //sent position to plan_set_position();
4693
-          plan_set_position(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS],current_position[E_AXIS]);
4689
+          sync_plan_position_delta();
4694 4690
         #else
4695 4691
           sync_plan_position();
4696 4692
         #endif
@@ -5279,104 +5275,99 @@ void clamp_to_software_endstops(float target[3])
5279 5275
 }
5280 5276
 
5281 5277
 #ifdef DELTA
5282
-void recalc_delta_settings(float radius, float diagonal_rod)
5283
-{
5284
-   delta_tower1_x= -SIN_60*radius; // front left tower
5285
-   delta_tower1_y= -COS_60*radius;     
5286
-   delta_tower2_x=  SIN_60*radius; // front right tower
5287
-   delta_tower2_y= -COS_60*radius;     
5288
-   delta_tower3_x= 0.0;                  // back middle tower
5289
-   delta_tower3_y= radius;
5290
-   delta_diagonal_rod_2= sq(diagonal_rod);
5291
-}
5292 5278
 
5293
-void calculate_delta(float cartesian[3])
5294
-{
5295
-  delta[X_AXIS] = sqrt(delta_diagonal_rod_2
5296
-                       - sq(delta_tower1_x-cartesian[X_AXIS])
5297
-                       - sq(delta_tower1_y-cartesian[Y_AXIS])
5298
-                       ) + cartesian[Z_AXIS];
5299
-  delta[Y_AXIS] = sqrt(delta_diagonal_rod_2
5300
-                       - sq(delta_tower2_x-cartesian[X_AXIS])
5301
-                       - sq(delta_tower2_y-cartesian[Y_AXIS])
5302
-                       ) + cartesian[Z_AXIS];
5303
-  delta[Z_AXIS] = sqrt(delta_diagonal_rod_2
5304
-                       - sq(delta_tower3_x-cartesian[X_AXIS])
5305
-                       - sq(delta_tower3_y-cartesian[Y_AXIS])
5306
-                       ) + cartesian[Z_AXIS];
5307
-  /*
5308
-  SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
5309
-  SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
5310
-  SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(cartesian[Z_AXIS]);
5279
+  void recalc_delta_settings(float radius, float diagonal_rod) {
5280
+    delta_tower1_x = -SIN_60 * radius;  // front left tower
5281
+    delta_tower1_y = -COS_60 * radius;
5282
+    delta_tower2_x =  SIN_60 * radius;  // front right tower
5283
+    delta_tower2_y = -COS_60 * radius;
5284
+    delta_tower3_x = 0.0;               // back middle tower
5285
+    delta_tower3_y = radius;
5286
+    delta_diagonal_rod_2 = sq(diagonal_rod);
5287
+  }
5311 5288
 
5312
-  SERIAL_ECHOPGM("delta x="); SERIAL_ECHO(delta[X_AXIS]);
5313
-  SERIAL_ECHOPGM(" y="); SERIAL_ECHO(delta[Y_AXIS]);
5314
-  SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(delta[Z_AXIS]);
5315
-  */
5316
-}
5289
+  void calculate_delta(float cartesian[3]) {
5290
+    delta[X_AXIS] = sqrt(delta_diagonal_rod_2
5291
+                         - sq(delta_tower1_x-cartesian[X_AXIS])
5292
+                         - sq(delta_tower1_y-cartesian[Y_AXIS])
5293
+                         ) + cartesian[Z_AXIS];
5294
+    delta[Y_AXIS] = sqrt(delta_diagonal_rod_2
5295
+                         - sq(delta_tower2_x-cartesian[X_AXIS])
5296
+                         - sq(delta_tower2_y-cartesian[Y_AXIS])
5297
+                         ) + cartesian[Z_AXIS];
5298
+    delta[Z_AXIS] = sqrt(delta_diagonal_rod_2
5299
+                         - sq(delta_tower3_x-cartesian[X_AXIS])
5300
+                         - sq(delta_tower3_y-cartesian[Y_AXIS])
5301
+                         ) + cartesian[Z_AXIS];
5302
+    /*
5303
+    SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
5304
+    SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
5305
+    SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(cartesian[Z_AXIS]);
5306
+
5307
+    SERIAL_ECHOPGM("delta x="); SERIAL_ECHO(delta[X_AXIS]);
5308
+    SERIAL_ECHOPGM(" y="); SERIAL_ECHO(delta[Y_AXIS]);
5309
+    SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(delta[Z_AXIS]);
5310
+    */
5311
+  }
5317 5312
 
5318
-#ifdef ENABLE_AUTO_BED_LEVELING
5319
-// Adjust print surface height by linear interpolation over the bed_level array.
5320
-int delta_grid_spacing[2] = { 0, 0 };
5321
-void adjust_delta(float cartesian[3])
5322
-{
5323
-  if (delta_grid_spacing[0] == 0 || delta_grid_spacing[1] == 0)
5324
-    return; // G29 not done
5325
-
5326
-  int half = (AUTO_BED_LEVELING_GRID_POINTS - 1) / 2;
5327
-  float grid_x = max(0.001-half, min(half-0.001, cartesian[X_AXIS] / delta_grid_spacing[0]));
5328
-  float grid_y = max(0.001-half, min(half-0.001, cartesian[Y_AXIS] / delta_grid_spacing[1]));
5329
-  int floor_x = floor(grid_x);
5330
-  int floor_y = floor(grid_y);
5331
-  float ratio_x = grid_x - floor_x;
5332
-  float ratio_y = grid_y - floor_y;
5333
-  float z1 = bed_level[floor_x+half][floor_y+half];
5334
-  float z2 = bed_level[floor_x+half][floor_y+half+1];
5335
-  float z3 = bed_level[floor_x+half+1][floor_y+half];
5336
-  float z4 = bed_level[floor_x+half+1][floor_y+half+1];
5337
-  float left = (1-ratio_y)*z1 + ratio_y*z2;
5338
-  float right = (1-ratio_y)*z3 + ratio_y*z4;
5339
-  float offset = (1-ratio_x)*left + ratio_x*right;
5340
-
5341
-  delta[X_AXIS] += offset;
5342
-  delta[Y_AXIS] += offset;
5343
-  delta[Z_AXIS] += offset;
5313
+  #ifdef ENABLE_AUTO_BED_LEVELING
5344 5314
 
5345
-  /*
5346
-  SERIAL_ECHOPGM("grid_x="); SERIAL_ECHO(grid_x);
5347
-  SERIAL_ECHOPGM(" grid_y="); SERIAL_ECHO(grid_y);
5348
-  SERIAL_ECHOPGM(" floor_x="); SERIAL_ECHO(floor_x);
5349
-  SERIAL_ECHOPGM(" floor_y="); SERIAL_ECHO(floor_y);
5350
-  SERIAL_ECHOPGM(" ratio_x="); SERIAL_ECHO(ratio_x);
5351
-  SERIAL_ECHOPGM(" ratio_y="); SERIAL_ECHO(ratio_y);
5352
-  SERIAL_ECHOPGM(" z1="); SERIAL_ECHO(z1);
5353
-  SERIAL_ECHOPGM(" z2="); SERIAL_ECHO(z2);
5354
-  SERIAL_ECHOPGM(" z3="); SERIAL_ECHO(z3);
5355
-  SERIAL_ECHOPGM(" z4="); SERIAL_ECHO(z4);
5356
-  SERIAL_ECHOPGM(" left="); SERIAL_ECHO(left);
5357
-  SERIAL_ECHOPGM(" right="); SERIAL_ECHO(right);
5358
-  SERIAL_ECHOPGM(" offset="); SERIAL_ECHOLN(offset);
5359
-  */
5360
-}
5361
-#endif //ENABLE_AUTO_BED_LEVELING
5315
+    // Adjust print surface height by linear interpolation over the bed_level array.
5316
+    int delta_grid_spacing[2] = { 0, 0 };
5317
+    void adjust_delta(float cartesian[3]) {
5318
+      if (delta_grid_spacing[0] == 0 || delta_grid_spacing[1] == 0) return; // G29 not done!
5319
+
5320
+      int half = (AUTO_BED_LEVELING_GRID_POINTS - 1) / 2;
5321
+      float h1 = 0.001 - half, h2 = half - 0.001,
5322
+            grid_x = max(h1, min(h2, cartesian[X_AXIS] / delta_grid_spacing[0])),
5323
+            grid_y = max(h1, min(h2, cartesian[Y_AXIS] / delta_grid_spacing[1]));
5324
+      int floor_x = floor(grid_x), floor_y = floor(grid_y);
5325
+      float ratio_x = grid_x - floor_x, ratio_y = grid_y - floor_y,
5326
+            z1 = bed_level[floor_x + half][floor_y + half],
5327
+            z2 = bed_level[floor_x + half][floor_y + half + 1],
5328
+            z3 = bed_level[floor_x + half + 1][floor_y + half],
5329
+            z4 = bed_level[floor_x + half + 1][floor_y + half + 1],
5330
+            left = (1 - ratio_y) * z1 + ratio_y * z2,
5331
+            right = (1 - ratio_y) * z3 + ratio_y * z4,
5332
+            offset = (1 - ratio_x) * left + ratio_x * right;
5333
+
5334
+      delta[X_AXIS] += offset;
5335
+      delta[Y_AXIS] += offset;
5336
+      delta[Z_AXIS] += offset;
5337
+
5338
+      /*
5339
+      SERIAL_ECHOPGM("grid_x="); SERIAL_ECHO(grid_x);
5340
+      SERIAL_ECHOPGM(" grid_y="); SERIAL_ECHO(grid_y);
5341
+      SERIAL_ECHOPGM(" floor_x="); SERIAL_ECHO(floor_x);
5342
+      SERIAL_ECHOPGM(" floor_y="); SERIAL_ECHO(floor_y);
5343
+      SERIAL_ECHOPGM(" ratio_x="); SERIAL_ECHO(ratio_x);
5344
+      SERIAL_ECHOPGM(" ratio_y="); SERIAL_ECHO(ratio_y);
5345
+      SERIAL_ECHOPGM(" z1="); SERIAL_ECHO(z1);
5346
+      SERIAL_ECHOPGM(" z2="); SERIAL_ECHO(z2);
5347
+      SERIAL_ECHOPGM(" z3="); SERIAL_ECHO(z3);
5348
+      SERIAL_ECHOPGM(" z4="); SERIAL_ECHO(z4);
5349
+      SERIAL_ECHOPGM(" left="); SERIAL_ECHO(left);
5350
+      SERIAL_ECHOPGM(" right="); SERIAL_ECHO(right);
5351
+      SERIAL_ECHOPGM(" offset="); SERIAL_ECHOLN(offset);
5352
+      */
5353
+    }
5354
+  #endif // ENABLE_AUTO_BED_LEVELING
5362 5355
 
5363
-void prepare_move_raw()
5364
-{
5365
-  previous_millis_cmd = millis();
5366
-  calculate_delta(destination);
5367
-  plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS],
5368
-                   destination[E_AXIS], feedrate*feedmultiply/60/100.0,
5369
-                   active_extruder);
5370
-  for(int8_t i=0; i < NUM_AXIS; i++) {
5371
-    current_position[i] = destination[i];
5356
+  void prepare_move_raw() {
5357
+    previous_millis_cmd = millis();
5358
+    calculate_delta(destination);
5359
+    plan_buffer_line(delta[X_AXIS], delta[Y_AXIS], delta[Z_AXIS], destination[E_AXIS], (feedrate/60)*(feedmultiply/100.0), active_extruder);
5360
+    for (int i = 0; i < NUM_AXIS; i++) current_position[i] = destination[i];
5372 5361
   }
5373
-}
5374
-#endif //DELTA
5362
+
5363
+#endif // DELTA
5375 5364
 
5376 5365
 #if defined(MESH_BED_LEVELING)
5377
-#if !defined(MIN)
5378
-#define MIN(_v1, _v2) (((_v1) < (_v2)) ? (_v1) : (_v2))
5379
-#endif  // ! MIN
5366
+
5367
+  #if !defined(MIN)
5368
+    #define MIN(_v1, _v2) (((_v1) < (_v2)) ? (_v1) : (_v2))
5369
+  #endif  // ! MIN
5370
+
5380 5371
 // This function is used to split lines on mesh borders so each segment is only part of one mesh area
5381 5372
 void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t &extruder, uint8_t x_splits=0xff, uint8_t y_splits=0xff)
5382 5373
 {
@@ -5448,8 +5439,7 @@ void mesh_plan_buffer_line(float x, float y, float z, const float e, float feed_
5448 5439
 }
5449 5440
 #endif  // MESH_BED_LEVELING
5450 5441
 
5451
-void prepare_move()
5452
-{
5442
+void prepare_move() {
5453 5443
   clamp_to_software_endstops(destination);
5454 5444
   previous_millis_cmd = millis();
5455 5445
   
@@ -5563,7 +5553,7 @@ void prepare_move()
5563 5553
   }
5564 5554
 #endif //DUAL_X_CARRIAGE
5565 5555
 
5566
-#if ! (defined DELTA || defined SCARA)
5556
+#if !defined(DELTA) && !defined(SCARA)
5567 5557
   // Do not use feedmultiply for E or Z only moves
5568 5558
   if( (current_position[X_AXIS] == destination [X_AXIS]) && (current_position[Y_AXIS] == destination [Y_AXIS])) {
5569 5559
     line_to_destination();

+ 70
- 1
Marlin/Sd2PinMap.h Bestand weergeven

@@ -312,6 +312,75 @@ static const pin_map_t digitalPinMap[] = {
312 312
   {&DDRC, &PINC, &PORTC, 4},  // C4 18
313 313
   {&DDRC, &PINC, &PORTC, 5}   // C5 19
314 314
 };
315
+#elif defined(__AVR_ATmega1281__)
316
+// Waspmote
317
+ 
318
+// Two Wire (aka I2C) ports
319
+uint8_t const SDA_PIN = 41;
320
+uint8_t const SCL_PIN = 40;
321
+ 
322
+ 
323
+#undef MOSI_PIN
324
+#undef MISO_PIN
325
+// SPI port
326
+uint8_t const SS_PIN = 16;    // B0
327
+uint8_t const MOSI_PIN = 11;  // B2
328
+uint8_t const MISO_PIN = 12;  // B3
329
+uint8_t const SCK_PIN = 10;   // B1
330
+ 
331
+static const pin_map_t digitalPinMap[] = {
332
+    {&DDRE, &PINE, &PORTE, 0}, // E0 0
333
+    {&DDRE, &PINE, &PORTE, 1}, // E1 1
334
+    {&DDRE, &PINE, &PORTE, 3}, // E3 2
335
+    {&DDRE, &PINE, &PORTE, 4}, // E4 3
336
+    {&DDRC, &PINC, &PORTC, 4}, // C4 4
337
+    {&DDRC, &PINC, &PORTC, 5}, // C5 5
338
+    {&DDRC, &PINC, &PORTC, 6}, // C6 6
339
+    {&DDRC, &PINC, &PORTC, 7}, // C7 7
340
+    {&DDRA, &PINA, &PORTA, 2}, // A2 8
341
+    {&DDRA, &PINA, &PORTA, 3}, // A3 9
342
+    {&DDRA, &PINA, &PORTA, 4}, // A4 10
343
+    {&DDRD, &PIND, &PORTD, 5}, // D5 11
344
+    {&DDRD, &PIND, &PORTD, 6}, // D6 12
345
+    {&DDRC, &PINC, &PORTC, 1}, // C1 13
346
+    {&DDRF, &PINF, &PORTF, 1}, // F1 14
347
+    {&DDRF, &PINF, &PORTF, 2}, // F2 15
348
+    {&DDRF, &PINF, &PORTF, 3}, // F3 16
349
+    {&DDRF, &PINF, &PORTF, 4}, // F4 17
350
+    {&DDRF, &PINF, &PORTF, 5}, // F5 18
351
+    {&DDRF, &PINF, &PORTF, 6}, // F6 19
352
+    {&DDRF, &PINF, &PORTF, 7}, // F7 20
353
+    {&DDRF, &PINF, &PORTF, 0}, // F0 21
354
+    {&DDRA, &PINA, &PORTA, 1}, // A1 22
355
+    {&DDRD, &PIND, &PORTD, 7}, // D7 23
356
+    {&DDRE, &PINE, &PORTE, 5}, // E5 24
357
+    {&DDRA, &PINA, &PORTA, 6}, // A6 25
358
+    {&DDRE, &PINE, &PORTE, 2}, // E2 26
359
+    {&DDRA, &PINA, &PORTA, 5}, // A5 27
360
+    {&DDRC, &PINC, &PORTC, 0}, // C0 28
361
+    {&DDRB, &PINB, &PORTB, 0}, // B0 29
362
+    {&DDRB, &PINB, &PORTB, 1}, // B1 30
363
+    {&DDRB, &PINB, &PORTB, 2}, // B2 31
364
+    {&DDRB, &PINB, &PORTB, 3}, // B3 32
365
+    {&DDRB, &PINB, &PORTB, 4}, // B4 33
366
+    {&DDRB, &PINB, &PORTB, 5}, // B5 34
367
+    {&DDRA, &PINA, &PORTA, 0}, // A0 35
368
+    {&DDRB, &PINB, &PORTB, 6}, // B6 36
369
+    {&DDRB, &PINB, &PORTB, 7}, // B7 37
370
+    {&DDRE, &PINE, &PORTE, 6}, // E6 38
371
+    {&DDRE, &PINE, &PORTE, 7}, // E7 39
372
+    {&DDRD, &PIND, &PORTD, 0}, // D0 40
373
+    {&DDRD, &PIND, &PORTD, 1}, // D1 41
374
+    {&DDRC, &PINC, &PORTC, 3}, // C3 42
375
+    {&DDRD, &PIND, &PORTD, 2}, // D2 43
376
+    {&DDRD, &PIND, &PORTD, 3}, // D3 44
377
+    {&DDRA, &PINA, &PORTA, 7}, // A7 45
378
+    {&DDRC, &PINC, &PORTC, 2}, // C2 46
379
+    {&DDRD, &PIND, &PORTD, 4}, // D4 47
380
+    {&DDRG, &PING, &PORTG, 2}, // G2 48
381
+    {&DDRG, &PING, &PORTG, 1}, // G1 49
382
+    {&DDRG, &PING, &PORTG, 0}, // G0 50
383
+};
315 384
 #else  // defined(__AVR_ATmega1280__)
316 385
 #error unknown chip
317 386
 #endif  // defined(__AVR_ATmega1280__)
@@ -364,4 +433,4 @@ static inline __attribute__((always_inline))
364 433
 #endif  // Sd2PinMap_h
365 434
 
366 435
 
367
-#endif
436
+#endif

+ 2
- 1
Marlin/ultralcd.h Bestand weergeven

@@ -99,7 +99,8 @@
99 99
 #else //no LCD
100 100
   FORCE_INLINE void lcd_update() {}
101 101
   FORCE_INLINE void lcd_init() {}
102
-  FORCE_INLINE void lcd_setstatus(const char* message) {}
102
+  FORCE_INLINE void lcd_setstatus(const char* message, const bool persist=false) {}
103
+  FORCE_INLINE void lcd_setstatuspgm(const char* message, const uint8_t level=0) {}
103 104
   FORCE_INLINE void lcd_buttons_update() {}
104 105
   FORCE_INLINE void lcd_reset_alert_level() {}
105 106
   FORCE_INLINE void lcd_buzz(long duration,uint16_t freq) {}

Laden…
Annuleren
Opslaan