diff --git a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp b/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp index e702539ca92d2820f62b1db5f6ac01db5a2606b9..5f2dd40e19daa960de75d04da1bef1ba7e389b4b 100644 --- a/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp +++ b/Marlin/src/HAL/HAL_ESP32/HAL_Servo_ESP32.cpp @@ -48,8 +48,8 @@ void Servo::detach() { ledcDetachPin(this->pin); } int Servo::read() { return this->degrees; } -void Servo::write(int degrees) { - this->degrees = constrain(degrees, MIN_ANGLE, MAX_ANGLE); +void Servo::write(int inDegrees) { + this->degrees = constrain(inDegrees, MIN_ANGLE, MAX_ANGLE); int us = map(this->degrees, MIN_ANGLE, MAX_ANGLE, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); int duty = map(us, 0, TAU_USEC, 0, MAX_COMPARE); ledcWrite(channel, duty); diff --git a/Marlin/src/HAL/shared/servo.cpp b/Marlin/src/HAL/shared/servo.cpp index af338536654ff0f93d27e1c699f0360e82db4915..7f807304506c17ff09f307a12838fb8e05977c20 100644 --- a/Marlin/src/HAL/shared/servo.cpp +++ b/Marlin/src/HAL/shared/servo.cpp @@ -127,7 +127,7 @@ void Servo::writeMicroseconds(int value) { byte channel = this->servoIndex; if (channel < MAX_SERVOS) { // ensure channel is valid // ensure pulse width is valid - value = constrain(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION); + LIMIT(value, SERVO_MIN(), SERVO_MAX()) - (TRIM_DURATION); value = usToTicks(value); // convert to ticks after compensating for interrupt overhead - 12 Aug 2009 CRITICAL_SECTION_START; diff --git a/Marlin/src/feature/bedlevel/abl/abl.cpp b/Marlin/src/feature/bedlevel/abl/abl.cpp index 85ec693203cdf415c9fcd7b98353a508f6d55258..c70cf62203fe2de00e9dc7947723e9c3e6ad860b 100644 --- a/Marlin/src/feature/bedlevel/abl/abl.cpp +++ b/Marlin/src/feature/bedlevel/abl/abl.cpp @@ -369,10 +369,10 @@ float bilinear_z_offset(const float raw[XYZ]) { cy1 = CELL_INDEX(Y, current_position[Y_AXIS]), cx2 = CELL_INDEX(X, destination[X_AXIS]), cy2 = CELL_INDEX(Y, destination[Y_AXIS]); - cx1 = constrain(cx1, 0, ABL_BG_POINTS_X - 2); - cy1 = constrain(cy1, 0, ABL_BG_POINTS_Y - 2); - cx2 = constrain(cx2, 0, ABL_BG_POINTS_X - 2); - cy2 = constrain(cy2, 0, ABL_BG_POINTS_Y - 2); + LIMIT(cx1, 0, ABL_BG_POINTS_X - 2); + LIMIT(cy1, 0, ABL_BG_POINTS_Y - 2); + LIMIT(cx2, 0, ABL_BG_POINTS_X - 2); + LIMIT(cy2, 0, ABL_BG_POINTS_Y - 2); // Start and end in the same cell? No split needed. if (cx1 == cx2 && cy1 == cy2) { diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index d3b012da5abc74957de5811ceda8503989ec9e4e..4bb29d7e0be269e00ba807cee1f42b8175450c51 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -443,8 +443,8 @@ int8_t cell_xi = (raw[X_AXIS] - (MESH_MIN_X)) * (1.0f / (MESH_X_DIST)), cell_yi = (raw[Y_AXIS] - (MESH_MIN_Y)) * (1.0f / (MESH_Y_DIST)); - cell_xi = constrain(cell_xi, 0, (GRID_MAX_POINTS_X) - 1); - cell_yi = constrain(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1); + LIMIT(cell_xi, 0, (GRID_MAX_POINTS_X) - 1); + LIMIT(cell_yi, 0, (GRID_MAX_POINTS_Y) - 1); const float x0 = mesh_index_to_xpos(cell_xi), // 64 byte table lookup avoids mul+add y0 = mesh_index_to_ypos(cell_yi); diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 817e5646a689fffb20d44d84216cc5449e1caf6e..b95fe8d165fb85a22c093889defb5914ad7b8494 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -337,9 +337,9 @@ inline bool look_for_lines_to_connect() { sx = _GET_MESH_X( i ) + (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // right edge ex = _GET_MESH_X(i + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // left edge - sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1); + LIMIT(sx, X_MIN_POS + 1, X_MAX_POS - 1); sy = ey = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1); - ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1); + LIMIT(ex, X_MIN_POS + 1, X_MAX_POS - 1); if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); @@ -358,8 +358,8 @@ inline bool look_for_lines_to_connect() { ey = _GET_MESH_Y(j + 1) - (INTERSECTION_CIRCLE_RADIUS - (CROSSHAIRS_SIZE)); // bottom edge sx = ex = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1); - sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1); - ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(sy, Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(ey, Y_MIN_POS + 1, Y_MAX_POS - 1); if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); @@ -832,10 +832,10 @@ void GcodeSuite::G26() { // Check to make sure this segment is entirely on the bed, skip if not. if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue; #else // not, we need to skip - rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops - ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1); - xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1); - ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops + LIMIT(ry, Y_MIN_POS + 1, Y_MAX_POS - 1); + LIMIT(xe, X_MIN_POS + 1, X_MAX_POS - 1); + LIMIT(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); #endif print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height); diff --git a/Marlin/src/gcode/bedlevel/abl/G29.cpp b/Marlin/src/gcode/bedlevel/abl/G29.cpp index 2a4b4f85bb7e7449aeaf42c17b0ba1a21a809ed1..64ae54ef214be523effd470b56c385845357e672 100644 --- a/Marlin/src/gcode/bedlevel/abl/G29.cpp +++ b/Marlin/src/gcode/bedlevel/abl/G29.cpp @@ -318,8 +318,8 @@ G29_TYPE GcodeSuite::G29() { // Get nearest i / j from rx / ry i = (rx - bilinear_start[X_AXIS] + 0.5 * xGridSpacing) / xGridSpacing; j = (ry - bilinear_start[Y_AXIS] + 0.5 * yGridSpacing) / yGridSpacing; - i = constrain(i, 0, GRID_MAX_POINTS_X - 1); - j = constrain(j, 0, GRID_MAX_POINTS_Y - 1); + LIMIT(i, 0, GRID_MAX_POINTS_X - 1); + LIMIT(j, 0, GRID_MAX_POINTS_Y - 1); } if (WITHIN(i, 0, GRID_MAX_POINTS_X - 1) && WITHIN(j, 0, GRID_MAX_POINTS_Y)) { set_bed_leveling_enabled(false); diff --git a/Marlin/src/gcode/calibrate/M48.cpp b/Marlin/src/gcode/calibrate/M48.cpp index 9f0fc714d6773a6f27b243df83d364a7aa9a97d0..ca54ae8f9cb812bfe2489ed0b744e3155ad91dcc 100644 --- a/Marlin/src/gcode/calibrate/M48.cpp +++ b/Marlin/src/gcode/calibrate/M48.cpp @@ -163,8 +163,8 @@ void GcodeSuite::M48() { Y_current = Y_probe_location - (Y_PROBE_OFFSET_FROM_EXTRUDER) + sin(RADIANS(angle)) * radius; #if DISABLED(DELTA) - X_current = constrain(X_current, X_MIN_POS, X_MAX_POS); - Y_current = constrain(Y_current, Y_MIN_POS, Y_MAX_POS); + LIMIT(X_current, X_MIN_POS, X_MAX_POS); + LIMIT(Y_current, Y_MIN_POS, Y_MAX_POS); #else // If we have gone out too far, we can do a simple fix and scale the numbers // back in closer to the origin. diff --git a/Marlin/src/lcd/extui_malyan_lcd.cpp b/Marlin/src/lcd/extui_malyan_lcd.cpp index e9e7dfdd593a6a6285e1c961629338ce7a139a8e..6b838273828afb40e4e20ebb918f568336021c7d 100644 --- a/Marlin/src/lcd/extui_malyan_lcd.cpp +++ b/Marlin/src/lcd/extui_malyan_lcd.cpp @@ -115,9 +115,8 @@ void process_lcd_c_command(const char* command) { switch (command[0]) { case 'C': // Cope with both V1 early rev and later LCDs. case 'S': { - int raw_feedrate = atoi(command + 1); - feedrate_percentage = raw_feedrate * 10; - feedrate_percentage = constrain(feedrate_percentage, 10, 999); + feedrate_percentage = atoi(command + 1) * 10; + LIMIT(feedrate_percentage, 10, 999); } break; case 'T': { thermalManager.setTargetHotend(atoi(command + 1), 0); diff --git a/Marlin/src/lcd/menu/game/brickout.cpp b/Marlin/src/lcd/menu/game/brickout.cpp index ad23031360bcd9f78a0d29d164ca894ab9538f4b..1cb19a5cd5cac61956a74894036771ee53dc79fe 100644 --- a/Marlin/src/lcd/menu/game/brickout.cpp +++ b/Marlin/src/lcd/menu/game/brickout.cpp @@ -67,8 +67,7 @@ void reset_ball() { void BrickoutGame::game_screen() { if (game_frame()) { // Run logic twice for finer resolution // Update Paddle Position - paddle_x = (int8_t)ui.encoderPosition; - paddle_x = constrain(paddle_x, 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL)); + paddle_x = constrain(int8_t(ui.encoderPosition), 0, (LCD_PIXEL_WIDTH - (PADDLE_W)) / (PADDLE_VEL)); ui.encoderPosition = paddle_x; paddle_x *= (PADDLE_VEL); diff --git a/Marlin/src/lcd/menu/game/invaders.cpp b/Marlin/src/lcd/menu/game/invaders.cpp index 55a1e4a8499baf3f1b68593f48a1fbd206017bbd..b54566c3f790b13f699e6c1386e89b75703b42aa 100644 --- a/Marlin/src/lcd/menu/game/invaders.cpp +++ b/Marlin/src/lcd/menu/game/invaders.cpp @@ -263,8 +263,7 @@ void InvadersGame::game_screen() { if (ui.first_page) { // Update Cannon Position - int16_t ep = int16_t(ui.encoderPosition); - ep = constrain(ep, 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL)); + int16_t ep = constrain(int16_t(ui.encoderPosition), 0, (LCD_PIXEL_WIDTH - (CANNON_W)) / (CANNON_VEL)); ui.encoderPosition = ep; ep *= (CANNON_VEL); diff --git a/Marlin/src/lcd/menu/menu_configuration.cpp b/Marlin/src/lcd/menu/menu_configuration.cpp index c1395e22fc8553f7134907b92f5d1b22c1c307e2..f01f2fd98621c855df1ed2c55fe6c63c51b6b72f 100644 --- a/Marlin/src/lcd/menu/menu_configuration.cpp +++ b/Marlin/src/lcd/menu/menu_configuration.cpp @@ -70,7 +70,7 @@ static void lcd_factory_settings() { return; } bar_percent += (int8_t)ui.encoderPosition; - bar_percent = constrain(bar_percent, 0, 100); + LIMIT(bar_percent, 0, 100); ui.encoderPosition = 0; draw_menu_item_static(0, PSTR(MSG_PROGRESS_BAR_TEST), true, true); lcd_moveto((LCD_WIDTH) / 2 - 2, LCD_HEIGHT - 2); diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index d652d90abf4343b45330ea2cd368e10ec3e94431..2fb2b209e9f3d779205542e969c8a6ab7294a3a4 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -548,7 +548,7 @@ void MarlinUI::status_screen() { else if ((old_frm < 100 && new_frm > 100) || (old_frm > 100 && new_frm < 100)) new_frm = 100; - new_frm = constrain(new_frm, 10, 999); + LIMIT(new_frm, 10, 999); if (old_frm != new_frm) { feedrate_percentage = new_frm; diff --git a/Marlin/src/module/planner.cpp b/Marlin/src/module/planner.cpp index 561d2b6469c31785f6c688c2a0bb3de948e546ee..a755cafca4affaa20ff1e8a207fe142f7b5802ec 100644 --- a/Marlin/src/module/planner.cpp +++ b/Marlin/src/module/planner.cpp @@ -1157,7 +1157,7 @@ void Planner::recalculate() { } float t = autotemp_min + high * autotemp_factor; - t = constrain(t, autotemp_min, autotemp_max); + LIMIT(t, autotemp_min, autotemp_max); if (t < oldt) t = t * (1 - float(AUTOTEMP_OLDWEIGHT)) + oldt * float(AUTOTEMP_OLDWEIGHT); oldt = t; thermalManager.setTargetHotend(t, 0); diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 43efb79333b978a72a5cf97a72a7f4c4f0de712b..d7e4423bc434875089356ef90f4d2f969796956c 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -460,7 +460,7 @@ temp_range_t Temperature::temp_range[HOTENDS] = ARRAY_BY_HOTENDS(sensor_heater_0 if (cycles > 0) { const long max_pow = GHV(MAX_BED_POWER, PID_MAX); bias += (d * (t_high - t_low)) / (t_low + t_high); - bias = constrain(bias, 20, max_pow - 20); + LIMIT(bias, 20, max_pow - 20); d = (bias > max_pow >> 1) ? max_pow - 1 - bias : bias; SERIAL_ECHOPAIR(MSG_BIAS, bias, MSG_D, d, MSG_T_MIN, min, MSG_T_MAX, max); @@ -874,7 +874,7 @@ float Temperature::get_pid_output_hotend(const uint8_t e) { } #endif // PID_EXTRUSION_SCALING - pid_output = constrain(pid_output, 0, PID_MAX); + LIMIT(pid_output, 0, PID_MAX); } temp_dState[ee] = temp_hotend[ee].current; @@ -1070,7 +1070,7 @@ void Temperature::manage_heater() { if (filament_sensor) { meas_shift_index = filwidth_delay_index[0] - meas_delay_cm; if (meas_shift_index < 0) meas_shift_index += MAX_MEASUREMENT_DELAY + 1; //loop around buffer if needed - meas_shift_index = constrain(meas_shift_index, 0, MAX_MEASUREMENT_DELAY); + LIMIT(meas_shift_index, 0, MAX_MEASUREMENT_DELAY); planner.calculate_volumetric_for_width_sensor(measurement_delay[meas_shift_index]); } #endif // FILAMENT_WIDTH_SENSOR