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:
Scott Lahteine
2019-08-08 01:51:37 -05:00
committed by GitHub
parent 3e5620283e
commit c8e30b6639
8 changed files with 75 additions and 76 deletions

View File

@ -666,17 +666,14 @@ void ST7920_Lite_Status_Screen::draw_position(const float x, const float y, cons
// If position is unknown, flash the labels.
const unsigned char alt_label = position_known ? 0 : (ui.get_blink() ? ' ' : 0);
dtostrf(x, -4, 0, str);
write_byte(alt_label ? alt_label : 'X');
write_str(str, 4);
write_str(dtostrf(x, -4, 0, str), 4);
dtostrf(y, -4, 0, str);
write_byte(alt_label ? alt_label : 'Y');
write_str(str, 4);
write_str(dtostrf(y, -4, 0, str), 4);
dtostrf(z, -5, 1, str);
write_byte(alt_label ? alt_label : 'Z');
write_str(str, 5);
write_str(dtostrf(z, -5, 1, str), 5);
}
bool ST7920_Lite_Status_Screen::indicators_changed() {

View File

@ -146,10 +146,10 @@ void process_lcd_eb_command(const char* command) {
char message_buffer[MAX_CURLY_COMMAND];
sprintf_P(message_buffer,
PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}{TQ:%03i}{TT:%s}"),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}{TQ:%03i}{TT:%s}"),
int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
thermalManager.degBed(), thermalManager.degTargetBed(),
int(thermalManager.degBed()), thermalManager.degTargetBed(),
#else
0, 0,
#endif
@ -199,8 +199,8 @@ void process_lcd_j_command(const char* command) {
case 'X': {
// G0 <AXIS><distance>
// The M200 class UI seems to send movement in .1mm values.
char cmd[20];
sprintf_P(cmd, PSTR("G1 %c%03.1f"), axis, atof(command + 1) / 10.0);
char cmd[20], pos[6];
sprintf_P(cmd, PSTR("G1 %c%s"), axis, dtostrf(atof(command + 1) / 10.0, -5, 3, pos));
queue.enqueue_one_now(cmd);
} break;
default:
@ -305,10 +305,10 @@ void process_lcd_s_command(const char* command) {
case 'I': {
// temperature information
char message_buffer[MAX_CURLY_COMMAND];
sprintf_P(message_buffer, PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}"),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
sprintf_P(message_buffer, PSTR("{T0:%03i/%03i}{T1:000/000}{TP:%03i/%03i}"),
int(thermalManager.degHotend(0)), thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
thermalManager.degBed(), thermalManager.degTargetBed()
int(thermalManager.degBed()), thermalManager.degTargetBed()
#else
0, 0
#endif

View File

@ -285,8 +285,7 @@ void _menu_move_distance(const AxisEnum axis, const screenFunc_t func, const int
// Determine digits needed right of decimal
const uint8_t digs = !UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 1000 - int((SHORT_MANUAL_Z_MOVE) * 1000)) ? 4 :
!UNEAR_ZERO((SHORT_MANUAL_Z_MOVE) * 100 - int((SHORT_MANUAL_Z_MOVE) * 100)) ? 3 : 2;
dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr);
sprintf_P(tmp, PSTR(MSG_MOVE_Z_DIST), numstr);
sprintf_P(tmp, PSTR(MSG_MOVE_Z_DIST), dtostrf(SHORT_MANUAL_Z_MOVE, 1, digs, numstr));
LCDPRINT(tmp);
MENU_ITEM_ADDON_END();
}