27
27
OpenFontRender ofr;
28
28
FT6236 ts = FT6236(TFT_HEIGHT, TFT_WIDTH);
29
29
TFT_eSPI tft = TFT_eSPI();
30
+ TFT_eSprite timeSprite = TFT_eSprite(&tft);
30
31
GfxUi ui = GfxUi(&tft, &ofr);
31
32
32
33
int lastMinute = -1 ;
@@ -45,12 +46,13 @@ OpenWeatherMapForecastData forecasts[MAX_FORECASTS];
45
46
// Function prototypes (declarations)
46
47
// ----------------------------------------------------------------------------
47
48
void drawProgress (const char *text, int8_t percentage);
49
+ void drawTime ();
48
50
void initJpegDecoder ();
49
51
void initOpenFontRender ();
50
52
bool pushImageToTft (int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap);
51
53
void syncTime ();
52
54
void update ();
53
- void updateData ();
55
+ void updateData (boolean updateProgressBar );
54
56
55
57
56
58
@@ -67,6 +69,7 @@ void setup(void) {
67
69
initJpegDecoder ();
68
70
initTouchScreen (&ts);
69
71
initTft (&tft);
72
+ timeSprite.createSprite (timeSpritePos.width , timeSpritePos.height );
70
73
logDisplayDebugInfo (&tft);
71
74
72
75
initFileSystem ();
@@ -81,7 +84,10 @@ void loop(void) {
81
84
lastUpdateMillis == 0 ||
82
85
(millis () - lastUpdateMillis) > updateIntervalMillis) {
83
86
update ();
87
+ } else {
88
+ drawTime ();
84
89
}
90
+ delay (1000 );
85
91
}
86
92
87
93
@@ -102,6 +108,16 @@ void drawProgress(const char *text, int8_t percentage) {
102
108
ui.drawProgressBar (pbX, pbY, pbWidth, 15 , percentage, TFT_WHITE, TFT_TP_BLUE);
103
109
}
104
110
111
+ void drawTime () {
112
+ timeSprite.fillSprite (TFT_BLACK);
113
+ ofr.setFontSize (48 );
114
+ ofr.setDrawer (timeSprite);
115
+ ofr.drawString (getCurrentTimestamp (UI_TIME_FORMAT).c_str (), timePosX, 0 );
116
+ timeSprite.pushSprite (timeSpritePos.x , timeSpritePos.y );
117
+ // set the drawer back since we temporarily changed it to the time sprite above
118
+ ofr.setDrawer (tft);
119
+ }
120
+
105
121
void initJpegDecoder () {
106
122
// The JPEG image can be scaled by a factor of 1, 2, 4, or 8 (default: 0)
107
123
TJpgDec.setJpgScale (1 );
@@ -140,6 +156,7 @@ void syncTime() {
140
156
}
141
157
142
158
void update () {
159
+ tft.fillScreen (TFT_BLACK);
143
160
ui.drawLogo ();
144
161
145
162
ofr.setFontSize (16 );
@@ -154,14 +171,20 @@ void update() {
154
171
drawProgress (" Synchronizing time..." , 30 );
155
172
syncTime ();
156
173
157
- updateData ();
174
+ updateData (true );
158
175
159
176
drawProgress (" Ready" , 100 );
160
177
lastUpdateMillis = millis ();
178
+
179
+ tft.fillScreen (TFT_BLACK);
180
+
181
+ ofr.setFontSize (16 );
182
+ ofr.cdrawString (String (" Last weather update: " + getCurrentTimestamp (UI_TIME_FORMAT_NO_SECONDS)).c_str (), tft.width () / 2 , 10 );
183
+ drawTime ();
161
184
}
162
185
163
- void updateData () {
164
- drawProgress (" Updating weather..." , 70 );
186
+ void updateData (boolean updateProgressBar ) {
187
+ if (updateProgressBar) drawProgress (" Updating weather..." , 70 );
165
188
OpenWeatherMapCurrent *currentWeatherClient = new OpenWeatherMapCurrent ();
166
189
currentWeatherClient->setMetric (IS_METRIC);
167
190
currentWeatherClient->setLanguage (OPEN_WEATHER_MAP_LANGUAGE);
@@ -170,7 +193,7 @@ void updateData() {
170
193
currentWeatherClient = nullptr ;
171
194
log_i (" Current weather in %s: %s, %.1fC°" , currentWeather.cityName , currentWeather.description .c_str (), currentWeather.feelsLike );
172
195
173
- drawProgress (" Updating forecasts ..." , 90 );
196
+ if (updateProgressBar) drawProgress (" Updating forecast ..." , 90 );
174
197
OpenWeatherMapForecast *forecastClient = new OpenWeatherMapForecast ();
175
198
forecastClient->setMetric (IS_METRIC);
176
199
forecastClient->setLanguage (OPEN_WEATHER_MAP_LANGUAGE);
0 commit comments