/* EventTimer.cpp - Event Timer Class Implementation */ #include "EventTimer.h" /* EventTimer - Default Constructor EventTimer () */ EventTimer::EventTimer () { } /* EventTimer - Constructor with Interval EventTimer (ULONG interval) */ EventTimer::EventTimer (ULONG interval) { _timer.setInterval(interval); } /* EventTimer - Constructor with Interval and Function EventTimer (ULONG interval, bool (*function)()) */ EventTimer::EventTimer (ULONG interval, bool (*function)()) { setInterval(interval); setFunction(function); } /* setInterval - Set Time Interval void setInterval (ULONG interval) */ void EventTimer::setInterval (ULONG interval) { _timer.setInterval(interval); } /* getInterval - Get Time Interval ULONG getInterval () */ ULONG EventTimer::getInterval () { return _timer.getInterval(); } /* setFunction - Set Event Function void setFunction ((*function)()); */ void EventTimer::setFunction (bool (*function)()) { _function = function; } /* start - Start Timer void start () */ void EventTimer::start () { _timer.start(); } /* start - Start Timer void start (ULONG now) */ void EventTimer::start (ULONG now) { _timer.start(now); } /* start - Start Timer void start (ULONG now, ULONG interval) */ void EventTimer::start (ULONG now, ULONG interval) { _timer.start(now, interval); } /* isRunning - Check if Timer is Running bool isRunning () */ bool EventTimer::isRunning () { return _timer.isRunning(); } /* isDone - Check if Timer is Done bool isDone () */ bool EventTimer::isDone () { return _timer.isDone(); } /* isDone - Check if Timer is Done bool isDone (ULONG now) */ bool EventTimer::isDone (ULONG now) { return _timer.isDone(now); } /* update - Update Event Timer bool update () */ bool EventTimer::update () { return update(millis()); } /* update - Update Event Timer bool update (ULONG now) If the timer is not running, false is returned. Otherwise, the timer is checked to see if the time has elapsed. If it has, the event function is called. If the event function returns true, the timer is restarted. As long as the timer is running, this function returns true. */ bool EventTimer::update (ULONG now) { if (isRunning()) { if (_timer.isDone(now)) { if ((_function)()) { _timer.start(now); } } return true; } return false; }