Selaa lähdekoodia

Add and apply WITHIN macro

Scott Lahteine 7 vuotta sitten
vanhempi
commit
25a6bfa7ed

+ 20
- 20
Marlin/Marlin_main.cpp Näytä tiedosto

@@ -2565,7 +2565,7 @@ static void clean_up_after_endstop_or_probe_move() {
2565 2565
           ep = ABL_GRID_MAX_POINTS_X - 1;
2566 2566
           ip = ABL_GRID_MAX_POINTS_X - 2;
2567 2567
         }
2568
-        if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
2568
+        if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
2569 2569
           return LINEAR_EXTRAPOLATION(
2570 2570
             bed_level_grid[ep][y - 1],
2571 2571
             bed_level_grid[ip][y - 1]
@@ -2581,7 +2581,7 @@ static void clean_up_after_endstop_or_probe_move() {
2581 2581
           ep = ABL_GRID_MAX_POINTS_Y - 1;
2582 2582
           ip = ABL_GRID_MAX_POINTS_Y - 2;
2583 2583
         }
2584
-        if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
2584
+        if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
2585 2585
           return LINEAR_EXTRAPOLATION(
2586 2586
             bed_level_grid[x - 1][ep],
2587 2587
             bed_level_grid[x - 1][ip]
@@ -3024,9 +3024,9 @@ bool position_is_reachable(float target[XYZ]
3024 3024
     return HYPOT2(dx, dy) <= sq((float)(DELTA_PRINTABLE_RADIUS));
3025 3025
   #else
3026 3026
     const float dz = RAW_Z_POSITION(target[Z_AXIS]);
3027
-    return dx >= X_MIN_POS - 0.0001 && dx <= X_MAX_POS + 0.0001
3028
-        && dy >= Y_MIN_POS - 0.0001 && dy <= Y_MAX_POS + 0.0001
3029
-        && 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);
3030 3030
   #endif
3031 3031
 }
3032 3032
 
@@ -3790,7 +3790,7 @@ inline void gcode_G28() {
3790 3790
     #endif
3791 3791
 
3792 3792
     const MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_byte() : MeshReport;
3793
-    if (state < 0 || state > 5) {
3793
+    if (!WITHIN(state, 0, 5)) {
3794 3794
       SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
3795 3795
       return;
3796 3796
     }
@@ -3865,7 +3865,7 @@ inline void gcode_G28() {
3865 3865
       case MeshSet:
3866 3866
         if (code_seen('X')) {
3867 3867
           px = code_value_int() - 1;
3868
-          if (px < 0 || px >= MESH_NUM_X_POINTS) {
3868
+          if (!WITHIN(px, 0, MESH_NUM_X_POINTS - 1)) {
3869 3869
             SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").");
3870 3870
             return;
3871 3871
           }
@@ -3877,7 +3877,7 @@ inline void gcode_G28() {
3877 3877
 
3878 3878
         if (code_seen('Y')) {
3879 3879
           py = code_value_int() - 1;
3880
-          if (py < 0 || py >= MESH_NUM_Y_POINTS) {
3880
+          if (!WITHIN(py, 0, MESH_NUM_Y_POINTS - 1)) {
3881 3881
             SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").");
3882 3882
             return;
3883 3883
           }
@@ -4967,7 +4967,7 @@ inline void gcode_M42() {
4967 4967
   if (!code_seen('S')) return;
4968 4968
 
4969 4969
   int pin_status = code_value_int();
4970
-  if (pin_status < 0 || pin_status > 255) return;
4970
+  if (!WITHIN(pin_status, 0, 255)) return;
4971 4971
 
4972 4972
   int pin_number = code_seen('P') ? code_value_int() : LED_PIN;
4973 4973
   if (pin_number < 0) return;
@@ -5111,7 +5111,7 @@ inline void gcode_M42() {
5111 5111
     if (axis_unhomed_error(true, true, true)) return;
5112 5112
 
5113 5113
     int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
5114
-    if (verbose_level < 0 || verbose_level > 4) {
5114
+    if (!WITHIN(verbose_level, 0, 4)) {
5115 5115
       SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4).");
5116 5116
       return;
5117 5117
     }
@@ -5120,7 +5120,7 @@ inline void gcode_M42() {
5120 5120
       SERIAL_PROTOCOLLNPGM("M48 Z-Probe Repeatability Test");
5121 5121
 
5122 5122
     int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
5123
-    if (n_samples < 4 || n_samples > 50) {
5123
+    if (!WITHIN(n_samples, 4, 50)) {
5124 5124
       SERIAL_PROTOCOLLNPGM("?Sample size not plausible (4-50).");
5125 5125
       return;
5126 5126
     }
@@ -5132,7 +5132,7 @@ inline void gcode_M42() {
5132 5132
 
5133 5133
     float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
5134 5134
     #if DISABLED(DELTA)
5135
-      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))) {
5136 5136
         out_of_range_error(PSTR("X"));
5137 5137
         return;
5138 5138
       }
@@ -5140,7 +5140,7 @@ inline void gcode_M42() {
5140 5140
 
5141 5141
     float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
5142 5142
     #if DISABLED(DELTA)
5143
-      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))) {
5144 5144
         out_of_range_error(PSTR("Y"));
5145 5145
         return;
5146 5146
       }
@@ -6791,7 +6791,7 @@ inline void gcode_M226() {
6791 6791
   inline void gcode_M280() {
6792 6792
     if (!code_seen('P')) return;
6793 6793
     int servo_index = code_value_int();
6794
-    if (servo_index >= 0 && servo_index < NUM_SERVOS) {
6794
+    if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
6795 6795
       if (code_seen('S'))
6796 6796
         MOVE_SERVO(servo_index, code_value_int());
6797 6797
       else {
@@ -6998,7 +6998,7 @@ inline void gcode_M303() {
6998 6998
 
6999 6999
     float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
7000 7000
 
7001
-    if (e >= 0 && e < HOTENDS)
7001
+    if (WITHIN(e, 0, HOTENDS - 1))
7002 7002
       target_extruder = e;
7003 7003
 
7004 7004
     KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
@@ -7219,7 +7219,7 @@ void quickstop_stepper() {
7219 7219
       if (code_seen('L')) {
7220 7220
         const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
7221 7221
         const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
7222
-        if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
7222
+        if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
7223 7223
           SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
7224 7224
           return;
7225 7225
         }
@@ -7312,7 +7312,7 @@ void quickstop_stepper() {
7312 7312
       }
7313 7313
     }
7314 7314
     else if (hasI && hasJ && hasZ) {
7315
-      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))
7316 7316
         mbl.set_z(px, py, z);
7317 7317
       else {
7318 7318
         SERIAL_ERROR_START;
@@ -7341,7 +7341,7 @@ void quickstop_stepper() {
7341 7341
     if ((hasZ = code_seen('Z'))) z = code_value_axis_units(Z_AXIS);
7342 7342
 
7343 7343
     if (hasI && hasJ && hasZ) {
7344
-      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)) {
7345 7345
         bed_level_grid[px][py] = z;
7346 7346
         #if ENABLED(ABL_BILINEAR_SUBDIVISION)
7347 7347
           bed_level_virt_interpolate();
@@ -7379,7 +7379,7 @@ void quickstop_stepper() {
7379 7379
       if (axis_homed[i]) {
7380 7380
         float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
7381 7381
               diff = current_position[i] - LOGICAL_POSITION(base, i);
7382
-        if (diff > -20 && diff < 20) {
7382
+        if (WITHIN(diff, -20, 20)) {
7383 7383
           set_home_offset((AxisEnum)i, home_offset[i] - diff);
7384 7384
         }
7385 7385
         else {
@@ -7453,7 +7453,7 @@ inline void gcode_M503() {
7453 7453
 
7454 7454
     if (code_seen('Z')) {
7455 7455
       float value = code_value_axis_units(Z_AXIS);
7456
-      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)) {
7457 7457
 
7458 7458
         #if ENABLED(AUTO_BED_LEVELING_BILINEAR)
7459 7459
           // Correct bilinear grid for new probe offset

+ 11
- 11
Marlin/SanityCheck.h Näytä tiedosto

@@ -540,13 +540,13 @@ static_assert(1 >= 0
540 540
  * Make sure Z_SAFE_HOMING point is reachable
541 541
  */
542 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 544
     #if HAS_BED_PROBE
545 545
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the Z probe."
546 546
     #else
547 547
       #error "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle."
548 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 550
     #if HAS_BED_PROBE
551 551
       #error "Z_SAFE_HOMING_Y_POINT can't be reached by the Z probe."
552 552
     #else
@@ -614,17 +614,17 @@ static_assert(1 >= 0
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
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 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 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 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 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 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 628
       #error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
629 629
     #endif
630 630
   #endif // AUTO_BED_LEVELING_3POINT
@@ -862,11 +862,11 @@ static_assert(1 >= 0
862 862
 /**
863 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 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 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 870
  #error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG."
871 871
 #elif ENABLED(Z_DUAL_ENDSTOPS)
872 872
   #if !Z2_USE_ENDSTOP

+ 27
- 27
Marlin/endstop_interrupts.h Näytä tiedosto

@@ -35,8 +35,10 @@
35 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 44
  * Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
@@ -47,39 +49,37 @@
47 49
  */
48 50
 #if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
49 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 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 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 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 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 78
 // Install Pin change interrupt for a pin. Can be called multiple times.
79 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 85
 // This is what is really done inside the interrupts.

+ 3
- 2
Marlin/macros.h Näytä tiedosto

@@ -75,7 +75,8 @@
75 75
 #define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
76 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 80
 #define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
80 81
 #define COUNT(a) (sizeof(a)/sizeof(*a))
81 82
 #define ZERO(a) memset(a,0,sizeof(a))
@@ -133,7 +134,7 @@
133 134
 #define MAX4(a, b, c, d) max(max(a, b), max(c, d))
134 135
 
135 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 138
 #define NEAR(x,y) NEAR_ZERO((x)-(y))
138 139
 
139 140
 #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))

+ 2
- 2
Marlin/mesh_bed_leveling.h Näytä tiedosto

@@ -88,12 +88,12 @@
88 88
 
89 89
     static int8_t probe_index_x(const float &x) {
90 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 94
     static int8_t probe_index_y(const float &y) {
95 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 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 Näytä tiedosto

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

+ 1
- 1
Marlin/planner.cpp Näytä tiedosto

@@ -999,7 +999,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
999 999
     unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
1000 1000
   #endif
1001 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 1003
       if (segment_time < min_segment_time) {
1004 1004
         // buffer is draining, add extra time.  The amount of time added increases if the buffer is still emptied more.
1005 1005
         inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));

+ 3
- 3
Marlin/temperature.cpp Näytä tiedosto

@@ -786,11 +786,11 @@ void Temperature::manage_heater() {
786 786
     #if ENABLED(PIDTEMPBED)
787 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 791
     #elif ENABLED(BED_LIMIT_SWITCHING)
792 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 794
         if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
795 795
           soft_pwm_bed = 0;
796 796
         else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
@@ -802,7 +802,7 @@ void Temperature::manage_heater() {
802 802
       }
803 803
     #else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
804 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 806
         soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
807 807
       }
808 808
       else {

+ 1
- 1
Marlin/twibus.cpp Näytä tiedosto

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

+ 2
- 2
Marlin/ultralcd_impl_DOGM.h Näytä tiedosto

@@ -213,7 +213,7 @@ static void lcd_setFont(const char font_nr) {
213 213
 }
214 214
 
215 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 217
     u8g.setFont(FONT_SPECIAL_NAME);
218 218
     u8g.print(c);
219 219
     lcd_setFont(currentfont);
@@ -222,7 +222,7 @@ void lcd_print(const char c) {
222 222
 }
223 223
 
224 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 226
     u8g.setFont(FONT_SPECIAL_NAME);
227 227
     u8g.print(c);
228 228
     lcd_setFont(currentfont);

+ 1
- 1
Marlin/utility.cpp Näytä tiedosto

@@ -134,7 +134,7 @@ void safe_delay(millis_t ms) {
134 134
     // Convert float to rj string with 1234, _123, -123, _-12, 12.3, _1.2, or -1.2 format
135 135
     char *ftostr4sign(const float& fx) {
136 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 138
       int xx = abs(x);
139 139
       conv[0] = x < 0 ? '-' : (xx >= 100 ? DIGIMOD(xx, 100) : ' ');
140 140
       conv[1] = DIGIMOD(xx, 10);

Loading…
Peruuta
Tallenna