瀏覽代碼

M421 tweaks, just to use const

Scott Lahteine 8 年之前
父節點
當前提交
cbfca29522
共有 1 個文件被更改,包括 34 次插入37 次删除
  1. 34
    37
      Marlin/Marlin_main.cpp

+ 34
- 37
Marlin/Marlin_main.cpp 查看文件

8414
    * Use either 'M421 X<linear> Y<linear> Z<linear>' or 'M421 I<xindex> J<yindex> Z<linear>'
8414
    * Use either 'M421 X<linear> Y<linear> Z<linear>' or 'M421 I<xindex> J<yindex> Z<linear>'
8415
    */
8415
    */
8416
   inline void gcode_M421() {
8416
   inline void gcode_M421() {
8417
-    int8_t px = 0, py = 0;
8418
-    float z = 0;
8419
-    bool hasX, hasY, hasZ, hasI, hasJ;
8420
-    if ((hasX = code_seen('X'))) px = mbl.probe_index_x(code_value_linear_units());
8421
-    if ((hasY = code_seen('Y'))) py = mbl.probe_index_y(code_value_linear_units());
8422
-    if ((hasI = code_seen('I'))) px = code_value_linear_units();
8423
-    if ((hasJ = code_seen('J'))) py = code_value_linear_units();
8424
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8425
 
8417
 
8426
-    if (hasX && hasY && hasZ) {
8418
+    const bool hasX = code_seen('X'), hasI = !hasX && code_seen('I');
8419
+    const int8_t px = hasX || hasI ? mbl.probe_index_x(code_value_linear_units()) : 0;
8420
+    const bool hasY = code_seen('Y'), hasJ = !hasY && code_seen('J');
8421
+    const int8_t py = hasY || hasJ ? mbl.probe_index_y(code_value_linear_units()) : 0;
8422
+    const bool hasZ = code_seen('Z');
8423
+    const float z = hasZ ? code_value_linear_units() : 0;
8427
 
8424
 
8425
+    if (hasX && hasY && hasZ) {
8428
       if (px >= 0 && py >= 0)
8426
       if (px >= 0 && py >= 0)
8429
         mbl.set_z(px, py, z);
8427
         mbl.set_z(px, py, z);
8430
       else {
8428
       else {
8451
   /**
8449
   /**
8452
    * M421: Set a single Mesh Bed Leveling Z coordinate
8450
    * M421: Set a single Mesh Bed Leveling Z coordinate
8453
    *
8451
    *
8452
+   * Usage:
8454
    *   M421 I<xindex> J<yindex> Z<linear>
8453
    *   M421 I<xindex> J<yindex> Z<linear>
8455
-   *   or
8456
    *   M421 I<xindex> J<yindex> Q<offset>
8454
    *   M421 I<xindex> J<yindex> Q<offset>
8457
    */
8455
    */
8458
   inline void gcode_M421() {
8456
   inline void gcode_M421() {
8459
-    int8_t px = 0, py = 0;
8460
-    float z = 0;
8461
-    bool hasI, hasJ, hasZ, hasQ;
8462
-    if ((hasI = code_seen('I'))) px = code_value_int();
8463
-    if ((hasJ = code_seen('J'))) py = code_value_int();
8464
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8465
-    if ((hasQ = code_seen('Q'))) z = code_value_linear_units();
8457
+
8458
+    const bool hasI = code_seen('I');
8459
+    const int8_t px = hasI ? code_value_int() : 0;
8460
+    const bool hasJ = code_seen('J');
8461
+    const int8_t py = hasJ ? code_value_int() : 0;
8462
+    const bool hasZ = code_seen('Z'), hasQ = !hasZ && code_seen('Q');
8463
+    const float z = hasZ || hasQ ? code_value_linear_units() : 0;
8466
 
8464
 
8467
     if (!hasI || !hasJ || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8465
     if (!hasI || !hasJ || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8468
       SERIAL_ERROR_START;
8466
       SERIAL_ERROR_START;
8495
   /**
8493
   /**
8496
    * M421: Set a single Mesh Bed Leveling Z coordinate
8494
    * M421: Set a single Mesh Bed Leveling Z coordinate
8497
    *
8495
    *
8496
+   * Usage:
8498
    *   M421 I<xindex> J<yindex> Z<linear>
8497
    *   M421 I<xindex> J<yindex> Z<linear>
8499
-   *   or
8500
    *   M421 I<xindex> J<yindex> Q<offset>
8498
    *   M421 I<xindex> J<yindex> Q<offset>
8499
+   *   M421 C Z<linear>
8500
+   *   M421 C Q<offset>
8501
    */
8501
    */
8502
 
8502
 
8503
-  //todo:  change multiple points simultaneously?
8504
-
8505
   inline void gcode_M421() {
8503
   inline void gcode_M421() {
8506
-    int8_t px = 0, py = 0;
8507
-    float z = 0;
8508
-    bool hasI, hasJ, hasZ, hasQ, hasC;
8509
-    if ((hasI = code_seen('I'))) px = code_value_int();
8510
-    if ((hasJ = code_seen('J'))) py = code_value_int();
8511
-    if ((hasZ = code_seen('Z'))) z = code_value_linear_units();
8512
-    if ((hasQ = code_seen('Q'))) z = code_value_linear_units();
8513
-    hasC = code_seen('C');
8514
-
8515
-    if ( (!(hasI && hasJ) && !hasC) || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8504
+
8505
+    // Get the closest position for 'C', if needed
8506
+    const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL, false);
8507
+
8508
+    const bool hasC = code_seen('C'), hasI = code_seen('I');
8509
+    const int8_t px = hasC ? location.x_index : hasI ? code_value_int() : 0;
8510
+
8511
+    const bool hasJ = code_seen('J');
8512
+    const int8_t py = hasC ? location.y_index : hasJ ? code_value_int() : 0;
8513
+
8514
+    const bool hasZ = code_seen('Z'), hasQ = !hasZ && code_seen('Q');
8515
+    const float z = hasZ || hasQ ? code_value_linear_units() : 0;
8516
+
8517
+    if ( ((hasI && hasJ) == hasC) || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8516
       SERIAL_ERROR_START;
8518
       SERIAL_ERROR_START;
8517
       SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8519
       SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8518
       return;
8520
       return;
8519
     }
8521
     }
8520
 
8522
 
8521
-    if (hasC) { // get closest position
8522
-      const mesh_index_pair location = find_closest_mesh_point_of_type(REAL, current_position[X_AXIS], current_position[Y_AXIS], USE_NOZZLE_AS_REFERENCE, NULL, false);
8523
-      px = location.x_index;
8524
-      py = location.y_index;
8525
-    }
8526
-
8527
     if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
8523
     if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
8528
       if (hasZ) // doing an absolute mesh value
8524
       if (hasZ) // doing an absolute mesh value
8529
         ubl.z_values[px][py] = z;
8525
         ubl.z_values[px][py] = z;
8535
       SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8531
       SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8536
     }
8532
     }
8537
   }
8533
   }
8538
-#endif
8534
+
8535
+#endif // AUTO_BED_LEVELING_UBL
8539
 
8536
 
8540
 #if HAS_M206_COMMAND
8537
 #if HAS_M206_COMMAND
8541
 
8538
 

Loading…
取消
儲存