Bladeren bron

Within applied to UBL

Scott Lahteine 7 jaren geleden
bovenliggende
commit
b19a15fa7f
5 gewijzigde bestanden met toevoegingen van 37 en 37 verwijderingen
  1. 10
    10
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 7
    7
      Marlin/SanityCheck.h
  3. 2
    2
      Marlin/UBL.h
  4. 2
    2
      Marlin/UBL_Bed_Leveling.cpp
  5. 16
    16
      Marlin/UBL_G29.cpp

+ 10
- 10
Marlin/G26_Mesh_Validation_Tool.cpp Bestand weergeven

@@ -267,7 +267,7 @@
267 267
         #endif
268 268
 
269 269
         // TODO: Change this to use `position_is_reachable`
270
-        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)) {
271 271
           SERIAL_ERROR_START;
272 272
           SERIAL_ERRORLNPGM("Attempt to print off the bed.");
273 273
           goto LEAVE;
@@ -638,7 +638,7 @@
638 638
 
639 639
     if (code_seen('B')) {
640 640
       bed_temp = code_value_float();
641
-      if (bed_temp < 15.0 || bed_temp > 140.0) {
641
+      if (!WITHIN(bed_temp, 15.0, 140.0)) {
642 642
         SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
643 643
         return UBL_ERR;
644 644
       }
@@ -648,7 +648,7 @@
648 648
 
649 649
     if (code_seen('L')) {
650 650
       layer_height = code_value_float();
651
-      if (layer_height < 0.0 || layer_height > 2.0) {
651
+      if (!WITHIN(layer_height, 0.0, 2.0)) {
652 652
         SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
653 653
         return UBL_ERR;
654 654
       }
@@ -657,7 +657,7 @@
657 657
     if (code_seen('Q')) {
658 658
       if (code_has_value()) {
659 659
         retraction_multiplier = code_value_float();
660
-        if (retraction_multiplier < 0.05 || retraction_multiplier > 15.0) {
660
+        if (!WITHIN(retraction_multiplier, 0.05, 15.0)) {
661 661
           SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible.");
662 662
           return UBL_ERR;
663 663
         }
@@ -670,7 +670,7 @@
670 670
 
671 671
     if (code_seen('N')) {
672 672
       nozzle = code_value_float();
673
-      if (nozzle < 0.1 || nozzle > 1.0) {
673
+      if (!WITHIN(nozzle, 0.1, 1.0)) {
674 674
         SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
675 675
         return UBL_ERR;
676 676
       }
@@ -687,7 +687,7 @@
687 687
       else {
688 688
         prime_flag++;
689 689
         prime_length = code_value_float();
690
-        if (prime_length < 0.0 || prime_length > 25.0) {
690
+        if (!WITHIN(prime_length, 0.0, 25.0)) {
691 691
           SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
692 692
           return UBL_ERR;
693 693
         }
@@ -696,7 +696,7 @@
696 696
 
697 697
     if (code_seen('F')) {
698 698
       filament_diameter = code_value_float();
699
-      if (filament_diameter < 1.0 || filament_diameter > 4.0) {
699
+      if (!WITHIN(filament_diameter, 1.0, 4.0)) {
700 700
         SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
701 701
         return UBL_ERR;
702 702
       }
@@ -709,7 +709,7 @@
709 709
 
710 710
     if (code_seen('H')) {
711 711
       hotend_temp = code_value_float();
712
-      if (hotend_temp < 165.0 || hotend_temp > 280.0) {
712
+      if (!WITHIN(hotend_temp, 165.0, 280.0)) {
713 713
         SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
714 714
         return UBL_ERR;
715 715
       }
@@ -725,7 +725,7 @@
725 725
 
726 726
     if (code_seen('X')) {
727 727
       x_pos = code_value_float();
728
-      if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
728
+      if (!WITHIN(x_pos, X_MIN_POS, X_MAX_POS)) {
729 729
         SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
730 730
         return UBL_ERR;
731 731
       }
@@ -734,7 +734,7 @@
734 734
 
735 735
     if (code_seen('Y')) {
736 736
       y_pos = code_value_float();
737
-      if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
737
+      if (!WITHIN(y_pos, Y_MIN_POS, Y_MAX_POS)) {
738 738
         SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
739 739
         return UBL_ERR;
740 740
       }

+ 7
- 7
Marlin/SanityCheck.h Bestand weergeven

@@ -598,19 +598,19 @@ static_assert(1 >= 0
598 598
   #elif ENABLED(AUTO_BED_LEVELING_UBL)
599 599
     #if DISABLED(EEPROM_SETTINGS)
600 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 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 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 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 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 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 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 614
       #error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
615 615
     #endif
616 616
   #else // AUTO_BED_LEVELING_3POINT

+ 2
- 2
Marlin/UBL.h Bestand weergeven

@@ -169,12 +169,12 @@
169 169
 
170 170
         static int8_t find_closest_x_index(const float &x) {
171 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 175
         static int8_t find_closest_y_index(const float &y) {
176 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
         /**

+ 2
- 2
Marlin/UBL_Bed_Leveling.cpp Bestand weergeven

@@ -118,7 +118,7 @@
118 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 122
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
123 123
       return;
124 124
     }
@@ -133,7 +133,7 @@
133 133
   void unified_bed_leveling::store_mesh(const int16_t m) {
134 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 137
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
138 138
       SERIAL_PROTOCOL(m);
139 139
       SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");

+ 16
- 16
Marlin/UBL_G29.cpp Bestand weergeven

@@ -341,7 +341,7 @@
341 341
     if (code_seen('Q')) {
342 342
 
343 343
       const int test_pattern = code_has_value() ? code_value_int() : -1;
344
-      if (test_pattern < 0 || test_pattern > 2) {
344
+      if (!WITHIN(test_pattern, 0, 2)) {
345 345
         SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
346 346
         return;
347 347
       }
@@ -374,7 +374,7 @@
374 374
     /*
375 375
     if (code_seen('U')) {
376 376
       unlevel_value = code_value_int();
377
-      //if (unlevel_value < 0 || unlevel_value > 7) {
377
+      //if (!WITHIN(unlevel_value, 0, 7)) {
378 378
       //  SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
379 379
       //  return;
380 380
       //}
@@ -383,7 +383,7 @@
383 383
 
384 384
     if (code_seen('P')) {
385 385
       phase_value = code_value_int();
386
-      if (phase_value < 0 || phase_value > 7) {
386
+      if (!WITHIN(phase_value, 0, 7)) {
387 387
         SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
388 388
         return;
389 389
       }
@@ -566,7 +566,7 @@
566 566
 
567 567
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
568 568
 
569
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
569
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
570 570
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
571 571
         return;
572 572
       }
@@ -600,7 +600,7 @@
600 600
 
601 601
       const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
602 602
 
603
-      if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
603
+      if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
604 604
         SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
605 605
         SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
606 606
         goto LEAVE;
@@ -760,7 +760,7 @@
760 760
                     rawy = ubl.mesh_index_to_ypos[location.y_index];
761 761
 
762 762
         // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
763
-        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)) {
764 764
           SERIAL_ERROR_START;
765 765
           SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
766 766
           ubl.has_control_of_lcd_panel = false;
@@ -910,7 +910,7 @@
910 910
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
911 911
 
912 912
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
913
-      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)) {
914 914
         SERIAL_ERROR_START;
915 915
         SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
916 916
         ubl.has_control_of_lcd_panel = false;
@@ -982,21 +982,21 @@
982 982
     #endif
983 983
 
984 984
     g29_verbose_level = code_seen('V') ? code_value_int() : 0;
985
-    if (g29_verbose_level < 0 || g29_verbose_level > 4) {
985
+    if (!WITHIN(g29_verbose_level, 0, 4)) {
986 986
       SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
987 987
       return UBL_ERR;
988 988
     }
989 989
 
990 990
     x_flag = code_seen('X') && code_has_value();
991 991
     x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
992
-    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)) {
993 993
       SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
994 994
       return UBL_ERR;
995 995
     }
996 996
 
997 997
     y_flag = code_seen('Y') && code_has_value();
998 998
     y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
999
-    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)) {
1000 1000
       SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
1001 1001
       return UBL_ERR;
1002 1002
     }
@@ -1024,7 +1024,7 @@
1024 1024
     #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
1025 1025
       if (code_seen('F') && code_has_value()) {
1026 1026
         const float fh = code_value_float();
1027
-        if (fh < 0.0 || fh > 100.0) {
1027
+        if (!WITHIN(fh, 0.0, 100.0)) {
1028 1028
           SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
1029 1029
           return UBL_ERR;
1030 1030
         }
@@ -1041,7 +1041,7 @@
1041 1041
     }
1042 1042
 
1043 1043
     map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
1044
-    if (map_type < 0 || map_type > 1) {
1044
+    if (!WITHIN(map_type, 0, 1)) {
1045 1045
       SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1046 1046
       return UBL_ERR;
1047 1047
     }
@@ -1049,7 +1049,7 @@
1049 1049
     /*
1050 1050
     if (code_seen('M')) {     // Check if a map type was specified
1051 1051
       map_type = code_has_value() ? code_value_int() : 0; 
1052
-      if (map_type < 0 || map_type > 1) {
1052
+      if (!WITHIN(map_type, 0, 1)) {
1053 1053
         SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
1054 1054
         return UBL_ERR;
1055 1055
       }
@@ -1249,7 +1249,7 @@
1249 1249
 
1250 1250
     int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
1251 1251
 
1252
-    if (storage_slot < 0 || storage_slot > j || ubl.eeprom_start <= 0) {
1252
+    if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
1253 1253
       SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
1254 1254
       return;
1255 1255
     }
@@ -1296,7 +1296,7 @@
1296 1296
           // Prune them from the list and ignore them till the next Phase (manual nozzle probing).
1297 1297
 
1298 1298
           if (probe_as_reference &&
1299
-            (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))
1300 1300
           ) continue;
1301 1301
 
1302 1302
           // Unreachable. Check if it's the closest location to the nozzle.
@@ -1360,7 +1360,7 @@
1360 1360
                   rawy = ubl.mesh_index_to_ypos[location.y_index];
1361 1361
 
1362 1362
       // TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
1363
-      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.
1364 1364
         SERIAL_ERROR_START;
1365 1365
         SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
1366 1366
         ubl.has_control_of_lcd_panel = false;

Laden…
Annuleren
Opslaan