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,
// 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);
}

View file

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

View file

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

View file

@ -210,7 +210,7 @@ inline void refresh_cmd_timeout() { previous_cmd_ms = millis(); }
/**
* Feedrate scaling and conversion
*/
extern int feedrate_percentage;
extern int16_t feedrate_percentage;
#define MMM_TO_MMS(MM_M) ((MM_M)/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 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 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];

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);
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);
bool axis_relative_modes[] = AXIS_RELATIVE_MODES,
@ -2968,7 +2968,7 @@ static void homeaxis(const AxisEnum axis) {
#if ENABLED(Z_DUAL_ENDSTOPS)
if (axis == Z_AXIS) {
float adj = fabs(z_endstop_adj);
float adj = FABS(z_endstop_adj);
bool lockZ1;
if (axis_home_dir > 0) {
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
dx = x2 - x1, dy = y2 - y1, // X and Y differences
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
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
@ -3448,7 +3448,7 @@ inline void gcode_G4() {
const float mlx = max_length(X_AXIS),
mly = max_length(Y_AXIS),
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);
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,
yBase = yCount * yGridSpacing + front_probe_bed_position;
xProbe = floor(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5));
xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
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,
yBase = front_probe_bed_position + yGridSpacing * yCount;
xProbe = floor(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = floor(yBase + (yBase < 0 ? 0 : 0.5));
xProbe = FLOOR(xBase + (xBase < 0 ? 0 : 0.5));
yProbe = FLOOR(yBase + (yBase < 0 ? 0 : 0.5));
#if ENABLED(AUTO_BED_LEVELING_LINEAR)
indexIntoAB[xCount][yCount] = ++abl_probe_index; // 0...
@ -5263,7 +5263,7 @@ void home_all_axes() { gcode_G28(true); }
N++;
}
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
@ -5464,7 +5464,7 @@ void home_all_axes() { gcode_G28(true); }
float retract_mm[XYZ];
LOOP_XYZ(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
@ -5528,7 +5528,7 @@ void home_all_axes() { gcode_G28(true); }
// If any axis has enough movement, do the move
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 G38.2 fails throw an error
if (!G38_run_probe() && is_38_2) {
@ -6851,7 +6851,7 @@ inline void gcode_M42() {
for (uint8_t j = 0; j <= n; j++)
sum += sq(sample_set[j] - mean);
sigma = sqrt(sum / (n + 1));
sigma = SQRT(sum / (n + 1));
if (verbose_level > 0) {
if (verbose_level > 1) {
SERIAL_PROTOCOL(n + 1);
@ -7266,7 +7266,7 @@ inline void gcode_M109() {
#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) {
// 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
const float temp_diff = fabs(target_temp - temp);
const float temp_diff = FABS(target_temp - temp);
if (!residency_start_ms) {
// 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 (!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
UNUSED(no_babystep);
#endif
@ -11171,7 +11171,7 @@ void ok_to_send() {
if (last_x != x) {
last_x = x;
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
#if DISABLED(EXTRAPOLATE_BEYOND_GRID)
@ -11188,7 +11188,7 @@ void ok_to_send() {
if (last_y != y) {
last_y = y;
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;
#if DISABLED(EXTRAPOLATE_BEYOND_GRID)
@ -11221,7 +11221,7 @@ void ok_to_send() {
/*
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_ECHOPAIR("x=", x);
SERIAL_ECHOPAIR(" / ", bilinear_grid_spacing[X_AXIS]);
@ -11290,7 +11290,7 @@ void ok_to_send() {
#else
#define _SQRT(n) sqrt(n)
#define _SQRT(n) SQRT(n)
#endif
@ -11364,7 +11364,7 @@ void ok_to_send() {
float distance = delta[A_AXIS];
cartesian[Y_AXIS] = LOGICAL_Y_POSITION(DELTA_PRINTABLE_RADIUS);
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 };
// 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.
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] };
// 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
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
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,
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
// 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
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 (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.
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];
// 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 (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])
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;
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;
/**
@ -12155,7 +12155,7 @@ void prepare_move_to_destination() {
else
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
SK1 = L1 + L2 * C2;
@ -12164,10 +12164,10 @@ void prepare_move_to_destination() {
SK2 = L2 * S2;
// 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
PSI = atan2(S2, C2);
PSI = ATAN2(S2, C2);
delta[A_AXIS] = DEGREES(THETA); // theta is support arm angle
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)
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] = {

View file

@ -38,7 +38,7 @@
#endif
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) {

View file

@ -213,7 +213,7 @@ public:
linear_unit_factor = 1.0;
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) {

View file

@ -59,7 +59,7 @@ int finish_incremental_LSF(struct linear_fit_data *lsf) {
lsf->xzbar = lsf->xzbar / N - lsf->xbar * lsf->zbar;
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;
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->yzbar += w * y * z;
lsf->N += w;
lsf->max_absx = max(fabs(w * x), lsf->max_absx);
lsf->max_absy = max(fabs(w * y), lsf->max_absy);
lsf->max_absx = max(FABS(w * x), lsf->max_absx);
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) {
@ -79,8 +79,8 @@ void inline incremental_LSF(struct linear_fit_data *lsf, const float &x, const f
lsf->xybar += x * y;
lsf->xzbar += x * z;
lsf->yzbar += y * z;
lsf->max_absx = max(fabs(x), lsf->max_absx);
lsf->max_absy = max(fabs(y), lsf->max_absy);
lsf->max_absx = max(FABS(x), lsf->max_absx);
lsf->max_absy = max(FABS(y), lsf->max_absy);
lsf->N += 1.0;
}

View file

@ -106,7 +106,6 @@
#define RADIANS(d) ((d)*M_PI/180.0)
#define DEGREES(r) ((r)*180.0/M_PI)
#define HYPOT2(x,y) (sq(x)+sq(y))
#define HYPOT(x,y) sqrt(HYPOT2(x,y))
#define SIGN(a) ((a>0)-(a<0))
@ -193,4 +192,17 @@
#define RECIPROCAL(x) (NEAR_ZERO(x) ? 0.0 : 1.0 / (x))
#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 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 y = start.y + (!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)) );
do_blocking_move_to_xy(x, y);
if (i == 0) do_blocking_move_to_z(start.z);
}
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 y = start.y + (!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)) );
do_blocking_move_to_xy(x, y);
}

View file

@ -29,8 +29,8 @@
#if ENABLED(NOZZLE_CLEAN_FEATURE)
constexpr float nozzle_clean_start_point[4] = NOZZLE_CLEAN_START_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_height = fabs(nozzle_clean_start_point[Y_AXIS] - nozzle_clean_end_point[Y_AXIS]); //abs y 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
constexpr bool nozzle_clean_horizontal = nozzle_clean_length >= nozzle_clean_height; //whether to zig-zag horizontally or vertically
#endif // NOZZLE_CLEAN_FEATURE

View file

@ -178,23 +178,23 @@ void Planner::init() {
* by the provided factors.
*/
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),
final_rate = ceil(block->nominal_rate * exit_factor); // (steps per second)
uint32_t initial_rate = CEIL(block->nominal_rate * entry_factor),
final_rate = CEIL(block->nominal_rate * exit_factor); // (steps per second)
// Limit minimal step rate (Otherwise the timer will overflow.)
NOLESS(initial_rate, MINIMAL_STEP_RATE);
NOLESS(final_rate, MINIMAL_STEP_RATE);
int32_t accel = block->acceleration_steps_per_s2,
accelerate_steps = ceil(estimate_acceleration_distance(initial_rate, block->nominal_rate, accel)),
decelerate_steps = floor(estimate_acceleration_distance(block->nominal_rate, final_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)),
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
// 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.
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
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;
@ -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
// velocities of the respective blocks.
//inline float junction_jerk(block_t *before, block_t *after) {
// return sqrt(
// pow((before->speed_x-after->speed_x), 2)+pow((before->speed_y-after->speed_y), 2));
// return SQRT(
// 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
//this should be done after the wait, because otherwise a M92 code within the gcode disrupts this calculation somehow
const long target[XYZE] = {
lround(a * axis_steps_per_mm[X_AXIS]),
lround(b * axis_steps_per_mm[Y_AXIS]),
lround(c * axis_steps_per_mm[Z_AXIS]),
lround(e * axis_steps_per_mm[E_AXIS_N])
LROUND(a * axis_steps_per_mm[X_AXIS]),
LROUND(b * axis_steps_per_mm[Y_AXIS]),
LROUND(c * axis_steps_per_mm[Z_AXIS]),
LROUND(e * axis_steps_per_mm[E_AXIS_N])
};
// When changing extruders recalculate steps corresponding to the E position
#if ENABLED(DISTINCT_E_FACTORS)
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;
}
#endif
#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
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];
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 {
block->millimeters = sqrt(
block->millimeters = SQRT(
#if CORE_IS_XY
sq(delta_mm[X_HEAD]) + sq(delta_mm[Y_HEAD]) + sq(delta_mm[Z_AXIS])
#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
#if ENABLED(SLOWDOWN) || ENABLED(ULTRA_LCD) || defined(XY_FREQUENCY_LIMIT)
// 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
#if ENABLED(SLOWDOWN)
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));
inverse_mm_s = 1000000.0 / (segment_time + LROUND(2 * (min_segment_time - segment_time) / moves_queued));
#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
}
}
@ -1082,7 +1082,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
#endif
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)
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
float current_speed[NUM_AXIS], speed_factor = 1.0; // factor <1 decreases speed
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 (i == E_AXIS) i += extruder;
#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
const unsigned char direction_change = block->direction_bits ^ old_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],
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;
if (!block->steps[X_AXIS] && !block->steps[Y_AXIS] && !block->steps[Z_AXIS]) {
// convert to: acceleration steps/sec^2
accel = ceil(retract_acceleration * steps_per_mm);
accel = CEIL(retract_acceleration * steps_per_mm);
}
else {
#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)
// 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)
#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.
if (cos_theta > -0.95) {
// 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.
NOMORE(vmax_junction, sqrt(block->acceleration * junction_deviation * sin_theta_d2 / (1.0 - sin_theta_d2)));
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)));
}
}
}
@ -1286,7 +1286,7 @@ void Planner::_buffer_line(const float &a, const float &b, const float &c, const
float safe_speed = block->nominal_speed;
uint8_t limited = 0;
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 (limited) {
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
&& de_float > 0.0;
if (block->use_advance_lead)
block->abs_adv_steps_multiplier8 = lround(
block->abs_adv_steps_multiplier8 = LROUND(
extruder_advance_k
* (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)
@ -1458,10 +1458,10 @@ void Planner::_set_position_mm(const float &a, const float &b, const float &c, c
#else
#define _EINDEX E_AXIS
#endif
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]),
nc = position[Z_AXIS] = lround(c * axis_steps_per_mm[Z_AXIS]),
ne = position[E_AXIS] = lround(e * axis_steps_per_mm[_EINDEX]);
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]),
nc = position[Z_AXIS] = LROUND(c * axis_steps_per_mm[Z_AXIS]),
ne = position[E_AXIS] = LROUND(e * axis_steps_per_mm[_EINDEX]);
#if ENABLED(LIN_ADVANCE)
position_float[X_AXIS] = a;
position_float[Y_AXIS] = b;
@ -1514,7 +1514,7 @@ void Planner::set_position_mm(const AxisEnum axis, const float &v) {
#else
const uint8_t axis_index = axis;
#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)
position_float[axis] = v;
#endif

View file

@ -454,7 +454,7 @@ class Planner {
* '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);

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
* 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

View file

@ -521,7 +521,7 @@ float dnrm2(int n, float x[], int incx)
}
ix += incx;
}
norm = scale * sqrt(ssq);
norm = scale * SQRT(ssq);
}
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);
if (pl <= j && j <= pu) {
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);
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)
qraux[j - 1] = qraux[j - 1] * sqrt(t);
qraux[j - 1] = qraux[j - 1] * SQRT(t);
else {
qraux[j - 1] = dnrm2(n - l, a + l + (j - 1) * lda, 1);
work[j - 1] = qraux[j - 1];

View file

@ -40,7 +40,7 @@
extern const char echomagic[] 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_PROTOCOLCHAR(x) SERIAL_CHAR(x)

View file

@ -749,7 +749,7 @@ void Temperature::manage_heater() {
#if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT)
// 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));
#endif

View file

@ -498,7 +498,7 @@
if (parser.seen('B')) {
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.");
return;
}
@ -562,7 +562,7 @@
// P3.13 1000X distance weighting, approaches simple average of nearest points
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);
}
break;
@ -774,7 +774,7 @@
SERIAL_ECHO_F(mean, 6);
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_ECHO_F(sigma, 6);
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_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);
has_control_of_lcd_panel = true;

View file

@ -492,15 +492,15 @@
#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,
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,
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,
delta_tower[C_AXIS][Y_AXIS] - ry ));
@ -516,8 +516,8 @@
inverse_kinematics(lseg); // this writes delta[ABC] from lseg[XYZ]
// should move the feedrate scaling to scara inverse_kinematics
float adiff = abs(delta[A_AXIS] - scara_oldA),
bdiff = abs(delta[B_AXIS] - scara_oldB);
const float adiff = FABS(delta[A_AXIS] - scara_oldA),
bdiff = FABS(delta[B_AXIS] - scara_oldB);
scara_oldA = delta[A_AXIS];
scara_oldB = delta[B_AXIS];
float s_feedrate = max(adiff, bdiff) * scara_feed_factor;

View file

@ -49,7 +49,7 @@
bool ubl_lcd_map_control = false;
#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)
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); \
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(float, float3);
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, float52);
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_callback_bool(const char* pstr, bool* ptr, screenFunc_t callbackFunc);
@ -602,7 +602,7 @@ void lcd_status_screen() {
}
#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
if ((feedrate_percentage < 100 && new_frm > 100) || (feedrate_percentage > 100 && new_frm < 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(); }
ENCODER_DIRECTION_NORMAL();
if (encoderPosition) {
const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
encoderPosition = 0;
lcdDrawUpdate = LCDVIEW_REDRAW_NOW;
thermalManager.babystep_axis(axis, babystep_increment);
@ -990,7 +990,7 @@ void kill_screen(const char* lcd_msg) {
defer_return_to_status = true;
ENCODER_DIRECTION_NORMAL();
if (encoderPosition) {
const int babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
const int16_t babystep_increment = (int32_t)encoderPosition * (BABYSTEP_MULTIPLICATOR);
encoderPosition = 0;
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
// 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) {
defer_return_to_status = true;
@ -1275,7 +1275,7 @@ void kill_screen(const char* lcd_msg) {
* "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 TEMP_SENSOR_BED != 0
if (tempb >= 0) thermalManager.setTargetBed(tempb);
@ -1806,7 +1806,7 @@ void kill_screen(const char* lcd_msg) {
void _lcd_ubl_level_bed();
static int ubl_storage_slot = 0,
static int16_t ubl_storage_slot = 0,
custom_bed_temp = 50,
custom_hotend_temp = 190,
side_points = 3,
@ -2624,7 +2624,7 @@ void kill_screen(const char* lcd_msg) {
// This assumes the center is 0,0
#if ENABLED(DELTA)
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;
}
#endif
@ -2872,14 +2872,14 @@ void kill_screen(const char* lcd_msg) {
#if ENABLED(PID_AUTOTUNE_MENU)
#if ENABLED(PIDTEMP)
int autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
int16_t autotune_temp[HOTENDS] = ARRAY_BY_HOTENDS1(150);
#endif
#if ENABLED(PIDTEMPBED)
int autotune_temp_bed = 70;
int16_t autotune_temp_bed = 70;
#endif
void _lcd_autotune(int e) {
void _lcd_autotune(int16_t e) {
char cmd[30];
sprintf_P(cmd, PSTR("M303 U1 E%i S%i"), e,
#if HAS_PID_FOR_BOTH
@ -2899,14 +2899,14 @@ void kill_screen(const char* lcd_msg) {
// Helpers for editing PID Ki & Kd values
// 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
UNUSED(e);
#endif
PID_PARAM(Ki, e) = scalePID_i(raw_Ki);
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
UNUSED(e);
#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("", 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("", false, false, buffer); // 125m
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.
*
* 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();
* void menu_edit_int3(); // edit int (interactively)
* void menu_edit_callback_int3(); // edit int (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, int * const ptr, const int minValue, const int 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_edit_int3(); // edit int16_t (interactively)
* void menu_edit_callback_int3(); // edit int16_t (interactively) with callback on completion
* 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, int16_t * const ptr, const int16_t minValue, const int16_t maxValue);
* 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:
* MENU_ITEM_EDIT(int3, MSG_SPEED, &feedrate_percentage, 10, 999)
@ -3936,7 +3936,7 @@ void kill_screen(const char* lcd_msg) {
} \
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(float, float3, ftostr3, 1.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, float52, ftostr52sign, 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)
void _reprapworld_keypad_move(AxisEnum axis, int dir) {
void _reprapworld_keypad_move(AxisEnum axis, int16_t dir) {
move_menu_scale = REPRAPWORLD_KEYPAD_MOVE_STEP;
encoderPosition = dir;
switch (axis) {
@ -4112,8 +4112,8 @@ void lcd_init() {
#endif
}
int lcd_strlen(const char* s) {
int i = 0, j = 0;
int16_t lcd_strlen(const char* s) {
int16_t i = 0, j = 0;
while (s[i]) {
if (PRINTABLE(s[i])) j++;
i++;
@ -4121,8 +4121,8 @@ int lcd_strlen(const char* s) {
return j;
}
int lcd_strlen_P(const char* s) {
int j = 0;
int16_t lcd_strlen_P(const char* s) {
int16_t j = 0;
while (pgm_read_byte(s)) {
if (PRINTABLE(pgm_read_byte(s))) j++;
s++;

View file

@ -30,10 +30,10 @@
#define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0)
#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);
int lcd_strlen_P(const char* s);
int16_t lcd_strlen(const char* s);
int16_t lcd_strlen_P(const char* s);
void lcd_update();
void lcd_init();
bool lcd_hasstatus();

View file

@ -346,7 +346,7 @@ void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
// 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
u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
lcd_print(itostr3(temp));
@ -484,7 +484,7 @@ static void lcd_implementation_status_screen() {
#if HAS_FAN0
if (PAGE_CONTAINS(20, 27)) {
// Fan
const int per = ((fanSpeeds[0] + 1) * 100) / 256;
const int16_t per = ((fanSpeeds[0] + 1) * 100) / 256;
if (per) {
u8g.setPrintPos(104, 27);
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)
u8g.drawBox(
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
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(float, float3, ftostr3);
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, float52, ftostr52sign);
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_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) {
char_mode = info_screen_charset;
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
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)
void lcd_erase_line(const int line) {
void lcd_erase_line(const int16_t line) {
lcd.setCursor(0, line);
for (uint8_t i = LCD_WIDTH + 1; --i;)
lcd.print(' ');
}
// 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};
int n = max(lcd_strlen_P(text) - len, 0);
for (int i = 0; i <= n; i++) {
int16_t n = max(lcd_strlen_P(text) - len, 0);
for (int16_t i = 0; i <= n; i++) {
strncpy_P(tmp, text + i, min(len, LCD_WIDTH));
lcd.setCursor(col, line);
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) {
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, 1); lcd_printPGM(PSTR("|Marlin|")); lcd_printPGM(extra);
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)
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,
rem = tix % 3;
uint8_t i = LCD_WIDTH;
@ -958,7 +958,7 @@ static void lcd_implementation_status_screen() {
} \
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(float, float3, ftostr3);
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, float52, ftostr52sign);
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_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;
}
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() {
const float inv_length = 1.0 / get_length();