Timer is now functional.
This commit is contained in:
@@ -25,7 +25,6 @@
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@
|
||||
|
||||
/*------------------------------- INCLUDES ----------------------------------*/
|
||||
|
||||
#include <ctime>
|
||||
|
||||
#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 */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user