diff --git a/src/domod/src/timers/Clock.cpp b/src/domod/src/timers/Clock.cpp index 635d9f40..ba815bb7 100644 --- a/src/domod/src/timers/Clock.cpp +++ b/src/domod/src/timers/Clock.cpp @@ -25,7 +25,6 @@ /*------------------------------- INCLUDES ----------------------------------*/ #include -#include #include "timers/Clock.h" @@ -53,22 +52,34 @@ Clock::~Clock (void) /*! ---------------------------------------------------------------------------- * @fn isEqual * - * @brief Constructor of the Clock Object. + * @brief Set an Event to the Clock. */ -bool Clock::isCurrentTimeEqualTo (const Event &anEvent) +int Clock::set (const Event &anEvent) +{ + mEvent = anEvent; + + mNow = time (NULL); + + return 0; +} + + +/*! ---------------------------------------------------------------------------- + * @fn isEqualToCurrentTime + * + * @brief return true if the clock is equal to current time. + */ +bool Clock::isEqualToCurrentTime (void) { - time_t theNow; struct tm theComparedTime; double theDiff; - theNow = time (NULL); + theComparedTime = *localtime (&mNow); - theComparedTime = *localtime (&theNow); + theComparedTime.tm_hour = mEvent.getHour(); + theComparedTime.tm_min = mEvent.getMinute(); - theComparedTime.tm_hour = anEvent.getHour(); - theComparedTime.tm_min = anEvent.getMinute(); - - theDiff = difftime (theNow, mktime (&theComparedTime)); + theDiff = difftime (mNow, mktime (&theComparedTime)); //printf ("%.f seconds of diff between current time and Timer time.\n", theDiff); @@ -77,3 +88,32 @@ bool Clock::isCurrentTimeEqualTo (const Event &anEvent) return false; } + + +/*! ---------------------------------------------------------------------------- + * @fn isExpired + * + * @brief Return true if the curent time has expired. + */ +bool Clock::isExpired (void) +{ + time_t theExpired; + struct tm theComparedTime; + double theDiff; + + theComparedTime = *localtime (&mNow); + + theComparedTime.tm_hour = mEvent.getHour(); + theComparedTime.tm_min = mEvent.getMinute(); + + theExpired = mktime (&theComparedTime) + (mEvent.getDuration() * 60); + + theDiff = difftime (mNow, theExpired); + + //printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired); + + if (theDiff == 0) + return true; + + return false; +} diff --git a/src/domod/src/timers/Clock.h b/src/domod/src/timers/Clock.h index b80b9851..0e0fbf92 100644 --- a/src/domod/src/timers/Clock.h +++ b/src/domod/src/timers/Clock.h @@ -28,6 +28,8 @@ /*------------------------------- INCLUDES ----------------------------------*/ +#include + #include "timers/Event.h" /*---------------------------------- Deps -----------------------------------*/ @@ -39,7 +41,14 @@ class Clock { public: Clock (void); ~Clock (void); - bool isCurrentTimeEqualTo (const Event &anEvent); + + int set (const Event &anEvent); + bool isEqualToCurrentTime (void); + bool isExpired (void); + +private: + Event mEvent; + time_t mNow; }; #endif /* _CLOCK_H */ diff --git a/src/domod/src/timers/Event.cpp b/src/domod/src/timers/Event.cpp index d7b5288f..801c9892 100644 --- a/src/domod/src/timers/Event.cpp +++ b/src/domod/src/timers/Event.cpp @@ -234,7 +234,7 @@ bool Event::isInProgress (void) const * * @brief Set the InProgress to a new state. */ -void setInProgress (bool aState) +void Event::setInProgress (bool aState) { mInProgress = aState; } diff --git a/src/domod/src/timers/Timers.cpp b/src/domod/src/timers/Timers.cpp index 2f86a788..095187ef 100644 --- a/src/domod/src/timers/Timers.cpp +++ b/src/domod/src/timers/Timers.cpp @@ -142,16 +142,19 @@ int Timers::Expire (void) theClock.set ((*timer_evt)); if ((*timer_evt).isInProgress()) { - if (theClock.IsExpired()) { + if (theClock.isExpired()) { // (*timer_evt).setInProgress (false); //TODO Action Stop. fprintf (stdout, "Timer Stop\n"); } + else { + fprintf (stdout, "Not expired yet.\n"); + } } else { - if (theClock.isEqualToCurrentTime () { + if (theClock.isEqualToCurrentTime ()) { (*timer_evt).setInProgress (true); // Action START.