LULZBOT_TOUCH_UI: Only use %S on AVR (#15292)

This commit is contained in:
Marcio Teixeira 2019-09-18 01:33:26 -06:00 committed by Scott Lahteine
parent ce74e4b3e4
commit b590ae4875
8 changed files with 154 additions and 51 deletions

View File

@ -691,8 +691,8 @@ LIBWARN = -w -Wno-packed-bitfield-compat
CSTANDARD = -std=gnu99 CSTANDARD = -std=gnu99
CXXSTANDARD = -std=gnu++11 CXXSTANDARD = -std=gnu++11
CDEBUG = -g$(DEBUG) CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter -Wno-format CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter -Wno-format CXXWARN = -Wall -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter
CTUNING = -fsigned-char -funsigned-bitfields -fno-exceptions \ CTUNING = -fsigned-char -funsigned-bitfields -fno-exceptions \
-fshort-enums -ffunction-sections -fdata-sections -fshort-enums -ffunction-sections -fdata-sections
ifneq ($(HARDWARE_MOTHERBOARD),) ifneq ($(HARDWARE_MOTHERBOARD),)

View File

@ -91,12 +91,12 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
.cmd(COLOR_RGB(bg_text_enabled)); .cmd(COLOR_RGB(bg_text_enabled));
if (!isHeaterIdle(BED) && getTargetTemp_celsius(BED) > 0) { if (!isHeaterIdle(BED) && getTargetTemp_celsius(BED) > 0) {
sprintf_P(bed_str, PSTR("%3d%S"), ROUND(getTargetTemp_celsius(BED)), GET_TEXT(UNITS_C)); format_temp(bed_str, getTargetTemp_celsius(BED));
ui.bounds(POLY(target_temp), x, y, h, v); ui.bounds(POLY(target_temp), x, y, h, v);
cmd.text(x, y, h, v, bed_str); cmd.text(x, y, h, v, bed_str);
} }
sprintf_P(bed_str, PSTR("%3d%S"), ROUND(getActualTemp_celsius(BED)), GET_TEXT(UNITS_C)); format_temp(bed_str, getActualTemp_celsius(BED));
ui.bounds(POLY(actual_temp), x, y, h, v); ui.bounds(POLY(actual_temp), x, y, h, v);
cmd.text(x, y, h, v, bed_str); cmd.text(x, y, h, v, bed_str);
} }

View File

@ -126,14 +126,15 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
} }
if (what & FOREGROUND) { if (what & FOREGROUND) {
const extruder_t e = getExtruder();
char e_str[15]; char e_str[15];
if (isHeaterIdle(e))
if (isHeaterIdle(getExtruder())) format_temp_and_idle(e_str, getActualTemp_celsius(e));
sprintf_P(e_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(getExtruder())), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
else else
sprintf_P(e_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(getExtruder())), ROUND(getTargetTemp_celsius(getExtruder())), GET_TEXT(UNITS_C)); format_temp_and_temp(e_str, getActualTemp_celsius(e), getTargetTemp_celsius(e));
const rgb_t tcol = getWarmColor(getActualTemp_celsius(getExtruder()), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP); const rgb_t tcol = getWarmColor(getActualTemp_celsius(e), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP);
cmd.cmd(COLOR_RGB(tcol)) cmd.cmd(COLOR_RGB(tcol))
.tag(15) .tag(15)
#ifdef TOUCH_UI_PORTRAIT #ifdef TOUCH_UI_PORTRAIT
@ -150,11 +151,11 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
#endif #endif
.colors(normal_btn); .colors(normal_btn);
const bool t_ok = getActualTemp_celsius(getExtruder()) > getSoftenTemp() - 10; const bool t_ok = getActualTemp_celsius(e) > getSoftenTemp() - 10;
if (screen_data.ChangeFilamentScreen.t_tag && !t_ok) { if (screen_data.ChangeFilamentScreen.t_tag && !t_ok) {
cmd.text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXTF(HEATING)); cmd.text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXTF(HEATING));
} else if (getActualTemp_celsius(getExtruder()) > 100) { } else if (getActualTemp_celsius(e) > 100) {
cmd.cmd(COLOR_RGB(0xFF0000)) cmd.cmd(COLOR_RGB(0xFF0000))
.text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(CAUTION)) .text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(CAUTION))
.colors(normal_btn) .colors(normal_btn)
@ -198,17 +199,14 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
#endif #endif
{ {
char str[30]; char str[30];
sprintf_P(str, PSTR("%3d%S (%S)"), LOW_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_PLA));
format_temp_and_material(str, LOW_TEMP, GET_TEXT(MATERIAL_PLA));
cmd.tag(2) .TOG_STYLE(tog2) .button (BTN_POS(2,6), BTN_SIZE(1,1), str); cmd.tag(2) .TOG_STYLE(tog2) .button (BTN_POS(2,6), BTN_SIZE(1,1), str);
}
{ format_temp_and_material(str, MED_TEMP, GET_TEXT(MATERIAL_ABS));
char str[30];
sprintf_P(str, PSTR("%3d%S (%S)"), MED_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_ABS));
cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str); cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str);
}
{ format_temp_and_material(str, HIGH_TEMP, GET_TEXT(MATERIAL_HIGH_TEMP));
char str[30];
sprintf_P(str, PSTR("%3d%S (%S)"), HIGH_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_HIGH_TEMP));
cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str); cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str);
} }
cmd.colors(normal_btn) cmd.colors(normal_btn)

View File

@ -74,11 +74,7 @@ void NudgeNozzleScreen::onRedraw(draw_mode_t what) {
#endif #endif
#if EXTRUDERS > 1 #if EXTRUDERS > 1
char num1[7], num2[7], num3[7]; format_position(str, getNozzleOffset_mm(X, E1), getNozzleOffset_mm(Y, E1), getNozzleOffset_mm(Z, E1));
dtostrf(getNozzleOffset_mm(X, E1), 4, 2, num1);
dtostrf(getNozzleOffset_mm(Y, E1), 4, 2, num2);
dtostrf(getNozzleOffset_mm(Z, E1), 4, 2, num3);
sprintf_P(str, PSTR("%s; %s; %s %S"), num1, num2, num3, GET_TEXT(UNITS_MM));
w.text_field (0, GET_TEXTF(TOOL_OFFSETS), str); w.text_field (0, GET_TEXTF(TOOL_OFFSETS), str);
#endif #endif
} }

View File

@ -25,8 +25,7 @@
#include "../ftdi_eve_lib/ftdi_eve_lib.h" #include "../ftdi_eve_lib/ftdi_eve_lib.h"
#include "../language/languages.h" #include "../language/languages.h"
#include "../theme/theme.h" #include "../theme/theme.h"
#include "string_format.h"
#define ROUND(val) uint16_t((val)+0.5)
extern tiny_timer_t refresh_timer; extern tiny_timer_t refresh_timer;

View File

@ -86,29 +86,20 @@ void StatusScreen::draw_axis_position(draw_mode_t what) {
char y_str[15]; char y_str[15];
char z_str[15]; char z_str[15];
if (isAxisPositionKnown(X)) { if (isAxisPositionKnown(X))
dtostrf(getAxisPosition_mm(X), 5, 1, x_str); format_position(x_str, getAxisPosition_mm(X));
strcat_P(x_str, " "); else
strcat_P(x_str, GET_TEXT(UNITS_MM));
} else {
strcpy_P(x_str, PSTR("?")); strcpy_P(x_str, PSTR("?"));
}
if (isAxisPositionKnown(Y)) { if (isAxisPositionKnown(Y))
dtostrf(getAxisPosition_mm(Y), 5, 1, y_str); format_position(y_str, getAxisPosition_mm(Y));
strcat_P(y_str, " "); else
strcat_P(y_str, GET_TEXT(UNITS_MM));
} else {
strcpy_P(y_str, PSTR("?")); strcpy_P(y_str, PSTR("?"));
}
if (isAxisPositionKnown(Z)) { if (isAxisPositionKnown(Z))
dtostrf(getAxisPosition_mm(Z), 5, 1, z_str); format_position(z_str, getAxisPosition_mm(Z));
strcat_P(z_str, " "); else
strcat_P(z_str, GET_TEXT(UNITS_MM));
} else {
strcpy_P(z_str, PSTR("?")); strcpy_P(z_str, PSTR("?"));
}
cmd.tag(6).font(Theme::font_medium) cmd.tag(6).font(Theme::font_medium)
#ifdef TOUCH_UI_PORTRAIT #ifdef TOUCH_UI_PORTRAIT
@ -197,20 +188,21 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
); );
if (isHeaterIdle(BED)) if (isHeaterIdle(BED))
sprintf_P(bed_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(BED)), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE)); format_temp_and_idle(bed_str, getActualTemp_celsius(BED));
else else
sprintf_P(bed_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(BED)), ROUND(getTargetTemp_celsius(BED)), GET_TEXT(UNITS_C)); format_temp_and_temp(bed_str, getActualTemp_celsius(BED), getTargetTemp_celsius(BED));
if (isHeaterIdle(H0)) if (isHeaterIdle(H0))
sprintf_P(e0_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(H0)), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE)); format_temp_and_idle(e0_str, getActualTemp_celsius(H0));
else else
sprintf_P(e0_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(H0)), ROUND(getTargetTemp_celsius(H0)), GET_TEXT(UNITS_C)); format_temp_and_temp(e0_str, getActualTemp_celsius(H0), getTargetTemp_celsius(H0));
#if EXTRUDERS == 2 #if EXTRUDERS == 2
if (isHeaterIdle(H1)) if (isHeaterIdle(H1))
sprintf_P(e1_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(H1)), PSTR(GET_TEXT(UNITS_C)), GET_TEXT(TEMP_IDLE)); format_temp_and_idle(e1_str, getActualTemp_celsius(H1));
else else
sprintf_P(e1_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(H1)), ROUND(getTargetTemp_celsius(H1)), GET_TEXT(UNITS_C)); format_temp_and_temp(e1_str, getActualTemp_celsius(H1), getTargetTemp_celsius(H1));
#else #else
strcpy_P( strcpy_P(
e1_str, e1_str,

View File

@ -0,0 +1,89 @@
/*********************
* string_format.cpp *
*********************/
/****************************************************************************
* Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* To view a copy of the GNU General Public License, go to the following *
* location: <http://www.gnu.org/licenses/>. *
****************************************************************************/
#include "../config.h"
#if ENABLED(LULZBOT_TOUCH_UI)
#include "screens.h"
#define ROUND(val) uint16_t((val)+0.5)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wno-format"
#ifdef __AVR__
#define S_FMT "%S"
#else
#define S_FMT "%s"
#endif
/**
* Formats a temperature string (e.g. "100°C")
*/
void format_temp(char *str, float t1) {
sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(UNITS_C));
}
/**
* Formats a temperature string for an idle heater (e.g. "100 °C / idle")
*/
void format_temp_and_idle(char *str, float t1) {
sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
}
/**
* Formats a temperature string for an active heater (e.g. "100 / 200°C")
*/
void format_temp_and_temp(char *str, float t1, float t2) {
sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(UNITS_C));
}
/**
* Formats a temperature string for a material (e.g. "100°C (PLA)")
*/
void format_temp_and_material(char *str, float t1, const char *material) {
sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(UNITS_C), material);
}
/**
* Formats a position value (e.g. "10 mm")
*/
void format_position(char *str, float p) {
dtostrf(p, 5, 1, str);
strcat_P(str, PSTR(" "));
strcat_P(str, GET_TEXT(UNITS_MM));
}
/**
* Formats a position vector (e.g. "10; 20; 30 mm")
*/
void format_position(char *str, float x, float y, float z) {
char num1[7], num2[7], num3[7];
dtostrf(x, 4, 2, num1);
dtostrf(y, 4, 2, num2);
dtostrf(z, 4, 2, num3);
sprintf_P(str, PSTR("%s; %s; %s " S_FMT), num1, num2, num3, GET_TEXT(UNITS_MM));
}
#pragma GCC diagnostic pop
#endif // LULZBOT_TOUCH_UI

View File

@ -0,0 +1,29 @@
/*******************
* string_format.h *
*******************/
/****************************************************************************
* Written By Marcio Teixeira 2018 - Aleph Objects, Inc. *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* To view a copy of the GNU General Public License, go to the following *
* location: <http://www.gnu.org/licenses/>. *
****************************************************************************/
#pragma once
void format_temp(char *str, float t1);
void format_temp_and_idle(char *str, float t1);
void format_temp_and_temp(char *str, float t1, float t2);
void format_temp_and_material(char *str, float t1, const char *material);
void format_position(char *str, float p);
void format_position(char *str, float x, float y, float z);