Skip to content

Commit dfc1e1f

Browse files
Merge pull request #946 from kimble4/tft-charging-power
TFT big power display during charging
2 parents 461cf4c + f312bfe commit dfc1e1f

File tree

2 files changed

+43
-14
lines changed

2 files changed

+43
-14
lines changed

src/lcd_tft.cpp

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
237237
_tft.startWrite();
238238
#endif
239239

240+
uint8_t evse_state = _evse->getEvseState();
241+
240242
switch(_state)
241243
{
242244
case State::Boot:
@@ -286,7 +288,12 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
286288
} break;
287289

288290
case State::Charge:
289-
{
291+
{
292+
//redraw when going in or out of charging state to switch between pilot and power display
293+
if ((evse_state == OPENEVSE_STATE_CHARGING || _previous_evse_state == OPENEVSE_STATE_CHARGING) && evse_state != _previous_evse_state) {
294+
_full_update = true;
295+
}
296+
290297
if(_full_update)
291298
{
292299
_screen.fillRect(DISPLAY_AREA_X, DISPLAY_AREA_Y, DISPLAY_AREA_WIDTH, DISPLAY_AREA_HEIGHT, TFT_OPENEVSE_BACK);
@@ -301,8 +308,8 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
301308
if(_evse->isVehicleConnected()) {
302309
car_icon = "/car_connected.png";
303310
}
304-
305-
switch (_evse->getEvseState())
311+
312+
switch (evse_state)
306313
{
307314
case OPENEVSE_STATE_STARTING:
308315
status_icon = "/start.png";
@@ -337,7 +344,7 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
337344
}
338345

339346
char buffer[32] = "";
340-
char buffer2[10];
347+
char buffer2[12];
341348

342349
if (wifi_client) {
343350
if (wifi_connected) {
@@ -358,17 +365,36 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
358365
render_image(car_icon.c_str(), 16, 92);
359366
render_image(wifi_icon.c_str(), 16, 132);
360367

361-
snprintf(buffer, sizeof(buffer), "%d", _evse->getChargeCurrent());
362-
render_right_text_box(buffer, 66, 175, 154, &FreeSans24pt7b, TFT_BLACK, TFT_WHITE, !_full_update, 2);
363-
if(_full_update) {
364-
render_left_text_box("A", 224, 165, 34, &FreeSans24pt7b, TFT_BLACK, TFT_WHITE, false, 1);
368+
369+
if (evse_state == OPENEVSE_STATE_CHARGING) {
370+
float power = _evse->getPower() / 1000.0; //kW
371+
if (power < 10) {
372+
snprintf(buffer, sizeof(buffer), "%.2f", power);
373+
} else if (power < 100) {
374+
snprintf(buffer, sizeof(buffer), "%.1f", power);
375+
} else {
376+
snprintf(buffer, sizeof(buffer), "%.0f", power);
377+
}
378+
render_left_text_box(buffer, 66, 157, 188, &FreeSans24pt7b, TFT_BLACK, TFT_WHITE, !_full_update, 2);
379+
render_left_text_box("kW", 224, 165, 34, &FreeSans9pt7b, TFT_BLACK, TFT_WHITE, false, 1);
380+
} else {
381+
snprintf(buffer, sizeof(buffer), "%d", _evse->getChargeCurrent());
382+
render_right_text_box(buffer, 66, 175, 154, &FreeSans24pt7b, TFT_BLACK, TFT_WHITE, !_full_update, 2);
383+
if (_full_update) {
384+
render_left_text_box("A", 224, 165, 34, &FreeSans24pt7b, TFT_BLACK, TFT_WHITE, false, 1);
385+
}
365386
}
366387
if (_evse->isTemperatureValid(EVSE_MONITOR_TEMP_MONITOR)) {
367388
snprintf(buffer, sizeof(buffer), "%.1fC", _evse->getTemperature(EVSE_MONITOR_TEMP_MONITOR));
368389
render_right_text_box(buffer, 415, 30, 50, &FreeSans9pt7b, TFT_WHITE, TFT_OPENEVSE_BACK, false, 1);
369390
}
391+
370392
snprintf(buffer, sizeof(buffer), "%.1f V %.2f A", _evse->getVoltage(), _evse->getAmps());
371-
get_scaled_number_value(_evse->getPower(), 2, "W", buffer2, sizeof(buffer2));
393+
if (evse_state == OPENEVSE_STATE_CHARGING) {
394+
snprintf(buffer2, sizeof(buffer2), "Pilot: %dA", _evse->getChargeCurrent());
395+
} else {
396+
get_scaled_number_value(_evse->getPower(), 2, "W", buffer2, sizeof(buffer2));
397+
}
372398
render_data_box(buffer2, buffer, 66, 175, INFO_BOX_WIDTH, INFO_BOX_HEIGHT, _full_update);
373399

374400
String line = getLine(0);
@@ -397,6 +423,8 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
397423
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", &timeinfo);
398424
render_left_text_box(buffer, 12, 30, 175, &FreeSans9pt7b, TFT_WHITE, TFT_OPENEVSE_BACK, false, 1);
399425

426+
_previous_evse_state = evse_state;
427+
400428
//sleep until next whole second so clock doesn't skip
401429
gettimeofday(&local_time, NULL);
402430
nextUpdate = 1000 - local_time.tv_usec/1000;
@@ -413,11 +441,9 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
413441
#endif
414442

415443
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
416-
uint8_t evse_state = _evse->getEvseState();
417444
bool vehicle_state = _evse->isVehicleConnected();
418445
if (evse_state != _previous_evse_state || vehicle_state != _previous_vehicle_state) { //wake backlight on state change
419446
wakeBacklight();
420-
_previous_evse_state = evse_state;
421447
_previous_vehicle_state = vehicle_state;
422448
} else { //otherwise timeout backlight in appropriate states
423449
bool timeout = true;
@@ -462,7 +488,7 @@ unsigned long LcdTask::loop(MicroTasks::WakeReason reason)
462488
}
463489
}
464490
#endif //TFT_BACKLIGHT_TIMEOUT_MS
465-
491+
_previous_evse_state = evse_state;
466492
DBUGVAR(nextUpdate);
467493
return nextUpdate;
468494
}

src/lcd_tft.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ class LcdTask : public MicroTasks::Task
9595
EvseManager *_evse;
9696
Scheduler *_scheduler;
9797
ManualOverride *_manual;
98+
uint8_t _previous_evse_state;
9899
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
99100
long _last_backlight_wakeup = 0;
100-
uint8_t _previous_evse_state;
101101
bool _previous_vehicle_state;
102102
#endif //TFT_BACKLIGHT_TIMEOUT_MS
103103
bool wifi_client;
@@ -116,7 +116,6 @@ class LcdTask : public MicroTasks::Task
116116
String getLine(int line);
117117

118118
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
119-
void wakeBacklight();
120119
void timeoutBacklight();
121120
#endif //TFT_BACKLIGHT_TIMEOUT_MS
122121

@@ -145,6 +144,10 @@ class LcdTask : public MicroTasks::Task
145144
void display(const char *msg, int x, int y, int time, uint32_t flags);
146145
void setWifiMode(bool client, bool connected);
147146

147+
#ifdef TFT_BACKLIGHT_TIMEOUT_MS
148+
void wakeBacklight();
149+
#endif //TFT_BACKLIGHT_TIMEOUT_MS
150+
148151
void fill_screen(uint16_t color) {
149152
_screen.fillScreen(color);
150153
}

0 commit comments

Comments
 (0)