Apply maths macros and type changes ahead of HAL

This commit is contained in:
Scott Lahteine 2017-06-19 22:39:23 -05:00
parent 0c616700f3
commit 6c45d0fd81
26 changed files with 181 additions and 166 deletions

View File

@ -600,7 +600,7 @@
// If the end point of the line is closer to the nozzle, flip the direction, // If the end point of the line is closer to the nozzle, flip the direction,
// moving from the end to the start. On very small lines the optimization isn't worth it. // moving from the end to the start. On very small lines the optimization isn't worth it.
if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) { if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < FABS(line_length)) {
return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz); return print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
} }

View File

@ -126,16 +126,16 @@
} }
lastPosition = position; lastPosition = position;
unsigned long positionTime = millis(); millis_t positionTime = millis();
//only do error correction if setup and enabled //only do error correction if setup and enabled
if (ec && ecMethod != I2CPE_ECM_NONE) { if (ec && ecMethod != I2CPE_ECM_NONE) {
#if defined(I2CPE_EC_THRESH_PROPORTIONAL) #if defined(I2CPE_EC_THRESH_PROPORTIONAL)
millis_t deltaTime = positionTime - lastPositionTime;
unsigned long distance = abs(position - lastPosition); unsigned long distance = abs(position - lastPosition);
unsigned long deltaTime = positionTime - lastPositionTime;
unsigned long speed = distance / deltaTime; unsigned long speed = distance / deltaTime;
float threshold = constrain((speed / 50), 1, 50) * ecThreshold; float threshold = constrain(speed / 50, 1, 50) * ecThreshold;
#else #else
float threshold = get_error_correct_threshold(); float threshold = get_error_correct_threshold();
#endif #endif
@ -162,7 +162,7 @@
//SERIAL_ECHOLN(error); //SERIAL_ECHOLN(error);
#if defined(I2CPE_ERR_THRESH_ABORT) #if defined(I2CPE_ERR_THRESH_ABORT)
if (abs(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) { if (labs(error) > I2CPE_ERR_THRESH_ABORT * planner.axis_steps_per_mm[encoderAxis]) {
//kill("Significant Error"); //kill("Significant Error");
SERIAL_ECHOPGM("Axis error greater than set threshold, aborting!"); SERIAL_ECHOPGM("Axis error greater than set threshold, aborting!");
SERIAL_ECHOLN(error); SERIAL_ECHOLN(error);
@ -174,29 +174,32 @@
if (errIdx == 0) { if (errIdx == 0) {
// in order to correct for "error" but avoid correcting for noise and non skips // in order to correct for "error" but avoid correcting for noise and non skips
// it must be > threshold and have a difference average of < 10 and be < 2000 steps // it must be > threshold and have a difference average of < 10 and be < 2000 steps
if (abs(error) > threshold * planner.axis_steps_per_mm[encoderAxis] && if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis] &&
diffSum < 10*(I2CPE_ERR_ARRAY_SIZE-1) && abs(error) < 2000) { //Check for persistent error (skip) diffSum < 10 * (I2CPE_ERR_ARRAY_SIZE - 1) && labs(error) < 2000) { //Check for persistent error (skip)
SERIAL_ECHO(axis_codes[encoderAxis]); SERIAL_ECHO(axis_codes[encoderAxis]);
SERIAL_ECHOPAIR(" diffSum: ", diffSum/(I2CPE_ERR_ARRAY_SIZE-1)); SERIAL_ECHOPAIR(" diffSum: ", diffSum / (I2CPE_ERR_ARRAY_SIZE - 1));
SERIAL_ECHOPAIR(" - err detected: ", error / planner.axis_steps_per_mm[encoderAxis]); SERIAL_ECHOPAIR(" - err detected: ", error / planner.axis_steps_per_mm[encoderAxis]);
SERIAL_ECHOLNPGM("mm; correcting!"); SERIAL_ECHOLNPGM("mm; correcting!");
thermalManager.babystepsTodo[encoderAxis] = -lround(error); thermalManager.babystepsTodo[encoderAxis] = -LROUND(error);
} }
} }
#else #else
if (abs(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) { if (labs(error) > threshold * planner.axis_steps_per_mm[encoderAxis]) {
//SERIAL_ECHOLN(error); //SERIAL_ECHOLN(error);
//SERIAL_ECHOLN(position); //SERIAL_ECHOLN(position);
thermalManager.babystepsTodo[encoderAxis] = -lround(error/2); thermalManager.babystepsTodo[encoderAxis] = -LROUND(error/2);
} }
#endif #endif
if (abs(error) > (I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) && millis() - lastErrorCountTime > I2CPE_ERR_CNT_DEBOUNCE_MS) { if (labs(error) > I2CPE_ERR_CNT_THRESH * planner.axis_steps_per_mm[encoderAxis]) {
SERIAL_ECHOPAIR("Large error on ", axis_codes[encoderAxis]); const millis_t ms = millis();
SERIAL_ECHOPAIR(" axis. error: ", (int)error); if (ELAPSED(ms, nextErrorCountTime)) {
SERIAL_ECHOLNPAIR("; diffSum: ", diffSum); SERIAL_ECHOPAIR("Large error on ", axis_codes[encoderAxis]);
errorCount++; SERIAL_ECHOPAIR(" axis. error: ", (int)error);
lastErrorCountTime = millis(); SERIAL_ECHOLNPAIR("; diffSum: ", diffSum);
errorCount++;
nextErrorCountTime = ms + I2CPE_ERR_CNT_DEBOUNCE_MS;
}
} }
} }
@ -255,7 +258,7 @@
actual = mm_from_count(position); actual = mm_from_count(position);
error = actual - target; error = actual - target;
if (abs(error) > 10000) error = 0; // ? if (labs(error) > 10000) error = 0; // ?
if (report) { if (report) {
SERIAL_ECHO(axis_codes[encoderAxis]); SERIAL_ECHO(axis_codes[encoderAxis]);
@ -284,13 +287,13 @@
stepperTicksPerUnit = (type == I2CPE_ENC_TYPE_ROTARY) ? stepperTicks : planner.axis_steps_per_mm[encoderAxis]; stepperTicksPerUnit = (type == I2CPE_ENC_TYPE_ROTARY) ? stepperTicks : planner.axis_steps_per_mm[encoderAxis];
//convert both 'ticks' into same units / base //convert both 'ticks' into same units / base
encoderCountInStepperTicksScaled = lround((stepperTicksPerUnit * encoderTicks) / encoderTicksPerUnit); encoderCountInStepperTicksScaled = LROUND((stepperTicksPerUnit * encoderTicks) / encoderTicksPerUnit);
long target = stepper.position(encoderAxis), long target = stepper.position(encoderAxis),
error = (encoderCountInStepperTicksScaled - target); error = (encoderCountInStepperTicksScaled - target);
//suppress discontinuities (might be caused by bad I2C readings...?) //suppress discontinuities (might be caused by bad I2C readings...?)
bool suppressOutput = (abs(error - errorPrev) > 100); bool suppressOutput = (labs(error - errorPrev) > 100);
if (report) { if (report) {
SERIAL_ECHO(axis_codes[encoderAxis]); SERIAL_ECHO(axis_codes[encoderAxis]);

View File

@ -136,7 +136,7 @@
position; position;
unsigned long lastPositionTime = 0, unsigned long lastPositionTime = 0,
lastErrorCountTime = 0, nextErrorCountTime = 0,
lastErrorTime; lastErrorTime;
//double positionMm; //calculate //double positionMm; //calculate

View File

@ -210,7 +210,7 @@ inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
/** /**
* Feedrate scaling and conversion * Feedrate scaling and conversion
*/ */
extern int feedrate_percentage; extern int16_t feedrate_percentage;
#define MMM_TO_MMS(MM_M) ((MM_M)/60.0) #define MMM_TO_MMS(MM_M) ((MM_M)/60.0)
#define MMS_TO_MMM(MM_S) ((MM_S)*60.0) #define MMS_TO_MMM(MM_S) ((MM_S)*60.0)
@ -218,7 +218,7 @@ extern int feedrate_percentage;
extern bool axis_relative_modes[]; extern bool axis_relative_modes[];
extern bool volumetric_enabled; extern bool volumetric_enabled;
extern int flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder extern int16_t flow_percentage[EXTRUDERS]; // Extrusion factor for each extruder
extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder. extern float filament_size[EXTRUDERS]; // cross-sectional area of filament (in millimeters), typically around 1.75 or 2.85, 0 disables the volumetric calculations for the extruder.
extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner extern float volumetric_multiplier[EXTRUDERS]; // reciprocal of cross-sectional area of filament (in square millimeters), stored this way to reduce computational burden in planner
extern bool axis_known_position[XYZ]; extern bool axis_known_position[XYZ];

View File

@ -421,7 +421,7 @@ FORCE_INLINE float homing_feedrate(const AxisEnum a) { return pgm_read_float(&ho
float feedrate_mm_s = MMM_TO_MMS(1500.0); float feedrate_mm_s = MMM_TO_MMS(1500.0);
static float saved_feedrate_mm_s; static float saved_feedrate_mm_s;
int feedrate_percentage = 100, saved_feedrate_percentage, int16_t feedrate_percentage = 100, saved_feedrate_percentage,
flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100); flow_percentage[EXTRUDERS] = ARRAY_BY_EXTRUDERS1(100);
bool axis_relative_modes[] = AXIS_RELATIVE_MODES, bool axis_relative_modes[] = AXIS_RELATIVE_MODES,
@ -2968,7 +2968,7 @@ static void homeaxis(const AxisEnum axis) {
#if ENABLED(Z_DUAL_ENDSTOPS) #if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) { if (axis == Z_AXIS) {
float adj = fabs(z_endstop_adj); float adj = FABS(z_endstop_adj);
bool lockZ1; bool lockZ1;
if (axis_home_dir > 0) { if (axis_home_dir > 0) {
adj = -adj; adj = -adj;
@ -3293,7 +3293,7 @@ inline void gcode_G0_G1(
const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1 const float e = clockwise ^ (r < 0) ? -1 : 1, // clockwise -1/1, counterclockwise 1/-1
dx = x2 - x1, dy = y2 - y1, // X and Y differences dx = x2 - x1, dy = y2 - y1, // X and Y differences
d = HYPOT(dx, dy), // Linear distance between the points d = HYPOT(dx, dy), // Linear distance between the points
h = sqrt(sq(r) - sq(d * 0.5)), // Distance to the arc pivot-point h = SQRT(sq(r) - sq(d * 0.5)), // Distance to the arc pivot-point
mx = (x1 + x2) * 0.5, my = (y1 + y2) * 0.5, // Point between the two points mx = (x1 + x2) * 0.5, my = (y1 + y2) * 0.5, // Point between the two points
sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector sx = -dy / d, sy = dx / d, // Slope of the perpendicular bisector
cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc cx = mx + e * h * sx, cy = my + e * h * sy; // Pivot-point of the arc
@ -3448,7 +3448,7 @@ inline void gcode_G4() {
const float mlx = max_length(X_AXIS), const float mlx = max_length(X_AXIS),
mly = max_length(Y_AXIS), mly = max_length(Y_AXIS),
mlratio = mlx > mly ? mly / mlx : mlx / mly, mlratio = mlx > mly ? mly / mlx : mlx / mly,
fr_mm_s = min(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * sqrt(sq(mlratio) + 1.0); fr_mm_s = min(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0);
do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s); do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s);
endstops.hit_on_purpose(); // clear endstop hit flags endstops.hit_on_purpose(); // clear endstop hit flags
@ -4605,8 +4605,8 @@ void home_all_axes() { gcode_G28(true); }
const float xBase = xCount * xGridSpacing + left_probe_bed_position, const float xBase = xCount * xGridSpacing + left_probe_bed_position,
yBase = yCount * yGridSpacing + front_probe_bed_position; yBase = yCount * yGridSpacing + front_probe_bed_position;
xProbe = floor(xBase + (xBase < 0 ? 0 : 0.5)); xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5)); yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
#if ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[xCount][yCount] = abl_probe_index; indexIntoAB[xCount][yCount] = abl_probe_index;
@ -4710,8 +4710,8 @@ void home_all_axes() { gcode_G28(true); }
float xBase = left_probe_bed_position + xGridSpacing * xCount, float xBase = left_probe_bed_position + xGridSpacing * xCount,
yBase = front_probe_bed_position + yGridSpacing * yCount; yBase = front_probe_bed_position + yGridSpacing * yCount;
xProbe = floor(xBase + (xBase < 0 ? 0 : 0.5)); xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5)); yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
#if ENABLED(AUTO_BED_LEVELING_LINEAR) #if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[xCount][yCount] = ++abl_probe_index; // 0... indexIntoAB[xCount][yCount] = ++abl_probe_index; // 0...
@ -5263,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
N++; N++;
} }
zero_std_dev_old = zero_std_dev; zero_std_dev_old = zero_std_dev;
zero_std_dev = round(sqrt(S2 / N) * 1000.0) / 1000.0 + 0.00001; zero_std_dev = round(SQRT(S2 / N) * 1000.0) / 1000.0 + 0.00001;
if (iterations == 1) home_offset[Z_AXIS] = zh_old; // reset height after 1st probe change if (iterations == 1) home_offset[Z_AXIS] = zh_old; // reset height after 1st probe change
@ -5464,7 +5464,7 @@ void home_all_axes() { gcode_G28(true); }
float retract_mm[XYZ]; float retract_mm[XYZ];
LOOP_XYZ(i) { LOOP_XYZ(i) {
float dist = destination[i] - current_position[i]; float dist = destination[i] - current_position[i];
retract_mm[i] = fabs(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1); retract_mm[i] = FABS(dist) < G38_MINIMUM_MOVE ? 0 : home_bump_mm((AxisEnum)i) * (dist > 0 ? -1 : 1);
} }
stepper.synchronize(); // wait until the machine is idle stepper.synchronize(); // wait until the machine is idle
@ -5528,7 +5528,7 @@ void home_all_axes() { gcode_G28(true); }
// If any axis has enough movement, do the move // If any axis has enough movement, do the move
LOOP_XYZ(i) LOOP_XYZ(i)
if (fabs(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) { if (FABS(destination[i] - current_position[i]) >= G38_MINIMUM_MOVE) {
if (!parser.seen('F')) feedrate_mm_s = homing_feedrate(i); if (!parser.seen('F')) feedrate_mm_s = homing_feedrate(i);
// If G38.2 fails throw an error // If G38.2 fails throw an error
if (!G38_run_probe() && is_38_2) { if (!G38_run_probe() && is_38_2) {
@ -6851,7 +6851,7 @@ inline void gcode_M42() {
for (uint8_t j = 0; j <= n; j++) for (uint8_t j = 0; j <= n; j++)
sum += sq(sample_set[j] - mean); sum += sq(sample_set[j] - mean);
sigma = sqrt(sum / (n + 1)); sigma = SQRT(sum / (n + 1));
if (verbose_level > 0) { if (verbose_level > 0) {
if (verbose_level > 1) { if (verbose_level > 1) {
SERIAL_PROTOCOL(n + 1); SERIAL_PROTOCOL(n + 1);
@ -7266,7 +7266,7 @@ inline void gcode_M109() {
#if TEMP_RESIDENCY_TIME > 0 #if TEMP_RESIDENCY_TIME > 0
const float temp_diff = fabs(target_temp - temp); const float temp_diff = FABS(target_temp - temp);
if (!residency_start_ms) { if (!residency_start_ms) {
// Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_RESIDENCY_TIME timer when we reach target temp for the first time.
@ -7395,7 +7395,7 @@ inline void gcode_M109() {
#if TEMP_BED_RESIDENCY_TIME > 0 #if TEMP_BED_RESIDENCY_TIME > 0
const float temp_diff = fabs(target_temp - temp); const float temp_diff = FABS(target_temp - temp);
if (!residency_start_ms) { if (!residency_start_ms) {
// Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time. // Start the TEMP_BED_RESIDENCY_TIME timer when we reach target temp for the first time.
@ -9252,7 +9252,7 @@ inline void gcode_M503() {
#if ENABLED(BABYSTEP_ZPROBE_OFFSET) #if ENABLED(BABYSTEP_ZPROBE_OFFSET)
if (!no_babystep && leveling_is_active()) if (!no_babystep && leveling_is_active())
thermalManager.babystep_axis(Z_AXIS, -lround(diff * planner.axis_steps_per_mm[Z_AXIS])); thermalManager.babystep_axis(Z_AXIS, -LROUND(diff * planner.axis_steps_per_mm[Z_AXIS]));
#else #else
UNUSED(no_babystep); UNUSED(no_babystep);
#endif #endif
@ -11171,7 +11171,7 @@ void ok_to_send() {
if (last_x != x) { if (last_x != x) {
last_x = x; last_x = x;
ratio_x = x * ABL_BG_FACTOR(X_AXIS); ratio_x = x * ABL_BG_FACTOR(X_AXIS);
const float gx = constrain(floor(ratio_x), 0, ABL_BG_POINTS_X - FAR_EDGE_OR_BOX); const float gx = constrain(FLOOR(ratio_x), 0, ABL_BG_POINTS_X - FAR_EDGE_OR_BOX);
ratio_x -= gx; // Subtract whole to get the ratio within the grid box ratio_x -= gx; // Subtract whole to get the ratio within the grid box
#if DISABLED(EXTRAPOLATE_BEYOND_GRID) #if DISABLED(EXTRAPOLATE_BEYOND_GRID)
@ -11188,7 +11188,7 @@ void ok_to_send() {
if (last_y != y) { if (last_y != y) {
last_y = y; last_y = y;
ratio_y = y * ABL_BG_FACTOR(Y_AXIS); ratio_y = y * ABL_BG_FACTOR(Y_AXIS);
const float gy = constrain(floor(ratio_y), 0, ABL_BG_POINTS_Y - FAR_EDGE_OR_BOX); const float gy = constrain(FLOOR(ratio_y), 0, ABL_BG_POINTS_Y - FAR_EDGE_OR_BOX);
ratio_y -= gy; ratio_y -= gy;
#if DISABLED(EXTRAPOLATE_BEYOND_GRID) #if DISABLED(EXTRAPOLATE_BEYOND_GRID)
@ -11221,7 +11221,7 @@ void ok_to_send() {
/* /*
static float last_offset = 0; static float last_offset = 0;
if (fabs(last_offset - offset) > 0.2) { if (FABS(last_offset - offset) > 0.2) {
SERIAL_ECHOPGM("Sudden Shift at "); SERIAL_ECHOPGM("Sudden Shift at ");
SERIAL_ECHOPAIR("x=", x); SERIAL_ECHOPAIR("x=", x);
SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]); SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]);
@ -11290,7 +11290,7 @@ void ok_to_send() {
#else #else
#define _SQRT(n) sqrt(n) #define _SQRT(n) SQRT(n)
#endif #endif
@ -11364,7 +11364,7 @@ void ok_to_send() {
float distance = delta[A_AXIS]; float distance = delta[A_AXIS];
cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS); cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS);
inverse_kinematics(cartesian); inverse_kinematics(cartesian);
return abs(distance - delta[A_AXIS]); return FABS(distance - delta[A_AXIS]);
} }
/** /**
@ -11397,7 +11397,7 @@ void ok_to_send() {
float p12[3] = { delta_tower[B_AXIS][X_AXIS] - delta_tower[A_AXIS][X_AXIS], delta_tower[B_AXIS][Y_AXIS] - delta_tower[A_AXIS][Y_AXIS], z2 - z1 }; float p12[3] = { delta_tower[B_AXIS][X_AXIS] - delta_tower[A_AXIS][X_AXIS], delta_tower[B_AXIS][Y_AXIS] - delta_tower[A_AXIS][Y_AXIS], z2 - z1 };
// Get the Magnitude of vector. // Get the Magnitude of vector.
float d = sqrt( sq(p12[0]) + sq(p12[1]) + sq(p12[2]) ); float d = SQRT( sq(p12[0]) + sq(p12[1]) + sq(p12[2]) );
// Create unit vector by dividing by magnitude. // Create unit vector by dividing by magnitude.
float ex[3] = { p12[0] / d, p12[1] / d, p12[2] / d }; float ex[3] = { p12[0] / d, p12[1] / d, p12[2] / d };
@ -11416,7 +11416,7 @@ void ok_to_send() {
float ey[3] = { p13[0] - iex[0], p13[1] - iex[1], p13[2] - iex[2] }; float ey[3] = { p13[0] - iex[0], p13[1] - iex[1], p13[2] - iex[2] };
// The magnitude of Y component // The magnitude of Y component
float j = sqrt( sq(ey[0]) + sq(ey[1]) + sq(ey[2]) ); float j = SQRT( sq(ey[0]) + sq(ey[1]) + sq(ey[2]) );
// Convert to a unit vector // Convert to a unit vector
ey[0] /= j; ey[1] /= j; ey[2] /= j; ey[0] /= j; ey[1] /= j; ey[2] /= j;
@ -11433,7 +11433,7 @@ void ok_to_send() {
// Plug them into the equations defined in Wikipedia for Xnew, Ynew and Znew // Plug them into the equations defined in Wikipedia for Xnew, Ynew and Znew
float Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + sq(d)) / (d * 2), float Xnew = (delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[B_AXIS] + sq(d)) / (d * 2),
Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + HYPOT2(i, j)) / 2 - i * Xnew) / j, Ynew = ((delta_diagonal_rod_2_tower[A_AXIS] - delta_diagonal_rod_2_tower[C_AXIS] + HYPOT2(i, j)) / 2 - i * Xnew) / j,
Znew = sqrt(delta_diagonal_rod_2_tower[A_AXIS] - HYPOT2(Xnew, Ynew)); Znew = SQRT(delta_diagonal_rod_2_tower[A_AXIS] - HYPOT2(Xnew, Ynew));
// Start from the origin of the old coordinates and add vectors in the // Start from the origin of the old coordinates and add vectors in the
// old coords that represent the Xnew, Ynew and Znew to find the point // old coords that represent the Xnew, Ynew and Znew to find the point
@ -11656,10 +11656,10 @@ void set_current_from_steppers_for_axis(const AxisEnum axis) {
}; };
// Get the linear distance in XYZ // Get the linear distance in XYZ
float cartesian_mm = sqrt(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS])); float cartesian_mm = SQRT(sq(difference[X_AXIS]) + sq(difference[Y_AXIS]) + sq(difference[Z_AXIS]));
// If the move is very short, check the E move distance // If the move is very short, check the E move distance
if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = abs(difference[E_AXIS]); if (UNEAR_ZERO(cartesian_mm)) cartesian_mm = FABS(difference[E_AXIS]);
// No E move either? Game over. // No E move either? Game over.
if (UNEAR_ZERO(cartesian_mm)) return true; if (UNEAR_ZERO(cartesian_mm)) return true;
@ -11947,7 +11947,7 @@ void prepare_move_to_destination() {
extruder_travel = logical[E_AXIS] - current_position[E_AXIS]; extruder_travel = logical[E_AXIS] - current_position[E_AXIS];
// CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required. // CCW angle of rotation between position and target from the circle center. Only one atan2() trig computation required.
float angular_travel = atan2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y); float angular_travel = ATAN2(r_X * rt_Y - r_Y * rt_X, r_X * rt_X + r_Y * rt_Y);
if (angular_travel < 0) angular_travel += RADIANS(360); if (angular_travel < 0) angular_travel += RADIANS(360);
if (clockwise) angular_travel -= RADIANS(360); if (clockwise) angular_travel -= RADIANS(360);
@ -11955,10 +11955,10 @@ void prepare_move_to_destination() {
if (angular_travel == 0 && current_position[X_AXIS] == logical[X_AXIS] && current_position[Y_AXIS] == logical[Y_AXIS]) if (angular_travel == 0 && current_position[X_AXIS] == logical[X_AXIS] && current_position[Y_AXIS] == logical[Y_AXIS])
angular_travel += RADIANS(360); angular_travel += RADIANS(360);
const float mm_of_travel = HYPOT(angular_travel * radius, fabs(linear_travel)); const float mm_of_travel = HYPOT(angular_travel * radius, FABS(linear_travel));
if (mm_of_travel < 0.001) return; if (mm_of_travel < 0.001) return;
uint16_t segments = floor(mm_of_travel / (MM_PER_ARC_SEGMENT)); uint16_t segments = FLOOR(mm_of_travel / (MM_PER_ARC_SEGMENT));
if (segments == 0) segments = 1; if (segments == 0) segments = 1;
/** /**
@ -12155,7 +12155,7 @@ void prepare_move_to_destination() {
else else
C2 = (HYPOT2(sx, sy) - (L1_2 + L2_2)) / (2.0 * L1 * L2); C2 = (HYPOT2(sx, sy) - (L1_2 + L2_2)) / (2.0 * L1 * L2);
S2 = sqrt(1 - sq(C2)); S2 = SQRT(1 - sq(C2));
// Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End // Unrotated Arm1 plus rotated Arm2 gives the distance from Center to End
SK1 = L1 + L2 * C2; SK1 = L1 + L2 * C2;
@ -12164,10 +12164,10 @@ void prepare_move_to_destination() {
SK2 = L2 * S2; SK2 = L2 * S2;
// Angle of Arm1 is the difference between Center-to-End angle and the Center-to-Elbow // Angle of Arm1 is the difference between Center-to-End angle and the Center-to-Elbow
THETA = atan2(SK1, SK2) - atan2(sx, sy); THETA = ATAN2(SK1, SK2) - ATAN2(sx, sy);
// Angle of Arm2 // Angle of Arm2
PSI = atan2(S2, C2); PSI = ATAN2(S2, C2);
delta[A_AXIS] = DEGREES(THETA); // theta is support arm angle delta[A_AXIS] = DEGREES(THETA); // theta is support arm angle
delta[B_AXIS] = DEGREES(THETA + PSI); // equal to sub arm angle (inverted motor) delta[B_AXIS] = DEGREES(THETA + PSI); // equal to sub arm angle (inverted motor)

View File

@ -44,7 +44,7 @@
#define DIGIPOT_A4988_MAX_CURRENT (DIGIPOT_A4988_Itripmax(DIGIPOT_A4988_Vrefmax) - 0.5) #define DIGIPOT_A4988_MAX_CURRENT (DIGIPOT_A4988_Itripmax(DIGIPOT_A4988_Vrefmax) - 0.5)
static byte current_to_wiper(const float current) { static byte current_to_wiper(const float current) {
return byte(ceil(float(DIGIPOT_A4988_FACTOR) * current)); return byte(CEIL(float(DIGIPOT_A4988_FACTOR) * current));
} }
const uint8_t sda_pins[DIGIPOT_I2C_NUM_CHANNELS] = { const uint8_t sda_pins[DIGIPOT_I2C_NUM_CHANNELS] = {

View File

@ -38,7 +38,7 @@
#endif #endif
static byte current_to_wiper(const float current) { static byte current_to_wiper(const float current) {
return byte(ceil(float((DIGIPOT_I2C_FACTOR * current)))); return byte(CEIL(float((DIGIPOT_I2C_FACTOR * current))));
} }
static void i2c_send(const byte addr, const byte a, const byte b) { static void i2c_send(const byte addr, const byte a, const byte b) {

View File

@ -213,7 +213,7 @@ public:
linear_unit_factor = 1.0; linear_unit_factor = 1.0;
break; break;
} }
volumetric_unit_factor = pow(linear_unit_factor, 3.0); volumetric_unit_factor = POW(linear_unit_factor, 3.0);
} }
inline static float axis_unit_factor(const AxisEnum axis) { inline static float axis_unit_factor(const AxisEnum axis) {

View File

@ -59,7 +59,7 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar; lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar;
const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar); const float DD = lsf->x2bar * lsf->y2bar - sq(lsf->xybar);
if (fabs(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy)) if (FABS(DD) <= 1e-10 * (lsf->max_absx + lsf->max_absy))
return 1; return 1;
lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD; lsf->A = (lsf->yzbar * lsf->xybar - lsf->xzbar * lsf->y2bar) / DD;

View File

@ -65,8 +65,8 @@ void inline incremental_WLSF(struct linear_fit_data *lsf, const float &x, const
lsf->xzbar += w * x * z; lsf->xzbar += w * x * z;
lsf->yzbar += w * y * z; lsf->yzbar += w * y * z;
lsf->N += w; lsf->N += w;
lsf->max_absx = max(fabs(w * x), lsf->max_absx); lsf->max_absx = max(FABS(w * x), lsf->max_absx);
lsf->max_absy = max(fabs(w * y), lsf->max_absy); lsf->max_absy = max(FABS(w * y), lsf->max_absy);
} }
void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z) { void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const float &y, const float &z) {
@ -79,8 +79,8 @@ void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const f
lsf->xybar += x * y; lsf->xybar += x * y;
lsf->xzbar += x * z; lsf->xzbar += x * z;
lsf->yzbar += y * z; lsf->yzbar += y * z;
lsf->max_absx = max(fabs(x), lsf->max_absx); lsf->max_absx = max(FABS(x), lsf->max_absx);
lsf->max_absy = max(fabs(y), lsf->max_absy); lsf->max_absy = max(FABS(y), lsf->max_absy);
lsf->N += 1.0; lsf->N += 1.0;
} }

View File

@ -106,7 +106,6 @@
#define RADIANS(d) ((d)*M_PI/180.0) #define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((r)*180.0/M_PI) #define DEGREES(r) ((r)*180.0/M_PI)
#define HYPOT2(x,y) (sq(x)+sq(y)) #define HYPOT2(x,y) (sq(x)+sq(y))
#define HYPOT(x,y) sqrt(HYPOT2(x,y))
#define SIGN(a) ((a>0)-(a<0)) #define SIGN(a) ((a>0)-(a<0))
@ -193,4 +192,17 @@
#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x)) #define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
#define FIXFLOAT(f) (f + 0.00001) #define FIXFLOAT(f) (f + 0.00001)
#endif // __MACROS_H //
// Maths macros that can be overridden by HAL
//
#define ATAN2(y, x) atan2(y, x)
#define FABS(x) fabs(x)
#define POW(x, y) pow(x, y)
#define SQRT(x) sqrt(x)
#define CEIL(x) ceil(x)
#define FLOOR(x) floor(x)
#define LROUND(x) lround(x)
#define FMOD(x, y) fmod(x, y)
#define HYPOT(x,y) SQRT(HYPOT2(x,y))
#endif //__MACROS_H

View File

@ -80,16 +80,16 @@ void Nozzle::zigzag(
for (uint8_t j = 0; j < strokes; j++) { for (uint8_t j = 0; j < strokes; j++) {
for (uint8_t i = 0; i < (objects << 1); i++) { for (uint8_t i = 0; i < (objects << 1); i++) {
float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) ); float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) ); float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
do_blocking_move_to_xy(x, y); do_blocking_move_to_xy(x, y);
if (i == 0) do_blocking_move_to_z(start.z); if (i == 0) do_blocking_move_to_z(start.z);
} }
for (int i = (objects << 1); i > -1; i--) { for (int i = (objects << 1); i > -1; i--) {
float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) ); float const x = start.x + ( nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - fabs(fmod((i*P), (2*P)) - P)) ); float const y = start.y + (!nozzle_clean_horizontal ? i * P : (A/P) * (P - FABS(FMOD((i*P), (2*P)) - P)) );
do_blocking_move_to_xy(x, y); do_blocking_move_to_xy(x, y);
} }

View File

@ -29,8 +29,8 @@
#if ENABLED(NOZZLE_CLEAN_FEATURE) #if ENABLED(NOZZLE_CLEAN_FEATURE)
constexpr float nozzle_clean_start_point[4] = NOZZLE_CLEAN_START_POINT, constexpr float nozzle_clean_start_point[4] = NOZZLE_CLEAN_START_POINT,
nozzle_clean_end_point[4] = NOZZLE_CLEAN_END_POINT, nozzle_clean_end_point[4] = NOZZLE_CLEAN_END_POINT,
nozzle_clean_length = fabs(nozzle_clean_start_point[X_AXIS] - nozzle_clean_end_point[X_AXIS]), //abs x size of wipe pad nozzle_clean_length = FABS(nozzle_clean_start_point[X_AXIS] - nozzle_clean_end_point[X_AXIS]), //abs x size of wipe pad
nozzle_clean_height = fabs(nozzle_clean_start_point[Y_AXIS] - nozzle_clean_end_point[Y_AXIS]); //abs y size of wipe pad nozzle_clean_height = FABS(nozzle_clean_start_point[Y_AXIS] - nozzle_clean_end_point[Y_AXIS]); //abs y size of wipe pad
constexpr bool nozzle_clean_horizontal = nozzle_clean_length >= nozzle_clean_height; //whether to zig-zag horizontally or vertically constexpr bool nozzle_clean_horizontal = nozzle_clean_length >= nozzle_clean_height; //whether to zig-zag horizontally or vertically
#endif // NOZZLE_CLEAN_FEATURE #endif // NOZZLE_CLEAN_FEATURE

View File

@ -178,23 +178,23 @@ void Planner::init() {
* by the provided factors. * by the provided factors.
*/ */
void Planner::calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor) { void Planner::calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor) {
uint32_t initial_rate = ceil(block->nominal_rate * entry_factor), uint32_t initial_rate = CEIL(block->nominal_rate * entry_factor),
final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second) final_rate = CEIL(block->nominal_rate * exit_factor); // (steps per second)
// Limit minimal step rate (Otherwise the timer will overflow.) // Limit minimal step rate (Otherwise the timer will overflow.)
NOLESS(initial_rate, MINIMAL_STEP_RATE); NOLESS(initial_rate, MINIMAL_STEP_RATE);
NOLESS(final_rate, MINIMAL_STEP_RATE); NOLESS(final_rate, MINIMAL_STEP_RATE);
int32_t accel = block->acceleration_steps_per_s2, int32_t accel = block->acceleration_steps_per_s2,
accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)), accelerate_steps = CEIL(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
decelerate_steps = floor(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)), decelerate_steps = FLOOR(estimate_acceleration_distance(block->nominal_rate, final_rate, -accel)),
plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps; plateau_steps = block->step_event_count - accelerate_steps - decelerate_steps;
// Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will // Is the Plateau of Nominal Rate smaller than nothing? That means no cruising, and we will
// have to use intersection_distance() to calculate when to abort accel and start braking // have to use intersection_distance() to calculate when to abort accel and start braking
// in order to reach the final_rate exactly at the end of this block. // in order to reach the final_rate exactly at the end of this block.
if (plateau_steps < 0) { if (plateau_steps < 0) {
accelerate_steps = ceil(intersection_distance(initial_rate, final_rate, accel, block->step_event_count)); accelerate_steps = CEIL(intersection_distance(initial_rate, final_rate, accel, block->step_event_count));
NOLESS(accelerate_steps, 0); // Check limits due to numerical round-off NOLESS(accelerate_steps, 0); // Check limits due to numerical round-off
accelerate_steps = min((uint32_t)accelerate_steps, block->step_event_count);//(We can cast here to unsigned, because the above line ensures that we are above zero) accelerate_steps = min((uint32_t)accelerate_steps, block->step_event_count);//(We can cast here to unsigned, because the above line ensures that we are above zero)
plateau_steps = 0; plateau_steps = 0;
@ -221,8 +221,8 @@ void Planner::calculate_trapezoid_for_block(block_t* const block, const float &e
// This method will calculate the junction jerk as the euclidean distance between the nominal // This method will calculate the junction jerk as the euclidean distance between the nominal
// velocities of the respective blocks. // velocities of the respective blocks.
//inline float junction_jerk(block_t *before, block_t *after) { //inline float junction_jerk(block_t *before, block_t *after) {
// return sqrt( // return SQRT(
// pow((before->speed_x-after->speed_x), 2)+pow((before->speed_y-after->speed_y), 2)); // POW((before->speed_x-after->speed_x), 2)+POW((before->speed_y-after->speed_y), 2));
//} //}
@ -693,22 +693,22 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
// Calculate target position in absolute steps // Calculate target position in absolute steps
//this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow //this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
const long target[XYZE] = { const long target[XYZE] = {
lround(a * axis_steps_per_mm[X_AXIS]), LROUND(a * axis_steps_per_mm[X_AXIS]),
lround(b * axis_steps_per_mm[Y_AXIS]), LROUND(b * axis_steps_per_mm[Y_AXIS]),
lround(c * axis_steps_per_mm[Z_AXIS]), LROUND(c * axis_steps_per_mm[Z_AXIS]),
lround(e * axis_steps_per_mm[E_AXIS_N]) LROUND(e * axis_steps_per_mm[E_AXIS_N])
}; };
// When changing extruders recalculate steps corresponding to the E position // When changing extruders recalculate steps corresponding to the E position
#if ENABLED(DISTINCT_E_FACTORS) #if ENABLED(DISTINCT_E_FACTORS)
if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) { if (last_extruder != extruder && axis_steps_per_mm[E_AXIS_N] != axis_steps_per_mm[E_AXIS + last_extruder]) {
position[E_AXIS] = lround(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]); position[E_AXIS] = LROUND(position[E_AXIS] * axis_steps_per_mm[E_AXIS_N] * steps_to_mm[E_AXIS + last_extruder]);
last_extruder = extruder; last_extruder = extruder;
} }
#endif #endif
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
const float mm_D_float = sqrt(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS])); const float mm_D_float = SQRT(sq(a - position_float[X_AXIS]) + sq(b - position_float[Y_AXIS]));
#endif #endif
const long da = target[X_AXIS] - position[X_AXIS], const long da = target[X_AXIS] - position[X_AXIS],
@ -1036,10 +1036,10 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS_N]; delta_mm[E_AXIS] = esteps_float * steps_to_mm[E_AXIS_N];
if (block->steps[X_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Y_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Z_AXIS] < MIN_STEPS_PER_SEGMENT) { if (block->steps[X_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Y_AXIS] < MIN_STEPS_PER_SEGMENT && block->steps[Z_AXIS] < MIN_STEPS_PER_SEGMENT) {
block->millimeters = fabs(delta_mm[E_AXIS]); block->millimeters = FABS(delta_mm[E_AXIS]);
} }
else { else {
block->millimeters = sqrt( block->millimeters = SQRT(
#if CORE_IS_XY #if CORE_IS_XY
sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS]) sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS])
#elif CORE_IS_XZ #elif CORE_IS_XZ
@ -1061,15 +1061,15 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
// Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill // Slow down when the buffer starts to empty, rather than wait at the corner for a buffer refill
#if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT) #if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
// Segment time im micro seconds // Segment time im micro seconds
unsigned long segment_time = lround(1000000.0 / inverse_mm_s); unsigned long segment_time = LROUND(1000000.0 / inverse_mm_s);
#endif #endif
#if ENABLED(SLOWDOWN) #if ENABLED(SLOWDOWN)
if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) { if (WITHIN(moves_queued, 2, (BLOCK_BUFFER_SIZE) / 2 - 1)) {
if (segment_time < min_segment_time) { 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. // 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)); inverse_mm_s = 1000000.0 / (segment_time + LROUND(2 * (min_segment_time - segment_time) / moves_queued));
#if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD) #if defined(XY_FREQUENCY_LIMIT) || ENABLED(ULTRA_LCD)
segment_time = lround(1000000.0 / inverse_mm_s); segment_time = LROUND(1000000.0 / inverse_mm_s);
#endif #endif
} }
} }
@ -1082,7 +1082,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
#endif #endif
block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0 block->nominal_speed = block->millimeters * inverse_mm_s; // (mm/sec) Always > 0
block->nominal_rate = ceil(block->step_event_count * inverse_mm_s); // (step/sec) Always > 0 block->nominal_rate = CEIL(block->step_event_count * inverse_mm_s); // (step/sec) Always > 0
#if ENABLED(FILAMENT_WIDTH_SENSOR) #if ENABLED(FILAMENT_WIDTH_SENSOR)
static float filwidth_e_count = 0, filwidth_delay_dist = 0; static float filwidth_e_count = 0, filwidth_delay_dist = 0;
@ -1121,7 +1121,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
// Calculate and limit speed in mm/sec for each axis // Calculate and limit speed in mm/sec for each axis
float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
LOOP_XYZE(i) { LOOP_XYZE(i) {
const float cs = fabs(current_speed[i] = delta_mm[i] * inverse_mm_s); const float cs = FABS(current_speed[i] = delta_mm[i] * inverse_mm_s);
#if ENABLED(DISTINCT_E_FACTORS) #if ENABLED(DISTINCT_E_FACTORS)
if (i == E_AXIS) i += extruder; if (i == E_AXIS) i += extruder;
#endif #endif
@ -1134,7 +1134,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
// Check and limit the xy direction change frequency // Check and limit the xy direction change frequency
const unsigned char direction_change = block->direction_bits ^ old_direction_bits; const unsigned char direction_change = block->direction_bits ^ old_direction_bits;
old_direction_bits = block->direction_bits; old_direction_bits = block->direction_bits;
segment_time = lround((float)segment_time / speed_factor); segment_time = LROUND((float)segment_time / speed_factor);
long xs0 = axis_segment_time[X_AXIS][0], long xs0 = axis_segment_time[X_AXIS][0],
xs1 = axis_segment_time[X_AXIS][1], xs1 = axis_segment_time[X_AXIS][1],
@ -1178,7 +1178,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
uint32_t accel; uint32_t accel;
if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) { if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
// convert to: acceleration steps/sec^2 // convert to: acceleration steps/sec^2
accel = ceil(retract_acceleration * steps_per_mm); accel = CEIL(retract_acceleration * steps_per_mm);
} }
else { else {
#define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \ #define LIMIT_ACCEL_LONG(AXIS,INDX) do{ \
@ -1196,7 +1196,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
}while(0) }while(0)
// Start with print or travel acceleration // Start with print or travel acceleration
accel = ceil((esteps ? acceleration : travel_acceleration) * steps_per_mm); accel = CEIL((esteps ? acceleration : travel_acceleration) * steps_per_mm);
#if ENABLED(DISTINCT_E_FACTORS) #if ENABLED(DISTINCT_E_FACTORS)
#define ACCEL_IDX extruder #define ACCEL_IDX extruder
@ -1267,8 +1267,8 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
// Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds. // Skip and avoid divide by zero for straight junctions at 180 degrees. Limit to min() of nominal speeds.
if (cos_theta > -0.95) { if (cos_theta > -0.95) {
// Compute maximum junction velocity based on maximum acceleration and junction deviation // Compute maximum junction velocity based on maximum acceleration and junction deviation
float sin_theta_d2 = sqrt(0.5 * (1.0 - cos_theta)); // Trig half angle identity. Always positive. float sin_theta_d2 = SQRT(0.5 * (1.0 - cos_theta)); // Trig half angle identity. Always positive.
NOMORE(vmax_junction, sqrt(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2))); NOMORE(vmax_junction, SQRT(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)));
} }
} }
} }
@ -1286,7 +1286,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
float safe_speed = block->nominal_speed; float safe_speed = block->nominal_speed;
uint8_t limited = 0; uint8_t limited = 0;
LOOP_XYZE(i) { LOOP_XYZE(i) {
const float jerk = fabs(current_speed[i]), maxj = max_jerk[i]; const float jerk = FABS(current_speed[i]), maxj = max_jerk[i];
if (jerk > maxj) { if (jerk > maxj) {
if (limited) { if (limited) {
const float mjerk = maxj * block->nominal_speed; const float mjerk = maxj * block->nominal_speed;
@ -1395,7 +1395,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
&& (uint32_t)esteps != block->step_event_count && (uint32_t)esteps != block->step_event_count
&& de_float > 0.0; && de_float > 0.0;
if (block->use_advance_lead) if (block->use_advance_lead)
block->abs_adv_steps_multiplier8 = lround( block->abs_adv_steps_multiplier8 = LROUND(
extruder_advance_k extruder_advance_k
* (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set * (UNEAR_ZERO(advance_ed_ratio) ? de_float / mm_D_float : advance_ed_ratio) // Use the fixed ratio, if set
* (block->nominal_speed / (float)block->nominal_rate) * (block->nominal_speed / (float)block->nominal_rate)
@ -1458,10 +1458,10 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
#else #else
#define _EINDEX E_AXIS #define _EINDEX E_AXIS
#endif #endif
long na = position[X_AXIS] = lround(a * axis_steps_per_mm[X_AXIS]), long na = position[X_AXIS] = LROUND(a * axis_steps_per_mm[X_AXIS]),
nb = position[Y_AXIS] = lround(b * axis_steps_per_mm[Y_AXIS]), nb = position[Y_AXIS] = LROUND(b * axis_steps_per_mm[Y_AXIS]),
nc = position[Z_AXIS] = lround(c * axis_steps_per_mm[Z_AXIS]), nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
ne = position[E_AXIS] = lround(e * axis_steps_per_mm[_EINDEX]); ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
position_float[X_AXIS] = a; position_float[X_AXIS] = a;
position_float[Y_AXIS] = b; position_float[Y_AXIS] = b;
@ -1514,7 +1514,7 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
#else #else
const uint8_t axis_index = axis; const uint8_t axis_index = axis;
#endif #endif
position[axis] = lround(v * axis_steps_per_mm[axis_index]); position[axis] = LROUND(v * axis_steps_per_mm[axis_index]);
#if ENABLED(LIN_ADVANCE) #if ENABLED(LIN_ADVANCE)
position_float[axis] = v; position_float[axis] = v;
#endif #endif

View File

@ -454,7 +454,7 @@ class Planner {
* 'distance'. * 'distance'.
*/ */
static float max_allowable_speed(const float &accel, const float &target_velocity, const float &distance) { static float max_allowable_speed(const float &accel, const float &target_velocity, const float &distance) {
return sqrt(sq(target_velocity) - 2 * accel * distance); return SQRT(sq(target_velocity) - 2 * accel * distance);
} }
static void calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor); static void calculate_trapezoid_for_block(block_t* const block, const float &entry_factor, const float &exit_factor);

View File

@ -64,7 +64,7 @@ inline static float eval_bezier(float a, float b, float c, float d, float t) {
* We approximate Euclidean distance with the sum of the coordinates * We approximate Euclidean distance with the sum of the coordinates
* offset (so-called "norm 1"), which is quicker to compute. * offset (so-called "norm 1"), which is quicker to compute.
*/ */
inline static float dist1(float x1, float y1, float x2, float y2) { return fabs(x1 - x2) + fabs(y1 - y2); } inline static float dist1(float x1, float y1, float x2, float y2) { return FABS(x1 - x2) + FABS(y1 - y2); }
/** /**
* The algorithm for computing the step is loosely based on the one in Kig * The algorithm for computing the step is loosely based on the one in Kig

View File

@ -521,7 +521,7 @@ float dnrm2(int n, float x[], int incx)
} }
ix += incx; ix += incx;
} }
norm = scale * sqrt(ssq); norm = scale * SQRT(ssq);
} }
return norm; return norm;
} }
@ -791,12 +791,12 @@ void dqrdc(float a[], int lda, int n, int p, float qraux[], int jpvt[],
daxpy(n - l + 1, t, a + l - 1 + (l - 1)*lda, 1, a + l - 1 + (j - 1)*lda, 1); daxpy(n - l + 1, t, a + l - 1 + (l - 1)*lda, 1, a + l - 1 + (j - 1)*lda, 1);
if (pl <= j && j <= pu) { if (pl <= j && j <= pu) {
if (qraux[j - 1] != 0.0) { if (qraux[j - 1] != 0.0) {
tt = 1.0 - pow(r8_abs(a[l - 1 + (j - 1) * lda]) / qraux[j - 1], 2); tt = 1.0 - POW(r8_abs(a[l - 1 + (j - 1) * lda]) / qraux[j - 1], 2);
tt = r8_max(tt, 0.0); tt = r8_max(tt, 0.0);
t = tt; t = tt;
tt = 1.0 + 0.05 * tt * pow(qraux[j - 1] / work[j - 1], 2); tt = 1.0 + 0.05 * tt * POW(qraux[j - 1] / work[j - 1], 2);
if (tt != 1.0) if (tt != 1.0)
qraux[j - 1] = qraux[j - 1] * sqrt(t); qraux[j - 1] = qraux[j - 1] * SQRT(t);
else { else {
qraux[j - 1] = dnrm2(n - l, a + l + (j - 1) * lda, 1); qraux[j - 1] = dnrm2(n - l, a + l + (j - 1) * lda, 1);
work[j - 1] = qraux[j - 1]; work[j - 1] = qraux[j - 1];

View File

@ -40,7 +40,7 @@
extern const char echomagic[] PROGMEM; extern const char echomagic[] PROGMEM;
extern const char errormagic[] PROGMEM; extern const char errormagic[] PROGMEM;
#define SERIAL_CHAR(x) (MYSERIAL.write(x)) #define SERIAL_CHAR(x) ((void)MYSERIAL.write(x))
#define SERIAL_EOL() SERIAL_CHAR('\n') #define SERIAL_EOL() SERIAL_CHAR('\n')
#define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x) #define SERIAL_PROTOCOLCHAR(x) SERIAL_CHAR(x)

View File

@ -749,7 +749,7 @@ void Temperature::manage_heater() {
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
// Make sure measured temperatures are close together // Make sure measured temperatures are close together
if (fabs(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF) if (FABS(current_temperature[0] - redundant_temperature) > MAX_REDUNDANT_TEMP_SENSOR_DIFF)
_temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP)); _temp_error(0, PSTR(MSG_REDUNDANCY), PSTR(MSG_ERR_REDUNDANT_TEMP));
#endif #endif

View File

@ -498,7 +498,7 @@
if (parser.seen('B')) { if (parser.seen('B')) {
g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness(height); g29_card_thickness = parser.has_value() ? parser.value_float() : measure_business_card_thickness(height);
if (fabs(g29_card_thickness) > 1.5) { if (FABS(g29_card_thickness) > 1.5) {
SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement."); SERIAL_PROTOCOLLNPGM("?Error in Business Card measurement.");
return; return;
} }
@ -562,7 +562,7 @@
// P3.13 1000X distance weighting, approaches simple average of nearest points // P3.13 1000X distance weighting, approaches simple average of nearest points
const float weight_power = (cvf - 3.10) * 100.0, // 3.12345 -> 2.345 const float weight_power = (cvf - 3.10) * 100.0, // 3.12345 -> 2.345
weight_factor = weight_power ? pow(10.0, weight_power) : 0; weight_factor = weight_power ? POW(10.0, weight_power) : 0;
smart_fill_wlsf(weight_factor); smart_fill_wlsf(weight_factor);
} }
break; break;
@ -774,7 +774,7 @@
SERIAL_ECHO_F(mean, 6); SERIAL_ECHO_F(mean, 6);
SERIAL_EOL(); SERIAL_EOL();
const float sigma = sqrt(sum_of_diff_squared / (n + 1)); const float sigma = SQRT(sum_of_diff_squared / (n + 1));
SERIAL_ECHOPGM("Standard Deviation: "); SERIAL_ECHOPGM("Standard Deviation: ");
SERIAL_ECHO_F(sigma, 6); SERIAL_ECHO_F(sigma, 6);
SERIAL_EOL(); SERIAL_EOL();
@ -1508,7 +1508,7 @@
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to where we are going to edit do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); // Move the nozzle to where we are going to edit
do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy)); do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
new_z = floor(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place new_z = FLOOR(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
has_control_of_lcd_panel = true; has_control_of_lcd_panel = true;

View File

@ -492,15 +492,15 @@
#if ENABLED(DELTA) // apply delta inverse_kinematics #if ENABLED(DELTA) // apply delta inverse_kinematics
const float delta_A = rz + sqrt( delta_diagonal_rod_2_tower[A_AXIS] const float delta_A = rz + SQRT( delta_diagonal_rod_2_tower[A_AXIS]
- HYPOT2( delta_tower[A_AXIS][X_AXIS] - rx, - HYPOT2( delta_tower[A_AXIS][X_AXIS] - rx,
delta_tower[A_AXIS][Y_AXIS] - ry )); delta_tower[A_AXIS][Y_AXIS] - ry ));
const float delta_B = rz + sqrt( delta_diagonal_rod_2_tower[B_AXIS] const float delta_B = rz + SQRT( delta_diagonal_rod_2_tower[B_AXIS]
- HYPOT2( delta_tower[B_AXIS][X_AXIS] - rx, - HYPOT2( delta_tower[B_AXIS][X_AXIS] - rx,
delta_tower[B_AXIS][Y_AXIS] - ry )); delta_tower[B_AXIS][Y_AXIS] - ry ));
const float delta_C = rz + sqrt( delta_diagonal_rod_2_tower[C_AXIS] const float delta_C = rz + SQRT( delta_diagonal_rod_2_tower[C_AXIS]
- HYPOT2( delta_tower[C_AXIS][X_AXIS] - rx, - HYPOT2( delta_tower[C_AXIS][X_AXIS] - rx,
delta_tower[C_AXIS][Y_AXIS] - ry )); delta_tower[C_AXIS][Y_AXIS] - ry ));
@ -516,8 +516,8 @@
inverse_kinematics(lseg); // this writes delta[ABC] from lseg[XYZ] inverse_kinematics(lseg); // this writes delta[ABC] from lseg[XYZ]
// should move the feedrate scaling to scara inverse_kinematics // should move the feedrate scaling to scara inverse_kinematics
float adiff = abs(delta[A_AXIS] - scara_oldA), const float adiff = FABS(delta[A_AXIS] - scara_oldA),
bdiff = abs(delta[B_AXIS] - scara_oldB); bdiff = FABS(delta[B_AXIS] - scara_oldB);
scara_oldA = delta[A_AXIS]; scara_oldA = delta[A_AXIS];
scara_oldB = delta[B_AXIS]; scara_oldB = delta[B_AXIS];
float s_feedrate = max(adiff, bdiff) * scara_feed_factor; float s_feedrate = max(adiff, bdiff) * scara_feed_factor;

View File

@ -49,7 +49,7 @@
bool ubl_lcd_map_control = false; bool ubl_lcd_map_control = false;
#endif #endif
int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2]; int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
#if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT) #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
millis_t previous_lcd_status_ms = 0; millis_t previous_lcd_status_ms = 0;
@ -184,7 +184,7 @@ uint16_t max_display_update_time = 0;
void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \ void menu_action_setting_edit_callback_ ## _name(const char * const pstr, _type * const ptr, const _type minValue, const _type maxValue, const screenFunc_t callback, const bool live=false); \
typedef void _name##_void typedef void _name##_void
DECLARE_MENU_EDIT_TYPE(int, int3); DECLARE_MENU_EDIT_TYPE(int16_t, int3);
DECLARE_MENU_EDIT_TYPE(uint8_t, int8); DECLARE_MENU_EDIT_TYPE(uint8_t, int8);
DECLARE_MENU_EDIT_TYPE(float, float3); DECLARE_MENU_EDIT_TYPE(float, float3);
DECLARE_MENU_EDIT_TYPE(float, float32); DECLARE_MENU_EDIT_TYPE(float, float32);
@ -193,7 +193,7 @@ uint16_t max_display_update_time = 0;
DECLARE_MENU_EDIT_TYPE(float, float51); DECLARE_MENU_EDIT_TYPE(float, float51);
DECLARE_MENU_EDIT_TYPE(float, float52); DECLARE_MENU_EDIT_TYPE(float, float52);
DECLARE_MENU_EDIT_TYPE(float, float62); DECLARE_MENU_EDIT_TYPE(float, float62);
DECLARE_MENU_EDIT_TYPE(unsigned long, long5); DECLARE_MENU_EDIT_TYPE(uint32_t, long5);
void menu_action_setting_edit_bool(const char* pstr, bool* ptr); void menu_action_setting_edit_bool(const char* pstr, bool* ptr);
void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc); void menu_action_setting_edit_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
@ -602,7 +602,7 @@ void lcd_status_screen() {
} }
#if ENABLED(ULTIPANEL_FEEDMULTIPLY) #if ENABLED(ULTIPANEL_FEEDMULTIPLY)
const int new_frm = feedrate_percentage + (int32_t)encoderPosition; const int16_t new_frm = feedrate_percentage + (int32_t)encoderPosition;
// Dead zone at 100% feedrate // Dead zone at 100% feedrate
if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) { if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 100)) {
feedrate_percentage = 100; feedrate_percentage = 100;
@ -966,7 +966,7 @@ void kill_screen(const char* lcd_msg) {
if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); } if (lcd_clicked) { defer_return_to_status = false; return lcd_goto_previous_menu(); }
ENCODER_DIRECTION_NORMAL(); ENCODER_DIRECTION_NORMAL();
if (encoderPosition) { if (encoderPosition) {
const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR); const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
encoderPosition = 0; encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_REDRAW_NOW; lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
thermalManager.babystep_axis(axis, babystep_increment); thermalManager.babystep_axis(axis, babystep_increment);
@ -990,7 +990,7 @@ void kill_screen(const char* lcd_msg) {
defer_return_to_status = true; defer_return_to_status = true;
ENCODER_DIRECTION_NORMAL(); ENCODER_DIRECTION_NORMAL();
if (encoderPosition) { if (encoderPosition) {
const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR); const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
encoderPosition = 0; encoderPosition = 0;
const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment; const float new_zoffset = zprobe_zoffset + planner.steps_to_mm[Z_AXIS] * babystep_increment;
@ -1021,7 +1021,7 @@ void kill_screen(const char* lcd_msg) {
float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a float mesh_edit_value, mesh_edit_accumulator; // We round mesh_edit_value to 2.5 decimal places. So we keep a
// separate value that doesn't lose precision. // separate value that doesn't lose precision.
static int ubl_encoderPosition = 0; static int16_t ubl_encoderPosition = 0;
static void _lcd_mesh_fine_tune(const char* msg) { static void _lcd_mesh_fine_tune(const char* msg) {
defer_return_to_status = true; defer_return_to_status = true;
@ -1275,7 +1275,7 @@ void kill_screen(const char* lcd_msg) {
* "Prepare" submenu items * "Prepare" submenu items
* *
*/ */
void _lcd_preheat(const int endnum, const int16_t temph, const int16_t tempb, const int16_t fan) { void _lcd_preheat(const int16_t endnum, const int16_t temph, const int16_t tempb, const int16_t fan) {
if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum); if (temph > 0) thermalManager.setTargetHotend(min(heater_maxtemp[endnum], temph), endnum);
#if TEMP_SENSOR_BED != 0 #if TEMP_SENSOR_BED != 0
if (tempb >= 0) thermalManager.setTargetBed(tempb); if (tempb >= 0) thermalManager.setTargetBed(tempb);
@ -1806,7 +1806,7 @@ void kill_screen(const char* lcd_msg) {
void _lcd_ubl_level_bed(); void _lcd_ubl_level_bed();
static int ubl_storage_slot = 0, static int16_t ubl_storage_slot = 0,
custom_bed_temp = 50, custom_bed_temp = 50,
custom_hotend_temp = 190, custom_hotend_temp = 190,
side_points = 3, side_points = 3,
@ -2624,7 +2624,7 @@ void kill_screen(const char* lcd_msg) {
// This assumes the center is 0,0 // This assumes the center is 0,0
#if ENABLED(DELTA) #if ENABLED(DELTA)
if (axis != Z_AXIS) { if (axis != Z_AXIS) {
max = sqrt(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis])); max = SQRT(sq((float)(DELTA_PRINTABLE_RADIUS)) - sq(current_position[Y_AXIS - axis]));
min = -max; min = -max;
} }
#endif #endif
@ -2872,14 +2872,14 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(PID_AUTOTUNE_MENU) #if ENABLED(PID_AUTOTUNE_MENU)
#if ENABLED(PIDTEMP) #if ENABLED(PIDTEMP)
int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150); int16_t autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
#endif #endif
#if ENABLED(PIDTEMPBED) #if ENABLED(PIDTEMPBED)
int autotune_temp_bed = 70; int16_t autotune_temp_bed = 70;
#endif #endif
void _lcd_autotune(int e) { void _lcd_autotune(int16_t e) {
char cmd[30]; char cmd[30];
sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e, sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
#if HAS_PID_FOR_BOTH #if HAS_PID_FOR_BOTH
@ -2899,14 +2899,14 @@ void kill_screen(const char* lcd_msg) {
// Helpers for editing PID Ki & Kd values // Helpers for editing PID Ki & Kd values
// grab the PID value out of the temp variable; scale it; then update the PID driver // grab the PID value out of the temp variable; scale it; then update the PID driver
void copy_and_scalePID_i(int e) { void copy_and_scalePID_i(int16_t e) {
#if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1 #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
UNUSED(e); UNUSED(e);
#endif #endif
PID_PARAM(Ki, e) = scalePID_i(raw_Ki); PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
thermalManager.updatePID(); thermalManager.updatePID();
} }
void copy_and_scalePID_d(int e) { void copy_and_scalePID_d(int16_t e) {
#if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1 #if DISABLED(PID_PARAMS_PER_HOTEND) || HOTENDS == 1
UNUSED(e); UNUSED(e);
#endif #endif
@ -3475,7 +3475,7 @@ void kill_screen(const char* lcd_msg) {
STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time: STATIC_ITEM(MSG_INFO_PRINT_LONGEST ": ", false, false); // Longest job time:
STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s STATIC_ITEM("", false, false, buffer); // 99y 364d 23h 59m 59s
sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int(stats.filamentUsed / 100) % 10); sprintf_P(buffer, PSTR("%ld.%im"), long(stats.filamentUsed / 1000), int16_t(stats.filamentUsed / 100) % 10);
STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total: STATIC_ITEM(MSG_INFO_PRINT_FILAMENT ": ", false, false); // Extruded total:
STATIC_ITEM("", false, false, buffer); // 125m STATIC_ITEM("", false, false, buffer); // 125m
END_SCREEN(); END_SCREEN();
@ -3878,14 +3878,14 @@ void kill_screen(const char* lcd_msg) {
* *
* The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value. * The "DEFINE_MENU_EDIT_TYPE" macro generates the functions needed to edit a numerical value.
* *
* For example, DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1) expands into these functions: * For example, DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1) expands into these functions:
* *
* bool _menu_edit_int3(); * bool _menu_edit_int3();
* void menu_edit_int3(); // edit int (interactively) * void menu_edit_int3(); // edit int16_t (interactively)
* void menu_edit_callback_int3(); // edit int (interactively) with callback on completion * void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
* void _menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue); * void _menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
* void menu_action_setting_edit_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue); * void menu_action_setting_edit_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
* void menu_action_setting_edit_callback_int3(const char * const pstr, int * const ptr, const int minValue, const int maxValue, const screenFunc_t callback, const bool live); // edit int with callback * void menu_action_setting_edit_callback_int3(const char * const pstr, int16_t * const ptr, const int16_t minValue, const int16_t maxValue, const screenFunc_t callback, const bool live); // edit int16_t with callback
* *
* You can then use one of the menu macros to present the edit interface: * You can then use one of the menu macros to present the edit interface:
* MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999) * MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
@ -3936,7 +3936,7 @@ void kill_screen(const char* lcd_msg) {
} \ } \
typedef void _name typedef void _name
DEFINE_MENU_EDIT_TYPE(int, int3, itostr3, 1); DEFINE_MENU_EDIT_TYPE(int16_t, int3, itostr3, 1);
DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1); DEFINE_MENU_EDIT_TYPE(uint8_t, int8, i8tostr3, 1);
DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0); DEFINE_MENU_EDIT_TYPE(float, float3, ftostr3, 1.0);
DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0); DEFINE_MENU_EDIT_TYPE(float, float32, ftostr32, 100.0);
@ -3945,7 +3945,7 @@ void kill_screen(const char* lcd_msg) {
DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0); DEFINE_MENU_EDIT_TYPE(float, float51, ftostr51sign, 10.0);
DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0); DEFINE_MENU_EDIT_TYPE(float, float52, ftostr52sign, 100.0);
DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0); DEFINE_MENU_EDIT_TYPE(float, float62, ftostr62rj, 100.0);
DEFINE_MENU_EDIT_TYPE(unsigned long, long5, ftostr5rj, 0.01); DEFINE_MENU_EDIT_TYPE(uint32_t, long5, ftostr5rj, 0.01);
/** /**
* *
@ -3953,7 +3953,7 @@ void kill_screen(const char* lcd_msg) {
* *
*/ */
#if ENABLED(REPRAPWORLD_KEYPAD) #if ENABLED(REPRAPWORLD_KEYPAD)
void _reprapworld_keypad_move(AxisEnum axis, int dir) { void _reprapworld_keypad_move(AxisEnum axis, int16_t dir) {
move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP; move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
encoderPosition = dir; encoderPosition = dir;
switch (axis) { switch (axis) {
@ -4112,8 +4112,8 @@ void lcd_init() {
#endif #endif
} }
int lcd_strlen(const char* s) { int16_t lcd_strlen(const char* s) {
int i = 0, j = 0; int16_t i = 0, j = 0;
while (s[i]) { while (s[i]) {
if (PRINTABLE(s[i])) j++; if (PRINTABLE(s[i])) j++;
i++; i++;
@ -4121,8 +4121,8 @@ int lcd_strlen(const char* s) {
return j; return j;
} }
int lcd_strlen_P(const char* s) { int16_t lcd_strlen_P(const char* s) {
int j = 0; int16_t j = 0;
while (pgm_read_byte(s)) { while (pgm_read_byte(s)) {
if (PRINTABLE(pgm_read_byte(s))) j++; if (PRINTABLE(pgm_read_byte(s))) j++;
s++; s++;

View File

@ -30,10 +30,10 @@
#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0) #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
#define BUTTON_PRESSED(BN) !READ(BTN_## BN) #define BUTTON_PRESSED(BN) !READ(BTN_## BN)
extern int lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2]; extern int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2];
int lcd_strlen(const char* s); int16_t lcd_strlen(const char* s);
int lcd_strlen_P(const char* s); int16_t lcd_strlen_P(const char* s);
void lcd_update(); void lcd_update();
void lcd_init(); void lcd_init();
bool lcd_hasstatus(); bool lcd_hasstatus();

View File

@ -346,7 +346,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
// Status Screen // Status Screen
// //
FORCE_INLINE void _draw_centered_temp(const int temp, const uint8_t x, const uint8_t y) { FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t x, const uint8_t y) {
const uint8_t degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width const uint8_t degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width
u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
lcd_print(itostr3(temp)); lcd_print(itostr3(temp));
@ -484,7 +484,7 @@ static void lcd_implementation_status_screen() {
#if HAS_FAN0 #if HAS_FAN0
if (PAGE_CONTAINS(20, 27)) { if (PAGE_CONTAINS(20, 27)) {
// Fan // Fan
const int per = ((fanSpeeds[0] + 1) * 100) / 256; const int16_t per = ((fanSpeeds[0] + 1) * 100) / 256;
if (per) { if (per) {
u8g.setPrintPos(104, 27); u8g.setPrintPos(104, 27);
lcd_print(itostr3(per)); lcd_print(itostr3(per));
@ -533,7 +533,7 @@ static void lcd_implementation_status_screen() {
if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION))) // 50-51 (or just 50) if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION))) // 50-51 (or just 50)
u8g.drawBox( u8g.drawBox(
PROGRESS_BAR_X + 1, 50, PROGRESS_BAR_X + 1, 50,
(unsigned int)((PROGRESS_BAR_WIDTH - 2) * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION) (uint16_t)((PROGRESS_BAR_WIDTH - 2) * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION)
); );
// //
@ -847,7 +847,7 @@ static void lcd_implementation_status_screen() {
} \ } \
typedef void _name##_void typedef void _name##_void
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
@ -856,7 +856,7 @@ static void lcd_implementation_status_screen() {
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(unsigned long, long5, ftostr5rj); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
#define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
#define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))

View File

@ -337,7 +337,7 @@ static void lcd_set_custom_characters(
if (info_screen_charset != char_mode) { if (info_screen_charset != char_mode) {
char_mode = info_screen_charset; char_mode = info_screen_charset;
if (info_screen_charset) { // Progress bar characters for info screen if (info_screen_charset) { // Progress bar characters for info screen
for (int i = 3; i--;) createChar_P(LCD_STR_PROGRESS[i], progress[i]); for (int16_t i = 3; i--;) createChar_P(LCD_STR_PROGRESS[i], progress[i]);
} }
else { // Custom characters for submenus else { // Custom characters for submenus
createChar_P(LCD_UPLEVEL_CHAR, uplevel); createChar_P(LCD_UPLEVEL_CHAR, uplevel);
@ -414,17 +414,17 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
#if ENABLED(SHOW_BOOTSCREEN) #if ENABLED(SHOW_BOOTSCREEN)
void lcd_erase_line(const int line) { void lcd_erase_line(const int16_t line) {
lcd.setCursor(0, line); lcd.setCursor(0, line);
for (uint8_t i = LCD_WIDTH + 1; --i;) for (uint8_t i = LCD_WIDTH + 1; --i;)
lcd.print(' '); lcd.print(' ');
} }
// Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line // Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
void lcd_scroll(const int col, const int line, const char* const text, const int len, const int time) { void lcd_scroll(const int16_t col, const int16_t line, const char* const text, const int16_t len, const int16_t time) {
char tmp[LCD_WIDTH + 1] = {0}; char tmp[LCD_WIDTH + 1] = {0};
int n = max(lcd_strlen_P(text) - len, 0); int16_t n = max(lcd_strlen_P(text) - len, 0);
for (int i = 0; i <= n; i++) { for (int16_t i = 0; i <= n; i++) {
strncpy_P(tmp, text + i, min(len, LCD_WIDTH)); strncpy_P(tmp, text + i, min(len, LCD_WIDTH));
lcd.setCursor(col, line); lcd.setCursor(col, line);
lcd_print(tmp); lcd_print(tmp);
@ -433,7 +433,7 @@ void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
} }
static void logo_lines(const char* const extra) { static void logo_lines(const char* const extra) {
int indent = (LCD_WIDTH - 8 - lcd_strlen_P(extra)) / 2; int16_t indent = (LCD_WIDTH - 8 - lcd_strlen_P(extra)) / 2;
lcd.setCursor(indent, 0); lcd.print('\x00'); lcd_printPGM(PSTR( "------" )); lcd.print('\x01'); lcd.setCursor(indent, 0); lcd.print('\x00'); lcd_printPGM(PSTR( "------" )); lcd.print('\x01');
lcd.setCursor(indent, 1); lcd_printPGM(PSTR("|Marlin|")); lcd_printPGM(extra); lcd.setCursor(indent, 1); lcd_printPGM(PSTR("|Marlin|")); lcd_printPGM(extra);
lcd.setCursor(indent, 2); lcd.print('\x02'); lcd_printPGM(PSTR( "------" )); lcd.print('\x03'); lcd.setCursor(indent, 2); lcd.print('\x02'); lcd_printPGM(PSTR( "------" )); lcd.print('\x03');
@ -628,7 +628,7 @@ FORCE_INLINE void _draw_heater_status(const int8_t heater, const char prefix, co
#if ENABLED(LCD_PROGRESS_BAR) #if ENABLED(LCD_PROGRESS_BAR)
inline void lcd_draw_progress_bar(const uint8_t percent) { inline void lcd_draw_progress_bar(const uint8_t percent) {
const int tix = (int)(percent * (LCD_WIDTH) * 3) / 100, const int16_t tix = (int16_t)(percent * (LCD_WIDTH) * 3) / 100,
cel = tix / 3, cel = tix / 3,
rem = tix % 3; rem = tix % 3;
uint8_t i = LCD_WIDTH; uint8_t i = LCD_WIDTH;
@ -958,7 +958,7 @@ static void lcd_implementation_status_screen() {
} \ } \
typedef void _name##_void typedef void _name##_void
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int16_t, int3, itostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint8_t, int8, i8tostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
@ -967,7 +967,7 @@ static void lcd_implementation_status_screen() {
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(unsigned long, long5, ftostr5rj); DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(uint32_t, long5, ftostr5rj);
#define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
#define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF)) #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, '>', (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))

View File

@ -63,7 +63,7 @@ vector_3 vector_3::get_normal() {
return normalized; return normalized;
} }
float vector_3::get_length() { return sqrt(sq(x) + sq(y) + sq(z)); } float vector_3::get_length() { return SQRT(sq(x) + sq(y) + sq(z)); }
void vector_3::normalize() { void vector_3::normalize() {
const float inv_length = 1.0 / get_length(); const float inv_length = 1.0 / get_length();