Smarter MIN, MAX, ABS macros
Use macros that explicitly avoid double-evaluation and can be used for any datatype, replacing `min`, `max`, `abs`, `fabs`, `labs`, and `FABS`. Co-Authored-By: ejtagle <ejtagle@hotmail.com>
This commit is contained in:
@ -50,7 +50,7 @@
|
||||
*/
|
||||
void GcodeSuite::M125() {
|
||||
// Initial retract before move to filament change position
|
||||
const float retract = -FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0
|
||||
const float retract = -ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS) : 0
|
||||
#ifdef PAUSE_PARK_RETRACT_LENGTH
|
||||
+ (PAUSE_PARK_RETRACT_LENGTH)
|
||||
#endif
|
||||
|
@ -74,7 +74,7 @@ void GcodeSuite::M600() {
|
||||
#endif
|
||||
|
||||
// Initial retract before move to filament change position
|
||||
const float retract = -FABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0
|
||||
const float retract = -ABS(parser.seen('E') ? parser.value_axis_units(E_AXIS) : 0
|
||||
#ifdef PAUSE_PARK_RETRACT_LENGTH
|
||||
+ (PAUSE_PARK_RETRACT_LENGTH)
|
||||
#endif
|
||||
@ -93,14 +93,14 @@ void GcodeSuite::M600() {
|
||||
#endif
|
||||
|
||||
// Unload filament
|
||||
const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
|
||||
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS)
|
||||
: filament_change_unload_length[active_extruder]);
|
||||
|
||||
// Slow load filament
|
||||
constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
|
||||
|
||||
// Fast load filament
|
||||
const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
|
||||
const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
|
||||
: filament_change_load_length[active_extruder]);
|
||||
|
||||
const int beep_count = parser.intval('B',
|
||||
|
@ -47,7 +47,7 @@ void GcodeSuite::M603() {
|
||||
|
||||
// Unload length
|
||||
if (parser.seen('U')) {
|
||||
filament_change_unload_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS));
|
||||
filament_change_unload_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS));
|
||||
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||
NOMORE(filament_change_unload_length[target_extruder], EXTRUDE_MAXLENGTH);
|
||||
#endif
|
||||
@ -55,7 +55,7 @@ void GcodeSuite::M603() {
|
||||
|
||||
// Load length
|
||||
if (parser.seen('L')) {
|
||||
filament_change_load_length[target_extruder] = FABS(parser.value_axis_units(E_AXIS));
|
||||
filament_change_load_length[target_extruder] = ABS(parser.value_axis_units(E_AXIS));
|
||||
#if ENABLED(PREVENT_LENGTHY_EXTRUDE)
|
||||
NOMORE(filament_change_load_length[target_extruder], EXTRUDE_MAXLENGTH);
|
||||
#endif
|
||||
|
@ -74,18 +74,18 @@ void GcodeSuite::M701() {
|
||||
|
||||
// Lift Z axis
|
||||
if (park_point.z > 0)
|
||||
do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
|
||||
do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
|
||||
|
||||
// Load filament
|
||||
constexpr float slow_load_length = FILAMENT_CHANGE_SLOW_LOAD_LENGTH;
|
||||
const float fast_load_length = FABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
|
||||
const float fast_load_length = ABS(parser.seen('L') ? parser.value_axis_units(E_AXIS)
|
||||
: filament_change_load_length[active_extruder]);
|
||||
load_filament(slow_load_length, fast_load_length, ADVANCED_PAUSE_PURGE_LENGTH, FILAMENT_CHANGE_ALERT_BEEPS,
|
||||
true, thermalManager.wait_for_heating(target_extruder), ADVANCED_PAUSE_MODE_LOAD_FILAMENT);
|
||||
|
||||
// Restore Z axis
|
||||
if (park_point.z > 0)
|
||||
do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
|
||||
do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
|
||||
|
||||
#if EXTRUDERS > 1
|
||||
// Restore toolhead if it was changed
|
||||
@ -136,7 +136,7 @@ void GcodeSuite::M702() {
|
||||
|
||||
// Lift Z axis
|
||||
if (park_point.z > 0)
|
||||
do_blocking_move_to_z(min(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
|
||||
do_blocking_move_to_z(MIN(current_position[Z_AXIS] + park_point.z, Z_MAX_POS), NOZZLE_PARK_Z_FEEDRATE);
|
||||
|
||||
// Unload filament
|
||||
#if EXTRUDERS > 1 && ENABLED(FILAMENT_UNLOAD_ALL_EXTRUDERS)
|
||||
@ -150,7 +150,7 @@ void GcodeSuite::M702() {
|
||||
#endif
|
||||
{
|
||||
// Unload length
|
||||
const float unload_length = -FABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
|
||||
const float unload_length = -ABS(parser.seen('U') ? parser.value_axis_units(E_AXIS) :
|
||||
filament_change_unload_length[target_extruder]);
|
||||
|
||||
unload_filament(unload_length, true, ADVANCED_PAUSE_MODE_UNLOAD_FILAMENT);
|
||||
@ -158,7 +158,7 @@ void GcodeSuite::M702() {
|
||||
|
||||
// Restore Z axis
|
||||
if (park_point.z > 0)
|
||||
do_blocking_move_to_z(max(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
|
||||
do_blocking_move_to_z(MAX(current_position[Z_AXIS] - park_point.z, 0), NOZZLE_PARK_Z_FEEDRATE);
|
||||
|
||||
#if EXTRUDERS > 1
|
||||
// Restore toolhead if it was changed
|
||||
|
Reference in New Issue
Block a user