jrullan/neotimer

repeat() requires two calls to restart -> timer become inaccurate

Opened this issue · 0 comments

Worst case example

  • interval is set 1 ms;
  • repeat() is called every 1 ms
  • repeat() will return true each 2 ms.

current implementation

boolean Neotimer::repeat(){
  if(this->done()){
    this->reset();
    return true;
  }
  if(!this->_timer.started){
    this->_timer.last = millis();
    this->_timer.started = true;
    this->_waiting = true;
  }
  return false;
}

suggested implementation

bool Neotimer::repeat(){
  bool ret = false;
  if(this->done()){
    this->reset();
    ret = true;
  }
  if(!this->_timer.started){
   this->_timer.last = _millis.get();
   this->_timer.started = true;
    this->_waiting = true;
  }
  return ret;
}