-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplayUI.cpp
More file actions
79 lines (63 loc) · 2 KB
/
DisplayUI.cpp
File metadata and controls
79 lines (63 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "DisplayUI.h"
#include "rm67162.h"
DisplayUI::DisplayUI()
: tft(), sprite(&tft) {}
void DisplayUI::begin() {
initDisplay();
sprite.createSprite(536, 241);
sprite.setTextColor(TFT_WHITE, TFT_BLACK);
}
void DisplayUI::initDisplay() {
rm67162_init();
lcd_setRotation(3);
}
void DisplayUI::pushSprite() {
lcd_PushColors(0, 0, 536, 240, (uint16_t*)sprite.getPointer());
}
void DisplayUI::clear() {
sprite.fillSprite(TFT_BLACK);
pushSprite();
}
String DisplayUI::getCurrentTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
return "--:--";
}
char buffer[6]; // "HH:MM"
snprintf(buffer, sizeof(buffer), "%02d:%02d", timeinfo.tm_hour, timeinfo.tm_min);
return String(buffer);
}
void DisplayUI::showModernUI(const char* mode, const char* station, const char* song, const char* time, int wifiDbm) {
sprite.fillSprite(TFT_BLACK);
// --- Top Bar: Mode and Time ---
sprite.setTextSize(2);
sprite.drawString(mode, 10, 10);
int timeWidth = sprite.textWidth(time);
sprite.drawString(time, 536 - timeWidth - 10, 10);
// --- Divider Line Below Top Bar ---
sprite.drawFastHLine(0, 35, 536, TFT_DARKGREY);
// --- Station Name (Centered) ---
sprite.setTextSize(4);
int stationW = sprite.textWidth(station);
sprite.drawString(station, (536 - stationW) / 2, 60);
// --- Song Info Below Station Name ---
sprite.setTextSize(2);
int songW = sprite.textWidth(song);
sprite.drawString(song, (536 - songW) / 2, 120);
// --- Divider Above Wi-Fi Bars ---
sprite.drawFastHLine(0, 185, 536, TFT_DARKGREY);
// --- Wi-Fi Signal Bars (bottom right) ---
int strength = constrain(map(wifiDbm, -90, -30, 0, 4), 0, 4);
int x = 500;
int y = 200;
int barWidth = 6;
int spacing = 4;
for (int i = 0; i < 4; i++) {
int barHeight = 5 + i * 6;
int barX = x + i * (barWidth + spacing);
int barY = y + 24 - barHeight;
uint16_t color = (i < strength) ? TFT_GREEN : TFT_DARKGREY;
sprite.fillRect(barX, barY, barWidth, barHeight, color);
}
pushSprite();
}