Skip to content

Commit

Permalink
Added support for displaying the vehicle stats on the LCD
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremypoulter committed May 15, 2021
1 parent a692fae commit 263e0ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
44 changes: 33 additions & 11 deletions src/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,25 @@ LcdTask::LcdInfoLine LcdTask::getNextInfoLine(LcdInfoLine info)
case LcdInfoLine::EnergyTotal:
return LcdInfoLine::Tempurature;
case LcdInfoLine::Tempurature:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerStop :
LcdInfoLine::EnergySession;
if(_scheduler->getNextEvent().isValid()) {
return LcdInfoLine::TimerStop;
}
case LcdInfoLine::TimerStop:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerRemaining :
LcdInfoLine::EnergySession;
if(_scheduler->getNextEvent().isValid()) {
return LcdInfoLine::TimerRemaining;
}
case LcdInfoLine::TimerRemaining:
if(_evse->isVehicleStateOfChargeValid()) {
return LcdInfoLine::BatterySOC;
}
case LcdInfoLine::BatterySOC:
if(_evse->isVehicleRangeValid()) {
return LcdInfoLine::Range;
}
case LcdInfoLine::Range:
if(_evse->isVehicleEtaValid()) {
return LcdInfoLine::TimeLeft;
}
default:
return LcdInfoLine::EnergySession;
}
Expand Down Expand Up @@ -531,20 +543,24 @@ void LcdTask::displayInfoLine(LcdInfoLine line, unsigned long &nextUpdate)

case LcdInfoLine::BatterySOC:
// Charge level 79%
displayNumberValue(1, "Charge level", _evse->getVehicleStateOfCharge(), 0, "%");
_updateInfoLine = false;
break;

case LcdInfoLine::ChargeLimit:
// Charge limit 85%
break;

case LcdInfoLine::Range:
displayNumberValue(1, "Range", _evse->getVehicleRange(), 0, "KM");
break;

case LcdInfoLine::RangeAdded:
// Added 127 miles
break;

case LcdInfoLine::TimeLeft:
displayStopWatchTime("ETA", _evse->getVehicleEta());
break;

case LcdInfoLine::Voltage:
Expand Down Expand Up @@ -573,11 +589,7 @@ void LcdTask::displayInfoLine(LcdInfoLine line, unsigned long &nextUpdate)
int32_t currentOffset;
Scheduler::getCurrentTime(currentDay, currentOffset);
uint32_t delay = event.getDelay(currentDay, currentOffset);
int hour = delay / 3600;
int min = (delay / 60) % 60;
int sec = delay % 60;
sprintf(temp, "Left %d:%02d:%02d", hour, min, sec);
showText(0, 1, temp, true);
displayStopWatchTime("Left", delay);
nextUpdate = 1000;
} else {
showText(0, 1, "Left --:--:--", true);
Expand Down Expand Up @@ -622,6 +634,16 @@ void LcdTask::displayInfoEventTime(const char *name, Scheduler::EventInstance &e
showText(0, 1, temp, true);
}

void LcdTask::displayStopWatchTime(const char *name, uint32_t time)
{
char temp[20];
int hour = time / 3600;
int min = (time / 60) % 60;
int sec = time % 60;
sprintf(temp, "%s %d:%02d:%02d", name, hour, min, sec);
showText(0, 1, temp, true);
}

void LcdTask::showText(int x, int y, const char *msg, bool clear)
{
DBUGF("LCD: %d %d %s", x, y, msg);
Expand Down
1 change: 1 addition & 0 deletions src/lcd.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class LcdTask : public MicroTasks::Task
void displayInfoLine(LcdInfoLine info, unsigned long &nextUpdate);
void displayNumberValue(int line, const char *name, double value, int precision, const char *unit);
void displayInfoEventTime(const char *name, Scheduler::EventInstance &event);
void displayStopWatchTime(const char *name, uint32_t time);
protected:
void setup();
unsigned long loop(MicroTasks::WakeReason reason);
Expand Down

0 comments on commit 263e0ec

Please sign in to comment.