Eventually
Eventually copied to clipboard
BUG: EvtTimeListener endless fire
I would like to create a one time event, but it trigger endless fire. Code snipped:
#include "Eventually.h"
EvtManager mgr;
void setup()
{
Serial.begin(9600);
mgr.addListener(new EvtTimeListener(1000, false, (EvtAction)sayHelloSerial));
}
void loop()
{
mgr.loopIteration();
}
bool sayHelloSerial() {
Serial.println("Hello Serial");
return false;
}
Expected result (after 1s says):
Hello Serial
Actual result (immediately prints endless):
Hello Serial
Hello Serial
Hello Serial
...
I am using version 0.1.5
But I think there is yet another problem with non-multiFire timer listeners: The startMillis
will not be updated after successful execution of the action. A fraction of a millisecond later when isEventTiggered
is called the next time, isEventTriggered
will again return true
because if(curTime - startMillis > this->millis)
still evaluates the same way. I introduced a hasExecuted
member in the EvtListener
class that gets set when the associated action executes for the first time. Then check for that condition in isEventTriggered
, like this...
bool EvtTimeListener::isEventTriggered() {
if (!this->multiFire && this->hasExecuted) return false;
...