Timer WIP.

This commit is contained in:
jbnadal
2016-05-20 19:37:53 +02:00
parent a299086f88
commit c0f600653f
4 changed files with 64 additions and 22 deletions

View File

@@ -58,14 +58,11 @@ Clock::~Clock (void)
bool Clock::isCurrentTimeEqualTo (const Event &anEvent)
{
time_t theNow;
struct tm *theNow_tm;
struct tm theComparedTime;
int theHour, theMinute;
struct tm theComparedTime;
double theDiff;
theNow = time (NULL);
theNow_tm = localtime (&theNow);
theComparedTime = *localtime (&theNow);
theComparedTime.tm_hour = anEvent.getHour();

View File

@@ -33,9 +33,16 @@
*
* @brief Constructor of Timer Event Object.
*/
Event::Event (void)
{
Event::Event (void):
mActive(false),
mID(0),
mHour(0),
mMinute(0),
mRecurrence(0),
mDuration(0),
mInProgress (false)
{
}
@@ -46,7 +53,6 @@ Event::Event (void)
*/
Event::~Event (void)
{
}
@@ -129,7 +135,7 @@ void Event::Dump (void)
*
* @brief return true if the Timer event is active.
*/
bool Event::isActive (void)
bool Event::isActive (void) const
{
return mActive;
}
@@ -140,7 +146,7 @@ bool Event::isActive (void)
*
* @brief return the capability of the Event.
*/
std::string Event::getCapability (void)
std::string Event::getCapability (void) const
{
return mCapability;
}
@@ -151,7 +157,7 @@ std::string Event::getCapability (void)
*
* @brief return the ID of the Event.
*/
uint16_t Event::getID (void)
uint16_t Event::getID (void) const
{
return mID;
}
@@ -184,7 +190,7 @@ uint8_t Event::getMinute (void) const
*
* @brief Return the Recurrency of the Event.
*/
uint16_t Event::getRecurrence (void)
uint16_t Event::getRecurrence (void) const
{
return mRecurrence;
}
@@ -195,7 +201,7 @@ uint16_t Event::getRecurrence (void)
*
* @brief Return the Duration of the Event.
*/
uint16_t Event::getDuration (void)
uint16_t Event::getDuration (void) const
{
return mDuration;
}
@@ -206,7 +212,29 @@ uint16_t Event::getDuration (void)
*
* @brief Return the Action of the Event.
*/
std::string Event::getAction (void)
std::string Event::getAction (void) const
{
return mAction;
}
/*! ----------------------------------------------------------------------------
* @fn isInProgress
*
* @brief Return true if the Event Is in Progress.
*/
bool Event::isInProgress (void) const
{
return mInProgress;
}
/*! ----------------------------------------------------------------------------
* @fn setInProgress
*
* @brief Set the InProgress to a new state.
*/
void setInProgress (bool aState)
{
mInProgress = aState;
}

View File

@@ -50,14 +50,18 @@ public:
void Dump (void);
/* Getter */
bool isActive (void);
std::string getCapability (void);
uint16_t getID (void);
bool isActive (void) const;
std::string getCapability (void) const;
uint16_t getID (void) const;
uint8_t getHour (void) const;
uint8_t getMinute (void) const;
uint16_t getRecurrence (void);
uint16_t getDuration (void);
std::string getAction (void);
uint16_t getRecurrence (void) const;
uint16_t getDuration (void) const;
std::string getAction (void) const;
bool isInProgress (void) const;
/* Setter */
void setInProgress (bool aState);
private:
bool mActive;
@@ -68,6 +72,7 @@ private:
uint16_t mRecurrence;
uint16_t mDuration;
std::string mAction;
bool mInProgress;
};
#endif /* _EVENT_H */

View File

@@ -139,12 +139,24 @@ int Timers::Expire (void)
if ((*timer_evt).isActive()) {
if (theClock.isCurrentTimeEqualTo ((*timer_evt))) {
theClock.set ((*timer_evt));
fprintf (stderr, "Time identique\n");
if ((*timer_evt).isInProgress()) {
if (theClock.IsExpired()) {
//
(*timer_evt).setInProgress (false);
//TODO Action Stop.
fprintf (stdout, "Timer Stop\n");
}
}
else {
fprintf (stderr, "Time PAS identique\n");
if (theClock.isEqualToCurrentTime () {
(*timer_evt).setInProgress (true);
// Action START.
fprintf (stdout, "Timer Start\n");
}
}
}
}