Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for infinate loop in getNextEvent #549

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions src/lcd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,13 @@ LcdTask::LcdInfoLine LcdTask::getNextInfoLine(LcdInfoLine info)
case LcdInfoLine::Time:
return LcdInfoLine::Date;
case LcdInfoLine::Date:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerStart :
LcdInfoLine::EnergySession;
if(_scheduler->getNextEvent(EvseState::Active).isValid()) {
return LcdInfoLine::TimerStart;
}
case LcdInfoLine::TimerStart:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerStop :
LcdInfoLine::EnergySession;
if(_scheduler->getNextEvent(EvseState::Disabled).isValid()) {
return LcdInfoLine::TimerStop;
}
default:
return LcdInfoLine::EnergySession;
}
Expand All @@ -353,7 +353,7 @@ LcdTask::LcdInfoLine LcdTask::getNextInfoLine(LcdInfoLine info)
case LcdInfoLine::EnergyTotal:
return LcdInfoLine::Temperature;
case LcdInfoLine::Temperature:
if(_scheduler->getNextEvent().isValid()) {
if(_scheduler->getNextEvent(EvseState::Disabled).isValid()) {
return LcdInfoLine::TimerStop;
}
case LcdInfoLine::TimerStop:
Expand Down Expand Up @@ -388,13 +388,13 @@ LcdTask::LcdInfoLine LcdTask::getNextInfoLine(LcdInfoLine info)
case LcdInfoLine::Time:
return LcdInfoLine::Date;
case LcdInfoLine::Date:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerStart :
LcdInfoLine::Time;
if(_scheduler->getNextEvent(EvseState::Active).isValid()) {
return LcdInfoLine::TimerStart;
}
case LcdInfoLine::TimerStart:
return _scheduler->getNextEvent().isValid() ?
LcdInfoLine::TimerStop :
LcdInfoLine::Time;
if(_scheduler->getNextEvent(EvseState::Disabled).isValid()) {
return LcdInfoLine::TimerStop;
}
default:
return LcdInfoLine::Time;
}
Expand Down
13 changes: 12 additions & 1 deletion src/scheduler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

uint32_t Scheduler::Event::_next_id = 1;

Scheduler::EventInstance nullEventInstance;

const char * days_of_the_week_strings[] = {
"sunday",
"monday",
Expand Down Expand Up @@ -422,14 +424,23 @@ Scheduler::EventInstance &Scheduler::getCurrentEvent()

Scheduler::EventInstance &Scheduler::getNextEvent(EvseState type)
{
DBUGVAR(type);
EventInstance *event = &_activeEvent; // Assume active event is correct
if(event->isValid())
{
event = &event->getNext();
if(EvseState::None != type)
{
while(event->getState() != type) {
EventInstance *startEvent = event;

while(event->getState() != type)
{
event = &event->getNext();
DBUGVAR((uint32_t)event, HEX);
DBUGVAR((uint32_t)startEvent, HEX);
if(startEvent == event) {
return nullEventInstance;
}
}
}
}
Expand Down