/**
 * Author : Anatole SCHRAMM-HENRY
 * Created on : 03/04/2022
 * Licence : MIT
 * 
 * Dead simple object implementing a non blocking delay using the Arduino framework.
 */
#include "NonBlockingDelay.h"

NonBlockingDelay::NonBlockingDelay(const unsigned long delay, unsigned long tickReference) : _delay(delay), _tickReference(tickReference){}

void NonBlockingDelay::reset()
{
    _tickReference = millis();
}

NonBlockingDelay::operator bool()
{
    bool isTimeElapsed(millis() - _tickReference > _delay);

    if(isTimeElapsed)
        reset();

    return isTimeElapsed;
}