Sfoglia il codice sorgente

M421 tweaks, just to use const

Scott Lahteine 8 anni fa
parent
commit
cbfca29522
1 ha cambiato i file con 34 aggiunte e 37 eliminazioni
  1. 34
    37
      Marlin/Marlin_main.cpp

+ 34
- 37
Marlin/Marlin_main.cpp Vedi File

@@ -8414,17 +8414,15 @@ void quickstop_stepper() {
8414 8414
    * Use either 'M421 X<linear> Y<linear> Z<linear>' or 'M421 I<xindex> J<yindex> Z<linear>'
8415 8415
    */
8416 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 8426
       if (px >= 0 && py >= 0)
8429 8427
         mbl.set_z(px, py, z);
8430 8428
       else {
@@ -8451,18 +8449,18 @@ void quickstop_stepper() {
8451 8449
   /**
8452 8450
    * M421: Set a single Mesh Bed Leveling Z coordinate
8453 8451
    *
8452
+   * Usage:
8454 8453
    *   M421 I<xindex> J<yindex> Z<linear>
8455
-   *   or
8456 8454
    *   M421 I<xindex> J<yindex> Q<offset>
8457 8455
    */
8458 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 8465
     if (!hasI || !hasJ || (hasQ && hasZ) || (!hasQ && !hasZ)) {
8468 8466
       SERIAL_ERROR_START;
@@ -8495,35 +8493,33 @@ void quickstop_stepper() {
8495 8493
   /**
8496 8494
    * M421: Set a single Mesh Bed Leveling Z coordinate
8497 8495
    *
8496
+   * Usage:
8498 8497
    *   M421 I<xindex> J<yindex> Z<linear>
8499
-   *   or
8500 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 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 8518
       SERIAL_ERROR_START;
8517 8519
       SERIAL_ERRORLNPGM(MSG_ERR_M421_PARAMETERS);
8518 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 8523
     if (WITHIN(px, 0, GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, GRID_MAX_POINTS_Y - 1)) {
8528 8524
       if (hasZ) // doing an absolute mesh value
8529 8525
         ubl.z_values[px][py] = z;
@@ -8535,7 +8531,8 @@ void quickstop_stepper() {
8535 8531
       SERIAL_ERRORLNPGM(MSG_ERR_MESH_XY);
8536 8532
     }
8537 8533
   }
8538
-#endif
8534
+
8535
+#endif // AUTO_BED_LEVELING_UBL
8539 8536
 
8540 8537
 #if HAS_M206_COMMAND
8541 8538
 

Loading…
Annulla
Salva