Преглед изворни кода

Merge pull request #5963 from thinkyhead/rc_no_offsets_optim

New option: NO_WORKSPACE_OFFSETS
Scott Lahteine пре 7 година
родитељ
комит
be98016674

+ 9
- 0
Marlin/Configuration_adv.h Прегледај датотеку

@@ -1169,4 +1169,13 @@
1169 1169
  */ 
1170 1170
 //#define VOLUMETRIC_DEFAULT_ON
1171 1171
 
1172
+/**
1173
+ * Enable this option for a leaner build of Marlin that removes all
1174
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1175
+ *
1176
+ *  - M206 and M428 are disabled.
1177
+ *  - G92 will revert to its behavior from Marlin 1.0.
1178
+ */
1179
+//#define NO_WORKSPACE_OFFSETS
1180
+
1172 1181
 #endif // CONFIGURATION_ADV_H

+ 26
- 14
Marlin/Marlin.h Прегледај датотеку

@@ -275,15 +275,35 @@ extern volatile bool wait_for_heatup;
275 275
 #endif
276 276
 
277 277
 extern float current_position[NUM_AXIS];
278
-extern float position_shift[XYZ];
279
-extern float home_offset[XYZ];
278
+
279
+// Workspace offsets
280
+#if DISABLED(NO_WORKSPACE_OFFSETS)
281
+  extern float position_shift[XYZ],
282
+               home_offset[XYZ],
283
+               workspace_offset[XYZ];
284
+  #define LOGICAL_POSITION(POS, AXIS) ((POS) + workspace_offset[AXIS])
285
+  #define RAW_POSITION(POS, AXIS)     ((POS) - workspace_offset[AXIS])
286
+#else
287
+  #define LOGICAL_POSITION(POS, AXIS) (POS)
288
+  #define RAW_POSITION(POS, AXIS)     (POS)
289
+#endif
290
+
291
+#define LOGICAL_X_POSITION(POS)     LOGICAL_POSITION(POS, X_AXIS)
292
+#define LOGICAL_Y_POSITION(POS)     LOGICAL_POSITION(POS, Y_AXIS)
293
+#define LOGICAL_Z_POSITION(POS)     LOGICAL_POSITION(POS, Z_AXIS)
294
+#define RAW_X_POSITION(POS)         RAW_POSITION(POS, X_AXIS)
295
+#define RAW_Y_POSITION(POS)         RAW_POSITION(POS, Y_AXIS)
296
+#define RAW_Z_POSITION(POS)         RAW_POSITION(POS, Z_AXIS)
297
+#define RAW_CURRENT_POSITION(AXIS)  RAW_POSITION(current_position[AXIS], AXIS)
280 298
 
281 299
 #if HOTENDS > 1
282 300
   extern float hotend_offset[XYZ][HOTENDS];
283 301
 #endif
284 302
 
285 303
 // Software Endstops
286
-void update_software_endstops(AxisEnum axis);
304
+extern float soft_endstop_min[XYZ];
305
+extern float soft_endstop_max[XYZ];
306
+
287 307
 #if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
288 308
   extern bool soft_endstops_enabled;
289 309
   void clamp_to_software_endstops(float target[XYZ]);
@@ -291,18 +311,10 @@ void update_software_endstops(AxisEnum axis);
291 311
   #define soft_endstops_enabled false
292 312
   #define clamp_to_software_endstops(x) NOOP
293 313
 #endif
294
-extern float soft_endstop_min[XYZ];
295
-extern float soft_endstop_max[XYZ];
296 314
 
297
-#define LOGICAL_POSITION(POS, AXIS) ((POS) + home_offset[AXIS] + position_shift[AXIS])
298
-#define RAW_POSITION(POS, AXIS)     ((POS) - home_offset[AXIS] - position_shift[AXIS])
299
-#define LOGICAL_X_POSITION(POS)     LOGICAL_POSITION(POS, X_AXIS)
300
-#define LOGICAL_Y_POSITION(POS)     LOGICAL_POSITION(POS, Y_AXIS)
301
-#define LOGICAL_Z_POSITION(POS)     LOGICAL_POSITION(POS, Z_AXIS)
302
-#define RAW_X_POSITION(POS)         RAW_POSITION(POS, X_AXIS)
303
-#define RAW_Y_POSITION(POS)         RAW_POSITION(POS, Y_AXIS)
304
-#define RAW_Z_POSITION(POS)         RAW_POSITION(POS, Z_AXIS)
305
-#define RAW_CURRENT_POSITION(AXIS)  RAW_POSITION(current_position[AXIS], AXIS)
315
+#if DISABLED(NO_WORKSPACE_OFFSETS) || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
316
+  void update_software_endstops(const AxisEnum axis);
317
+#endif
306 318
 
307 319
 // GCode support for external objects
308 320
 bool code_seen(char);

+ 189
- 148
Marlin/Marlin_main.cpp Прегледај датотеку

@@ -396,12 +396,19 @@ bool axis_relative_modes[] = AXIS_RELATIVE_MODES,
396 396
 float filament_size[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(DEFAULT_NOMINAL_FILAMENT_DIA),
397 397
       volumetric_multiplier[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(1.0);
398 398
 
399
-// The distance that XYZ has been offset by G92. Reset by G28.
400
-float position_shift[XYZ] = { 0 };
399
+#if DISABLED(NO_WORKSPACE_OFFSETS)
401 400
 
402
-// This offset is added to the configured home position.
403
-// Set by M206, M428, or menu item. Saved to EEPROM.
404
-float home_offset[XYZ] = { 0 };
401
+  // The distance that XYZ has been offset by G92. Reset by G28.
402
+  float position_shift[XYZ] = { 0 };
403
+
404
+  // This offset is added to the configured home position.
405
+  // Set by M206, M428, or menu item. Saved to EEPROM.
406
+  float home_offset[XYZ] = { 0 };
407
+
408
+  // The above two are combined to save on computes
409
+  float workspace_offset[XYZ] = { 0 };
410
+
411
+#endif
405 412
 
406 413
 // Software Endstops are based on the configured limits.
407 414
 #if ENABLED(min_software_endstops) || ENABLED(max_software_endstops)
@@ -1333,76 +1340,83 @@ bool get_target_extruder_from_command(int code) {
1333 1340
 
1334 1341
 #endif // DUAL_X_CARRIAGE
1335 1342
 
1336
-/**
1337
- * Software endstops can be used to monitor the open end of
1338
- * an axis that has a hardware endstop on the other end. Or
1339
- * they can prevent axes from moving past endstops and grinding.
1340
- *
1341
- * To keep doing their job as the coordinate system changes,
1342
- * the software endstop positions must be refreshed to remain
1343
- * at the same positions relative to the machine.
1344
- */
1345
-void update_software_endstops(AxisEnum axis) {
1346
-  float offs = LOGICAL_POSITION(0, axis);
1343
+#if DISABLED(NO_WORKSPACE_OFFSETS) || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
1347 1344
 
1348
-  #if ENABLED(DUAL_X_CARRIAGE)
1349
-    if (axis == X_AXIS) {
1345
+  /**
1346
+   * Software endstops can be used to monitor the open end of
1347
+   * an axis that has a hardware endstop on the other end. Or
1348
+   * they can prevent axes from moving past endstops and grinding.
1349
+   *
1350
+   * To keep doing their job as the coordinate system changes,
1351
+   * the software endstop positions must be refreshed to remain
1352
+   * at the same positions relative to the machine.
1353
+   */
1354
+  void update_software_endstops(const AxisEnum axis) {
1355
+    const float offs = workspace_offset[axis] = LOGICAL_POSITION(0, axis);
1350 1356
 
1351
-      // In Dual X mode hotend_offset[X] is T1's home position
1352
-      float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
1357
+    #if ENABLED(DUAL_X_CARRIAGE)
1358
+      if (axis == X_AXIS) {
1353 1359
 
1354
-      if (active_extruder != 0) {
1355
-        // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
1356
-        soft_endstop_min[X_AXIS] = X2_MIN_POS + offs;
1357
-        soft_endstop_max[X_AXIS] = dual_max_x + offs;
1358
-      }
1359
-      else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
1360
-        // In Duplication Mode, T0 can move as far left as X_MIN_POS
1361
-        // but not so far to the right that T1 would move past the end
1362
-        soft_endstop_min[X_AXIS] = base_min_pos(X_AXIS) + offs;
1363
-        soft_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset) + offs;
1364
-      }
1365
-      else {
1366
-        // In other modes, T0 can move from X_MIN_POS to X_MAX_POS
1367
-        soft_endstop_min[axis] = base_min_pos(axis) + offs;
1368
-        soft_endstop_max[axis] = base_max_pos(axis) + offs;
1360
+        // In Dual X mode hotend_offset[X] is T1's home position
1361
+        float dual_max_x = max(hotend_offset[X_AXIS][1], X2_MAX_POS);
1362
+
1363
+        if (active_extruder != 0) {
1364
+          // T1 can move from X2_MIN_POS to X2_MAX_POS or X2 home position (whichever is larger)
1365
+          soft_endstop_min[X_AXIS] = X2_MIN_POS + offs;
1366
+          soft_endstop_max[X_AXIS] = dual_max_x + offs;
1367
+        }
1368
+        else if (dual_x_carriage_mode == DXC_DUPLICATION_MODE) {
1369
+          // In Duplication Mode, T0 can move as far left as X_MIN_POS
1370
+          // but not so far to the right that T1 would move past the end
1371
+          soft_endstop_min[X_AXIS] = base_min_pos(X_AXIS) + offs;
1372
+          soft_endstop_max[X_AXIS] = min(base_max_pos(X_AXIS), dual_max_x - duplicate_extruder_x_offset) + offs;
1373
+        }
1374
+        else {
1375
+          // In other modes, T0 can move from X_MIN_POS to X_MAX_POS
1376
+          soft_endstop_min[axis] = base_min_pos(axis) + offs;
1377
+          soft_endstop_max[axis] = base_max_pos(axis) + offs;
1378
+        }
1369 1379
       }
1370
-    }
1371
-  #else
1372
-    soft_endstop_min[axis] = base_min_pos(axis) + offs;
1373
-    soft_endstop_max[axis] = base_max_pos(axis) + offs;
1374
-  #endif
1380
+    #else
1381
+      soft_endstop_min[axis] = base_min_pos(axis) + offs;
1382
+      soft_endstop_max[axis] = base_max_pos(axis) + offs;
1383
+    #endif
1375 1384
 
1376
-  #if ENABLED(DEBUG_LEVELING_FEATURE)
1377
-    if (DEBUGGING(LEVELING)) {
1378
-      SERIAL_ECHOPAIR("For ", axis_codes[axis]);
1379
-      SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
1380
-      SERIAL_ECHOPAIR("\n position_shift = ", position_shift[axis]);
1381
-      SERIAL_ECHOPAIR("\n soft_endstop_min = ", soft_endstop_min[axis]);
1382
-      SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
1383
-    }
1384
-  #endif
1385
+    #if ENABLED(DEBUG_LEVELING_FEATURE)
1386
+      if (DEBUGGING(LEVELING)) {
1387
+        SERIAL_ECHOPAIR("For ", axis_codes[axis]);
1388
+        #if DISABLED(NO_WORKSPACE_OFFSETS)
1389
+          SERIAL_ECHOPAIR(" axis:\n home_offset = ", home_offset[axis]);
1390
+          SERIAL_ECHOPAIR("\n position_shift = ", position_shift[axis]);
1391
+        #endif
1392
+        SERIAL_ECHOPAIR("\n soft_endstop_min = ", soft_endstop_min[axis]);
1393
+        SERIAL_ECHOLNPAIR("\n soft_endstop_max = ", soft_endstop_max[axis]);
1394
+      }
1395
+    #endif
1385 1396
 
1386
-  #if ENABLED(DELTA)
1387
-    if (axis == Z_AXIS)
1388
-      delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1389
-  #endif
1397
+    #if ENABLED(DELTA)
1398
+      if (axis == Z_AXIS)
1399
+        delta_clip_start_height = soft_endstop_max[axis] - delta_safe_distance_from_top();
1400
+    #endif
1401
+  }
1390 1402
 
1391
-}
1403
+#endif // NO_WORKSPACE_OFFSETS
1392 1404
 
1393
-/**
1394
- * Change the home offset for an axis, update the current
1395
- * position and the software endstops to retain the same
1396
- * relative distance to the new home.
1397
- *
1398
- * Since this changes the current_position, code should
1399
- * call sync_plan_position soon after this.
1400
- */
1401
-static void set_home_offset(AxisEnum axis, float v) {
1402
-  current_position[axis] += v - home_offset[axis];
1403
-  home_offset[axis] = v;
1404
-  update_software_endstops(axis);
1405
-}
1405
+#if DISABLED(NO_WORKSPACE_OFFSETS)
1406
+  /**
1407
+   * Change the home offset for an axis, update the current
1408
+   * position and the software endstops to retain the same
1409
+   * relative distance to the new home.
1410
+   *
1411
+   * Since this changes the current_position, code should
1412
+   * call sync_plan_position soon after this.
1413
+   */
1414
+  static void set_home_offset(const AxisEnum axis, const float v) {
1415
+    current_position[axis] += v - home_offset[axis];
1416
+    home_offset[axis] = v;
1417
+    update_software_endstops(axis);
1418
+  }
1419
+#endif // NO_WORKSPACE_OFFSETS
1406 1420
 
1407 1421
 /**
1408 1422
  * Set an axis' current position to its home position (after homing).
@@ -1433,8 +1447,10 @@ static void set_axis_is_at_home(AxisEnum axis) {
1433 1447
 
1434 1448
   axis_known_position[axis] = axis_homed[axis] = true;
1435 1449
 
1436
-  position_shift[axis] = 0;
1437
-  update_software_endstops(axis);
1450
+  #if DISABLED(NO_WORKSPACE_OFFSETS)
1451
+    position_shift[axis] = 0;
1452
+    update_software_endstops(axis);
1453
+  #endif
1438 1454
 
1439 1455
   #if ENABLED(DUAL_X_CARRIAGE)
1440 1456
     if (axis == X_AXIS && (active_extruder == 1 || dual_x_carriage_mode == DXC_DUPLICATION_MODE)) {
@@ -1507,8 +1523,10 @@ static void set_axis_is_at_home(AxisEnum axis) {
1507 1523
 
1508 1524
   #if ENABLED(DEBUG_LEVELING_FEATURE)
1509 1525
     if (DEBUGGING(LEVELING)) {
1510
-      SERIAL_ECHOPAIR("> home_offset[", axis_codes[axis]);
1511
-      SERIAL_ECHOLNPAIR("] = ", home_offset[axis]);
1526
+      #if DISABLED(NO_WORKSPACE_OFFSETS)
1527
+        SERIAL_ECHOPAIR("> home_offset[", axis_codes[axis]);
1528
+        SERIAL_ECHOLNPAIR("] = ", home_offset[axis]);
1529
+      #endif
1512 1530
       DEBUG_POS("", current_position);
1513 1531
       SERIAL_ECHOPAIR("<<< set_axis_is_at_home(", axis_codes[axis]);
1514 1532
       SERIAL_CHAR(')');
@@ -1549,8 +1567,8 @@ inline void line_to_destination(float fr_mm_s) {
1549 1567
 }
1550 1568
 inline void line_to_destination() { line_to_destination(feedrate_mm_s); }
1551 1569
 
1552
-inline void set_current_to_destination() { memcpy(current_position, destination, sizeof(current_position)); }
1553
-inline void set_destination_to_current() { memcpy(destination, current_position, sizeof(destination)); }
1570
+inline void set_current_to_destination() { COPY(current_position, destination); }
1571
+inline void set_destination_to_current() { COPY(destination, current_position); }
1554 1572
 
1555 1573
 #if IS_KINEMATIC
1556 1574
   /**
@@ -3557,7 +3575,7 @@ inline void gcode_G28() {
3557 3575
         HOMEAXIS(X);
3558 3576
 
3559 3577
         // Consider the active extruder to be parked
3560
-        memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
3578
+        COPY(raised_parked_position, current_position);
3561 3579
         delayed_move_time = 0;
3562 3580
         active_extruder_parked = true;
3563 3581
 
@@ -4357,7 +4375,7 @@ inline void gcode_G28() {
4357 4375
         #endif
4358 4376
 
4359 4377
         float converted[XYZ];
4360
-        memcpy(converted, current_position, sizeof(converted));
4378
+        COPY(converted, current_position);
4361 4379
 
4362 4380
         planner.abl_enabled = true;
4363 4381
         planner.unapply_leveling(converted); // use conversion machinery
@@ -4379,7 +4397,7 @@ inline void gcode_G28() {
4379 4397
         }
4380 4398
 
4381 4399
         // The rotated XY and corrected Z are now current_position
4382
-        memcpy(current_position, converted, sizeof(converted));
4400
+        COPY(current_position, converted);
4383 4401
 
4384 4402
         #if ENABLED(DEBUG_LEVELING_FEATURE)
4385 4403
           if (DEBUGGING(LEVELING)) DEBUG_POS("G29 corrected XYZ", current_position);
@@ -4595,8 +4613,10 @@ inline void gcode_G92() {
4595 4613
 
4596 4614
         if (i != E_AXIS) {
4597 4615
           didXYZ = true;
4598
-          position_shift[i] += v - p; // Offset the coordinate space
4599
-          update_software_endstops((AxisEnum)i);
4616
+          #if DISABLED(NO_WORKSPACE_OFFSETS)
4617
+            position_shift[i] += v - p; // Offset the coordinate space
4618
+            update_software_endstops((AxisEnum)i);
4619
+          #endif
4600 4620
         }
4601 4621
       #endif
4602 4622
     }
@@ -6326,22 +6346,26 @@ inline void gcode_M205() {
6326 6346
   if (code_seen('E')) planner.max_jerk[E_AXIS] = code_value_axis_units(E_AXIS);
6327 6347
 }
6328 6348
 
6329
-/**
6330
- * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
6331
- */
6332
-inline void gcode_M206() {
6333
-  LOOP_XYZ(i)
6334
-    if (code_seen(axis_codes[i]))
6335
-      set_home_offset((AxisEnum)i, code_value_axis_units(i));
6349
+#if DISABLED(NO_WORKSPACE_OFFSETS)
6336 6350
 
6337
-  #if ENABLED(MORGAN_SCARA)
6338
-    if (code_seen('T')) set_home_offset(A_AXIS, code_value_axis_units(A_AXIS)); // Theta
6339
-    if (code_seen('P')) set_home_offset(B_AXIS, code_value_axis_units(B_AXIS)); // Psi
6340
-  #endif
6351
+  /**
6352
+   * M206: Set Additional Homing Offset (X Y Z). SCARA aliases T=X, P=Y
6353
+   */
6354
+  inline void gcode_M206() {
6355
+    LOOP_XYZ(i)
6356
+      if (code_seen(axis_codes[i]))
6357
+        set_home_offset((AxisEnum)i, code_value_axis_units(i));
6341 6358
 
6342
-  SYNC_PLAN_POSITION_KINEMATIC();
6343
-  report_current_position();
6344
-}
6359
+    #if ENABLED(MORGAN_SCARA)
6360
+      if (code_seen('T')) set_home_offset(A_AXIS, code_value_axis_units(A_AXIS)); // Theta
6361
+      if (code_seen('P')) set_home_offset(B_AXIS, code_value_axis_units(B_AXIS)); // Psi
6362
+    #endif
6363
+
6364
+    SYNC_PLAN_POSITION_KINEMATIC();
6365
+    report_current_position();
6366
+  }
6367
+
6368
+#endif // NO_WORKSPACE_OFFSETS
6345 6369
 
6346 6370
 #if ENABLED(DELTA)
6347 6371
   /**
@@ -7165,45 +7189,49 @@ void quickstop_stepper() {
7165 7189
 
7166 7190
 #endif
7167 7191
 
7168
-/**
7169
- * M428: Set home_offset based on the distance between the
7170
- *       current_position and the nearest "reference point."
7171
- *       If an axis is past center its endstop position
7172
- *       is the reference-point. Otherwise it uses 0. This allows
7173
- *       the Z offset to be set near the bed when using a max endstop.
7174
- *
7175
- *       M428 can't be used more than 2cm away from 0 or an endstop.
7176
- *
7177
- *       Use M206 to set these values directly.
7178
- */
7179
-inline void gcode_M428() {
7180
-  bool err = false;
7181
-  LOOP_XYZ(i) {
7182
-    if (axis_homed[i]) {
7183
-      float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7184
-            diff = current_position[i] - LOGICAL_POSITION(base, i);
7185
-      if (diff > -20 && diff < 20) {
7186
-        set_home_offset((AxisEnum)i, home_offset[i] - diff);
7187
-      }
7188
-      else {
7189
-        SERIAL_ERROR_START;
7190
-        SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
7191
-        LCD_ALERTMESSAGEPGM("Err: Too far!");
7192
-        BUZZ(200, 40);
7193
-        err = true;
7194
-        break;
7192
+#if DISABLED(NO_WORKSPACE_OFFSETS)
7193
+
7194
+  /**
7195
+   * M428: Set home_offset based on the distance between the
7196
+   *       current_position and the nearest "reference point."
7197
+   *       If an axis is past center its endstop position
7198
+   *       is the reference-point. Otherwise it uses 0. This allows
7199
+   *       the Z offset to be set near the bed when using a max endstop.
7200
+   *
7201
+   *       M428 can't be used more than 2cm away from 0 or an endstop.
7202
+   *
7203
+   *       Use M206 to set these values directly.
7204
+   */
7205
+  inline void gcode_M428() {
7206
+    bool err = false;
7207
+    LOOP_XYZ(i) {
7208
+      if (axis_homed[i]) {
7209
+        float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7210
+              diff = current_position[i] - LOGICAL_POSITION(base, i);
7211
+        if (diff > -20 && diff < 20) {
7212
+          set_home_offset((AxisEnum)i, home_offset[i] - diff);
7213
+        }
7214
+        else {
7215
+          SERIAL_ERROR_START;
7216
+          SERIAL_ERRORLNPGM(MSG_ERR_M428_TOO_FAR);
7217
+          LCD_ALERTMESSAGEPGM("Err: Too far!");
7218
+          BUZZ(200, 40);
7219
+          err = true;
7220
+          break;
7221
+        }
7195 7222
       }
7196 7223
     }
7197
-  }
7198 7224
 
7199
-  if (!err) {
7200
-    SYNC_PLAN_POSITION_KINEMATIC();
7201
-    report_current_position();
7202
-    LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
7203
-    BUZZ(200, 659);
7204
-    BUZZ(200, 698);
7225
+    if (!err) {
7226
+      SYNC_PLAN_POSITION_KINEMATIC();
7227
+      report_current_position();
7228
+      LCD_MESSAGEPGM(MSG_HOME_OFFSETS_APPLIED);
7229
+      BUZZ(200, 659);
7230
+      BUZZ(200, 698);
7231
+    }
7205 7232
   }
7206
-}
7233
+
7234
+#endif // NO_WORKSPACE_OFFSETS
7207 7235
 
7208 7236
 /**
7209 7237
  * M500: Store settings in EEPROM
@@ -7929,7 +7957,7 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
7929 7957
               break;
7930 7958
             case DXC_AUTO_PARK_MODE:
7931 7959
               // record raised toolhead position for use by unpark
7932
-              memcpy(raised_parked_position, current_position, sizeof(raised_parked_position));
7960
+              COPY(raised_parked_position, current_position);
7933 7961
               raised_parked_position[Z_AXIS] += TOOLCHANGE_UNPARK_ZLIFT;
7934 7962
               #if ENABLED(max_software_endstops)
7935 7963
                 NOMORE(raised_parked_position[Z_AXIS], soft_endstop_max[Z_AXIS]);
@@ -8073,10 +8101,14 @@ void tool_change(const uint8_t tmp_extruder, const float fr_mm_s/*=0.0*/, bool n
8073 8101
           // The newly-selected extruder XY is actually at...
8074 8102
           current_position[X_AXIS] += xydiff[X_AXIS];
8075 8103
           current_position[Y_AXIS] += xydiff[Y_AXIS];
8076
-          for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
8077
-            position_shift[i] += xydiff[i];
8078
-            update_software_endstops((AxisEnum)i);
8079
-          }
8104
+          #if DISABLED(NO_WORKSPACE_OFFSETS) || ENABLED(DUAL_X_CARRIAGE)
8105
+            for (uint8_t i = X_AXIS; i <= Y_AXIS; i++) {
8106
+              #if DISABLED(NO_WORKSPACE_OFFSETS)
8107
+                position_shift[i] += xydiff[i];
8108
+              #endif
8109
+              update_software_endstops((AxisEnum)i);
8110
+            }
8111
+          #endif
8080 8112
 
8081 8113
           // Set the new active extruder
8082 8114
           active_extruder = tmp_extruder;
@@ -8631,9 +8663,12 @@ void process_next_command() {
8631 8663
       case 205: //M205: Set advanced settings
8632 8664
         gcode_M205();
8633 8665
         break;
8634
-      case 206: // M206: Set home offsets
8635
-        gcode_M206();
8636
-        break;
8666
+
8667
+      #if DISABLED(NO_WORKSPACE_OFFSETS)
8668
+        case 206: // M206: Set home offsets
8669
+          gcode_M206();
8670
+          break;
8671
+      #endif
8637 8672
 
8638 8673
       #if ENABLED(DELTA)
8639 8674
         case 665: // M665: Set delta configurations
@@ -8797,9 +8832,11 @@ void process_next_command() {
8797 8832
           break;
8798 8833
       #endif
8799 8834
 
8800
-      case 428: // M428: Apply current_position to home_offset
8801
-        gcode_M428();
8802
-        break;
8835
+      #if DISABLED(NO_WORKSPACE_OFFSETS)
8836
+        case 428: // M428: Apply current_position to home_offset
8837
+          gcode_M428();
8838
+          break;
8839
+      #endif
8803 8840
 
8804 8841
       case 500: // M500: Store settings in EEPROM
8805 8842
         gcode_M500();
@@ -9287,7 +9324,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9287 9324
     planner.unapply_leveling(cartes);
9288 9325
   #endif
9289 9326
   if (axis == ALL_AXES)
9290
-    memcpy(current_position, cartes, sizeof(cartes));
9327
+    COPY(current_position, cartes);
9291 9328
   else
9292 9329
     current_position[axis] = cartes[axis];
9293 9330
 }
@@ -9322,14 +9359,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9322 9359
     // Split at the left/front border of the right/top square
9323 9360
     int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
9324 9361
     if (cx2 != cx1 && TEST(x_splits, gcx)) {
9325
-      memcpy(end, destination, sizeof(end));
9362
+      COPY(end, destination);
9326 9363
       destination[X_AXIS] = LOGICAL_X_POSITION(mbl.get_probe_x(gcx));
9327 9364
       normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
9328 9365
       destination[Y_AXIS] = MBL_SEGMENT_END(Y);
9329 9366
       CBI(x_splits, gcx);
9330 9367
     }
9331 9368
     else if (cy2 != cy1 && TEST(y_splits, gcy)) {
9332
-      memcpy(end, destination, sizeof(end));
9369
+      COPY(end, destination);
9333 9370
       destination[Y_AXIS] = LOGICAL_Y_POSITION(mbl.get_probe_y(gcy));
9334 9371
       normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
9335 9372
       destination[X_AXIS] = MBL_SEGMENT_END(X);
@@ -9349,7 +9386,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9349 9386
     mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
9350 9387
 
9351 9388
     // Restore destination from stack
9352
-    memcpy(destination, end, sizeof(end));
9389
+    COPY(destination, end);
9353 9390
     mesh_line_to_destination(fr_mm_s, x_splits, y_splits);
9354 9391
   }
9355 9392
 
@@ -9385,14 +9422,14 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9385 9422
     // Split at the left/front border of the right/top square
9386 9423
     int8_t gcx = max(cx1, cx2), gcy = max(cy1, cy2);
9387 9424
     if (cx2 != cx1 && TEST(x_splits, gcx)) {
9388
-      memcpy(end, destination, sizeof(end));
9425
+      COPY(end, destination);
9389 9426
       destination[X_AXIS] = LOGICAL_X_POSITION(bilinear_start[X_AXIS] + ABL_BG_SPACING(X_AXIS) * gcx);
9390 9427
       normalized_dist = (destination[X_AXIS] - current_position[X_AXIS]) / (end[X_AXIS] - current_position[X_AXIS]);
9391 9428
       destination[Y_AXIS] = LINE_SEGMENT_END(Y);
9392 9429
       CBI(x_splits, gcx);
9393 9430
     }
9394 9431
     else if (cy2 != cy1 && TEST(y_splits, gcy)) {
9395
-      memcpy(end, destination, sizeof(end));
9432
+      COPY(end, destination);
9396 9433
       destination[Y_AXIS] = LOGICAL_Y_POSITION(bilinear_start[Y_AXIS] + ABL_BG_SPACING(Y_AXIS) * gcy);
9397 9434
       normalized_dist = (destination[Y_AXIS] - current_position[Y_AXIS]) / (end[Y_AXIS] - current_position[Y_AXIS]);
9398 9435
       destination[X_AXIS] = LINE_SEGMENT_END(X);
@@ -9412,7 +9449,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9412 9449
     bilinear_line_to_destination(fr_mm_s, x_splits, y_splits);
9413 9450
 
9414 9451
     // Restore destination from stack
9415
-    memcpy(destination, end, sizeof(end));
9452
+    COPY(destination, end);
9416 9453
     bilinear_line_to_destination(fr_mm_s, x_splits, y_splits);
9417 9454
   }
9418 9455
 
@@ -9507,7 +9544,7 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
9507 9544
 
9508 9545
       // Get the logical current position as starting point
9509 9546
       float logical[XYZE];
9510
-      memcpy(logical, current_position, sizeof(logical));
9547
+      COPY(logical, current_position);
9511 9548
 
9512 9549
       #define DELTA_VAR logical
9513 9550
 
@@ -10480,8 +10517,12 @@ void setup() {
10480 10517
   // This also updates variables in the planner, elsewhere
10481 10518
   Config_RetrieveSettings();
10482 10519
 
10483
-  // Initialize current position based on home_offset
10484
-  memcpy(current_position, home_offset, sizeof(home_offset));
10520
+  #if DISABLED(NO_WORKSPACE_OFFSETS)
10521
+    // Initialize current position based on home_offset
10522
+    COPY(current_position, home_offset);
10523
+  #else
10524
+    ZERO(current_position);
10525
+  #endif
10485 10526
 
10486 10527
   // Vital to init stepper/planner equivalent for current_position
10487 10528
   SYNC_PLAN_POSITION_KINEMATIC();

+ 3
- 1
Marlin/Version.h Прегледај датотеку

@@ -61,7 +61,9 @@
61 61
   #define REQUIRED_CONFIGURATION_ADV_H_VERSION 010100
62 62
 
63 63
   /**
64
-   * @todo: Missing documentation block
64
+   * The protocol for communication to the host. Protocol indicates communication
65
+   * standards such as the use of ASCII, "echo:" and "error:" line prefixes, etc.
66
+   * (Other behaviors are given by the firmware version and capabilities report.)
65 67
    */
66 68
   #define PROTOCOL_VERSION "1.0"
67 69
 

+ 24
- 11
Marlin/configuration_store.cpp Прегледај датотеку

@@ -171,8 +171,10 @@ void Config_Postprocess() {
171 171
 
172 172
   calculate_volumetric_multipliers();
173 173
 
174
-  // Software endstops depend on home_offset
175
-  LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
174
+  #if DISABLED(NO_WORKSPACE_OFFSETS) || ENABLED(DUAL_X_CARRIAGE) || ENABLED(DELTA)
175
+    // Software endstops depend on home_offset
176
+    LOOP_XYZ(i) update_software_endstops((AxisEnum)i);
177
+  #endif
176 178
 }
177 179
 
178 180
 #if ENABLED(EEPROM_SETTINGS)
@@ -251,6 +253,9 @@ void Config_Postprocess() {
251 253
     EEPROM_WRITE(planner.min_travel_feedrate_mm_s);
252 254
     EEPROM_WRITE(planner.min_segment_time);
253 255
     EEPROM_WRITE(planner.max_jerk);
256
+    #if ENABLED(NO_WORKSPACE_OFFSETS)
257
+      float home_offset[XYZ] = { 0 };
258
+    #endif
254 259
     EEPROM_WRITE(home_offset);
255 260
 
256 261
     #if HOTENDS > 1
@@ -501,6 +506,10 @@ void Config_Postprocess() {
501 506
       EEPROM_READ(planner.min_travel_feedrate_mm_s);
502 507
       EEPROM_READ(planner.min_segment_time);
503 508
       EEPROM_READ(planner.max_jerk);
509
+
510
+      #if ENABLED(NO_WORKSPACE_OFFSETS)
511
+        float home_offset[XYZ];
512
+      #endif
504 513
       EEPROM_READ(home_offset);
505 514
 
506 515
       #if HOTENDS > 1
@@ -729,7 +738,9 @@ void Config_ResetDefault() {
729 738
   planner.max_jerk[Y_AXIS] = DEFAULT_YJERK;
730 739
   planner.max_jerk[Z_AXIS] = DEFAULT_ZJERK;
731 740
   planner.max_jerk[E_AXIS] = DEFAULT_EJERK;
732
-  home_offset[X_AXIS] = home_offset[Y_AXIS] = home_offset[Z_AXIS] = 0;
741
+  #if DISABLED(NO_WORKSPACE_OFFSETS)
742
+    ZERO(home_offset);
743
+  #endif
733 744
 
734 745
   #if HOTENDS > 1
735 746
     constexpr float tmp4[XYZ][HOTENDS] = {
@@ -940,15 +951,17 @@ void Config_ResetDefault() {
940 951
     SERIAL_ECHOPAIR(" E", planner.max_jerk[E_AXIS]);
941 952
     SERIAL_EOL;
942 953
 
943
-    CONFIG_ECHO_START;
944
-    if (!forReplay) {
945
-      SERIAL_ECHOLNPGM("Home offset (mm)");
954
+    #if DISABLED(NO_WORKSPACE_OFFSETS)
946 955
       CONFIG_ECHO_START;
947
-    }
948
-    SERIAL_ECHOPAIR("  M206 X", home_offset[X_AXIS]);
949
-    SERIAL_ECHOPAIR(" Y", home_offset[Y_AXIS]);
950
-    SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
951
-    SERIAL_EOL;
956
+      if (!forReplay) {
957
+        SERIAL_ECHOLNPGM("Home offset (mm)");
958
+        CONFIG_ECHO_START;
959
+      }
960
+      SERIAL_ECHOPAIR("  M206 X", home_offset[X_AXIS]);
961
+      SERIAL_ECHOPAIR(" Y", home_offset[Y_AXIS]);
962
+      SERIAL_ECHOPAIR(" Z", home_offset[Z_AXIS]);
963
+      SERIAL_EOL;
964
+    #endif
952 965
 
953 966
     #if HOTENDS > 1
954 967
       CONFIG_ECHO_START;

+ 9
- 0
Marlin/example_configurations/Cartesio/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/Felix/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/Hephestos/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/Hephestos_2/Configuration_adv.h Прегледај датотеку

@@ -1149,4 +1149,13 @@
1149 1149
  */ 
1150 1150
 //#define VOLUMETRIC_DEFAULT_ON
1151 1151
 
1152
+/**
1153
+ * Enable this option for a leaner build of Marlin that removes all
1154
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1155
+ *
1156
+ *  - M206 and M428 are disabled.
1157
+ *  - G92 will revert to its behavior from Marlin 1.0.
1158
+ */
1159
+//#define NO_WORKSPACE_OFFSETS
1160
+
1152 1161
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/K8200/Configuration_adv.h Прегледај датотеку

@@ -1179,4 +1179,13 @@
1179 1179
  */ 
1180 1180
 //#define VOLUMETRIC_DEFAULT_ON
1181 1181
 
1182
+/**
1183
+ * Enable this option for a leaner build of Marlin that removes all
1184
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1185
+ *
1186
+ *  - M206 and M428 are disabled.
1187
+ *  - G92 will revert to its behavior from Marlin 1.0.
1188
+ */
1189
+//#define NO_WORKSPACE_OFFSETS
1190
+
1182 1191
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/K8400/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/RigidBot/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/SCARA/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/TAZ4/Configuration_adv.h Прегледај датотеку

@@ -1174,4 +1174,13 @@
1174 1174
  */ 
1175 1175
 //#define VOLUMETRIC_DEFAULT_ON
1176 1176
 
1177
+/**
1178
+ * Enable this option for a leaner build of Marlin that removes all
1179
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1180
+ *
1181
+ *  - M206 and M428 are disabled.
1182
+ *  - G92 will revert to its behavior from Marlin 1.0.
1183
+ */
1184
+//#define NO_WORKSPACE_OFFSETS
1185
+
1177 1186
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/WITBOX/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/delta/generic/Configuration_adv.h Прегледај датотеку

@@ -1168,4 +1168,13 @@
1168 1168
  */ 
1169 1169
 //#define VOLUMETRIC_DEFAULT_ON
1170 1170
 
1171
+/**
1172
+ * Enable this option for a leaner build of Marlin that removes all
1173
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1174
+ *
1175
+ *  - M206 and M428 are disabled.
1176
+ *  - G92 will revert to its behavior from Marlin 1.0.
1177
+ */
1178
+//#define NO_WORKSPACE_OFFSETS
1179
+
1171 1180
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/delta/kossel_mini/Configuration_adv.h Прегледај датотеку

@@ -1168,4 +1168,13 @@
1168 1168
  */ 
1169 1169
 //#define VOLUMETRIC_DEFAULT_ON
1170 1170
 
1171
+/**
1172
+ * Enable this option for a leaner build of Marlin that removes all
1173
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1174
+ *
1175
+ *  - M206 and M428 are disabled.
1176
+ *  - G92 will revert to its behavior from Marlin 1.0.
1177
+ */
1178
+//#define NO_WORKSPACE_OFFSETS
1179
+
1171 1180
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/delta/kossel_pro/Configuration_adv.h Прегледај датотеку

@@ -1173,4 +1173,13 @@
1173 1173
  */ 
1174 1174
 //#define VOLUMETRIC_DEFAULT_ON
1175 1175
 
1176
+/**
1177
+ * Enable this option for a leaner build of Marlin that removes all
1178
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1179
+ *
1180
+ *  - M206 and M428 are disabled.
1181
+ *  - G92 will revert to its behavior from Marlin 1.0.
1182
+ */
1183
+//#define NO_WORKSPACE_OFFSETS
1184
+
1176 1185
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/delta/kossel_xl/Configuration_adv.h Прегледај датотеку

@@ -1168,4 +1168,13 @@
1168 1168
  */ 
1169 1169
 //#define VOLUMETRIC_DEFAULT_ON
1170 1170
 
1171
+/**
1172
+ * Enable this option for a leaner build of Marlin that removes all
1173
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1174
+ *
1175
+ *  - M206 and M428 are disabled.
1176
+ *  - G92 will revert to its behavior from Marlin 1.0.
1177
+ */
1178
+//#define NO_WORKSPACE_OFFSETS
1179
+
1171 1180
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/makibox/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 9
- 0
Marlin/example_configurations/tvrrug/Round2/Configuration_adv.h Прегледај датотеку

@@ -1166,4 +1166,13 @@
1166 1166
  */ 
1167 1167
 //#define VOLUMETRIC_DEFAULT_ON
1168 1168
 
1169
+/**
1170
+ * Enable this option for a leaner build of Marlin that removes all
1171
+ * workspace offsets, simplifying coordinate transformations, leveling, etc.
1172
+ *
1173
+ *  - M206 and M428 are disabled.
1174
+ *  - G92 will revert to its behavior from Marlin 1.0.
1175
+ */
1176
+//#define NO_WORKSPACE_OFFSETS
1177
+
1169 1178
 #endif // CONFIGURATION_ADV_H

+ 1
- 0
Marlin/macros.h Прегледај датотеку

@@ -79,6 +79,7 @@
79 79
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80 80
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81 81
 #define ZERO(a) memset(a,0,sizeof(a))
82
+#define COPY(a,b) memcpy(a,b,min(sizeof(a),sizeof(b)))
82 83
 
83 84
 // Macros for initializing arrays
84 85
 #define ARRAY_6(v1, v2, v3, v4, v5, v6, ...) { v1, v2, v3, v4, v5, v6 }

+ 2
- 2
Marlin/planner.cpp Прегледај датотеку

@@ -1298,7 +1298,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1298 1298
   block->flag |= BLOCK_FLAG_RECALCULATE | (block->nominal_speed <= v_allowable ? BLOCK_FLAG_NOMINAL_LENGTH : 0);
1299 1299
 
1300 1300
   // Update previous path unit_vector and nominal speed
1301
-  memcpy(previous_speed, current_speed, sizeof(previous_speed));
1301
+  COPY(previous_speed, current_speed);
1302 1302
   previous_nominal_speed = block->nominal_speed;
1303 1303
   previous_safe_speed = safe_speed;
1304 1304
 
@@ -1360,7 +1360,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
1360 1360
   block_buffer_head = next_buffer_head;
1361 1361
 
1362 1362
   // Update the position (only when a move was queued)
1363
-  memcpy(position, target, sizeof(position));
1363
+  COPY(position, target);
1364 1364
   #if ENABLED(LIN_ADVANCE)
1365 1365
     position_float[X_AXIS] = a;
1366 1366
     position_float[Y_AXIS] = b;

Loading…
Откажи
Сачувај