Pārlūkot izejas kodu

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

Marcio Teixeira 4 gadus atpakaļ
vecāks
revīzija
b590ae4875

+ 2
- 2
Marlin/Makefile Parādīt failu

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

+ 2
- 2
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/bio_status_screen.cpp Parādīt failu

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

+ 14
- 16
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/change_filament_screen.cpp Parādīt failu

@@ -126,14 +126,15 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
126 126
   }
127 127
 
128 128
   if (what & FOREGROUND) {
129
-    char e_str[15];
129
+    const extruder_t e = getExtruder();
130 130
 
131
-      if (isHeaterIdle(getExtruder()))
132
-      sprintf_P(e_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(getExtruder())), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
131
+    char e_str[15];
132
+    if (isHeaterIdle(e))
133
+      format_temp_and_idle(e_str, getActualTemp_celsius(e));
133 134
     else
134
-      sprintf_P(e_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(getExtruder())), ROUND(getTargetTemp_celsius(getExtruder())), GET_TEXT(UNITS_C));
135
+      format_temp_and_temp(e_str, getActualTemp_celsius(e), getTargetTemp_celsius(e));
135 136
 
136
-    const rgb_t tcol = getWarmColor(getActualTemp_celsius(getExtruder()), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP);
137
+    const rgb_t tcol = getWarmColor(getActualTemp_celsius(e), COOL_TEMP, LOW_TEMP, MED_TEMP, HIGH_TEMP);
137 138
     cmd.cmd(COLOR_RGB(tcol))
138 139
        .tag(15)
139 140
     #ifdef TOUCH_UI_PORTRAIT
@@ -150,11 +151,11 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
150 151
     #endif
151 152
        .colors(normal_btn);
152 153
 
153
-    const bool t_ok = getActualTemp_celsius(getExtruder()) > getSoftenTemp() - 10;
154
+    const bool t_ok = getActualTemp_celsius(e) > getSoftenTemp() - 10;
154 155
 
155 156
     if (screen_data.ChangeFilamentScreen.t_tag && !t_ok) {
156 157
       cmd.text(BTN_POS(1,6), BTN_SIZE(1,1), GET_TEXTF(HEATING));
157
-    } else if (getActualTemp_celsius(getExtruder()) > 100) {
158
+    } else if (getActualTemp_celsius(e) > 100) {
158 159
       cmd.cmd(COLOR_RGB(0xFF0000))
159 160
          .text(BTN_POS(1,4), BTN_SIZE(1,1), GET_TEXTF(CAUTION))
160 161
          .colors(normal_btn)
@@ -198,17 +199,14 @@ void ChangeFilamentScreen::onRedraw(draw_mode_t what) {
198 199
     #endif
199 200
     {
200 201
       char str[30];
201
-      sprintf_P(str, PSTR("%3d%S (%S)"), LOW_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_PLA));
202
+
203
+      format_temp_and_material(str, LOW_TEMP, GET_TEXT(MATERIAL_PLA));
202 204
       cmd.tag(2) .TOG_STYLE(tog2) .button (BTN_POS(2,6), BTN_SIZE(1,1), str);
203
-    }
204
-    {
205
-      char str[30];
206
-      sprintf_P(str, PSTR("%3d%S (%S)"), MED_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_ABS));
205
+
206
+      format_temp_and_material(str, MED_TEMP, GET_TEXT(MATERIAL_ABS));
207 207
       cmd.tag(3) .TOG_STYLE(tog3) .button (BTN_POS(2,5), BTN_SIZE(1,1), str);
208
-    }
209
-    {
210
-      char str[30];
211
-      sprintf_P(str, PSTR("%3d%S (%S)"), HIGH_TEMP, GET_TEXT(UNITS_C), GET_TEXT(MATERIAL_HIGH_TEMP));
208
+
209
+      format_temp_and_material(str, HIGH_TEMP, GET_TEXT(MATERIAL_HIGH_TEMP));
212 210
       cmd.tag(4) .TOG_STYLE(tog4) .button (BTN_POS(2,4), BTN_SIZE(1,1), str);
213 211
     }
214 212
     cmd.colors(normal_btn)

+ 1
- 5
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/nudge_nozzle_screen.cpp Parādīt failu

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

+ 1
- 2
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/screens.h Parādīt failu

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

+ 16
- 24
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/status_screen.cpp Parādīt failu

@@ -86,29 +86,20 @@ void StatusScreen::draw_axis_position(draw_mode_t what) {
86 86
     char y_str[15];
87 87
     char z_str[15];
88 88
 
89
-    if (isAxisPositionKnown(X)) {
90
-      dtostrf(getAxisPosition_mm(X), 5, 1, x_str);
91
-      strcat_P(x_str, " ");
92
-      strcat_P(x_str, GET_TEXT(UNITS_MM));
93
-    } else {
89
+    if (isAxisPositionKnown(X))
90
+      format_position(x_str, getAxisPosition_mm(X));
91
+    else
94 92
       strcpy_P(x_str, PSTR("?"));
95
-    }
96 93
 
97
-    if (isAxisPositionKnown(Y)) {
98
-      dtostrf(getAxisPosition_mm(Y), 5, 1, y_str);
99
-      strcat_P(y_str, " ");
100
-      strcat_P(y_str, GET_TEXT(UNITS_MM));
101
-    } else {
94
+    if (isAxisPositionKnown(Y))
95
+      format_position(y_str, getAxisPosition_mm(Y));
96
+    else
102 97
       strcpy_P(y_str, PSTR("?"));
103
-    }
104 98
 
105
-    if (isAxisPositionKnown(Z)) {
106
-      dtostrf(getAxisPosition_mm(Z), 5, 1, z_str);
107
-      strcat_P(z_str, " ");
108
-      strcat_P(z_str, GET_TEXT(UNITS_MM));
109
-    } else {
99
+    if (isAxisPositionKnown(Z))
100
+      format_position(z_str, getAxisPosition_mm(Z));
101
+    else
110 102
       strcpy_P(z_str, PSTR("?"));
111
-    }
112 103
 
113 104
     cmd.tag(6).font(Theme::font_medium)
114 105
     #ifdef TOUCH_UI_PORTRAIT
@@ -197,20 +188,21 @@ void StatusScreen::draw_temperature(draw_mode_t what) {
197 188
     );
198 189
 
199 190
     if (isHeaterIdle(BED))
200
-      sprintf_P(bed_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(BED)), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
191
+      format_temp_and_idle(bed_str, getActualTemp_celsius(BED));
201 192
     else
202
-      sprintf_P(bed_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(BED)), ROUND(getTargetTemp_celsius(BED)), GET_TEXT(UNITS_C));
193
+      format_temp_and_temp(bed_str, getActualTemp_celsius(BED), getTargetTemp_celsius(BED));
203 194
 
204 195
     if (isHeaterIdle(H0))
205
-      sprintf_P(e0_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(H0)), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
196
+      format_temp_and_idle(e0_str, getActualTemp_celsius(H0));
206 197
     else
207
-      sprintf_P(e0_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(H0)), ROUND(getTargetTemp_celsius(H0)), GET_TEXT(UNITS_C));
198
+      format_temp_and_temp(e0_str, getActualTemp_celsius(H0), getTargetTemp_celsius(H0));
199
+
208 200
 
209 201
     #if EXTRUDERS == 2
210 202
       if (isHeaterIdle(H1))
211
-        sprintf_P(e1_str, PSTR("%3d%S / %S"), ROUND(getActualTemp_celsius(H1)), PSTR(GET_TEXT(UNITS_C)), GET_TEXT(TEMP_IDLE));
203
+        format_temp_and_idle(e1_str, getActualTemp_celsius(H1));
212 204
       else
213
-        sprintf_P(e1_str, PSTR("%3d / %3d%S"), ROUND(getActualTemp_celsius(H1)), ROUND(getTargetTemp_celsius(H1)), GET_TEXT(UNITS_C));
205
+        format_temp_and_temp(e1_str, getActualTemp_celsius(H1), getTargetTemp_celsius(H1));
214 206
     #else
215 207
       strcpy_P(
216 208
         e1_str,

+ 89
- 0
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/string_format.cpp Parādīt failu

@@ -0,0 +1,89 @@
1
+/*********************
2
+ * string_format.cpp *
3
+ *********************/
4
+
5
+/****************************************************************************
6
+ *   Written By Marcio Teixeira 2018 - Aleph Objects, Inc.                  *
7
+ *                                                                          *
8
+ *   This program is free software: you can redistribute it and/or modify   *
9
+ *   it under the terms of the GNU General Public License as published by   *
10
+ *   the Free Software Foundation, either version 3 of the License, or      *
11
+ *   (at your option) any later version.                                    *
12
+ *                                                                          *
13
+ *   This program is distributed in the hope that it will be useful,        *
14
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of         *
15
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
16
+ *   GNU General Public License for more details.                           *
17
+ *                                                                          *
18
+ *   To view a copy of the GNU General Public License, go to the following  *
19
+ *   location: <http://www.gnu.org/licenses/>.                              *
20
+ ****************************************************************************/
21
+
22
+#include "../config.h"
23
+
24
+#if ENABLED(LULZBOT_TOUCH_UI)
25
+
26
+#include "screens.h"
27
+
28
+#define ROUND(val) uint16_t((val)+0.5)
29
+
30
+#pragma GCC diagnostic push
31
+#pragma GCC diagnostic ignored "-Wno-format"
32
+
33
+#ifdef __AVR__
34
+  #define S_FMT "%S"
35
+#else
36
+  #define S_FMT "%s"
37
+#endif
38
+
39
+/**
40
+ * Formats a temperature string (e.g. "100°C")
41
+ */
42
+void format_temp(char *str, float t1) {
43
+  sprintf_P(str, PSTR("%3d" S_FMT), ROUND(t1), GET_TEXT(UNITS_C));
44
+}
45
+
46
+/**
47
+ * Formats a temperature string for an idle heater (e.g. "100 °C / idle")
48
+ */
49
+void format_temp_and_idle(char *str, float t1) {
50
+  sprintf_P(str, PSTR("%3d" S_FMT " / " S_FMT), ROUND(t1), GET_TEXT(UNITS_C), GET_TEXT(TEMP_IDLE));
51
+}
52
+
53
+/**
54
+ * Formats a temperature string for an active heater (e.g. "100 / 200°C")
55
+ */
56
+void format_temp_and_temp(char *str, float t1, float t2) {
57
+  sprintf_P(str, PSTR("%3d / %3d" S_FMT), ROUND(t1), ROUND(t2), GET_TEXT(UNITS_C));
58
+}
59
+
60
+/**
61
+ * Formats a temperature string for a material (e.g. "100°C (PLA)")
62
+ */
63
+void format_temp_and_material(char *str, float t1, const char *material) {
64
+  sprintf_P(str, PSTR("%3d" S_FMT " (" S_FMT ")"), ROUND(t1), GET_TEXT(UNITS_C), material);
65
+}
66
+
67
+/**
68
+ * Formats a position value (e.g. "10 mm")
69
+ */
70
+void format_position(char *str, float p) {
71
+  dtostrf(p, 5, 1, str);
72
+  strcat_P(str, PSTR(" "));
73
+  strcat_P(str, GET_TEXT(UNITS_MM));
74
+}
75
+
76
+/**
77
+ * Formats a position vector (e.g. "10; 20; 30 mm")
78
+ */
79
+void format_position(char *str, float x, float y, float z) {
80
+  char num1[7], num2[7], num3[7];
81
+  dtostrf(x, 4, 2, num1);
82
+  dtostrf(y, 4, 2, num2);
83
+  dtostrf(z, 4, 2, num3);
84
+  sprintf_P(str, PSTR("%s; %s; %s " S_FMT), num1, num2, num3, GET_TEXT(UNITS_MM));
85
+}
86
+
87
+#pragma GCC diagnostic pop
88
+
89
+#endif // LULZBOT_TOUCH_UI

+ 29
- 0
Marlin/src/lcd/extensible_ui/lib/lulzbot/screens/string_format.h Parādīt failu

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

Notiek ielāde…
Atcelt
Saglabāt