55 lines
986 B
C++
55 lines
986 B
C++
#include "component.h"
|
|
|
|
Component::Component(uint16_t loopDelay) : loopDelay{loopDelay}
|
|
{
|
|
}
|
|
|
|
void Component::loop()
|
|
{
|
|
if (!this->active)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (this->childComponents.size())
|
|
{
|
|
std::list<Component *>::iterator it;
|
|
for (it = this->childComponents.begin(); it != this->childComponents.end(); it++)
|
|
{
|
|
(*it)->loop();
|
|
}
|
|
}
|
|
this->runAsChild();F
|
|
|
|
if (this->onlyChilds)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (static_cast<bool>(this->loopDelay) && millis() - this->lastMillis < this->loopDelay)
|
|
{
|
|
return;
|
|
}
|
|
|
|
this->lastMillis = millis();
|
|
|
|
this->beforeRun();
|
|
this->run();
|
|
this->afterRun();
|
|
|
|
if (this->timeUpdateAfter)
|
|
{
|
|
this->lastMillis = millis();
|
|
}
|
|
}
|
|
|
|
void Component::addChildComponent(Component *child)
|
|
{
|
|
this->childComponents.push_back(child);
|
|
}
|
|
|
|
void Component::removeChildComponent(Component *child)
|
|
{
|
|
this->childComponents.remove(child);
|
|
}
|