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

View file

@ -540,13 +540,13 @@ static_assert(1 >= 0
* Make sure Z_SAFE_HOMING point is reachable
*/
#if ENABLED(Z_SAFE_HOMING)
#if Z_SAFE_HOMING_X_POINT < MIN_PROBE_X || Z_SAFE_HOMING_X_POINT > MAX_PROBE_X
#if !WITHIN(Z_SAFE_HOMING_X_POINT, MIN_PROBE_X, MAX_PROBE_X)
#if HAS_BED_PROBE
#error "Z_SAFE_HOMING_X_POINT can't be reached by the Z probe."
#else
#error "Z_SAFE_HOMING_X_POINT can't be reached by the nozzle."
#endif
#elif Z_SAFE_HOMING_Y_POINT < MIN_PROBE_Y || Z_SAFE_HOMING_Y_POINT > MAX_PROBE_Y
#elif !WITHIN(Z_SAFE_HOMING_Y_POINT, MIN_PROBE_Y, MAX_PROBE_Y)
#if HAS_BED_PROBE
#error "Z_SAFE_HOMING_Y_POINT can't be reached by the Z probe."
#else
@ -614,17 +614,17 @@ static_assert(1 >= 0
#error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
#endif
#else // AUTO_BED_LEVELING_3POINT
#if ABL_PROBE_PT_1_X < MIN_PROBE_X || ABL_PROBE_PT_1_X > MAX_PROBE_X
#if !WITHIN(ABL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_1_X can't be reached by the Z probe."
#elif ABL_PROBE_PT_2_X < MIN_PROBE_X || ABL_PROBE_PT_2_X > MAX_PROBE_X
#elif !WITHIN(ABL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_2_X can't be reached by the Z probe."
#elif ABL_PROBE_PT_3_X < MIN_PROBE_X || ABL_PROBE_PT_3_X > MAX_PROBE_X
#elif !WITHIN(ABL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given ABL_PROBE_PT_3_X can't be reached by the Z probe."
#elif ABL_PROBE_PT_1_Y < MIN_PROBE_Y || ABL_PROBE_PT_1_Y > MAX_PROBE_Y
#elif !WITHIN(ABL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_1_Y can't be reached by the Z probe."
#elif ABL_PROBE_PT_2_Y < MIN_PROBE_Y || ABL_PROBE_PT_2_Y > MAX_PROBE_Y
#elif !WITHIN(ABL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_2_Y can't be reached by the Z probe."
#elif ABL_PROBE_PT_3_Y < MIN_PROBE_Y || ABL_PROBE_PT_3_Y > MAX_PROBE_Y
#elif !WITHIN(ABL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given ABL_PROBE_PT_3_Y can't be reached by the Z probe."
#endif
#endif // AUTO_BED_LEVELING_3POINT
@ -862,11 +862,11 @@ static_assert(1 >= 0
/**
* Endstops
*/
#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _XMAX_ && Z2_USE_ENDSTOP <= _XMIN_)
#if DISABLED(USE_XMIN_PLUG) && DISABLED(USE_XMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _XMAX_, _XMIN_))
#error "You must enable USE_XMIN_PLUG or USE_XMAX_PLUG."
#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _YMAX_ && Z2_USE_ENDSTOP <= _YMIN_)
#elif DISABLED(USE_YMIN_PLUG) && DISABLED(USE_YMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _YMAX_, _YMIN_))
#error "You must enable USE_YMIN_PLUG or USE_YMAX_PLUG."
#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && Z2_USE_ENDSTOP >= _ZMAX_ && Z2_USE_ENDSTOP <= _ZMIN_)
#elif DISABLED(USE_ZMIN_PLUG) && DISABLED(USE_ZMAX_PLUG) && !(ENABLED(Z_DUAL_ENDSTOPS) && WITHIN(Z2_USE_ENDSTOP, _ZMAX_, _ZMIN_))
#error "You must enable USE_ZMIN_PLUG or USE_ZMAX_PLUG."
#elif ENABLED(Z_DUAL_ENDSTOPS)
#if !Z2_USE_ENDSTOP

View file

@ -38,6 +38,8 @@
#ifndef _ENDSTOP_INTERRUPTS_H_
#define _ENDSTOP_INTERRUPTS_H_
#include "macros.h"
/**
* Patch for pins_arduino.h (...\Arduino\hardware\arduino\avr\variants\mega\pins_arduino.h)
*
@ -47,39 +49,37 @@
*/
#if defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA)
#undef digitalPinToPCICR
#define digitalPinToPCICR(p) ( (((p) >= 10) && ((p) <= 15)) || \
(((p) >= 50) && ((p) <= 53)) || \
(((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )
#define digitalPinToPCICR(p) ( WITHIN(p, 10, 15) || \
WITHIN(p, 50, 53) || \
WITHIN(p, 62, 69) ? &PCICR : (uint8_t*)0 )
#undef digitalPinToPCICRbit
#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
( (((p) >= 14) && ((p) <= 15)) ? 1 : \
( (((p) >= 62) && ((p) <= 69)) ? 2 : \
0 ) ) )
#define digitalPinToPCICRbit(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? 0 : \
WITHIN(p, 14, 15) ? 1 : \
WITHIN(p, 62, 69) ? 2 : \
0 )
#undef digitalPinToPCMSK
#define digitalPinToPCMSK(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
( (((p) >= 14) && ((p) <= 15)) ? (&PCMSK1) : \
( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
((uint8_t *)0) ) ) )
#define digitalPinToPCMSK(p) ( WITHIN(p, 10, 13) || WITHIN(p, 50, 53) ? &PCMSK0 : \
WITHIN(p, 14, 15) ? &PCMSK1 : \
WITHIN(p, 62, 69) ? &PCMSK2 : \
(uint8_t *)0 )
#undef digitalPinToPCMSKbit
#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
( ((p) == 14) ? 2 : \
( ((p) == 15) ? 1 : \
( ((p) == 50) ? 3 : \
( ((p) == 51) ? 2 : \
( ((p) == 52) ? 1 : \
( ((p) == 53) ? 0 : \
( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
0 ) ) ) ) ) ) ) )
#define digitalPinToPCMSKbit(p) ( WITHIN(p, 10, 13) ? ((p) - 6) : \
(p) == 14 || (p) == 51 ? 2 : \
(p) == 15 || (p) == 52 ? 1 : \
(p) == 50 ? 3 : \
(p) == 53 ? 0 : \
WITHIN(p, 62, 69) ? ((p) - 62) : \
0 )
#endif
volatile uint8_t e_hit = 0; // Different from 0 when the endstops shall be tested in detail.
// Must be reset to 0 by the test function when the tests are finished.
volatile uint8_t e_hit = 0; // Different from 0 when the endstops should be tested in detail.
// Must be reset to 0 by the test function when finished.
// Install Pin change interrupt for a pin. Can be called multiple times.
void pciSetup(byte pin) {
*digitalPinToPCMSK(pin) |= bit (digitalPinToPCMSKbit(pin)); // enable pin
PCIFR |= bit (digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
PCICR |= bit (digitalPinToPCICRbit(pin)); // enable interrupt for the group
SBI(*digitalPinToPCMSK(pin), digitalPinToPCMSKbit(pin)); // enable pin
SBI(PCIFR, digitalPinToPCICRbit(pin)); // clear any outstanding interrupt
SBI(PCICR, digitalPinToPCICRbit(pin)); // enable interrupt for the group
}
// This is what is really done inside the interrupts.

View file

@ -75,7 +75,8 @@
#define ENABLED(b) _CAT(SWITCH_ENABLED_, b)
#define DISABLED(b) (!_CAT(SWITCH_ENABLED_, b))
#define NUMERIC(a) ((a) >= '0' && '9' >= (a))
#define WITHIN(V,L,H) ((V) >= (L) && (V) <= (H))
#define NUMERIC(a) WITHIN(a, '0', '9')
#define NUMERIC_SIGNED(a) (NUMERIC(a) || (a) == '-')
#define COUNT(a) (sizeof(a)/sizeof(*a))
#define ZERO(a) memset(a,0,sizeof(a))
@ -133,7 +134,7 @@
#define MAX4(a, b, c, d) max(max(a, b), max(c, d))
#define UNEAR_ZERO(x) ((x) < 0.000001)
#define NEAR_ZERO(x) ((x) > -0.000001 && (x) < 0.000001)
#define NEAR_ZERO(x) WITHIN(x, -0.000001, 0.000001)
#define NEAR(x,y) NEAR_ZERO((x)-(y))
#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))

View file

@ -88,12 +88,12 @@
static int8_t probe_index_x(const float &x) {
int8_t px = (x - (MESH_MIN_X) + 0.5 * (MESH_X_DIST)) * (1.0 / (MESH_X_DIST));
return (px >= 0 && px < (MESH_NUM_X_POINTS)) ? px : -1;
return WITHIN(px, 0, MESH_NUM_X_POINTS - 1) ? px : -1;
}
static int8_t probe_index_y(const float &y) {
int8_t py = (y - (MESH_MIN_Y) + 0.5 * (MESH_Y_DIST)) * (1.0 / (MESH_Y_DIST));
return (py >= 0 && py < (MESH_NUM_Y_POINTS)) ? py : -1;
return WITHIN(py, 0, MESH_NUM_Y_POINTS - 1) ? py : -1;
}
static float calc_z0(const float &a0, const float &a1, const float &z1, const float &a2, const float &z2) {

View file

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

View file

@ -999,7 +999,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
unsigned long segment_time = lround(1000000.0 / inverse_mm_s);
#endif
#if ENABLED(SLOWDOWN)
if (moves_queued > 1 && moves_queued < (BLOCK_BUFFER_SIZE) / 2) {
if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
if (segment_time < min_segment_time) {
// buffer is draining, add extra time. The amount of time added increases if the buffer is still emptied more.
inverse_mm_s = 1000000.0 / (segment_time + lround(2 * (min_segment_time - segment_time) / moves_queued));

View file

@ -786,11 +786,11 @@ void Temperature::manage_heater() {
#if ENABLED(PIDTEMPBED)
float pid_output = get_pid_output_bed();
soft_pwm_bed = current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP ? (int)pid_output >> 1 : 0;
soft_pwm_bed = WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP) ? (int)pid_output >> 1 : 0;
#elif ENABLED(BED_LIMIT_SWITCHING)
// Check if temperature is within the correct band
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
if (current_temperature_bed >= target_temperature_bed + BED_HYSTERESIS)
soft_pwm_bed = 0;
else if (current_temperature_bed <= target_temperature_bed - (BED_HYSTERESIS))
@ -802,7 +802,7 @@ void Temperature::manage_heater() {
}
#else // !PIDTEMPBED && !BED_LIMIT_SWITCHING
// Check if temperature is within the correct range
if (current_temperature_bed > BED_MINTEMP && current_temperature_bed < BED_MAXTEMP) {
if (WITHIN(current_temperature_bed, BED_MINTEMP, BED_MAXTEMP)) {
soft_pwm_bed = current_temperature_bed < target_temperature_bed ? MAX_BED_POWER >> 1 : 0;
}
else {

View file

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

View file

@ -213,7 +213,7 @@ static void lcd_setFont(const char font_nr) {
}
void lcd_print(const char c) {
if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
u8g.setFont(FONT_SPECIAL_NAME);
u8g.print(c);
lcd_setFont(currentfont);
@ -222,7 +222,7 @@ void lcd_print(const char c) {
}
char lcd_print_and_count(const char c) {
if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
u8g.setFont(FONT_SPECIAL_NAME);
u8g.print(c);
lcd_setFont(currentfont);

View file

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