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
CXXSTANDARD = -std=gnu++11
CDEBUG = -g$(DEBUG)
CWARN = -Wall -Wstrict-prototypes -Wno-packed-bitfield-compat -Wno-pragmas -Wunused-parameter -Wno-format
CXXWARN = -Wall -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
CTUNING = -fsigned-char -funsigned-bitfields -fno-exceptions \
-fshort-enums -ffunction-sections -fdata-sections
ifneq ($(HARDWARE_MOTHERBOARD),)

View file

@ -91,12 +91,12 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
.cmd(COLOR_RGB(bg_text_enabled));
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);
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);
cmd.text(x, y, h, v, bed_str);
}

View file

@ -126,14 +126,15 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
}
if (what & FOREGROUND) {
const extruder_t e = getExtruder();
char e_str[15];
if (isHeaterIdle(getExtruder()))
sprintf_P(e_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(getExtruder())), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
if (isHeaterIdle(e))
format_temp_and_idle(e_str, getActualTemp_celsius(e));
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))
.tag(15)
#ifdef TOUCH_UI_PORTRAIT
@ -150,11 +151,11 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
#endif
.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) {
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))
.text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(CAUTION))
.colors(normal_btn)
@ -198,17 +199,14 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
#endif
{
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);
}
{
char str[30];
sprintf_P(str, PSTR("%3d%S (%S)"), MED_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_ABS));
format_temp_and_material(str, MED_TEMP, GET_TEXT(MATERIAL_ABS));
cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str);
}
{
char str[30];
sprintf_P(str, PSTR("%3d%S (%S)"), HIGH_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_HIGH_TEMP));
format_temp_and_material(str, HIGH_TEMP, GET_TEXT(MATERIAL_HIGH_TEMP));
cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str);
}
cmd.colors(normal_btn)

View file

@ -74,11 +74,7 @@ void NudgeNozzleScreen::onRedraw(draw_mode_t what) {
#endif
#if EXTRUDERS > 1
char num1[7], num2[7], num3[7];
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));
format_position(str, getNozzleOffset_mm(X, E1), getNozzleOffset_mm(Y, E1), getNozzleOffset_mm(Z, E1));
w.text_field (0, GET_TEXTF(TOOL_OFFSETS), str);
#endif
}

View file

@ -25,8 +25,7 @@
#include "../ftdi_eve_lib/ftdi_eve_lib.h"
#include "../language/languages.h"
#include "../theme/theme.h"
#define ROUND(val) uint16_t((val)+0.5)
#include "string_format.h"
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 z_str[15];
if (isAxisPositionKnown(X)) {
dtostrf(getAxisPosition_mm(X), 5, 1, x_str);
strcat_P(x_str, " ");
strcat_P(x_str, GET_TEXT(UNITS_MM));
} else {
if (isAxisPositionKnown(X))
format_position(x_str, getAxisPosition_mm(X));
else
strcpy_P(x_str, PSTR("?"));
}
if (isAxisPositionKnown(Y)) {
dtostrf(getAxisPosition_mm(Y), 5, 1, y_str);
strcat_P(y_str, " ");
strcat_P(y_str, GET_TEXT(UNITS_MM));
} else {
if (isAxisPositionKnown(Y))
format_position(y_str, getAxisPosition_mm(Y));
else
strcpy_P(y_str, PSTR("?"));
}
if (isAxisPositionKnown(Z)) {
dtostrf(getAxisPosition_mm(Z), 5, 1, z_str);
strcat_P(z_str, " ");
strcat_P(z_str, GET_TEXT(UNITS_MM));
} else {
if (isAxisPositionKnown(Z))
format_position(z_str, getAxisPosition_mm(Z));
else
strcpy_P(z_str, PSTR("?"));
}
cmd.tag(6).font(Theme::font_medium)
#ifdef TOUCH_UI_PORTRAIT
@ -197,20 +188,21 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
);
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
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))
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
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 (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
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
strcpy_P(
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);