-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.cpp
More file actions
98 lines (81 loc) · 2.53 KB
/
Display.cpp
File metadata and controls
98 lines (81 loc) · 2.53 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "Display.h"
#include <Arduino.h>
#include "AppConfig.h"
#include "app/BacklightPwm.h"
namespace display
{
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite clk = TFT_eSprite(&tft);
namespace
{
uint8_t s_loadingProgress = 6;
bool s_loadingUiDrawn = false;
}
void begin(uint8_t rotation)
{
Serial.println(F("[Display] begin enter"));
pinMode(app_config::kPinLcdBacklight, OUTPUT);
analogWriteRange(app::kBacklightPwmRange);
analogWrite(app_config::kPinLcdBacklight,
app::backlightPwmDutyForPercent(app_config::kDefaultLcdBrightness));
Serial.println(F("[Display] backlight ready"));
Serial.println(F("[Display] tft.begin"));
tft.begin();
Serial.println(F("[Display] tft.begin ok"));
Serial.println(F("[Display] invertDisplay"));
tft.invertDisplay(1);
Serial.println(F("[Display] setRotation"));
tft.setRotation(rotation);
Serial.println(F("[Display] fillScreen"));
tft.fillScreen(app_config::kColorBg);
s_loadingUiDrawn = false;
Serial.println(F("[Display] text color"));
tft.setTextColor(TFT_BLACK, app_config::kColorBg);
Serial.println(F("[Display] begin done"));
}
void setBrightness(uint8_t percent)
{
analogWriteRange(app::kBacklightPwmRange);
analogWrite(app_config::kPinLcdBacklight, app::backlightPwmDutyForPercent(percent));
}
void setRotation(uint8_t rotation)
{
tft.setRotation(rotation);
}
void clear()
{
tft.fillScreen(app_config::kColorBg);
s_loadingUiDrawn = false;
}
void drawLoading(uint32_t delayMs, uint8_t step)
{
s_loadingProgress += step;
if (s_loadingProgress > 194)
s_loadingProgress = 194;
constexpr int kPanelX = 20;
constexpr int kPanelY = 120;
constexpr int kPanelWidth = 200;
constexpr int kPanelHeight = 100;
constexpr int kBarX = kPanelX;
constexpr int kBarY = kPanelY;
constexpr int kBarInnerX = kPanelX + 3;
constexpr int kBarInnerY = kPanelY + 3;
if (!s_loadingUiDrawn)
{
tft.fillRect(kPanelX, kPanelY, kPanelWidth, kPanelHeight, app_config::kColorBg);
tft.drawRoundRect(kBarX, kBarY, 200, 16, 8, 0xFFFF);
tft.setTextDatum(CC_DATUM);
tft.setTextColor(TFT_GREEN, app_config::kColorBg);
tft.drawString("Connecting to WiFi......", 120, 160, 2);
tft.setTextColor(TFT_WHITE, app_config::kColorBg);
tft.drawRightString(app_config::kVersion, 200, 180, 2);
s_loadingUiDrawn = true;
}
// Avoid sprite push on ESP8266+WiFi: direct primitives do not hit TFT_eSPI::pushPixels().
tft.fillRoundRect(kBarInnerX, kBarInnerY, s_loadingProgress, 10, 5, 0xFFFF);
if (delayMs > 0)
{
delay(delayMs);
}
}
} // namespace display