Fix code attempting to sprintf %f (#14869)
Arduino doesn't (always) support `float` formatting in strings. So either cast to `int` or use `dtostrf()` to fix these usages.
This commit is contained in:
@ -252,8 +252,7 @@ void GcodeSuite::M48() {
|
||||
#if HAS_SPI_LCD
|
||||
// Display M48 results in the status bar
|
||||
char sigma_str[8];
|
||||
dtostrf(sigma, 2, 6, sigma_str);
|
||||
ui.status_printf_P(0, PSTR(MSG_M48_DEVIATION ": %s"), sigma_str);
|
||||
ui.status_printf_P(0, PSTR(MSG_M48_DEVIATION ": %s"), dtostrf(sigma, 2, 6, sigma_str));
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -101,8 +101,12 @@ void L6470_report_current(L6470 &motor, const uint8_t axis) {
|
||||
#endif
|
||||
sprintf_P(temp_buf, PSTR("\n...OverCurrent Threshold: %2d (%4d mA)"), overcurrent_threshold, (overcurrent_threshold + 1) * 375);
|
||||
SERIAL_ECHO(temp_buf);
|
||||
sprintf_P(temp_buf, PSTR(" Stall Threshold: %2d (%7.2f mA)"), stall_threshold, (stall_threshold + 1) * 31.25);
|
||||
|
||||
char numstr[11];
|
||||
dtostrf((stall_threshold + 1) * 31.25, 1, 2, numstr);
|
||||
sprintf_P(temp_buf, PSTR(" Stall Threshold: %2d (%s mA)"), stall_threshold, numstr);
|
||||
SERIAL_ECHO(temp_buf);
|
||||
|
||||
SERIAL_ECHOPGM(" Motor Status: ");
|
||||
const char * const stat_str;
|
||||
switch (motor_status) {
|
||||
@ -114,24 +118,42 @@ void L6470_report_current(L6470 &motor, const uint8_t axis) {
|
||||
}
|
||||
serialprintPGM(stat_str);
|
||||
SERIAL_EOL();
|
||||
|
||||
SERIAL_ECHOPAIR("...microsteps: ", microsteps);
|
||||
SERIAL_ECHOPAIR(" ADC_OUT: ", adc_out);
|
||||
SERIAL_ECHOPGM(" Vs_compensation: ");
|
||||
serialprintPGM((motor.GetParam(L6470_CONFIG) & CONFIG_EN_VSCOMP) ? PSTR("ENABLED ") : PSTR("DISABLED"));
|
||||
sprintf_P(temp_buf, PSTR(" Compensation coefficient: ~%4.2f\n"), comp_coef * 0.01f);
|
||||
SERIAL_ECHO(temp_buf);
|
||||
|
||||
SERIAL_ECHOLNPGM(" Compensation coefficient: ", dtostrf(comp_coef * 0.01f, 7, 2, numstr));
|
||||
SERIAL_ECHOPAIR("...KVAL_HOLD: ", motor.GetParam(L6470_KVAL_HOLD));
|
||||
SERIAL_ECHOPAIR(" KVAL_RUN : ", motor.GetParam(L6470_KVAL_RUN));
|
||||
SERIAL_ECHOPAIR(" KVAL_ACC: ", motor.GetParam(L6470_KVAL_ACC));
|
||||
SERIAL_ECHOPAIR(" KVAL_DEC: ", motor.GetParam(L6470_KVAL_DEC));
|
||||
SERIAL_ECHOPGM(" V motor max = ");
|
||||
float val;
|
||||
PGM_P suf;
|
||||
switch (motor_status) {
|
||||
case 0: sprintf_P(temp_buf, PSTR(" %4.1f%% (KVAL_HOLD)\n"), float(motor.GetParam(L6470_KVAL_HOLD)) * 100 / 256); break;
|
||||
case 1: sprintf_P(temp_buf, PSTR(" %4.1f%% (KVAL_RUN) \n"), float(motor.GetParam(L6470_KVAL_RUN)) * 100 / 256); break;
|
||||
case 2: sprintf_P(temp_buf, PSTR(" %4.1f%% (KVAL_ACC) \n"), float(motor.GetParam(L6470_KVAL_ACC)) * 100 / 256); break;
|
||||
case 3: sprintf_P(temp_buf, PSTR(" %4.1f%% (KVAL_DEC) \n"), float(motor.GetParam(L6470_KVAL_DEC)) * 100 / 256); break;
|
||||
case 0:
|
||||
val = motor.GetParam(L6470_KVAL_HOLD);
|
||||
suf = PSTR("(KVAL_HOLD)");
|
||||
break;
|
||||
case 1:
|
||||
val = motor.GetParam(L6470_KVAL_RUN);
|
||||
suf = PSTR("(KVAL_RUN)");
|
||||
break;
|
||||
case 2:
|
||||
val = motor.GetParam(L6470_KVAL_ACC);
|
||||
suf = PSTR("(KVAL_ACC)");
|
||||
break;
|
||||
case 3:
|
||||
val = motor.GetParam(L6470_KVAL_DEC);
|
||||
suf = PSTR("(KVAL_DEC)");
|
||||
break;
|
||||
}
|
||||
SERIAL_ECHO(temp_buf);
|
||||
SERIAL_ECHO(dtostrf(val * 100 / 256, 10, 2, numstr));
|
||||
SERIAL_ECHO("%% ");
|
||||
serialprintPGM(suf);
|
||||
SERIAL_EOL();
|
||||
}
|
||||
|
||||
void GcodeSuite::M906() {
|
||||
@ -150,7 +172,7 @@ void GcodeSuite::M906() {
|
||||
report_current = false;
|
||||
|
||||
if (planner.has_blocks_queued() || planner.cleaning_buffer_counter) {
|
||||
SERIAL_ECHOLNPGM("ERROR - can't set KVAL_HOLD while steppers are moving");
|
||||
SERIAL_ECHOLNPGM("!Can't set KVAL_HOLD with steppers moving");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,19 @@
|
||||
#define DEBUG_OUT ENABLED(L6470_CHITCHAT)
|
||||
#include "../../../core/debug_out.h"
|
||||
|
||||
static void jiggle_axis(const char axis_char, const float &min, const float &max, const float &rate) {
|
||||
char gcode_string[30], str1[11], str2[11];
|
||||
|
||||
// Turn the motor(s) both directions
|
||||
sprintf_P(gcode_string, PSTR("G0 %c%s F%s"), axis_char, dtostrf(min, 1, 3, str1), dtostrf(rate, 1, 3, str2));
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %c%s F%s"), axis_char, dtostrf(max, 1, 3, str1), str2);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
planner.synchronize();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* M916: Increase KVAL_HOLD until thermal warning
|
||||
@ -85,14 +98,11 @@ void GcodeSuite::M916() {
|
||||
|
||||
DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
|
||||
|
||||
planner.synchronize(); // wait for all current movement commands to complete
|
||||
planner.synchronize(); // Wait for moves to finish
|
||||
|
||||
for (j = 0; j < driver_count; j++)
|
||||
L6470.get_status(axis_index[j]); // clear out any pre-existing error flags
|
||||
L6470.get_status(axis_index[j]); // Clear out error flags
|
||||
|
||||
char temp_axis_string[] = " ";
|
||||
temp_axis_string[0] = axis_mon[0][0]; // need to have a string for use within sprintf format section
|
||||
char gcode_string[80];
|
||||
uint16_t status_composite = 0;
|
||||
|
||||
DEBUG_ECHOLNPGM(".\n.");
|
||||
@ -104,15 +114,8 @@ void GcodeSuite::M916() {
|
||||
for (j = 0; j < driver_count; j++)
|
||||
L6470.set_param(axis_index[j], L6470_KVAL_HOLD, kval_hold);
|
||||
|
||||
// turn the motor(s) both directions
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_min, final_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_max, final_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
// get the status after the motors have stopped
|
||||
planner.synchronize();
|
||||
// Turn the motor(s) both directions
|
||||
jiggle_axis(axis_mon[0][0], position_min, position_max, final_feedrate);
|
||||
|
||||
status_composite = 0; // clear out the old bits
|
||||
|
||||
@ -201,12 +204,9 @@ void GcodeSuite::M917() {
|
||||
|
||||
DEBUG_ECHOLNPAIR("feedrate = ", final_feedrate);
|
||||
|
||||
planner.synchronize(); // wait for all current movement commands to complete
|
||||
planner.synchronize(); // Wait for moves to finish
|
||||
for (j = 0; j < driver_count; j++)
|
||||
L6470.get_status(axis_index[j]); // clear out any pre-existing error flags
|
||||
char temp_axis_string[] = " ";
|
||||
temp_axis_string[0] = axis_mon[0][0]; // need to have a string for use within sprintf format section
|
||||
char gcode_string[80];
|
||||
L6470.get_status(axis_index[j]); // Clear out error flags
|
||||
uint16_t status_composite = 0;
|
||||
uint8_t test_phase = 0;
|
||||
// 0 - decreasing OCD - exit when OCD warning occurs (ignore STALL)
|
||||
@ -225,13 +225,7 @@ void GcodeSuite::M917() {
|
||||
DEBUG_ECHOPAIR("STALL threshold : ", (stall_th_val + 1) * 31.25);
|
||||
DEBUG_ECHOLNPAIR(" OCD threshold : ", (ocd_th_val + 1) * 375);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_min, final_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_max, final_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
planner.synchronize();
|
||||
jiggle_axis(axis_mon[0][0], position_min, position_max, final_feedrate);
|
||||
|
||||
status_composite = 0; // clear out the old bits
|
||||
|
||||
@ -500,30 +494,19 @@ void GcodeSuite::M918() {
|
||||
float feedrate_inc = final_feedrate / 10, // start at 1/10 of max & go up by 1/10 per step)
|
||||
current_feedrate = 0;
|
||||
|
||||
planner.synchronize(); // wait for all current movement commands to complete
|
||||
planner.synchronize(); // Wait for moves to finish
|
||||
|
||||
for (j = 0; j < driver_count; j++)
|
||||
L6470.get_status(axis_index[j]); // clear all error flags
|
||||
L6470.get_status(axis_index[j]); // Clear all error flags
|
||||
|
||||
char temp_axis_string[2];
|
||||
temp_axis_string[0] = axis_mon[0][0]; // need to have a string for use within sprintf format section
|
||||
temp_axis_string[1] = '\n';
|
||||
|
||||
char gcode_string[80];
|
||||
uint16_t status_composite = 0;
|
||||
DEBUG_ECHOLNPGM(".\n.\n."); // make the feedrate prints easier to see
|
||||
DEBUG_ECHOLNPGM(".\n.\n."); // Make the feedrate prints easier to see
|
||||
|
||||
do {
|
||||
current_feedrate += feedrate_inc;
|
||||
DEBUG_ECHOLNPAIR("...feedrate = ", current_feedrate);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_min, current_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
sprintf_P(gcode_string, PSTR("G0 %s%4.3f F%4.3f"), temp_axis_string, position_max, current_feedrate);
|
||||
process_subcommands_now(gcode_string);
|
||||
|
||||
planner.synchronize();
|
||||
jiggle_axis(axis_mon[0][0], position_min, position_max, current_feedrate);
|
||||
|
||||
for (j = 0; j < driver_count; j++) {
|
||||
axis_status[j] = (~L6470.get_status(axis_index[j])) & 0x0800; // bits of interest are all active low
|
||||
|
@ -42,7 +42,7 @@
|
||||
SERIAL_CHAR(' ');
|
||||
SERIAL_CHAR(axis_codes[i]);
|
||||
SERIAL_CHAR(':');
|
||||
SERIAL_ECHO(dtostrf(pos[i], 8, precision, str));
|
||||
SERIAL_ECHO(dtostrf(pos[i], 1, precision, str));
|
||||
}
|
||||
SERIAL_EOL();
|
||||
}
|
||||
|
Reference in New Issue
Block a user