Bläddra i källkod

Merge pull request #6181 from thinkyhead/rc_ubl_further_fixes

Further adjustments to UBL code
Scott Lahteine 8 år sedan
förälder
incheckning
541165e878

+ 1
- 1
.travis.yml Visa fil

120
   # Test a simple build of AUTO_BED_LEVELING_UBL
120
   # Test a simple build of AUTO_BED_LEVELING_UBL
121
   #
121
   #
122
   - restore_configs
122
   - restore_configs
123
-  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING FIX_MOUNTED_PROBE EEPROM_SETTINGS G3D_PANEL
123
+  - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT FIX_MOUNTED_PROBE EEPROM_SETTINGS G3D_PANEL
124
   - build_marlin
124
   - build_marlin
125
   #
125
   #
126
   # Test a Sled Z Probe
126
   # Test a Sled Z Probe

+ 46
- 71
Marlin/G26_Mesh_Validation_Tool.cpp Visa fil

47
   #define OOZE_AMOUNT 0.3
47
   #define OOZE_AMOUNT 0.3
48
 
48
 
49
   #define SIZE_OF_INTERSECTION_CIRCLES 5
49
   #define SIZE_OF_INTERSECTION_CIRCLES 5
50
-  #define SIZE_OF_CROSS_HAIRS 3 // cross hairs inside the circle.  This number should be
51
-                                // less than SIZE_OR_INTERSECTION_CIRCLES
50
+  #define SIZE_OF_CROSSHAIRS 3 // crosshairs inside the circle.  This number should be
51
+                               // less than SIZE_OR_INTERSECTION_CIRCLES
52
 
52
 
53
   /**
53
   /**
54
    *   Roxy's G26 Mesh Validation Tool
54
    *   Roxy's G26 Mesh Validation Tool
132
   void line_to_destination(float );
132
   void line_to_destination(float );
133
   void gcode_G28();
133
   void gcode_G28();
134
   void sync_plan_position_e();
134
   void sync_plan_position_e();
135
-  void un_retract_filament();
136
-  void retract_filament();
135
+  void un_retract_filament(float where[XYZE]);
136
+  void retract_filament(float where[XYZE]);
137
   void look_for_lines_to_connect();
137
   void look_for_lines_to_connect();
138
   bool parse_G26_parameters();
138
   bool parse_G26_parameters();
139
   void move_to(const float&, const float&, const float&, const float&) ;
139
   void move_to(const float&, const float&, const float&, const float&) ;
140
-  void print_line_from_here_to_there(float sx, float sy, float sz, float ex, float ey, float ez);
140
+  void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&);
141
   bool turn_on_heaters();
141
   bool turn_on_heaters();
142
   bool prime_nozzle();
142
   bool prime_nozzle();
143
   void chirp_at_user();
143
   void chirp_at_user();
154
 
154
 
155
   float valid_trig_angle(float);
155
   float valid_trig_angle(float);
156
   mesh_index_pair find_closest_circle_to_print(float, float);
156
   mesh_index_pair find_closest_circle_to_print(float, float);
157
-  void ubl_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
158
-  //uint16_t x_splits = 0xFFFF, uint16_t y_splits = 0xFFFF);  /* needed for the old mesh_buffer_line() routine */
159
 
157
 
160
   static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
158
   static float extrusion_multiplier = EXTRUSION_MULTIPLIER,
161
                retraction_multiplier = RETRACTION_MULTIPLIER,
159
                retraction_multiplier = RETRACTION_MULTIPLIER,
269
         #endif
267
         #endif
270
 
268
 
271
         // TODO: Change this to use `position_is_reachable`
269
         // TODO: Change this to use `position_is_reachable`
272
-        if (circle_x < (X_MIN_POS) || circle_x > (X_MAX_POS) || circle_y < (Y_MIN_POS) || circle_y > (Y_MAX_POS)) {
270
+        if (!WITHIN(circle_x, X_MIN_POS, X_MAX_POS) || !WITHIN(circle_y, Y_MIN_POS, Y_MAX_POS)) {
273
           SERIAL_ERROR_START;
271
           SERIAL_ERROR_START;
274
           SERIAL_ERRORLNPGM("Attempt to print off the bed.");
272
           SERIAL_ERRORLNPGM("Attempt to print off the bed.");
275
           goto LEAVE;
273
           goto LEAVE;
359
     lcd_reset_alert_level();
357
     lcd_reset_alert_level();
360
     lcd_setstatuspgm(PSTR("Leaving G26"));
358
     lcd_setstatuspgm(PSTR("Leaving G26"));
361
 
359
 
362
-    retract_filament();
360
+    retract_filament(destination);
363
     destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
361
     destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES;
364
 
362
 
365
     //debug_current_and_destination((char*)"ready to do Z-Raise.");
363
     //debug_current_and_destination((char*)"ready to do Z-Raise.");
445
               // We found two circles that need a horizontal line to connect them
443
               // We found two circles that need a horizontal line to connect them
446
               // Print it!
444
               // Print it!
447
               //
445
               //
448
-              sx = ubl.mesh_index_to_xpos[i];
449
-              sx = sx + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the right edge of the circle
450
-              sy = ubl.mesh_index_to_ypos[j];
446
+              sx = ubl.mesh_index_to_xpos[  i  ] + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // right edge
447
+              ex = ubl.mesh_index_to_xpos[i + 1] - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // left edge
451
 
448
 
452
-              ex = ubl.mesh_index_to_xpos[i + 1];
453
-              ex = ex - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the left edge of the circle
454
-              ey = sy;
455
-
456
-              sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
457
-              sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
449
+              sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);
450
+              sy = ey = constrain(ubl.mesh_index_to_ypos[j], Y_MIN_POS + 1, Y_MAX_POS - 1);
458
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
451
               ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
459
-              ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
460
 
452
 
461
               if (ubl.g26_debug_flag) {
453
               if (ubl.g26_debug_flag) {
462
                 SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
454
                 SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
468
                 //debug_current_and_destination((char*)"Connecting horizontal line.");
460
                 //debug_current_and_destination((char*)"Connecting horizontal line.");
469
               }
461
               }
470
 
462
 
471
-              print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
463
+              print_line_from_here_to_there(LOGICAL_X_POSITION(sx), LOGICAL_Y_POSITION(sy), layer_height, LOGICAL_X_POSITION(ex), LOGICAL_Y_POSITION(ey), layer_height);
472
               bit_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
464
               bit_set(horizontal_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
473
             }
465
             }
474
           }
466
           }
482
                 // We found two circles that need a vertical line to connect them
474
                 // We found two circles that need a vertical line to connect them
483
                 // Print it!
475
                 // Print it!
484
                 //
476
                 //
485
-                sx = ubl.mesh_index_to_xpos[i];
486
-                sy = ubl.mesh_index_to_ypos[j];
487
-                sy = sy + SIZE_OF_INTERSECTION_CIRCLES - SIZE_OF_CROSS_HAIRS; // get the top edge of the circle
488
-
489
-                ex = sx;
490
-                ey = ubl.mesh_index_to_ypos[j + 1];
491
-                ey = ey - SIZE_OF_INTERSECTION_CIRCLES + SIZE_OF_CROSS_HAIRS; // get the bottom edge of the circle
477
+                sy = ubl.mesh_index_to_ypos[  j  ] + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // top edge
478
+                ey = ubl.mesh_index_to_ypos[j + 1] - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // bottom edge
492
 
479
 
493
-                sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1);             // This keeps us from bumping the endstops
480
+                sx = ex = constrain(ubl.mesh_index_to_xpos[i], X_MIN_POS + 1, X_MAX_POS - 1);
494
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
481
                 sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1);
495
-                ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
496
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
482
                 ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
497
 
483
 
498
                 if (ubl.g26_debug_flag) {
484
                 if (ubl.g26_debug_flag) {
504
                   SERIAL_EOL;
490
                   SERIAL_EOL;
505
                   debug_current_and_destination((char*)"Connecting vertical line.");
491
                   debug_current_and_destination((char*)"Connecting vertical line.");
506
                 }
492
                 }
507
-                print_line_from_here_to_there(sx, sy, layer_height, ex, ey, layer_height);
508
-                bit_set( vertical_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
493
+                print_line_from_here_to_there(LOGICAL_X_POSITION(sx), LOGICAL_Y_POSITION(sy), layer_height, LOGICAL_X_POSITION(ex), LOGICAL_Y_POSITION(ey), layer_height);
494
+                bit_set(vertical_mesh_line_flags, i, j);   // Mark it as done so we don't do it again
509
               }
495
               }
510
             }
496
             }
511
           }
497
           }
533
       destination[Z_AXIS] = z;                          // We know the last_z==z or we wouldn't be in this block of code.
519
       destination[Z_AXIS] = z;                          // We know the last_z==z or we wouldn't be in this block of code.
534
       destination[E_AXIS] = current_position[E_AXIS];
520
       destination[E_AXIS] = current_position[E_AXIS];
535
 
521
 
536
-      ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
522
+      ubl_line_to_destination(feed_value, 0);
537
 
523
 
538
       stepper.synchronize();
524
       stepper.synchronize();
539
       set_destination_to_current();
525
       set_destination_to_current();
553
 
539
 
554
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
540
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
555
 
541
 
556
-    ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
542
+    ubl_line_to_destination(feed_value, 0);
557
 
543
 
558
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
544
     //if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
559
 
545
 
562
 
548
 
563
   }
549
   }
564
 
550
 
565
-  void retract_filament() {
551
+  void retract_filament(float where[XYZE]) {
566
     if (!g26_retracted) { // Only retract if we are not already retracted!
552
     if (!g26_retracted) { // Only retract if we are not already retracted!
567
       g26_retracted = true;
553
       g26_retracted = true;
568
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
554
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
569
-      move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], -1.0 * retraction_multiplier);
555
+      move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], -1.0 * retraction_multiplier);
570
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
556
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
571
     }
557
     }
572
   }
558
   }
573
 
559
 
574
-  void un_retract_filament() {
560
+  void un_retract_filament(float where[XYZE]) {
575
     if (g26_retracted) { // Only un-retract if we are retracted.
561
     if (g26_retracted) { // Only un-retract if we are retracted.
576
-      move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 1.2 * retraction_multiplier);
562
+      move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], 1.2 * retraction_multiplier);
577
       g26_retracted = false;
563
       g26_retracted = false;
578
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
564
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
579
     }
565
     }
594
    * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
580
    * segment of a 'circle'.   The time this requires is very short and is easily saved by the other
595
    * cases where the optimization comes into play.
581
    * cases where the optimization comes into play.
596
    */
582
    */
597
-  void print_line_from_here_to_there( float sx, float sy, float sz, float ex, float ey, float ez) {
583
+  void print_line_from_here_to_there(const float &sx, const float &sy, const float &sz, const float &ex, const float &ey, const float &ez) {
598
     const float dx_s = current_position[X_AXIS] - sx,   // find our distance from the start of the actual line segment
584
     const float dx_s = current_position[X_AXIS] - sx,   // find our distance from the start of the actual line segment
599
                 dy_s = current_position[Y_AXIS] - sy,
585
                 dy_s = current_position[Y_AXIS] - sy,
600
                 dist_start = HYPOT2(dx_s, dy_s),        // We don't need to do a sqrt(), we can compare the distance^2
586
                 dist_start = HYPOT2(dx_s, dy_s),        // We don't need to do a sqrt(), we can compare the distance^2
603
                 dy_e = current_position[Y_AXIS] - ey,
589
                 dy_e = current_position[Y_AXIS] - ey,
604
                 dist_end = HYPOT2(dx_e, dy_e),
590
                 dist_end = HYPOT2(dx_e, dy_e),
605
 
591
 
606
-                dx = ex - sx,
607
-                dy = ey - sy,
608
-                line_length = HYPOT(dx, dy);
592
+                line_length = HYPOT(ex - sx, ey - sy);
609
 
593
 
610
-    // If the end point of the line is closer to the nozzle, we are going to
611
-    // flip the direction of this line.   We will print it from the end to the start.
612
-    // On very small lines we don't do the optimization because it just isn't worth it.
613
-    //
594
+    // If the end point of the line is closer to the nozzle, flip the direction,
595
+    // moving from the end to the start. On very small lines the optimization isn't worth it.
614
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
596
     if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
615
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Reversing start and end of print_line_from_here_to_there()");
597
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  Reversing start and end of print_line_from_here_to_there()");
616
-      print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
617
-      return;
598
+      return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
618
     }
599
     }
619
 
600
 
620
-    // Now decide if we should retract.
601
+    // Decide whether to retract.
621
 
602
 
622
     if (dist_start > 2.0) {
603
     if (dist_start > 2.0) {
623
-      retract_filament();
604
+      retract_filament(destination);
624
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
605
       //if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM("  filament retracted.");
625
     }
606
     }
626
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
607
     move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
627
 
608
 
628
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
609
     const float e_pos_delta = line_length * g26_e_axis_feedrate * extrusion_multiplier;
629
 
610
 
630
-    un_retract_filament();
611
+    un_retract_filament(destination);
631
 
612
 
632
     //if (ubl.g26_debug_flag) {
613
     //if (ubl.g26_debug_flag) {
633
     //  SERIAL_ECHOLNPGM("  doing printing move.");
614
     //  SERIAL_ECHOLNPGM("  doing printing move.");
657
 
638
 
658
     if (code_seen('B')) {
639
     if (code_seen('B')) {
659
       bed_temp = code_value_float();
640
       bed_temp = code_value_float();
660
-      if (bed_temp < 15.0 || bed_temp > 140.0) {
641
+      if (!WITHIN(bed_temp, 15.0, 140.0)) {
661
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
642
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
662
         return UBL_ERR;
643
         return UBL_ERR;
663
       }
644
       }
667
 
648
 
668
     if (code_seen('L')) {
649
     if (code_seen('L')) {
669
       layer_height = code_value_float();
650
       layer_height = code_value_float();
670
-      if (layer_height < 0.0 || layer_height > 2.0) {
651
+      if (!WITHIN(layer_height, 0.0, 2.0)) {
671
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
652
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
672
         return UBL_ERR;
653
         return UBL_ERR;
673
       }
654
       }
676
     if (code_seen('Q')) {
657
     if (code_seen('Q')) {
677
       if (code_has_value()) {
658
       if (code_has_value()) {
678
         retraction_multiplier = code_value_float();
659
         retraction_multiplier = code_value_float();
679
-        if (retraction_multiplier < 0.05 || retraction_multiplier > 15.0) {
660
+        if (!WITHIN(retraction_multiplier, 0.05, 15.0)) {
680
           SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible.");
661
           SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible.");
681
           return UBL_ERR;
662
           return UBL_ERR;
682
         }
663
         }
689
 
670
 
690
     if (code_seen('N')) {
671
     if (code_seen('N')) {
691
       nozzle = code_value_float();
672
       nozzle = code_value_float();
692
-      if (nozzle < 0.1 || nozzle > 1.0) {
673
+      if (!WITHIN(nozzle, 0.1, 1.0)) {
693
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
674
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
694
         return UBL_ERR;
675
         return UBL_ERR;
695
       }
676
       }
706
       else {
687
       else {
707
         prime_flag++;
688
         prime_flag++;
708
         prime_length = code_value_float();
689
         prime_length = code_value_float();
709
-        if (prime_length < 0.0 || prime_length > 25.0) {
690
+        if (!WITHIN(prime_length, 0.0, 25.0)) {
710
           SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
691
           SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
711
           return UBL_ERR;
692
           return UBL_ERR;
712
         }
693
         }
715
 
696
 
716
     if (code_seen('F')) {
697
     if (code_seen('F')) {
717
       filament_diameter = code_value_float();
698
       filament_diameter = code_value_float();
718
-      if (filament_diameter < 1.0 || filament_diameter > 4.0) {
699
+      if (!WITHIN(filament_diameter, 1.0, 4.0)) {
719
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
700
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
720
         return UBL_ERR;
701
         return UBL_ERR;
721
       }
702
       }
728
 
709
 
729
     if (code_seen('H')) {
710
     if (code_seen('H')) {
730
       hotend_temp = code_value_float();
711
       hotend_temp = code_value_float();
731
-      if (hotend_temp < 165.0 || hotend_temp > 280.0) {
712
+      if (!WITHIN(hotend_temp, 165.0, 280.0)) {
732
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
713
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
733
         return UBL_ERR;
714
         return UBL_ERR;
734
       }
715
       }
744
 
725
 
745
     if (code_seen('X')) {
726
     if (code_seen('X')) {
746
       x_pos = code_value_float();
727
       x_pos = code_value_float();
747
-      if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
728
+      if (!WITHIN(x_pos, X_MIN_POS, X_MAX_POS)) {
748
         SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
729
         SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
749
         return UBL_ERR;
730
         return UBL_ERR;
750
       }
731
       }
753
 
734
 
754
     if (code_seen('Y')) {
735
     if (code_seen('Y')) {
755
       y_pos = code_value_float();
736
       y_pos = code_value_float();
756
-      if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
737
+      if (!WITHIN(y_pos, Y_MIN_POS, Y_MAX_POS)) {
757
         SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
738
         SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
758
         return UBL_ERR;
739
         return UBL_ERR;
759
       }
740
       }
814
       lcd_setstatuspgm(PSTR(""));
795
       lcd_setstatuspgm(PSTR(""));
815
       lcd_quick_feedback();
796
       lcd_quick_feedback();
816
     #endif
797
     #endif
798
+
817
     return UBL_OK;
799
     return UBL_OK;
818
   }
800
   }
819
 
801
 
832
 
814
 
833
       set_destination_to_current();
815
       set_destination_to_current();
834
 
816
 
835
-      un_retract_filament();    // Lets make sure the G26 command doesn't think the filament is
836
-                                // retracted().  We are here because we want to prime the nozzle.
837
-                                // So let's just unretract just to be sure.
817
+      un_retract_filament(destination); // Make sure G26 doesn't think the filament is retracted().
818
+
838
       while (!ubl_lcd_clicked()) {
819
       while (!ubl_lcd_clicked()) {
839
         chirp_at_user();
820
         chirp_at_user();
840
         destination[E_AXIS] += 0.25;
821
         destination[E_AXIS] += 0.25;
842
           Total_Prime += 0.25;
823
           Total_Prime += 0.25;
843
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR;
824
           if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR;
844
         #endif
825
         #endif
845
-        ubl_line_to_destination(
846
-          destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
847
-          planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
848
-        );
826
+        ubl_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0);
849
 
827
 
850
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
828
         stepper.synchronize();    // Without this synchronize, the purge is more consistent,
851
                                   // but because the planner has a buffer, we won't be able
829
                                   // but because the planner has a buffer, we won't be able
874
       #endif
852
       #endif
875
       set_destination_to_current();
853
       set_destination_to_current();
876
       destination[E_AXIS] += prime_length;
854
       destination[E_AXIS] += prime_length;
877
-      ubl_line_to_destination(
878
-        destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
879
-        planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0
880
-      );
855
+      ubl_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0, 0);
881
       stepper.synchronize();
856
       stepper.synchronize();
882
       set_destination_to_current();
857
       set_destination_to_current();
883
-      retract_filament();
858
+      retract_filament(destination);
884
     }
859
     }
885
 
860
 
886
     return UBL_OK;
861
     return UBL_OK;

+ 0
- 1
Marlin/Marlin.h Visa fil

244
 inline bool IsStopped() { return !Running; }
244
 inline bool IsStopped() { return !Running; }
245
 
245
 
246
 bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
246
 bool enqueue_and_echo_command(const char* cmd, bool say_ok=false); //put a single ASCII command at the end of the current buffer or return false when it is full
247
-void enqueue_and_echo_command_now(const char* cmd); // enqueue now, only return when the command has been enqueued
248
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
247
 void enqueue_and_echo_commands_P(const char* cmd); //put one or many ASCII commands at the end of the current buffer, read from flash
249
 void clear_command_queue();
248
 void clear_command_queue();
250
 
249
 

+ 36
- 44
Marlin/Marlin_main.cpp Visa fil

896
   return false;
896
   return false;
897
 }
897
 }
898
 
898
 
899
-void enqueue_and_echo_command_now(const char* cmd) {
900
-  while (!enqueue_and_echo_command(cmd)) idle();
901
-}
902
-
903
 void setup_killpin() {
899
 void setup_killpin() {
904
   #if HAS_KILL
900
   #if HAS_KILL
905
     SET_INPUT_PULLUP(KILL_PIN);
901
     SET_INPUT_PULLUP(KILL_PIN);
2237
         SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - current_position[Z_AXIS]);
2233
         SERIAL_ECHOLNPAIR(" Discrepancy:", first_probe_z - current_position[Z_AXIS]);
2238
       }
2234
       }
2239
     #endif
2235
     #endif
2240
-    return current_position[Z_AXIS];
2236
+    return current_position[Z_AXIS] + zprobe_zoffset;
2241
   }
2237
   }
2242
 
2238
 
2243
   //
2239
   //
2291
       SERIAL_PROTOCOLPGM(" Y: ");
2287
       SERIAL_PROTOCOLPGM(" Y: ");
2292
       SERIAL_PROTOCOL_F(y, 3);
2288
       SERIAL_PROTOCOL_F(y, 3);
2293
       SERIAL_PROTOCOLPGM(" Z: ");
2289
       SERIAL_PROTOCOLPGM(" Z: ");
2294
-      SERIAL_PROTOCOL_F(measured_z - -zprobe_zoffset + 0.0001, 3);
2290
+      SERIAL_PROTOCOL_F(FIXFLOAT(measured_z), 3);
2295
       SERIAL_EOL;
2291
       SERIAL_EOL;
2296
     }
2292
     }
2297
 
2293
 
2569
           ep = ABL_GRID_MAX_POINTS_X - 1;
2565
           ep = ABL_GRID_MAX_POINTS_X - 1;
2570
           ip = ABL_GRID_MAX_POINTS_X - 2;
2566
           ip = ABL_GRID_MAX_POINTS_X - 2;
2571
         }
2567
         }
2572
-        if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
2568
+        if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
2573
           return LINEAR_EXTRAPOLATION(
2569
           return LINEAR_EXTRAPOLATION(
2574
             bed_level_grid[ep][y - 1],
2570
             bed_level_grid[ep][y - 1],
2575
             bed_level_grid[ip][y - 1]
2571
             bed_level_grid[ip][y - 1]
2585
           ep = ABL_GRID_MAX_POINTS_Y - 1;
2581
           ep = ABL_GRID_MAX_POINTS_Y - 1;
2586
           ip = ABL_GRID_MAX_POINTS_Y - 2;
2582
           ip = ABL_GRID_MAX_POINTS_Y - 2;
2587
         }
2583
         }
2588
-        if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
2584
+        if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
2589
           return LINEAR_EXTRAPOLATION(
2585
           return LINEAR_EXTRAPOLATION(
2590
             bed_level_grid[x - 1][ep],
2586
             bed_level_grid[x - 1][ep],
2591
             bed_level_grid[x - 1][ip]
2587
             bed_level_grid[x - 1][ip]
3028
     return HYPOT2(dx, dy) <= sq((float)(DELTA_PRINTABLE_RADIUS));
3024
     return HYPOT2(dx, dy) <= sq((float)(DELTA_PRINTABLE_RADIUS));
3029
   #else
3025
   #else
3030
     const float dz = RAW_Z_POSITION(target[Z_AXIS]);
3026
     const float dz = RAW_Z_POSITION(target[Z_AXIS]);
3031
-    return dx >= X_MIN_POS - 0.0001 && dx <= X_MAX_POS + 0.0001
3032
-        && dy >= Y_MIN_POS - 0.0001 && dy <= Y_MAX_POS + 0.0001
3033
-        && dz >= Z_MIN_POS - 0.0001 && dz <= Z_MAX_POS + 0.0001;
3027
+    return WITHIN(dx, X_MIN_POS - 0.0001, X_MAX_POS + 0.0001)
3028
+        && WITHIN(dy, Y_MIN_POS - 0.0001, Y_MAX_POS + 0.0001)
3029
+        && WITHIN(dz, Z_MIN_POS - 0.0001, Z_MAX_POS + 0.0001);
3034
   #endif
3030
   #endif
3035
 }
3031
 }
3036
 
3032
 
3788
    */
3784
    */
3789
   inline void gcode_G29() {
3785
   inline void gcode_G29() {
3790
 
3786
 
3791
-    static int probe_index = -1;
3787
+    static int mbl_probe_index = -1;
3792
     #if HAS_SOFTWARE_ENDSTOPS
3788
     #if HAS_SOFTWARE_ENDSTOPS
3793
       static bool enable_soft_endstops;
3789
       static bool enable_soft_endstops;
3794
     #endif
3790
     #endif
3795
 
3791
 
3796
     const MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_byte() : MeshReport;
3792
     const MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_byte() : MeshReport;
3797
-    if (state < 0 || state > 5) {
3793
+    if (!WITHIN(state, 0, 5)) {
3798
       SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
3794
       SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
3799
       return;
3795
       return;
3800
     }
3796
     }
3813
 
3809
 
3814
       case MeshStart:
3810
       case MeshStart:
3815
         mbl.reset();
3811
         mbl.reset();
3816
-        probe_index = 0;
3812
+        mbl_probe_index = 0;
3817
         enqueue_and_echo_commands_P(PSTR("G28\nG29 S2"));
3813
         enqueue_and_echo_commands_P(PSTR("G28\nG29 S2"));
3818
         break;
3814
         break;
3819
 
3815
 
3820
       case MeshNext:
3816
       case MeshNext:
3821
-        if (probe_index < 0) {
3817
+        if (mbl_probe_index < 0) {
3822
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
3818
           SERIAL_PROTOCOLLNPGM("Start mesh probing with \"G29 S1\" first.");
3823
           return;
3819
           return;
3824
         }
3820
         }
3825
         // For each G29 S2...
3821
         // For each G29 S2...
3826
-        if (probe_index == 0) {
3822
+        if (mbl_probe_index == 0) {
3827
           #if HAS_SOFTWARE_ENDSTOPS
3823
           #if HAS_SOFTWARE_ENDSTOPS
3828
             // For the initial G29 S2 save software endstop state
3824
             // For the initial G29 S2 save software endstop state
3829
             enable_soft_endstops = soft_endstops_enabled;
3825
             enable_soft_endstops = soft_endstops_enabled;
3831
         }
3827
         }
3832
         else {
3828
         else {
3833
           // For G29 S2 after adjusting Z.
3829
           // For G29 S2 after adjusting Z.
3834
-          mbl.set_zigzag_z(probe_index - 1, current_position[Z_AXIS]);
3830
+          mbl.set_zigzag_z(mbl_probe_index - 1, current_position[Z_AXIS]);
3835
           #if HAS_SOFTWARE_ENDSTOPS
3831
           #if HAS_SOFTWARE_ENDSTOPS
3836
             soft_endstops_enabled = enable_soft_endstops;
3832
             soft_endstops_enabled = enable_soft_endstops;
3837
           #endif
3833
           #endif
3838
         }
3834
         }
3839
         // If there's another point to sample, move there with optional lift.
3835
         // If there's another point to sample, move there with optional lift.
3840
-        if (probe_index < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
3841
-          mbl.zigzag(probe_index, px, py);
3836
+        if (mbl_probe_index < (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS)) {
3837
+          mbl.zigzag(mbl_probe_index, px, py);
3842
           _mbl_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
3838
           _mbl_goto_xy(mbl.index_to_xpos[px], mbl.index_to_ypos[py]);
3843
 
3839
 
3844
           #if HAS_SOFTWARE_ENDSTOPS
3840
           #if HAS_SOFTWARE_ENDSTOPS
3847
             soft_endstops_enabled = false;
3843
             soft_endstops_enabled = false;
3848
           #endif
3844
           #endif
3849
 
3845
 
3850
-          probe_index++;
3846
+          mbl_probe_index++;
3851
         }
3847
         }
3852
         else {
3848
         else {
3853
           // One last "return to the bed" (as originally coded) at completion
3849
           // One last "return to the bed" (as originally coded) at completion
3857
 
3853
 
3858
           // After recording the last point, activate the mbl and home
3854
           // After recording the last point, activate the mbl and home
3859
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3855
           SERIAL_PROTOCOLLNPGM("Mesh probing done.");
3860
-          probe_index = -1;
3856
+          mbl_probe_index = -1;
3861
           mbl.set_has_mesh(true);
3857
           mbl.set_has_mesh(true);
3862
           mbl.set_reactivate(true);
3858
           mbl.set_reactivate(true);
3863
           enqueue_and_echo_commands_P(PSTR("G28"));
3859
           enqueue_and_echo_commands_P(PSTR("G28"));
3869
       case MeshSet:
3865
       case MeshSet:
3870
         if (code_seen('X')) {
3866
         if (code_seen('X')) {
3871
           px = code_value_int() - 1;
3867
           px = code_value_int() - 1;
3872
-          if (px < 0 || px >= MESH_NUM_X_POINTS) {
3868
+          if (!WITHIN(px, 0, MESH_NUM_X_POINTS - 1)) {
3873
             SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").");
3869
             SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").");
3874
             return;
3870
             return;
3875
           }
3871
           }
3881
 
3877
 
3882
         if (code_seen('Y')) {
3878
         if (code_seen('Y')) {
3883
           py = code_value_int() - 1;
3879
           py = code_value_int() - 1;
3884
-          if (py < 0 || py >= MESH_NUM_Y_POINTS) {
3880
+          if (!WITHIN(py, 0, MESH_NUM_Y_POINTS - 1)) {
3885
             SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").");
3881
             SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").");
3886
             return;
3882
             return;
3887
           }
3883
           }
4412
         if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
4408
         if ( NEAR(current_position[X_AXIS], xProbe - (X_PROBE_OFFSET_FROM_EXTRUDER))
4413
           && NEAR(current_position[Y_AXIS], yProbe - (Y_PROBE_OFFSET_FROM_EXTRUDER))
4409
           && NEAR(current_position[Y_AXIS], yProbe - (Y_PROBE_OFFSET_FROM_EXTRUDER))
4414
         ) {
4410
         ) {
4415
-          float simple_z = current_position[Z_AXIS] - (measured_z - (-zprobe_zoffset));
4411
+          float simple_z = current_position[Z_AXIS] - measured_z;
4416
           #if ENABLED(DEBUG_LEVELING_FEATURE)
4412
           #if ENABLED(DEBUG_LEVELING_FEATURE)
4417
             if (DEBUGGING(LEVELING)) {
4413
             if (DEBUGGING(LEVELING)) {
4418
               SERIAL_ECHOPAIR("Z from Probe:", simple_z);
4414
               SERIAL_ECHOPAIR("Z from Probe:", simple_z);
4503
     float measured_z = probe_pt(X_probe_location, Y_probe_location, stow, 1);
4499
     float measured_z = probe_pt(X_probe_location, Y_probe_location, stow, 1);
4504
 
4500
 
4505
     SERIAL_PROTOCOLPGM("Bed X: ");
4501
     SERIAL_PROTOCOLPGM("Bed X: ");
4506
-    SERIAL_PROTOCOL(X_probe_location + 0.0001);
4502
+    SERIAL_PROTOCOL(FIXFLOAT(X_probe_location));
4507
     SERIAL_PROTOCOLPGM(" Y: ");
4503
     SERIAL_PROTOCOLPGM(" Y: ");
4508
-    SERIAL_PROTOCOL(Y_probe_location + 0.0001);
4504
+    SERIAL_PROTOCOL(FIXFLOAT(Y_probe_location));
4509
     SERIAL_PROTOCOLPGM(" Z: ");
4505
     SERIAL_PROTOCOLPGM(" Z: ");
4510
-    SERIAL_PROTOCOLLN(measured_z - -zprobe_zoffset + 0.0001);
4506
+    SERIAL_PROTOCOLLN(FIXFLOAT(measured_z));
4511
 
4507
 
4512
     clean_up_after_endstop_or_probe_move();
4508
     clean_up_after_endstop_or_probe_move();
4513
 
4509
 
4971
   if (!code_seen('S')) return;
4967
   if (!code_seen('S')) return;
4972
 
4968
 
4973
   int pin_status = code_value_int();
4969
   int pin_status = code_value_int();
4974
-  if (pin_status < 0 || pin_status > 255) return;
4970
+  if (!WITHIN(pin_status, 0, 255)) return;
4975
 
4971
 
4976
   int pin_number = code_seen('P') ? code_value_int() : LED_PIN;
4972
   int pin_number = code_seen('P') ? code_value_int() : LED_PIN;
4977
   if (pin_number < 0) return;
4973
   if (pin_number < 0) return;
5115
     if (axis_unhomed_error(true, true, true)) return;
5111
     if (axis_unhomed_error(true, true, true)) return;
5116
 
5112
 
5117
     int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
5113
     int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
5118
-    if (verbose_level < 0 || verbose_level > 4) {
5114
+    if (!WITHIN(verbose_level, 0, 4)) {
5119
       SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4).");
5115
       SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4).");
5120
       return;
5116
       return;
5121
     }
5117
     }
5124
       SERIAL_PROTOCOLLNPGM("M48 Z-Probe Repeatability Test");
5120
       SERIAL_PROTOCOLLNPGM("M48 Z-Probe Repeatability Test");
5125
 
5121
 
5126
     int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
5122
     int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
5127
-    if (n_samples < 4 || n_samples > 50) {
5123
+    if (!WITHIN(n_samples, 4, 50)) {
5128
       SERIAL_PROTOCOLLNPGM("?Sample size not plausible (4-50).");
5124
       SERIAL_PROTOCOLLNPGM("?Sample size not plausible (4-50).");
5129
       return;
5125
       return;
5130
     }
5126
     }
5136
 
5132
 
5137
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
5133
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
5138
     #if DISABLED(DELTA)
5134
     #if DISABLED(DELTA)
5139
-      if (X_probe_location < LOGICAL_X_POSITION(MIN_PROBE_X) || X_probe_location > LOGICAL_X_POSITION(MAX_PROBE_X)) {
5135
+      if (!WITHIN(X_probe_location, LOGICAL_X_POSITION(MIN_PROBE_X), LOGICAL_X_POSITION(MAX_PROBE_X))) {
5140
         out_of_range_error(PSTR("X"));
5136
         out_of_range_error(PSTR("X"));
5141
         return;
5137
         return;
5142
       }
5138
       }
5144
 
5140
 
5145
     float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
5141
     float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
5146
     #if DISABLED(DELTA)
5142
     #if DISABLED(DELTA)
5147
-      if (Y_probe_location < LOGICAL_Y_POSITION(MIN_PROBE_Y) || Y_probe_location > LOGICAL_Y_POSITION(MAX_PROBE_Y)) {
5143
+      if (!WITHIN(Y_probe_location, LOGICAL_Y_POSITION(MIN_PROBE_Y), LOGICAL_Y_POSITION(MAX_PROBE_Y))) {
5148
         out_of_range_error(PSTR("Y"));
5144
         out_of_range_error(PSTR("Y"));
5149
         return;
5145
         return;
5150
       }
5146
       }
6795
   inline void gcode_M280() {
6791
   inline void gcode_M280() {
6796
     if (!code_seen('P')) return;
6792
     if (!code_seen('P')) return;
6797
     int servo_index = code_value_int();
6793
     int servo_index = code_value_int();
6798
-    if (servo_index >= 0 && servo_index < NUM_SERVOS) {
6794
+    if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
6799
       if (code_seen('S'))
6795
       if (code_seen('S'))
6800
         MOVE_SERVO(servo_index, code_value_int());
6796
         MOVE_SERVO(servo_index, code_value_int());
6801
       else {
6797
       else {
7002
 
6998
 
7003
     float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
6999
     float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
7004
 
7000
 
7005
-    if (e >= 0 && e < HOTENDS)
7001
+    if (WITHIN(e, 0, HOTENDS - 1))
7006
       target_extruder = e;
7002
       target_extruder = e;
7007
 
7003
 
7008
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
7004
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
7223
       if (code_seen('L')) {
7219
       if (code_seen('L')) {
7224
         const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
7220
         const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
7225
         const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
7221
         const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
7226
-        if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
7222
+        if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
7227
           SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
7223
           SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
7228
           return;
7224
           return;
7229
         }
7225
         }
7316
       }
7312
       }
7317
     }
7313
     }
7318
     else if (hasI && hasJ && hasZ) {
7314
     else if (hasI && hasJ && hasZ) {
7319
-      if (px >= 0 && px < MESH_NUM_X_POINTS && py >= 0 && py < MESH_NUM_Y_POINTS)
7315
+      if (WITHIN(px, 0, MESH_NUM_X_POINTS - 1) && WITHIN(py, 0, MESH_NUM_Y_POINTS - 1))
7320
         mbl.set_z(px, py, z);
7316
         mbl.set_z(px, py, z);
7321
       else {
7317
       else {
7322
         SERIAL_ERROR_START;
7318
         SERIAL_ERROR_START;
7345
     if ((hasZ = code_seen('Z'))) z = code_value_axis_units(Z_AXIS);
7341
     if ((hasZ = code_seen('Z'))) z = code_value_axis_units(Z_AXIS);
7346
 
7342
 
7347
     if (hasI && hasJ && hasZ) {
7343
     if (hasI && hasJ && hasZ) {
7348
-      if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
7344
+      if (WITHIN(px, 0, ABL_GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, ABL_GRID_MAX_POINTS_X - 1)) {
7349
         bed_level_grid[px][py] = z;
7345
         bed_level_grid[px][py] = z;
7350
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7346
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7351
           bed_level_virt_interpolate();
7347
           bed_level_virt_interpolate();
7383
       if (axis_homed[i]) {
7379
       if (axis_homed[i]) {
7384
         float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7380
         float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7385
               diff = current_position[i] - LOGICAL_POSITION(base, i);
7381
               diff = current_position[i] - LOGICAL_POSITION(base, i);
7386
-        if (diff > -20 && diff < 20) {
7382
+        if (WITHIN(diff, -20, 20)) {
7387
           set_home_offset((AxisEnum)i, home_offset[i] - diff);
7383
           set_home_offset((AxisEnum)i, home_offset[i] - diff);
7388
         }
7384
         }
7389
         else {
7385
         else {
7457
 
7453
 
7458
     if (code_seen('Z')) {
7454
     if (code_seen('Z')) {
7459
       float value = code_value_axis_units(Z_AXIS);
7455
       float value = code_value_axis_units(Z_AXIS);
7460
-      if (Z_PROBE_OFFSET_RANGE_MIN <= value && value <= Z_PROBE_OFFSET_RANGE_MAX) {
7456
+      if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
7461
 
7457
 
7462
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7458
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7463
           // Correct bilinear grid for new probe offset
7459
           // Correct bilinear grid for new probe offset
9905
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
9901
       #elif ENABLED(AUTO_BED_LEVELING_UBL)
9906
         if (ubl.state.active) {
9902
         if (ubl.state.active) {
9907
 
9903
 
9908
-//        ubl_line_to_destination(MMS_SCALED(feedrate_mm_s));
9909
-
9910
-          ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS],
9911
-//                      (feedrate*(1.0/60.0))*(feedrate_percentage*(1.0/100.0) ), active_extruder);
9912
-                      MMS_SCALED(feedrate_mm_s), active_extruder);
9904
+          ubl_line_to_destination(MMS_SCALED(feedrate_mm_s), active_extruder);
9913
 
9905
 
9914
           return false;
9906
           return false;
9915
         }
9907
         }

+ 18
- 18
Marlin/SanityCheck.h Visa fil

540
  * Make sure Z_SAFE_HOMING point is reachable
540
  * Make sure Z_SAFE_HOMING point is reachable
541
  */
541
  */
542
 #if ENABLED(Z_SAFE_HOMING)
542
 #if ENABLED(Z_SAFE_HOMING)
543
-  #if Z_SAFE_HOMING_X_POINT < MIN_PROBE_X || Z_SAFE_HOMING_X_POINT > MAX_PROBE_X
543
+  #if !WITHIN(Z_SAFE_HOMING_X_POINT, MIN_PROBE_X, MAX_PROBE_X)
544
     #if HAS_BED_PROBE
544
     #if HAS_BED_PROBE
545
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the Z probe."
545
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the Z probe."
546
     #else
546
     #else
547
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle."
547
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle."
548
     #endif
548
     #endif
549
-  #elif Z_SAFE_HOMING_Y_POINT < MIN_PROBE_Y || Z_SAFE_HOMING_Y_POINT > MAX_PROBE_Y
549
+  #elif !WITHIN(Z_SAFE_HOMING_Y_POINT, MIN_PROBE_Y, MAX_PROBE_Y)
550
     #if HAS_BED_PROBE
550
     #if HAS_BED_PROBE
551
       #error "Z_SAFE_HOMING_Y_POINT can't be reached by the Z probe."
551
       #error "Z_SAFE_HOMING_Y_POINT can't be reached by the Z probe."
552
     #else
552
     #else
598
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
598
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
599
     #if DISABLED(EEPROM_SETTINGS)
599
     #if DISABLED(EEPROM_SETTINGS)
600
       #error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
600
       #error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
601
-    #elif UBL_MESH_NUM_X_POINTS < 3 || UBL_MESH_NUM_X_POINTS > 15 || UBL_MESH_NUM_Y_POINTS < 3 || UBL_MESH_NUM_Y_POINTS > 15
601
+    #elif !WITHIN(UBL_MESH_NUM_X_POINTS, 3, 15) || !WITHIN(UBL_MESH_NUM_Y_POINTS, 3, 15)
602
       #error "UBL_MESH_NUM_[XY]_POINTS must be a whole number between 3 and 15."
602
       #error "UBL_MESH_NUM_[XY]_POINTS must be a whole number between 3 and 15."
603
-    #elif UBL_PROBE_PT_1_X < MIN_PROBE_X || UBL_PROBE_PT_1_X > MAX_PROBE_X
603
+    #elif !WITHIN(UBL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
604
       #error "The given UBL_PROBE_PT_1_X can't be reached by the Z probe."
604
       #error "The given UBL_PROBE_PT_1_X can't be reached by the Z probe."
605
-    #elif UBL_PROBE_PT_2_X < MIN_PROBE_X || UBL_PROBE_PT_2_X > MAX_PROBE_X
605
+    #elif !WITHIN(UBL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
606
       #error "The given UBL_PROBE_PT_2_X can't be reached by the Z probe."
606
       #error "The given UBL_PROBE_PT_2_X can't be reached by the Z probe."
607
-    #elif UBL_PROBE_PT_3_X < MIN_PROBE_X || UBL_PROBE_PT_3_X > MAX_PROBE_X
607
+    #elif !WITHIN(UBL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
608
       #error "The given UBL_PROBE_PT_3_X can't be reached by the Z probe."
608
       #error "The given UBL_PROBE_PT_3_X can't be reached by the Z probe."
609
-    #elif UBL_PROBE_PT_1_Y < MIN_PROBE_Y || UBL_PROBE_PT_1_Y > MAX_PROBE_Y
609
+    #elif !WITHIN(UBL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
610
       #error "The given UBL_PROBE_PT_1_Y can't be reached by the Z probe."
610
       #error "The given UBL_PROBE_PT_1_Y can't be reached by the Z probe."
611
-    #elif UBL_PROBE_PT_2_Y < MIN_PROBE_Y || UBL_PROBE_PT_2_Y > MAX_PROBE_Y
611
+    #elif !WITHIN(UBL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
612
       #error "The given UBL_PROBE_PT_2_Y can't be reached by the Z probe."
612
       #error "The given UBL_PROBE_PT_2_Y can't be reached by the Z probe."
613
-    #elif UBL_PROBE_PT_3_Y < MIN_PROBE_Y || UBL_PROBE_PT_3_Y > MAX_PROBE_Y
613
+    #elif !WITHIN(UBL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
614
       #error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
614
       #error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
615
     #endif
615
     #endif
616
   #else // AUTO_BED_LEVELING_3POINT
616
   #else // AUTO_BED_LEVELING_3POINT
617
-    #if ABL_PROBE_PT_1_X < MIN_PROBE_X || ABL_PROBE_PT_1_X > MAX_PROBE_X
617
+    #if !WITHIN(ABL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
618
       #error "The given ABL_PROBE_PT_1_X can't be reached by the Z probe."
618
       #error "The given ABL_PROBE_PT_1_X can't be reached by the Z probe."
619
-    #elif ABL_PROBE_PT_2_X < MIN_PROBE_X || ABL_PROBE_PT_2_X > MAX_PROBE_X
619
+    #elif !WITHIN(ABL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
620
       #error "The given ABL_PROBE_PT_2_X can't be reached by the Z probe."
620
       #error "The given ABL_PROBE_PT_2_X can't be reached by the Z probe."
621
-    #elif ABL_PROBE_PT_3_X < MIN_PROBE_X || ABL_PROBE_PT_3_X > MAX_PROBE_X
621
+    #elif !WITHIN(ABL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
622
       #error "The given ABL_PROBE_PT_3_X can't be reached by the Z probe."
622
       #error "The given ABL_PROBE_PT_3_X can't be reached by the Z probe."
623
-    #elif ABL_PROBE_PT_1_Y < MIN_PROBE_Y || ABL_PROBE_PT_1_Y > MAX_PROBE_Y
623
+    #elif !WITHIN(ABL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
624
       #error "The given ABL_PROBE_PT_1_Y can't be reached by the Z probe."
624
       #error "The given ABL_PROBE_PT_1_Y can't be reached by the Z probe."
625
-    #elif ABL_PROBE_PT_2_Y < MIN_PROBE_Y || ABL_PROBE_PT_2_Y > MAX_PROBE_Y
625
+    #elif !WITHIN(ABL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
626
       #error "The given ABL_PROBE_PT_2_Y can't be reached by the Z probe."
626
       #error "The given ABL_PROBE_PT_2_Y can't be reached by the Z probe."
627
-    #elif ABL_PROBE_PT_3_Y < MIN_PROBE_Y || ABL_PROBE_PT_3_Y > MAX_PROBE_Y
627
+    #elif !WITHIN(ABL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
628
       #error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
628
       #error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
629
     #endif
629
     #endif
630
   #endif // AUTO_BED_LEVELING_3POINT
630
   #endif // AUTO_BED_LEVELING_3POINT
862
 /**
862
 /**
863
  * Endstops
863
  * Endstops
864
  */
864
  */
865
-#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _XMAX_ && Z2_USE_ENDSTOP <= _XMIN_)
865
+#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _XMAX_, _XMIN_))
866
  #error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG."
866
  #error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG."
867
-#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _YMAX_ && Z2_USE_ENDSTOP <= _YMIN_)
867
+#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _YMAX_, _YMIN_))
868
  #error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG."
868
  #error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG."
869
-#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _ZMAX_ && Z2_USE_ENDSTOP <= _ZMIN_)
869
+#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _ZMAX_, _ZMIN_))
870
  #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG."
870
  #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG."
871
 #elif ENABLED(Z_DUAL_ENDSTOPS)
871
 #elif ENABLED(Z_DUAL_ENDSTOPS)
872
   #if !Z2_USE_ENDSTOP
872
   #if !Z2_USE_ENDSTOP

+ 33
- 43
Marlin/UBL.h Visa fil

43
     bool ubl_lcd_clicked();
43
     bool ubl_lcd_clicked();
44
     void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
44
     void probe_entire_mesh(const float&, const float&, const bool, const bool, const bool);
45
     void debug_current_and_destination(char *title);
45
     void debug_current_and_destination(char *title);
46
-    void ubl_line_to_destination(const float&, const float&, const float&, const float&, const float&, uint8_t);
46
+    void ubl_line_to_destination(const float&, uint8_t);
47
     void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
47
     void manually_probe_remaining_mesh(const float&, const float&, const float&, const float&, const bool);
48
     vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
48
     vector_3 tilt_mesh_based_on_3pts(const float&, const float&, const float&);
49
     float measure_business_card_thickness(const float&);
49
     float measure_business_card_thickness(const float&);
169
 
169
 
170
         static int8_t find_closest_x_index(const float &x) {
170
         static int8_t find_closest_x_index(const float &x) {
171
           const int8_t px = (x - (UBL_MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
171
           const int8_t px = (x - (UBL_MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
172
-          return (px >= 0 && px < (UBL_MESH_NUM_X_POINTS)) ? px : -1;
172
+          return WITHIN(px, 0, UBL_MESH_NUM_X_POINTS - 1) ? px : -1;
173
         }
173
         }
174
 
174
 
175
         static int8_t find_closest_y_index(const float &y) {
175
         static int8_t find_closest_y_index(const float &y) {
176
           const int8_t py = (y - (UBL_MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
176
           const int8_t py = (y - (UBL_MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
177
-          return (py >= 0 && py < (UBL_MESH_NUM_Y_POINTS)) ? py : -1;
177
+          return WITHIN(py, 0, UBL_MESH_NUM_Y_POINTS - 1) ? py : -1;
178
         }
178
         }
179
 
179
 
180
         /**
180
         /**
193
          *  multiplications.
193
          *  multiplications.
194
          */
194
          */
195
         static FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
195
         static FORCE_INLINE float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
196
-          const float delta_z = (z2 - z1),
197
-                      delta_a = (a0 - a1) / (a2 - a1);
198
-          return z1 + delta_a * delta_z;
196
+          return z1 + (z2 - z1) * (a0 - a1) / (a2 - a1);
199
         }
197
         }
200
 
198
 
201
         /**
199
         /**
202
-         * get_z_correction_at_Y_intercept(float x0, int x1_i, int yi) only takes
203
-         * three parameters. It assumes the x0 point is on a Mesh line denoted by yi. In theory
204
-         * we could use get_cell_index_x(float x) to obtain the 2nd parameter x1_i but any code calling
205
-         * the get_z_correction_along_vertical_mesh_line_at_specific_X routine  will already have
206
-         * the X index of the x0 intersection available and we don't want to perform any extra floating
207
-         * point operations.
200
+         * z_correction_for_x_on_horizontal_mesh_line is an optimization for
201
+         * the rare occasion when a point lies exactly on a Mesh line (denoted by index yi).
208
          */
202
          */
209
-        static inline float get_z_correction_along_horizontal_mesh_line_at_specific_X(const float &x0, const int x1_i, const int yi) {
210
-          if (x1_i < 0 || yi < 0 || x1_i >= UBL_MESH_NUM_X_POINTS || yi >= UBL_MESH_NUM_Y_POINTS) {
211
-            SERIAL_ECHOPAIR("? in get_z_correction_along_horizontal_mesh_line_at_specific_X(x0=", x0);
203
+        static inline float z_correction_for_x_on_horizontal_mesh_line(const float &lx0, const int x1_i, const int yi) {
204
+          if (!WITHIN(x1_i, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(yi, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
205
+            SERIAL_ECHOPAIR("? in z_correction_for_x_on_horizontal_mesh_line(lx0=", lx0);
212
             SERIAL_ECHOPAIR(",x1_i=", x1_i);
206
             SERIAL_ECHOPAIR(",x1_i=", x1_i);
213
             SERIAL_ECHOPAIR(",yi=", yi);
207
             SERIAL_ECHOPAIR(",yi=", yi);
214
             SERIAL_CHAR(')');
208
             SERIAL_CHAR(')');
216
             return NAN;
210
             return NAN;
217
           }
211
           }
218
 
212
 
219
-          const float xratio = (RAW_X_POSITION(x0) - mesh_index_to_xpos[x1_i]) * (1.0 / (MESH_X_DIST)),
220
-                      z1 = z_values[x1_i][yi],
221
-                      z2 = z_values[x1_i + 1][yi],
222
-                      dz = (z2 - z1);
213
+          const float xratio = (RAW_X_POSITION(lx0) - mesh_index_to_xpos[x1_i]) * (1.0 / (MESH_X_DIST)),
214
+                      z1 = z_values[x1_i][yi];
223
 
215
 
224
-          return z1 + xratio * dz;
216
+          return z1 + xratio * (z_values[x1_i + 1][yi] - z1);
225
         }
217
         }
226
 
218
 
227
         //
219
         //
228
-        // See comments above for get_z_correction_along_horizontal_mesh_line_at_specific_X
220
+        // See comments above for z_correction_for_x_on_horizontal_mesh_line
229
         //
221
         //
230
-        static inline float get_z_correction_along_vertical_mesh_line_at_specific_Y(const float &y0, const int xi, const int y1_i) {
231
-          if (xi < 0 || y1_i < 0 || xi >= UBL_MESH_NUM_X_POINTS || y1_i >= UBL_MESH_NUM_Y_POINTS) {
232
-            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_X(y0=", y0);
222
+        static inline float z_correction_for_y_on_vertical_mesh_line(const float &ly0, const int xi, const int y1_i) {
223
+          if (!WITHIN(xi, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(y1_i, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
224
+            SERIAL_ECHOPAIR("? in get_z_correction_along_vertical_mesh_line_at_specific_x(ly0=", ly0);
233
             SERIAL_ECHOPAIR(", x1_i=", xi);
225
             SERIAL_ECHOPAIR(", x1_i=", xi);
234
             SERIAL_ECHOPAIR(", yi=", y1_i);
226
             SERIAL_ECHOPAIR(", yi=", y1_i);
235
             SERIAL_CHAR(')');
227
             SERIAL_CHAR(')');
237
             return NAN;
229
             return NAN;
238
           }
230
           }
239
 
231
 
240
-          const float yratio = (RAW_Y_POSITION(y0) - mesh_index_to_ypos[y1_i]) * (1.0 / (MESH_Y_DIST)),
241
-                      z1 = z_values[xi][y1_i],
242
-                      z2 = z_values[xi][y1_i + 1],
243
-                      dz = (z2 - z1);
232
+          const float yratio = (RAW_Y_POSITION(ly0) - mesh_index_to_ypos[y1_i]) * (1.0 / (MESH_Y_DIST)),
233
+                      z1 = z_values[xi][y1_i];
244
 
234
 
245
-          return z1 + yratio * dz;
235
+          return z1 + yratio * (z_values[xi][y1_i + 1] - z1);
246
         }
236
         }
247
 
237
 
248
         /**
238
         /**
251
          * Z-Height at both ends. Then it does a linear interpolation of these heights based
241
          * Z-Height at both ends. Then it does a linear interpolation of these heights based
252
          * on the Y position within the cell.
242
          * on the Y position within the cell.
253
          */
243
          */
254
-        static float get_z_correction(const float &x0, const float &y0) {
255
-          const int8_t cx = get_cell_index_x(RAW_X_POSITION(x0)),
256
-                       cy = get_cell_index_y(RAW_Y_POSITION(y0));
244
+        static float get_z_correction(const float &lx0, const float &ly0) {
245
+          const int8_t cx = get_cell_index_x(RAW_X_POSITION(lx0)),
246
+                       cy = get_cell_index_y(RAW_Y_POSITION(ly0));
257
 
247
 
258
-          if (cx < 0 || cy < 0 || cx >= UBL_MESH_NUM_X_POINTS || cy >= UBL_MESH_NUM_Y_POINTS) {
248
+          if (!WITHIN(cx, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(cy, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
259
 
249
 
260
-            SERIAL_ECHOPAIR("? in get_z_correction(x0=", x0);
261
-            SERIAL_ECHOPAIR(", y0=", y0);
250
+            SERIAL_ECHOPAIR("? in get_z_correction(lx0=", lx0);
251
+            SERIAL_ECHOPAIR(", ly0=", ly0);
262
             SERIAL_CHAR(')');
252
             SERIAL_CHAR(')');
263
             SERIAL_EOL;
253
             SERIAL_EOL;
264
 
254
 
269
             return 0.0; // this used to return state.z_offset
259
             return 0.0; // this used to return state.z_offset
270
           }
260
           }
271
 
261
 
272
-          const float z1 = calc_z0(RAW_X_POSITION(x0),
262
+          const float z1 = calc_z0(RAW_X_POSITION(lx0),
273
                         mesh_index_to_xpos[cx], z_values[cx][cy],
263
                         mesh_index_to_xpos[cx], z_values[cx][cy],
274
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy]),
264
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy]),
275
-                      z2 = calc_z0(RAW_X_POSITION(x0),
265
+                      z2 = calc_z0(RAW_X_POSITION(lx0),
276
                         mesh_index_to_xpos[cx], z_values[cx][cy + 1],
266
                         mesh_index_to_xpos[cx], z_values[cx][cy + 1],
277
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy + 1]);
267
                         mesh_index_to_xpos[cx + 1], z_values[cx + 1][cy + 1]);
278
-                float z0 = calc_z0(RAW_Y_POSITION(y0),
268
+                float z0 = calc_z0(RAW_Y_POSITION(ly0),
279
                     mesh_index_to_ypos[cy], z1,
269
                     mesh_index_to_ypos[cy], z1,
280
                     mesh_index_to_ypos[cy + 1], z2);
270
                     mesh_index_to_ypos[cy + 1], z2);
281
 
271
 
282
           #if ENABLED(DEBUG_LEVELING_FEATURE)
272
           #if ENABLED(DEBUG_LEVELING_FEATURE)
283
             if (DEBUGGING(MESH_ADJUST)) {
273
             if (DEBUGGING(MESH_ADJUST)) {
284
-              SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
274
+              SERIAL_ECHOPAIR(" raw get_z_correction(", lx0);
285
               SERIAL_CHAR(',')
275
               SERIAL_CHAR(',')
286
-              SERIAL_ECHO(y0);
276
+              SERIAL_ECHO(ly0);
287
               SERIAL_ECHOPGM(") = ");
277
               SERIAL_ECHOPGM(") = ");
288
               SERIAL_ECHO_F(z0, 6);
278
               SERIAL_ECHO_F(z0, 6);
289
             }
279
             }
305
 
295
 
306
             #if ENABLED(DEBUG_LEVELING_FEATURE)
296
             #if ENABLED(DEBUG_LEVELING_FEATURE)
307
               if (DEBUGGING(MESH_ADJUST)) {
297
               if (DEBUGGING(MESH_ADJUST)) {
308
-                SERIAL_ECHOPAIR("??? Yikes!  NAN in get_z_correction(", x0);
298
+                SERIAL_ECHOPAIR("??? Yikes!  NAN in get_z_correction(", lx0);
309
                 SERIAL_CHAR(',');
299
                 SERIAL_CHAR(',');
310
-                SERIAL_ECHO(y0);
300
+                SERIAL_ECHO(ly0);
311
                 SERIAL_CHAR(')');
301
                 SERIAL_CHAR(')');
312
                 SERIAL_EOL;
302
                 SERIAL_EOL;
313
               }
303
               }
327
          */
317
          */
328
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
318
         #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
329
 
319
 
330
-          FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
320
+          static FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
331
             const float rz = RAW_Z_POSITION(lz);
321
             const float rz = RAW_Z_POSITION(lz);
332
             if (last_specified_z != rz) {
322
             if (last_specified_z != rz) {
333
               last_specified_z = rz;
323
               last_specified_z = rz;

+ 3
- 3
Marlin/UBL_Bed_Leveling.cpp Visa fil

118
       return;
118
       return;
119
     }
119
     }
120
 
120
 
121
-    if (m < 0 || m >= j || eeprom_start <= 0) {
121
+    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
122
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
122
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
123
       return;
123
       return;
124
     }
124
     }
133
   void unified_bed_leveling::store_mesh(const int16_t m) {
133
   void unified_bed_leveling::store_mesh(const int16_t m) {
134
     int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
134
     int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
135
 
135
 
136
-    if (m < 0 || m >= j || eeprom_start <= 0) {
136
+    if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
137
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
137
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
138
       SERIAL_PROTOCOL(m);
138
       SERIAL_PROTOCOL(m);
139
       SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
139
       SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
203
 
203
 
204
         const float f = z_values[i][j];
204
         const float f = z_values[i][j];
205
         if (isnan(f)) {
205
         if (isnan(f)) {
206
-          serialprintPGM(map0 ? PSTR("    .    ") : PSTR("NAN"));
206
+          serialprintPGM(map0 ? PSTR("   .  ") : PSTR("NAN"));
207
         }
207
         }
208
         else {
208
         else {
209
           // if we don't do this, the columns won't line up nicely
209
           // if we don't do this, the columns won't line up nicely

+ 39
- 32
Marlin/UBL_G29.cpp Visa fil

49
   extern bool code_value_bool();
49
   extern bool code_value_bool();
50
   extern bool code_has_value();
50
   extern bool code_has_value();
51
   extern float probe_pt(float x, float y, bool, int);
51
   extern float probe_pt(float x, float y, bool, int);
52
-  extern float zprobe_zoffset;
53
   extern bool set_probe_deployed(bool);
52
   extern bool set_probe_deployed(bool);
54
   #define DEPLOY_PROBE() set_probe_deployed(true)
53
   #define DEPLOY_PROBE() set_probe_deployed(true)
55
   #define STOW_PROBE() set_probe_deployed(false)
54
   #define STOW_PROBE() set_probe_deployed(false)
342
     if (code_seen('Q')) {
341
     if (code_seen('Q')) {
343
 
342
 
344
       const int test_pattern = code_has_value() ? code_value_int() : -1;
343
       const int test_pattern = code_has_value() ? code_value_int() : -1;
345
-      if (test_pattern < 0 || test_pattern > 2) {
344
+      if (!WITHIN(test_pattern, 0, 2)) {
346
         SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
345
         SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
347
         return;
346
         return;
348
       }
347
       }
375
     /*
374
     /*
376
     if (code_seen('U')) {
375
     if (code_seen('U')) {
377
       unlevel_value = code_value_int();
376
       unlevel_value = code_value_int();
378
-      //if (unlevel_value < 0 || unlevel_value > 7) {
377
+      //if (!WITHIN(unlevel_value, 0, 7)) {
379
       //  SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
378
       //  SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
380
       //  return;
379
       //  return;
381
       //}
380
       //}
384
 
383
 
385
     if (code_seen('P')) {
384
     if (code_seen('P')) {
386
       phase_value = code_value_int();
385
       phase_value = code_value_int();
387
-      if (phase_value < 0 || phase_value > 7) {
386
+      if (!WITHIN(phase_value, 0, 7)) {
388
         SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
387
         SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
389
         return;
388
         return;
390
       }
389
       }
516
     }
515
     }
517
 
516
 
518
     if (code_seen('T')) {
517
     if (code_seen('T')) {
519
-      float z1 = probe_pt(ubl_3_point_1_X, ubl_3_point_1_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
520
-            z2 = probe_pt(ubl_3_point_2_X, ubl_3_point_2_Y, false /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset,
521
-            z3 = probe_pt(ubl_3_point_3_X, ubl_3_point_3_Y, true  /*Stow Flag*/, g29_verbose_level) + zprobe_zoffset;
518
+      const float lx1 = LOGICAL_X_POSITION(ubl_3_point_1_X),
519
+                  lx2 = LOGICAL_X_POSITION(ubl_3_point_2_X),
520
+                  lx3 = LOGICAL_X_POSITION(ubl_3_point_3_X),
521
+                  ly1 = LOGICAL_Y_POSITION(ubl_3_point_1_Y),
522
+                  ly2 = LOGICAL_Y_POSITION(ubl_3_point_2_Y),
523
+                  ly3 = LOGICAL_Y_POSITION(ubl_3_point_3_Y);
524
+
525
+      float z1 = probe_pt(lx1, ly1, false /*Stow Flag*/, g29_verbose_level),
526
+            z2 = probe_pt(lx2, ly2, false /*Stow Flag*/, g29_verbose_level),
527
+            z3 = probe_pt(lx3, ly3, true  /*Stow Flag*/, g29_verbose_level);
522
 
528
 
523
       //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
529
       //  We need to adjust z1, z2, z3 by the Mesh Height at these points. Just because they are non-zero doesn't mean
524
       //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
530
       //  the Mesh is tilted!  (We need to compensate each probe point by what the Mesh says that location's height is)
525
 
531
 
526
-      z1 -= ubl.get_z_correction(ubl_3_point_1_X, ubl_3_point_1_Y);
527
-      z2 -= ubl.get_z_correction(ubl_3_point_2_X, ubl_3_point_2_Y);
528
-      z3 -= ubl.get_z_correction(ubl_3_point_3_X, ubl_3_point_3_Y);
532
+      z1 -= ubl.get_z_correction(lx1, ly1);
533
+      z2 -= ubl.get_z_correction(lx2, ly2);
534
+      z3 -= ubl.get_z_correction(lx3, ly3);
529
 
535
 
530
       do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
536
       do_blocking_move_to_xy((X_MAX_POS - (X_MIN_POS)) / 2.0, (Y_MAX_POS - (Y_MIN_POS)) / 2.0);
531
       tilt_mesh_based_on_3pts(z1, z2, z3);
537
       tilt_mesh_based_on_3pts(z1, z2, z3);
560
 
566
 
561
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
567
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
562
 
568
 
563
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
569
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
564
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
570
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
565
         return;
571
         return;
566
       }
572
       }
594
 
600
 
595
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
601
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
596
 
602
 
597
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
603
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
598
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
604
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
599
         SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
605
         SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
600
         goto LEAVE;
606
         goto LEAVE;
754
                     rawy = ubl.mesh_index_to_ypos[location.y_index];
760
                     rawy = ubl.mesh_index_to_ypos[location.y_index];
755
 
761
 
756
         // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
762
         // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
757
-        if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
763
+        if (!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y)) {
758
           SERIAL_ERROR_START;
764
           SERIAL_ERROR_START;
759
           SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
765
           SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
760
           ubl.has_control_of_lcd_panel = false;
766
           ubl.has_control_of_lcd_panel = false;
761
           goto LEAVE;
767
           goto LEAVE;
762
         }
768
         }
763
         const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level);
769
         const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level);
764
-        ubl.z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
770
+        ubl.z_values[location.x_index][location.y_index] = measured_z;
765
       }
771
       }
766
 
772
 
767
       if (do_ubl_mesh_map) ubl.display_map(map_type);
773
       if (do_ubl_mesh_map) ubl.display_map(map_type);
779
     );
785
     );
780
   }
786
   }
781
 
787
 
782
-  vector_3 tilt_mesh_based_on_3pts(const float &pt1, const float &pt2, const float &pt3) {
788
+  vector_3 tilt_mesh_based_on_3pts(const float &z1, const float &z2, const float &z3) {
783
     float c, d, t;
789
     float c, d, t;
784
     int i, j;
790
     int i, j;
785
 
791
 
786
     vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
792
     vector_3 v1 = vector_3( (ubl_3_point_1_X - ubl_3_point_2_X),
787
                             (ubl_3_point_1_Y - ubl_3_point_2_Y),
793
                             (ubl_3_point_1_Y - ubl_3_point_2_Y),
788
-                            (pt1 - pt2) ),
794
+                            (z1 - z2) ),
789
 
795
 
790
              v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
796
              v2 = vector_3( (ubl_3_point_3_X - ubl_3_point_2_X),
791
                             (ubl_3_point_3_Y - ubl_3_point_2_Y),
797
                             (ubl_3_point_3_Y - ubl_3_point_2_Y),
792
-                            (pt3 - pt2) ),
798
+                            (z3 - z2) ),
793
 
799
 
794
              normal = vector_3::cross(v1, v2);
800
              normal = vector_3::cross(v1, v2);
795
 
801
 
811
     // All of 3 of these points should give us the same d constant
817
     // All of 3 of these points should give us the same d constant
812
     //
818
     //
813
     t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
819
     t = normal.x * ubl_3_point_1_X + normal.y * ubl_3_point_1_Y;
814
-    d = t + normal.z * pt1;
820
+    d = t + normal.z * z1;
815
     c = d - t;
821
     c = d - t;
816
     SERIAL_ECHOPGM("d from 1st point: ");
822
     SERIAL_ECHOPGM("d from 1st point: ");
817
     SERIAL_ECHO_F(d, 6);
823
     SERIAL_ECHO_F(d, 6);
819
     SERIAL_ECHO_F(c, 6);
825
     SERIAL_ECHO_F(c, 6);
820
     SERIAL_EOL;
826
     SERIAL_EOL;
821
     t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
827
     t = normal.x * ubl_3_point_2_X + normal.y * ubl_3_point_2_Y;
822
-    d = t + normal.z * pt2;
828
+    d = t + normal.z * z2;
823
     c = d - t;
829
     c = d - t;
824
     SERIAL_ECHOPGM("d from 2nd point: ");
830
     SERIAL_ECHOPGM("d from 2nd point: ");
825
     SERIAL_ECHO_F(d, 6);
831
     SERIAL_ECHO_F(d, 6);
827
     SERIAL_ECHO_F(c, 6);
833
     SERIAL_ECHO_F(c, 6);
828
     SERIAL_EOL;
834
     SERIAL_EOL;
829
     t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
835
     t = normal.x * ubl_3_point_3_X + normal.y * ubl_3_point_3_Y;
830
-    d = t + normal.z * pt3;
836
+    d = t + normal.z * z3;
831
     c = d - t;
837
     c = d - t;
832
     SERIAL_ECHOPGM("d from 3rd point: ");
838
     SERIAL_ECHOPGM("d from 3rd point: ");
833
     SERIAL_ECHO_F(d, 6);
839
     SERIAL_ECHO_F(d, 6);
904
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
910
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
905
 
911
 
906
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
912
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
907
-      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
913
+      if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) {
908
         SERIAL_ERROR_START;
914
         SERIAL_ERROR_START;
909
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
915
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
910
         ubl.has_control_of_lcd_panel = false;
916
         ubl.has_control_of_lcd_panel = false;
976
     #endif
982
     #endif
977
 
983
 
978
     g29_verbose_level = code_seen('V') ? code_value_int() : 0;
984
     g29_verbose_level = code_seen('V') ? code_value_int() : 0;
979
-    if (g29_verbose_level < 0 || g29_verbose_level > 4) {
985
+    if (!WITHIN(g29_verbose_level, 0, 4)) {
980
       SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
986
       SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
981
       return UBL_ERR;
987
       return UBL_ERR;
982
     }
988
     }
983
 
989
 
984
     x_flag = code_seen('X') && code_has_value();
990
     x_flag = code_seen('X') && code_has_value();
985
     x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
991
     x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
986
-    if (x_pos < LOGICAL_X_POSITION(X_MIN_POS) || x_pos > LOGICAL_X_POSITION(X_MAX_POS)) {
992
+    if (!WITHIN(RAW_X_POSITION(x_pos), X_MIN_POS, X_MAX_POS)) {
987
       SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
993
       SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
988
       return UBL_ERR;
994
       return UBL_ERR;
989
     }
995
     }
990
 
996
 
991
     y_flag = code_seen('Y') && code_has_value();
997
     y_flag = code_seen('Y') && code_has_value();
992
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
998
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
993
-    if (y_pos < LOGICAL_Y_POSITION(Y_MIN_POS) || y_pos > LOGICAL_Y_POSITION(Y_MAX_POS)) {
999
+    if (!WITHIN(RAW_Y_POSITION(y_pos), Y_MIN_POS, Y_MAX_POS)) {
994
       SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
1000
       SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
995
       return UBL_ERR;
1001
       return UBL_ERR;
996
     }
1002
     }
1018
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1024
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1019
       if (code_seen('F') && code_has_value()) {
1025
       if (code_seen('F') && code_has_value()) {
1020
         const float fh = code_value_float();
1026
         const float fh = code_value_float();
1021
-        if (fh < 0.0 || fh > 100.0) {
1027
+        if (!WITHIN(fh, 0.0, 100.0)) {
1022
           SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
1028
           SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
1023
           return UBL_ERR;
1029
           return UBL_ERR;
1024
         }
1030
         }
1035
     }
1041
     }
1036
 
1042
 
1037
     map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
1043
     map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
1038
-    if (map_type < 0 || map_type > 1) {
1044
+    if (!WITHIN(map_type, 0, 1)) {
1039
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1045
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1040
       return UBL_ERR;
1046
       return UBL_ERR;
1041
     }
1047
     }
1043
     /*
1049
     /*
1044
     if (code_seen('M')) {     // Check if a map type was specified
1050
     if (code_seen('M')) {     // Check if a map type was specified
1045
       map_type = code_has_value() ? code_value_int() : 0; 
1051
       map_type = code_has_value() ? code_value_int() : 0; 
1046
-      if (map_type < 0 || map_type > 1) {
1052
+      if (!WITHIN(map_type, 0, 1)) {
1047
         SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1053
         SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1048
         return UBL_ERR;
1054
         return UBL_ERR;
1049
       }
1055
       }
1109
     const uint16_t k = E2END - ubl.eeprom_start;
1115
     const uint16_t k = E2END - ubl.eeprom_start;
1110
 
1116
 
1111
     SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
1117
     SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
1112
-    if (ubl.state.active)  
1118
+    if (ubl.state.active)
1113
       SERIAL_PROTOCOLCHAR('A');
1119
       SERIAL_PROTOCOLCHAR('A');
1114
     else
1120
     else
1115
       SERIAL_PROTOCOLPGM("In");
1121
       SERIAL_PROTOCOLPGM("In");
1243
 
1249
 
1244
     int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
1250
     int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
1245
 
1251
 
1246
-    if (storage_slot < 0 || storage_slot > j || ubl.eeprom_start <= 0) {
1252
+    if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
1247
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
1253
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
1248
       return;
1254
       return;
1249
     }
1255
     }
1290
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1296
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1291
 
1297
 
1292
           if (probe_as_reference &&
1298
           if (probe_as_reference &&
1293
-            (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y))
1299
+            (!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y))
1294
           ) continue;
1300
           ) continue;
1295
 
1301
 
1296
           // Unreachable. Check if it's the closest location to the nozzle.
1302
           // Unreachable. Check if it's the closest location to the nozzle.
1354
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
1360
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
1355
 
1361
 
1356
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
1362
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
1357
-      if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
1363
+      if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) { // In theory, we don't need this check.
1358
         SERIAL_ERROR_START;
1364
         SERIAL_ERROR_START;
1359
         SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
1365
         SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
1360
         ubl.has_control_of_lcd_panel = false;
1366
         ubl.has_control_of_lcd_panel = false;
1363
 
1369
 
1364
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1370
       do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);    // Move the nozzle to where we are going to edit
1365
       do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1371
       do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
1372
+
1366
       float new_z = ubl.z_values[location.x_index][location.y_index];
1373
       float new_z = ubl.z_values[location.x_index][location.y_index];
1367
       
1374
       
1368
       round_off = (int32_t)(new_z * 1000.0);    // we chop off the last digits just to be clean. We are rounding to the
1375
       round_off = (int32_t)(new_z * 1000.0);    // we chop off the last digits just to be clean. We are rounding to the
1425
     SERIAL_ECHOLNPGM("Done Editing Mesh.");
1432
     SERIAL_ECHOLNPGM("Done Editing Mesh.");
1426
   }
1433
   }
1427
 
1434
 
1428
-#endif // AUTO_BED_LEVELING_UBL
1435
+#endif // AUTO_BED_LEVELING_UBL

+ 88
- 95
Marlin/UBL_line_to_destination.cpp Visa fil

31
 
31
 
32
   extern float destination[XYZE];
32
   extern float destination[XYZE];
33
   extern void set_current_to_destination();
33
   extern void set_current_to_destination();
34
-  extern float destination[];
34
+
35
+  static void debug_echo_axis(const AxisEnum axis) {
36
+    if (current_position[axis] == destination[axis])
37
+      SERIAL_ECHOPGM("-------------");
38
+    else
39
+      SERIAL_ECHO_F(destination[X_AXIS], 6);
40
+  }
41
+
35
   void debug_current_and_destination(char *title) {
42
   void debug_current_and_destination(char *title) {
36
 
43
 
37
     // if the title message starts with a '!' it is so important, we are going to
44
     // if the title message starts with a '!' it is so important, we are going to
67
     SERIAL_ECHOPGM(", ");
74
     SERIAL_ECHOPGM(", ");
68
     SERIAL_ECHO_F(current_position[E_AXIS], 6);
75
     SERIAL_ECHO_F(current_position[E_AXIS], 6);
69
     SERIAL_ECHOPGM(" )   destination=( ");
76
     SERIAL_ECHOPGM(" )   destination=( ");
70
-    if (current_position[X_AXIS] == destination[X_AXIS])
71
-      SERIAL_ECHOPGM("-------------");
72
-    else
73
-      SERIAL_ECHO_F(destination[X_AXIS], 6);
74
-
77
+    debug_echo_axis(X_AXIS);
75
     SERIAL_ECHOPGM(", ");
78
     SERIAL_ECHOPGM(", ");
76
-
77
-    if (current_position[Y_AXIS] == destination[Y_AXIS])
78
-      SERIAL_ECHOPGM("-------------");
79
-    else
80
-      SERIAL_ECHO_F(destination[Y_AXIS], 6);
81
-
79
+    debug_echo_axis(Y_AXIS);
82
     SERIAL_ECHOPGM(", ");
80
     SERIAL_ECHOPGM(", ");
83
-
84
-    if (current_position[Z_AXIS] == destination[Z_AXIS])
85
-      SERIAL_ECHOPGM("-------------");
86
-    else
87
-      SERIAL_ECHO_F(destination[Z_AXIS], 6);
88
-
81
+    debug_echo_axis(Z_AXIS);
89
     SERIAL_ECHOPGM(", ");
82
     SERIAL_ECHOPGM(", ");
90
-
91
-    if (current_position[E_AXIS] == destination[E_AXIS])
92
-      SERIAL_ECHOPGM("-------------");
93
-    else
94
-      SERIAL_ECHO_F(destination[E_AXIS], 6);
95
-
83
+    debug_echo_axis(E_AXIS);
96
     SERIAL_ECHOPGM(" )   ");
84
     SERIAL_ECHOPGM(" )   ");
97
     SERIAL_ECHO(title);
85
     SERIAL_ECHO(title);
98
     SERIAL_EOL;
86
     SERIAL_EOL;
105
     //}
93
     //}
106
   }
94
   }
107
 
95
 
108
-  void ubl_line_to_destination(const float &x_end, const float &y_end, const float &z_end, const float &e_end, const float &feed_rate, uint8_t extruder) {
96
+  void ubl_line_to_destination(const float &feed_rate, uint8_t extruder) {
109
     /**
97
     /**
110
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
98
      * Much of the nozzle movement will be within the same cell. So we will do as little computation
111
      * as possible to determine if this is the case. If this move is within the same cell, we will
99
      * as possible to determine if this is the case. If this move is within the same cell, we will
112
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
100
      * just do the required Z-Height correction, call the Planner's buffer_line() routine, and leave
113
      */
101
      */
114
-    const float x_start = current_position[X_AXIS],
115
-                y_start = current_position[Y_AXIS],
116
-                z_start = current_position[Z_AXIS],
117
-                e_start = current_position[E_AXIS];
118
-
119
-    const int cell_start_xi = ubl.get_cell_index_x(RAW_X_POSITION(x_start)),
120
-              cell_start_yi = ubl.get_cell_index_y(RAW_Y_POSITION(y_start)),
121
-              cell_dest_xi  = ubl.get_cell_index_x(RAW_X_POSITION(x_end)),
122
-              cell_dest_yi  = ubl.get_cell_index_y(RAW_Y_POSITION(y_end));
102
+    const float start[XYZE] = {
103
+                  current_position[X_AXIS],
104
+                  current_position[Y_AXIS],
105
+                  current_position[Z_AXIS],
106
+                  current_position[E_AXIS]
107
+                },
108
+                end[XYZE] = {
109
+                  destination[X_AXIS],
110
+                  destination[Y_AXIS],
111
+                  destination[Z_AXIS],
112
+                  destination[E_AXIS]
113
+                };
114
+
115
+    const int cell_start_xi = ubl.get_cell_index_x(RAW_X_POSITION(start[X_AXIS])),
116
+              cell_start_yi = ubl.get_cell_index_y(RAW_Y_POSITION(start[Y_AXIS])),
117
+              cell_dest_xi  = ubl.get_cell_index_x(RAW_X_POSITION(end[X_AXIS])),
118
+              cell_dest_yi  = ubl.get_cell_index_y(RAW_Y_POSITION(end[Y_AXIS]));
123
 
119
 
124
     if (ubl.g26_debug_flag) {
120
     if (ubl.g26_debug_flag) {
125
-      SERIAL_ECHOPGM(" ubl_line_to_destination(xe=");
126
-      SERIAL_ECHO(x_end);
127
-      SERIAL_ECHOPGM(", ye=");
128
-      SERIAL_ECHO(y_end);
129
-      SERIAL_ECHOPGM(", ze=");
130
-      SERIAL_ECHO(z_end);
131
-      SERIAL_ECHOPGM(", ee=");
132
-      SERIAL_ECHO(e_end);
133
-      SERIAL_ECHOLNPGM(")");
121
+      SERIAL_ECHOPAIR(" ubl_line_to_destination(xe=", end[X_AXIS]);
122
+      SERIAL_ECHOPAIR(", ye=", end[Y_AXIS]);
123
+      SERIAL_ECHOPAIR(", ze=", end[Z_AXIS]);
124
+      SERIAL_ECHOPAIR(", ee=", end[E_AXIS]);
125
+      SERIAL_CHAR(')');
126
+      SERIAL_EOL;
134
       debug_current_and_destination((char*)"Start of ubl_line_to_destination()");
127
       debug_current_and_destination((char*)"Start of ubl_line_to_destination()");
135
     }
128
     }
136
 
129
 
142
        * But we detect it and isolate it. For now, we just pass along the request.
135
        * But we detect it and isolate it. For now, we just pass along the request.
143
        */
136
        */
144
 
137
 
145
-      if (cell_dest_xi < 0 || cell_dest_yi < 0 || cell_dest_xi >= UBL_MESH_NUM_X_POINTS || cell_dest_yi >= UBL_MESH_NUM_Y_POINTS) {
138
+      if (!WITHIN(cell_dest_xi, 0, UBL_MESH_NUM_X_POINTS - 1) || !WITHIN(cell_dest_yi, 0, UBL_MESH_NUM_Y_POINTS - 1)) {
146
 
139
 
147
         // Note: There is no Z Correction in this case. We are off the grid and don't know what
140
         // Note: There is no Z Correction in this case. We are off the grid and don't know what
148
         // a reasonable correction would be.
141
         // a reasonable correction would be.
149
 
142
 
150
-        planner.buffer_line(x_end, y_end, z_end + ubl.state.z_offset, e_end, feed_rate, extruder);
143
+        planner.buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + ubl.state.z_offset, end[E_AXIS], feed_rate, extruder);
151
         set_current_to_destination();
144
         set_current_to_destination();
152
 
145
 
153
         if (ubl.g26_debug_flag)
146
         if (ubl.g26_debug_flag)
167
        * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
160
        * to create a 1-over number for us. That will allow us to do a floating point multiply instead of a floating point divide.
168
        */
161
        */
169
 
162
 
170
-      const float xratio = (RAW_X_POSITION(x_end) - ubl.mesh_index_to_xpos[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
163
+      const float xratio = (RAW_X_POSITION(end[X_AXIS]) - ubl.mesh_index_to_xpos[cell_dest_xi]) * (1.0 / (MESH_X_DIST)),
171
                   z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
164
                   z1 = ubl.z_values[cell_dest_xi    ][cell_dest_yi    ] + xratio *
172
                       (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
165
                       (ubl.z_values[cell_dest_xi + 1][cell_dest_yi    ] - ubl.z_values[cell_dest_xi][cell_dest_yi    ]),
173
                   z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
166
                   z2 = ubl.z_values[cell_dest_xi    ][cell_dest_yi + 1] + xratio *
176
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
169
       // we are done with the fractional X distance into the cell. Now with the two Z-Heights we have calculated, we
177
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
170
       // are going to apply the Y-Distance into the cell to interpolate the final Z correction.
178
 
171
 
179
-      const float yratio = (RAW_Y_POSITION(y_end) - ubl.mesh_index_to_ypos[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
172
+      const float yratio = (RAW_Y_POSITION(end[Y_AXIS]) - ubl.mesh_index_to_ypos[cell_dest_yi]) * (1.0 / (MESH_Y_DIST));
180
 
173
 
181
       float z0 = z1 + (z2 - z1) * yratio;
174
       float z0 = z1 + (z2 - z1) * yratio;
182
 
175
 
186
        */
179
        */
187
       /*
180
       /*
188
         z_optimized = z0;
181
         z_optimized = z0;
189
-        z0 = ubl.get_z_correction(x_end, y_end);
182
+        z0 = ubl.get_z_correction(end[X_AXIS], end[Y_AXIS]);
190
         if (fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized)) {
183
         if (fabs(z_optimized - z0) > .01 || isnan(z0) || isnan(z_optimized)) {
191
         debug_current_and_destination((char*)"FINAL_MOVE: z_correction()");
184
         debug_current_and_destination((char*)"FINAL_MOVE: z_correction()");
192
         if (isnan(z0)) SERIAL_ECHO(" z0==NAN  ");
185
         if (isnan(z0)) SERIAL_ECHO(" z0==NAN  ");
193
         if (isnan(z_optimized)) SERIAL_ECHO(" z_optimized==NAN  ");
186
         if (isnan(z_optimized)) SERIAL_ECHO(" z_optimized==NAN  ");
194
-        SERIAL_ECHOPAIR("  x_end=", x_end);
195
-        SERIAL_ECHOPAIR("  y_end=", y_end);
187
+        SERIAL_ECHOPAIR("  end[X_AXIS]=", end[X_AXIS]);
188
+        SERIAL_ECHOPAIR("  end[Y_AXIS]=", end[Y_AXIS]);
196
         SERIAL_ECHOPAIR("  z0=", z0);
189
         SERIAL_ECHOPAIR("  z0=", z0);
197
         SERIAL_ECHOPAIR("  z_optimized=", z_optimized);
190
         SERIAL_ECHOPAIR("  z_optimized=", z_optimized);
198
         SERIAL_ECHOPAIR("  err=",fabs(z_optimized - z0));
191
         SERIAL_ECHOPAIR("  err=",fabs(z_optimized - z0));
199
         SERIAL_EOL;
192
         SERIAL_EOL;
200
         }
193
         }
201
       //*/
194
       //*/
202
-      z0 *= ubl.fade_scaling_factor_for_z(z_end);
195
+      z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
203
 
196
 
204
       /**
197
       /**
205
        * If part of the Mesh is undefined, it will show up as NAN
198
        * If part of the Mesh is undefined, it will show up as NAN
210
        */
203
        */
211
       if (isnan(z0)) z0 = 0.0;
204
       if (isnan(z0)) z0 = 0.0;
212
 
205
 
213
-      planner.buffer_line(x_end, y_end, z_end + z0 + ubl.state.z_offset, e_end, feed_rate, extruder);
206
+      planner.buffer_line(end[X_AXIS], end[Y_AXIS], end[Z_AXIS] + z0 + ubl.state.z_offset, end[E_AXIS], feed_rate, extruder);
214
 
207
 
215
       if (ubl.g26_debug_flag)
208
       if (ubl.g26_debug_flag)
216
         debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
209
         debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
227
      * blocks of code:
220
      * blocks of code:
228
      */
221
      */
229
 
222
 
230
-    const float dx = x_end - x_start,
231
-                dy = y_end - y_start;
223
+    const float dx = end[X_AXIS] - start[X_AXIS],
224
+                dy = end[Y_AXIS] - start[Y_AXIS];
232
 
225
 
233
     const int left_flag = dx < 0.0 ? 1 : 0,
226
     const int left_flag = dx < 0.0 ? 1 : 0,
234
               down_flag = dy < 0.0 ? 1 : 0;
227
               down_flag = dy < 0.0 ? 1 : 0;
251
     const bool use_x_dist = adx > ady;
244
     const bool use_x_dist = adx > ady;
252
 
245
 
253
     float on_axis_distance = use_x_dist ? dx : dy,
246
     float on_axis_distance = use_x_dist ? dx : dy,
254
-          e_position = e_end - e_start,
255
-          z_position = z_end - z_start;
247
+          e_position = end[E_AXIS] - start[E_AXIS],
248
+          z_position = end[Z_AXIS] - start[Z_AXIS];
256
 
249
 
257
     const float e_normalized_dist = e_position / on_axis_distance,
250
     const float e_normalized_dist = e_position / on_axis_distance,
258
                 z_normalized_dist = z_position / on_axis_distance;
251
                 z_normalized_dist = z_position / on_axis_distance;
260
     int current_xi = cell_start_xi, current_yi = cell_start_yi;
253
     int current_xi = cell_start_xi, current_yi = cell_start_yi;
261
 
254
 
262
     const float m = dy / dx,
255
     const float m = dy / dx,
263
-                c = y_start - m * x_start;
256
+                c = start[Y_AXIS] - m * start[X_AXIS];
264
 
257
 
265
     const bool inf_normalized_flag = NEAR_ZERO(on_axis_distance),
258
     const bool inf_normalized_flag = NEAR_ZERO(on_axis_distance),
266
                inf_m_flag = NEAR_ZERO(dx);
259
                inf_m_flag = NEAR_ZERO(dx);
281
          * else, we know the next X is the same so we can recover and continue!
274
          * else, we know the next X is the same so we can recover and continue!
282
          * Calculate X at the next Y mesh line
275
          * Calculate X at the next Y mesh line
283
          */
276
          */
284
-        const float x = inf_m_flag ? x_start : (next_mesh_line_y - c) / m;
277
+        const float x = inf_m_flag ? start[X_AXIS] : (next_mesh_line_y - c) / m;
285
 
278
 
286
-        float z0 = ubl.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi, current_yi);
279
+        float z0 = ubl.z_correction_for_x_on_horizontal_mesh_line(x, current_xi, current_yi);
287
 
280
 
288
         /**
281
         /**
289
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
282
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
305
           }
298
           }
306
         //*/
299
         //*/
307
 
300
 
308
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
301
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
309
 
302
 
310
         /**
303
         /**
311
          * If part of the Mesh is undefined, it will show up as NAN
304
          * If part of the Mesh is undefined, it will show up as NAN
324
          * happens, it might be best to remove the check and always 'schedule' the move because
317
          * happens, it might be best to remove the check and always 'schedule' the move because
325
          * the planner.buffer_line() routine will filter it if that happens.
318
          * the planner.buffer_line() routine will filter it if that happens.
326
          */
319
          */
327
-        if (y != y_start) {
320
+        if (y != start[Y_AXIS]) {
328
           if (!inf_normalized_flag) {
321
           if (!inf_normalized_flag) {
329
-            on_axis_distance = y - y_start;                               // we don't need to check if the extruder position
330
-            e_position = e_start + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a vertical move
331
-            z_position = z_start + on_axis_distance * z_normalized_dist;
322
+            on_axis_distance = y - start[Y_AXIS];                               // we don't need to check if the extruder position
323
+            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a vertical move
324
+            z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
332
           }
325
           }
333
           else {
326
           else {
334
-            e_position = e_start;
335
-            z_position = z_start;
327
+            e_position = start[E_AXIS];
328
+            z_position = start[Z_AXIS];
336
           }
329
           }
337
 
330
 
338
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
331
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
345
       //
338
       //
346
       // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
339
       // Check if we are at the final destination. Usually, we won't be, but if it is on a Y Mesh Line, we are done.
347
       //
340
       //
348
-      if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end)
341
+      if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
349
         goto FINAL_MOVE;
342
         goto FINAL_MOVE;
350
 
343
 
351
       set_current_to_destination();
344
       set_current_to_destination();
368
         const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
361
         const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi]),
369
                     y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
362
                     y = m * next_mesh_line_x + c;   // Calculate X at the next Y mesh line
370
 
363
 
371
-        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi, current_yi);
364
+        float z0 = ubl.z_correction_for_y_on_vertical_mesh_line(y, current_xi, current_yi);
372
 
365
 
373
         /**
366
         /**
374
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
367
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
390
           }
383
           }
391
         //*/
384
         //*/
392
 
385
 
393
-        z0 = z0 * ubl.fade_scaling_factor_for_z(z_end);
386
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
394
 
387
 
395
         /**
388
         /**
396
          * If part of the Mesh is undefined, it will show up as NAN
389
          * If part of the Mesh is undefined, it will show up as NAN
409
          * that happens, it might be best to remove the check and always 'schedule' the move because
402
          * that happens, it might be best to remove the check and always 'schedule' the move because
410
          * the planner.buffer_line() routine will filter it if that happens.
403
          * the planner.buffer_line() routine will filter it if that happens.
411
          */
404
          */
412
-        if (x != x_start) {
405
+        if (x != start[X_AXIS]) {
413
           if (!inf_normalized_flag) {
406
           if (!inf_normalized_flag) {
414
-            on_axis_distance = x - x_start;                               // we don't need to check if the extruder position
415
-            e_position = e_start + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
416
-            z_position = z_start + on_axis_distance * z_normalized_dist;
407
+            on_axis_distance = x - start[X_AXIS];                               // we don't need to check if the extruder position
408
+            e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;  // is based on X or Y because this is a horizontal move
409
+            z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
417
           }
410
           }
418
           else {
411
           else {
419
-            e_position = e_start;
420
-            z_position = z_start;
412
+            e_position = start[E_AXIS];
413
+            z_position = start[Z_AXIS];
421
           }
414
           }
422
 
415
 
423
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
416
           planner.buffer_line(x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
427
       if (ubl.g26_debug_flag)
420
       if (ubl.g26_debug_flag)
428
         debug_current_and_destination((char*)"horizontal move done in ubl_line_to_destination()");
421
         debug_current_and_destination((char*)"horizontal move done in ubl_line_to_destination()");
429
 
422
 
430
-      if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end)
423
+      if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
431
         goto FINAL_MOVE;
424
         goto FINAL_MOVE;
432
 
425
 
433
       set_current_to_destination();
426
       set_current_to_destination();
454
       const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
447
       const float next_mesh_line_x = LOGICAL_X_POSITION(ubl.mesh_index_to_xpos[current_xi + dxi]),
455
                   next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
448
                   next_mesh_line_y = LOGICAL_Y_POSITION(ubl.mesh_index_to_ypos[current_yi + dyi]),
456
                   y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
449
                   y = m * next_mesh_line_x + c,   // Calculate Y at the next X mesh line
457
-                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line    (we don't have to worry
458
-                                                  // about m being equal to 0.0  If this was the case, we would have
459
-                                                  // detected this as a vertical line move up above and we wouldn't
460
-                                                  // be down here doing a generic type of move.
450
+                  x = (next_mesh_line_y - c) / m; // Calculate X at the next Y mesh line
451
+                                                  // (No need to worry about m being zero.
452
+                                                  //  If that was the case, it was already detected
453
+                                                  //  as a vertical line move above.)
461
 
454
 
462
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
455
       if (left_flag == (x > next_mesh_line_x)) { // Check if we hit the Y line first
463
         //
456
         //
464
         // Yes!  Crossing a Y Mesh Line next
457
         // Yes!  Crossing a Y Mesh Line next
465
         //
458
         //
466
-        float z0 = ubl.get_z_correction_along_horizontal_mesh_line_at_specific_X(x, current_xi - left_flag, current_yi + dyi);
459
+        float z0 = ubl.z_correction_for_x_on_horizontal_mesh_line(x, current_xi - left_flag, current_yi + dyi);
467
 
460
 
468
         /**
461
         /**
469
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
462
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
486
           }
479
           }
487
         //*/
480
         //*/
488
 
481
 
489
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
482
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
490
 
483
 
491
         /**
484
         /**
492
          * If part of the Mesh is undefined, it will show up as NAN
485
          * If part of the Mesh is undefined, it will show up as NAN
498
         if (isnan(z0)) z0 = 0.0;
491
         if (isnan(z0)) z0 = 0.0;
499
 
492
 
500
         if (!inf_normalized_flag) {
493
         if (!inf_normalized_flag) {
501
-          on_axis_distance = use_x_dist ? x - x_start : next_mesh_line_y - y_start;
502
-          e_position = e_start + on_axis_distance * e_normalized_dist;
503
-          z_position = z_start + on_axis_distance * z_normalized_dist;
494
+          on_axis_distance = use_x_dist ? x - start[X_AXIS] : next_mesh_line_y - start[Y_AXIS];
495
+          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
496
+          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
504
         }
497
         }
505
         else {
498
         else {
506
-          e_position = e_start;
507
-          z_position = z_start;
499
+          e_position = start[E_AXIS];
500
+          z_position = start[Z_AXIS];
508
         }
501
         }
509
         planner.buffer_line(x, next_mesh_line_y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
502
         planner.buffer_line(x, next_mesh_line_y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
510
         current_yi += dyi;
503
         current_yi += dyi;
514
         //
507
         //
515
         // Yes!  Crossing a X Mesh Line next
508
         // Yes!  Crossing a X Mesh Line next
516
         //
509
         //
517
-        float z0 = ubl.get_z_correction_along_vertical_mesh_line_at_specific_Y(y, current_xi + dxi, current_yi - down_flag);
510
+        float z0 = ubl.z_correction_for_y_on_vertical_mesh_line(y, current_xi + dxi, current_yi - down_flag);
518
 
511
 
519
         /**
512
         /**
520
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
513
          * Debug code to use non-optimized get_z_correction() and to do a sanity check
536
           }
529
           }
537
         //*/
530
         //*/
538
 
531
 
539
-        z0 *= ubl.fade_scaling_factor_for_z(z_end);
532
+        z0 *= ubl.fade_scaling_factor_for_z(end[Z_AXIS]);
540
 
533
 
541
         /**
534
         /**
542
          * If part of the Mesh is undefined, it will show up as NAN
535
          * If part of the Mesh is undefined, it will show up as NAN
548
         if (isnan(z0)) z0 = 0.0;
541
         if (isnan(z0)) z0 = 0.0;
549
 
542
 
550
         if (!inf_normalized_flag) {
543
         if (!inf_normalized_flag) {
551
-          on_axis_distance = use_x_dist ? next_mesh_line_x - x_start : y - y_start;
552
-          e_position = e_start + on_axis_distance * e_normalized_dist;
553
-          z_position = z_start + on_axis_distance * z_normalized_dist;
544
+          on_axis_distance = use_x_dist ? next_mesh_line_x - start[X_AXIS] : y - start[Y_AXIS];
545
+          e_position = start[E_AXIS] + on_axis_distance * e_normalized_dist;
546
+          z_position = start[Z_AXIS] + on_axis_distance * z_normalized_dist;
554
         }
547
         }
555
         else {
548
         else {
556
-          e_position = e_start;
557
-          z_position = z_start;
549
+          e_position = start[E_AXIS];
550
+          z_position = start[Z_AXIS];
558
         }
551
         }
559
 
552
 
560
         planner.buffer_line(next_mesh_line_x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
553
         planner.buffer_line(next_mesh_line_x, y, z_position + z0 + ubl.state.z_offset, e_position, feed_rate, extruder);
566
     if (ubl.g26_debug_flag)
559
     if (ubl.g26_debug_flag)
567
       debug_current_and_destination((char*)"generic move done in ubl_line_to_destination()");
560
       debug_current_and_destination((char*)"generic move done in ubl_line_to_destination()");
568
 
561
 
569
-    if (current_position[0] != x_end || current_position[1] != y_end)
562
+    if (current_position[X_AXIS] != end[X_AXIS] || current_position[Y_AXIS] != end[Y_AXIS])
570
       goto FINAL_MOVE;
563
       goto FINAL_MOVE;
571
 
564
 
572
     set_current_to_destination();
565
     set_current_to_destination();

+ 27
- 27
Marlin/endstop_interrupts.h Visa fil

35
  * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
35
  * (Located in Marlin/buildroot/share/pin_interrupt_test/pin_interrupt_test.ino)
36
  */
36
  */
37
 
37
 
38
- #ifndef _ENDSTOP_INTERRUPTS_H_
39
- #define _ENDSTOP_INTERRUPTS_H_
38
+#ifndef _ENDSTOP_INTERRUPTS_H_
39
+#define _ENDSTOP_INTERRUPTS_H_
40
+
41
+#include "macros.h"
40
 
42
 
41
 /**
43
 /**
42
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
44
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
47
  */
49
  */
48
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
50
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
49
   #undef  digitalPinToPCICR
51
   #undef  digitalPinToPCICR
50
-  #define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 15)) || \
51
-                                  (((p) >= 50) && ((p) <= 53)) || \
52
-                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
52
+  #define digitalPinToPCICR(p)    ( WITHIN(p, 10, 15) || \
53
+                                    WITHIN(p, 50, 53) || \
54
+                                    WITHIN(p, 62, 69) ? &PCICR : (uint8_t*)0 )
53
   #undef  digitalPinToPCICRbit
55
   #undef  digitalPinToPCICRbit
54
-  #define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
55
-                                  ( (((p) >= 14) && ((p) <= 15)) ? 1 : \
56
-                                  ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
57
-                                  0 ) ) )
56
+  #define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
57
+                                    WITHIN(p, 14, 15) ? 1 : \
58
+                                    WITHIN(p, 62, 69) ? 2 : \
59
+                                    0 )
58
   #undef  digitalPinToPCMSK
60
   #undef  digitalPinToPCMSK
59
-  #define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
60
-                                  ( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \
61
-                                  ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
62
-                                  ((uint8_t *)0) ) ) )
61
+  #define digitalPinToPCMSK(p)    ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
62
+                                    WITHIN(p, 14, 15) ? &PCMSK1 : \
63
+                                    WITHIN(p, 62, 69) ? &PCMSK2 : \
64
+                                    (uint8_t *)0 )
63
   #undef  digitalPinToPCMSKbit
65
   #undef  digitalPinToPCMSKbit
64
-  #define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
65
-                                  ( ((p) == 14) ? 2 : \
66
-                                  ( ((p) == 15) ? 1 : \
67
-                                  ( ((p) == 50) ? 3 : \
68
-                                  ( ((p) == 51) ? 2 : \
69
-                                  ( ((p) == 52) ? 1 : \
70
-                                  ( ((p) == 53) ? 0 : \
71
-                                  ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
72
-                                  0 ) ) ) ) ) ) ) )
66
+  #define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
67
+                                    (p) == 14 || (p) == 51 ? 2 : \
68
+                                    (p) == 15 || (p) == 52 ? 1 : \
69
+                                    (p) == 50 ? 3 : \
70
+                                    (p) == 53 ? 0 : \
71
+                                    WITHIN(p, 62, 69) ? ((p) - 62) : \
72
+                                    0 )
73
 #endif
73
 #endif
74
 
74
 
75
-volatile uint8_t e_hit = 0; // Different from 0 when the endstops shall be tested in detail.
76
-                            // Must be reset to 0 by the test function when the tests are finished.
75
+volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
76
+                            // Must be reset to 0 by the test function when finished.
77
 
77
 
78
 // Install Pin change interrupt for a pin. Can be called multiple times.
78
 // Install Pin change interrupt for a pin. Can be called multiple times.
79
 void pciSetup(byte pin) {
79
 void pciSetup(byte pin) {
80
-  *digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin));  // enable pin
81
-  PCIFR  |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
82
-  PCICR  |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
80
+  SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin));  // enable pin
81
+  SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
82
+  SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
83
 }
83
 }
84
 
84
 
85
 // This is what is really done inside the interrupts.
85
 // This is what is really done inside the interrupts.

+ 4
- 2
Marlin/macros.h Visa fil

75
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
75
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
76
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
76
 #define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
77
 
77
 
78
-#define NUMERIC(a) ((a) >= '0' && '9' >= (a))
78
+#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
79
+#define NUMERIC(a) WITHIN(a, '0', '9')
79
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81
 #define ZERO(a) memset(a,0,sizeof(a))
82
 #define ZERO(a) memset(a,0,sizeof(a))
133
 #define MAX4(a, b, c, d) max(max(a, b), max(c, d))
134
 #define MAX4(a, b, c, d) max(max(a, b), max(c, d))
134
 
135
 
135
 #define UNEAR_ZERO(x) ((x) < 0.000001)
136
 #define UNEAR_ZERO(x) ((x) < 0.000001)
136
-#define NEAR_ZERO(x) ((x) > -0.000001 && (x) < 0.000001)
137
+#define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001)
137
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
138
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
138
 
139
 
139
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
140
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
141
+#define FIXFLOAT(f) (f + 0.00001)
140
 
142
 
141
 #endif //__MACROS_H
143
 #endif //__MACROS_H

+ 2
- 2
Marlin/mesh_bed_leveling.h Visa fil

88
 
88
 
89
     static int8_t probe_index_x(const float &x) {
89
     static int8_t probe_index_x(const float &x) {
90
       int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
90
       int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
91
-      return (px >= 0 && px < (MESH_NUM_X_POINTS)) ? px : -1;
91
+      return WITHIN(px, 0, MESH_NUM_X_POINTS - 1) ? px : -1;
92
     }
92
     }
93
 
93
 
94
     static int8_t probe_index_y(const float &y) {
94
     static int8_t probe_index_y(const float &y) {
95
       int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
95
       int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
96
-      return (py >= 0 && py < (MESH_NUM_Y_POINTS)) ? py : -1;
96
+      return WITHIN(py, 0, MESH_NUM_Y_POINTS - 1) ? py : -1;
97
     }
97
     }
98
 
98
 
99
     static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {
99
     static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {

+ 3
- 1
Marlin/pinsDebug.h Visa fil

20
  *
20
  *
21
  */
21
  */
22
 
22
 
23
+#include "macros.h"
24
+
23
 bool endstop_monitor_flag = false;
25
 bool endstop_monitor_flag = false;
24
 
26
 
25
 #if !defined(TIMER1B)    // working with Teensyduino extension so need to re-define some things
27
 #if !defined(TIMER1B)    // working with Teensyduino extension so need to re-define some things
35
 #define _ANALOG_PIN_SAY(NAME) { sprintf(buffer, NAME_FORMAT, NAME); SERIAL_ECHO(buffer); pin_is_analog = true; return true; }
37
 #define _ANALOG_PIN_SAY(NAME) { sprintf(buffer, NAME_FORMAT, NAME); SERIAL_ECHO(buffer); pin_is_analog = true; return true; }
36
 #define ANALOG_PIN_SAY(NAME) if (pin == analogInputToDigitalPin(NAME)) _ANALOG_PIN_SAY(#NAME);
38
 #define ANALOG_PIN_SAY(NAME) if (pin == analogInputToDigitalPin(NAME)) _ANALOG_PIN_SAY(#NAME);
37
 
39
 
38
-#define IS_ANALOG(P) ((P) >= analogInputToDigitalPin(0) && ((P) <= analogInputToDigitalPin(15) || (P) <= analogInputToDigitalPin(5)))
40
+#define IS_ANALOG(P) ( WITHIN(P, analogInputToDigitalPin(0), analogInputToDigitalPin(15)) || (P) <= analogInputToDigitalPin(5) )
39
 
41
 
40
 int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
42
 int digitalRead_mod(int8_t pin) { // same as digitalRead except the PWM stop section has been removed
41
   uint8_t port = digitalPinToPort(pin);
43
   uint8_t port = digitalPinToPort(pin);

+ 1
- 1
Marlin/planner.cpp Visa fil

999
     unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
999
     unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
1000
   #endif
1000
   #endif
1001
   #if ENABLED(SLOWDOWN)
1001
   #if ENABLED(SLOWDOWN)
1002
-    if (moves_queued > 1 && moves_queued < (BLOCK_BUFFER_SIZE) / 2) {
1002
+    if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
1003
       if (segment_time < min_segment_time) {
1003
       if (segment_time < min_segment_time) {
1004
         // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
1004
         // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
1005
         inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));
1005
         inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));

+ 3
- 3
Marlin/temperature.cpp Visa fil

786
     #if ENABLED(PIDTEMPBED)
786
     #if ENABLED(PIDTEMPBED)
787
       float pid_output = get_pid_output_bed();
787
       float pid_output = get_pid_output_bed();
788
 
788
 
789
-      soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
789
+      soft_pwm_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)pid_output >> 1 : 0;
790
 
790
 
791
     #elif ENABLED(BED_LIMIT_SWITCHING)
791
     #elif ENABLED(BED_LIMIT_SWITCHING)
792
       // Check if temperature is within the correct band
792
       // Check if temperature is within the correct band
793
-      if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
793
+      if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
794
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
794
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
795
           soft_pwm_bed = 0;
795
           soft_pwm_bed = 0;
796
         else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
796
         else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
802
       }
802
       }
803
     #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
803
     #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
804
       // Check if temperature is within the correct range
804
       // Check if temperature is within the correct range
805
-      if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
805
+      if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
806
         soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
806
         soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
807
       }
807
       }
808
       else {
808
       else {

+ 1
- 1
Marlin/twibus.cpp Visa fil

42
 }
42
 }
43
 
43
 
44
 void TWIBus::address(const uint8_t adr) {
44
 void TWIBus::address(const uint8_t adr) {
45
-  if (adr < 8 || adr > 127) {
45
+  if (!WITHIN(adr, 8, 127)) {
46
     SERIAL_ECHO_START;
46
     SERIAL_ECHO_START;
47
     SERIAL_ECHOLNPGM("Bad I2C address (8-127)");
47
     SERIAL_ECHOLNPGM("Bad I2C address (8-127)");
48
   }
48
   }

+ 0
- 2
Marlin/ultralcd.cpp Visa fil

30
 #include "configuration_store.h"
30
 #include "configuration_store.h"
31
 #include "utility.h"
31
 #include "utility.h"
32
 
32
 
33
-extern float zprobe_zoffset;
34
-
35
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
33
 #if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
36
   #include "buzzer.h"
34
   #include "buzzer.h"
37
 #endif
35
 #endif

+ 3
- 3
Marlin/ultralcd_impl_DOGM.h Visa fil

213
 }
213
 }
214
 
214
 
215
 void lcd_print(const char c) {
215
 void lcd_print(const char c) {
216
-  if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
216
+  if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
217
     u8g.setFont(FONT_SPECIAL_NAME);
217
     u8g.setFont(FONT_SPECIAL_NAME);
218
     u8g.print(c);
218
     u8g.print(c);
219
     lcd_setFont(currentfont);
219
     lcd_setFont(currentfont);
222
 }
222
 }
223
 
223
 
224
 char lcd_print_and_count(const char c) {
224
 char lcd_print_and_count(const char c) {
225
-  if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
225
+  if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
226
     u8g.setFont(FONT_SPECIAL_NAME);
226
     u8g.setFont(FONT_SPECIAL_NAME);
227
     u8g.print(c);
227
     u8g.print(c);
228
     lcd_setFont(currentfont);
228
     lcd_setFont(currentfont);
543
   if (page.page == 0) {
543
   if (page.page == 0) {
544
     strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
544
     strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
545
     strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
545
     strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
546
-    strcpy(zstring, ftostr52sp(current_position[Z_AXIS] + 0.00001));
546
+    strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
547
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
547
     #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
548
       strcpy(wstring, ftostr12ns(filament_width_meas));
548
       strcpy(wstring, ftostr12ns(filament_width_meas));
549
       strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
549
       strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));

+ 1
- 1
Marlin/ultralcd_impl_HD44780.h Visa fil

729
 
729
 
730
     lcd.setCursor(LCD_WIDTH - 8, 1);
730
     lcd.setCursor(LCD_WIDTH - 8, 1);
731
     _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
731
     _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
732
-    lcd.print(ftostr52sp(current_position[Z_AXIS] + 0.00001));
732
+    lcd.print(ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
733
 
733
 
734
   #endif // LCD_HEIGHT > 2
734
   #endif // LCD_HEIGHT > 2
735
 
735
 

+ 1
- 1
Marlin/utility.cpp Visa fil

134
     // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
134
     // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
135
     char *ftostr4sign(const float& fx) {
135
     char *ftostr4sign(const float& fx) {
136
       int x = fx * 10;
136
       int x = fx * 10;
137
-      if (x <= -100 || x >= 1000) return itostr4sign((int)fx);
137
+      if (WITHIN(x, -99, 999)) return itostr4sign((int)fx);
138
       int xx = abs(x);
138
       int xx = abs(x);
139
       conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
139
       conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
140
       conv[1] = DIGIMOD(xx, 10);
140
       conv[1] = DIGIMOD(xx, 10);

Laddar…
Avbryt
Spara