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

BUG: EvtTimeListener endless fire #5

Open
olivernadj opened this issue Oct 29, 2017 · 1 comment
Open

BUG: EvtTimeListener endless fire #5

olivernadj opened this issue Oct 29, 2017 · 1 comment

Comments

@olivernadj
Copy link

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

jaredwhite128 added a commit to jaredwhite128/Eventually that referenced this issue Sep 23, 2018
@cwienands1
Copy link

cwienands1 commented Jan 28, 2021

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;
   ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants