Skip to content

Commit c2d33f5

Browse files
committed
Fixed text display
1 parent 18691d2 commit c2d33f5

File tree

4 files changed

+50
-37
lines changed

4 files changed

+50
-37
lines changed

src/lcd_tft.cpp

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "emonesp.h"
99
#include "lcd.h"
1010
#include "lcd_common.h"
11+
#include "screens/screen_renderer.h"
1112
#include "RapiSender.h"
1213
#include "openevse.h"
1314
#include "input.h"
@@ -20,9 +21,6 @@
2021

2122
PNG png; // Global PNG decoder instance
2223

23-
// Global message buffer shared with renderers
24-
char _msg[LCD_MAX_LINES][LCD_MAX_LEN + 1];
25-
2624
LcdTask::Message::Message(const __FlashStringHelper *msg, int x, int y, int time, uint32_t flags) :
2725
_next(NULL),
2826
_msg(""),
@@ -65,9 +63,8 @@ LcdTask::LcdTask() :
6563
#endif
6664
{
6765
for(int i = 0; i < LCD_MAX_LINES; i++) {
68-
clearLine(i);
66+
clear_message_line(i);
6967
}
70-
_msg_cleared = true;
7168
}
7269

7370
LcdTask::~LcdTask()
@@ -194,7 +191,7 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
194191
{
195192
DBUGLN("Clearing message lines");
196193
for(int i = 0; i < LCD_MAX_LINES; i++) {
197-
clearLine(i);
194+
clear_message_line(i);
198195
}
199196
_msg_cleared = true;
200197
}
@@ -238,7 +235,7 @@ unsigned long LcdTask::displayNextMessage()
238235
_screenManager->wakeBacklight();
239236
}
240237
#endif //TFT_BACKLIGHT_TIMEOUT_MS
241-
showText(msg->getX(), msg->getY(), msg->getMsg(), msg->getClear());
238+
set_message_line(msg->getX(), msg->getY(), msg->getMsg(), msg->getClear());
242239

243240
_nextMessageTime = millis() + msg->getTime();
244241

@@ -251,29 +248,6 @@ unsigned long LcdTask::displayNextMessage()
251248
return nextUpdate;
252249
}
253250

254-
void LcdTask::showText(int x, int y, const char *msg, bool clear)
255-
{
256-
DBUGF("LCD: %d %d %s, clear=%s", x, y, msg, clear ? "true" : "false");
257-
258-
if(clear) {
259-
clearLine(y);
260-
}
261-
262-
strncpy(_msg[y], msg + x, LCD_MAX_LEN - x);
263-
_msg[y][LCD_MAX_LEN] = '\0';
264-
_msg_cleared = false;
265-
}
266-
267-
void LcdTask::clearLine(int line)
268-
{
269-
if(line < 0 || line >= LCD_MAX_LINES) {
270-
return;
271-
}
272-
273-
memset(_msg[line], ' ', LCD_MAX_LEN);
274-
_msg[line][LCD_MAX_LEN] = '\0';
275-
}
276-
277251
LcdTask lcd;
278252

279253
#endif // ENABLE_SCREEN_LCD_TFT

src/lcd_tft.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,8 @@ class LcdTask : public MicroTasks::Task
9393
bool _previous_vehicle_state;
9494
#endif //TFT_BACKLIGHT_TIMEOUT_MS
9595

96-
char _msg[LCD_MAX_LINES][LCD_MAX_LEN + 1];
97-
bool _msg_cleared;
98-
9996
void display(Message *msg, uint32_t flags);
10097
unsigned long displayNextMessage();
101-
void clearLine(int line);
102-
void showText(int x, int y, const char *msg, bool clear);
10398

10499
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
105100
void timeoutBacklight();

src/screens/screen_renderer.cpp

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313

1414
extern PNG png;
1515

16+
// Global message buffer shared with renderers
17+
char _msg[LCD_MAX_LINES][LCD_MAX_LEN + 1];
18+
bool _msg_cleared = false;
19+
1620
#define MAX_IMAGE_WIDTH TFT_HEIGHT // Adjust for your images
1721

1822
struct image_render_state {
@@ -133,8 +137,38 @@ void get_scaled_number_value(double value, int precision, const char *unit, char
133137
snprintf(buffer, size, "%.*f %s%s", precision, value, mod[index], unit);
134138
}
135139

136-
// Message line buffer management - will need to be moved from LcdTask to here or a separate file
137-
extern char _msg[LCD_MAX_LINES][LCD_MAX_LEN + 1]; // This should be defined in lcd_common.h
140+
void set_message_line(int x, int y, const char *msg, bool clear)
141+
{
142+
DBUGF("LCD: %d %d %s, clear=%s", x, y, msg, clear ? "true" : "false");
143+
144+
if(y < 0 || y >= LCD_MAX_LINES) {
145+
return;
146+
}
147+
148+
if(clear) {
149+
clear_message_line(y);
150+
}
151+
152+
if(x < 0 || x >= LCD_MAX_LEN) {
153+
return;
154+
}
155+
156+
strncpy(_msg[y] + x, msg, LCD_MAX_LEN - x);
157+
_msg[y][LCD_MAX_LEN] = '\0';
158+
_msg_cleared = false;
159+
160+
DBUGF("LCD: %s (%p)", _msg[y], _msg[y]);
161+
}
162+
163+
void clear_message_line(int line)
164+
{
165+
if(line < 0 || line >= LCD_MAX_LINES) {
166+
return;
167+
}
168+
169+
memset(_msg[line], ' ', LCD_MAX_LEN);
170+
_msg[line][LCD_MAX_LEN] = '\0';
171+
}
138172

139173
String get_message_line(int line)
140174
{
@@ -153,6 +187,8 @@ String get_message_line(int line)
153187
len--;
154188
}
155189

190+
DBUGF("get_message_line: %d, '%s' (%p) -> '%.*s'", line, _msg[line], _msg[line], len, start);
191+
156192
return String(start, len);
157193
}
158194

src/screens/screen_renderer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <TFT_eSPI.h>
55
#include <PNGdec.h>
66

7+
#include "lcd_common.h"
8+
79
// The TFT screen is portrait natively, so we need to rotate it
810
#define TFT_SCREEN_WIDTH TFT_HEIGHT
911
#define TFT_SCREEN_HEIGHT TFT_WIDTH
@@ -36,6 +38,12 @@ extern void render_info_box(const char *title, const char *text, int16_t x, int1
3638
extern void get_scaled_number_value(double value, int precision, const char *unit,
3739
char *buffer, size_t size);
3840

41+
// Message line buffer - shared across screens
42+
extern char _msg[LCD_MAX_LINES][LCD_MAX_LEN + 1];
43+
extern bool _msg_cleared;
44+
45+
extern void set_message_line(int x, int y, const char *msg, bool clear);
46+
extern void clear_message_line(int line);
3947
extern String get_message_line(int line);
4048

4149
#endif // __SCREEN_RENDERER_H

0 commit comments

Comments
 (0)