Add and apply WITHIN macro

This commit is contained in:
Scott Lahteine
2017-03-31 09:00:49 -05:00
parent 93aad54dc1
commit 25a6bfa7ed
11 changed files with 74 additions and 71 deletions

View File

@@ -2565,7 +2565,7 @@ static void clean_up_after_endstop_or_probe_move() {
ep = ABL_GRID_MAX_POINTS_X - 1;
ip = ABL_GRID_MAX_POINTS_X - 2;
}
if (y > 0 && y < ABL_TEMP_POINTS_Y - 1)
if (WITHIN(y, 1, ABL_TEMP_POINTS_Y - 2))
return LINEAR_EXTRAPOLATION(
bed_level_grid[ep][y - 1],
bed_level_grid[ip][y - 1]
@@ -2581,7 +2581,7 @@ static void clean_up_after_endstop_or_probe_move() {
ep = ABL_GRID_MAX_POINTS_Y - 1;
ip = ABL_GRID_MAX_POINTS_Y - 2;
}
if (x > 0 && x < ABL_TEMP_POINTS_X - 1)
if (WITHIN(x, 1, ABL_TEMP_POINTS_X - 2))
return LINEAR_EXTRAPOLATION(
bed_level_grid[x - 1][ep],
bed_level_grid[x - 1][ip]
@@ -3024,9 +3024,9 @@ bool position_is_reachable(float target[XYZ]
return HYPOT2(dx, dy) <= sq((float)(DELTA_PRINTABLE_RADIUS));
#else
const float dz = RAW_Z_POSITION(target[Z_AXIS]);
return dx >= X_MIN_POS - 0.0001 && dx <= X_MAX_POS + 0.0001
&& dy >= Y_MIN_POS - 0.0001 && dy <= Y_MAX_POS + 0.0001
&& dz >= Z_MIN_POS - 0.0001 && dz <= Z_MAX_POS + 0.0001;
return WITHIN(dx, X_MIN_POS - 0.0001, X_MAX_POS + 0.0001)
&& WITHIN(dy, Y_MIN_POS - 0.0001, Y_MAX_POS + 0.0001)
&& WITHIN(dz, Z_MIN_POS - 0.0001, Z_MAX_POS + 0.0001);
#endif
}
@@ -3790,7 +3790,7 @@ inline void gcode_G28() {
#endif
const MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_byte() : MeshReport;
if (state < 0 || state > 5) {
if (!WITHIN(state, 0, 5)) {
SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
return;
}
@@ -3865,7 +3865,7 @@ inline void gcode_G28() {
case MeshSet:
if (code_seen('X')) {
px = code_value_int() - 1;
if (px < 0 || px >= MESH_NUM_X_POINTS) {
if (!WITHIN(px, 0, MESH_NUM_X_POINTS - 1)) {
SERIAL_PROTOCOLLNPGM("X out of range (1-" STRINGIFY(MESH_NUM_X_POINTS) ").");
return;
}
@@ -3877,7 +3877,7 @@ inline void gcode_G28() {
if (code_seen('Y')) {
py = code_value_int() - 1;
if (py < 0 || py >= MESH_NUM_Y_POINTS) {
if (!WITHIN(py, 0, MESH_NUM_Y_POINTS - 1)) {
SERIAL_PROTOCOLLNPGM("Y out of range (1-" STRINGIFY(MESH_NUM_Y_POINTS) ").");
return;
}
@@ -4967,7 +4967,7 @@ inline void gcode_M42() {
if (!code_seen('S')) return;
int pin_status = code_value_int();
if (pin_status < 0 || pin_status > 255) return;
if (!WITHIN(pin_status, 0, 255)) return;
int pin_number = code_seen('P') ? code_value_int() : LED_PIN;
if (pin_number < 0) return;
@@ -5111,7 +5111,7 @@ inline void gcode_M42() {
if (axis_unhomed_error(true, true, true)) return;
int8_t verbose_level = code_seen('V') ? code_value_byte() : 1;
if (verbose_level < 0 || verbose_level > 4) {
if (!WITHIN(verbose_level, 0, 4)) {
SERIAL_PROTOCOLLNPGM("?Verbose Level not plausible (0-4).");
return;
}
@@ -5120,7 +5120,7 @@ inline void gcode_M42() {
SERIAL_PROTOCOLLNPGM("M48 Z-Probe Repeatability Test");
int8_t n_samples = code_seen('P') ? code_value_byte() : 10;
if (n_samples < 4 || n_samples > 50) {
if (!WITHIN(n_samples, 4, 50)) {
SERIAL_PROTOCOLLNPGM("?Sample size not plausible (4-50).");
return;
}
@@ -5132,7 +5132,7 @@ inline void gcode_M42() {
float X_probe_location = code_seen('X') ? code_value_axis_units(X_AXIS) : X_current + X_PROBE_OFFSET_FROM_EXTRUDER;
#if DISABLED(DELTA)
if (X_probe_location < LOGICAL_X_POSITION(MIN_PROBE_X) || X_probe_location > LOGICAL_X_POSITION(MAX_PROBE_X)) {
if (!WITHIN(X_probe_location, LOGICAL_X_POSITION(MIN_PROBE_X), LOGICAL_X_POSITION(MAX_PROBE_X))) {
out_of_range_error(PSTR("X"));
return;
}
@@ -5140,7 +5140,7 @@ inline void gcode_M42() {
float Y_probe_location = code_seen('Y') ? code_value_axis_units(Y_AXIS) : Y_current + Y_PROBE_OFFSET_FROM_EXTRUDER;
#if DISABLED(DELTA)
if (Y_probe_location < LOGICAL_Y_POSITION(MIN_PROBE_Y) || Y_probe_location > LOGICAL_Y_POSITION(MAX_PROBE_Y)) {
if (!WITHIN(Y_probe_location, LOGICAL_Y_POSITION(MIN_PROBE_Y), LOGICAL_Y_POSITION(MAX_PROBE_Y))) {
out_of_range_error(PSTR("Y"));
return;
}
@@ -6791,7 +6791,7 @@ inline void gcode_M226() {
inline void gcode_M280() {
if (!code_seen('P')) return;
int servo_index = code_value_int();
if (servo_index >= 0 && servo_index < NUM_SERVOS) {
if (WITHIN(servo_index, 0, NUM_SERVOS - 1)) {
if (code_seen('S'))
MOVE_SERVO(servo_index, code_value_int());
else {
@@ -6998,7 +6998,7 @@ inline void gcode_M303() {
float temp = code_seen('S') ? code_value_temp_abs() : (e < 0 ? 70.0 : 150.0);
if (e >= 0 && e < HOTENDS)
if (WITHIN(e, 0, HOTENDS - 1))
target_extruder = e;
KEEPALIVE_STATE(NOT_BUSY); // don't send "busy: processing" messages during autotune output
@@ -7219,7 +7219,7 @@ void quickstop_stepper() {
if (code_seen('L')) {
const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
@@ -7312,7 +7312,7 @@ void quickstop_stepper() {
}
}
else if (hasI && hasJ && hasZ) {
if (px >= 0 && px < MESH_NUM_X_POINTS && py >= 0 && py < MESH_NUM_Y_POINTS)
if (WITHIN(px, 0, MESH_NUM_X_POINTS - 1) && WITHIN(py, 0, MESH_NUM_Y_POINTS - 1))
mbl.set_z(px, py, z);
else {
SERIAL_ERROR_START;
@@ -7341,7 +7341,7 @@ void quickstop_stepper() {
if ((hasZ = code_seen('Z'))) z = code_value_axis_units(Z_AXIS);
if (hasI && hasJ && hasZ) {
if (px >= 0 && px < ABL_GRID_MAX_POINTS_X && py >= 0 && py < ABL_GRID_MAX_POINTS_X) {
if (WITHIN(px, 0, ABL_GRID_MAX_POINTS_X - 1) && WITHIN(py, 0, ABL_GRID_MAX_POINTS_X - 1)) {
bed_level_grid[px][py] = z;
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
bed_level_virt_interpolate();
@@ -7379,7 +7379,7 @@ void quickstop_stepper() {
if (axis_homed[i]) {
float base = (current_position[i] > (soft_endstop_min[i] + soft_endstop_max[i]) * 0.5) ? base_home_pos((AxisEnum)i) : 0,
diff = current_position[i] - LOGICAL_POSITION(base, i);
if (diff > -20 && diff < 20) {
if (WITHIN(diff, -20, 20)) {
set_home_offset((AxisEnum)i, home_offset[i] - diff);
}
else {
@@ -7453,7 +7453,7 @@ inline void gcode_M503() {
if (code_seen('Z')) {
float value = code_value_axis_units(Z_AXIS);
if (Z_PROBE_OFFSET_RANGE_MIN <= value && value <= Z_PROBE_OFFSET_RANGE_MAX) {
if (WITHIN(value, Z_PROBE_OFFSET_RANGE_MIN, Z_PROBE_OFFSET_RANGE_MAX)) {
#if ENABLED(AUTO_BED_LEVELING_BILINEAR)
// Correct bilinear grid for new probe offset