Timer WIP.
This commit is contained in:
@@ -58,14 +58,11 @@ Clock::~Clock (void)
|
|||||||
bool Clock::isCurrentTimeEqualTo (const Event &anEvent)
|
bool Clock::isCurrentTimeEqualTo (const Event &anEvent)
|
||||||
{
|
{
|
||||||
time_t theNow;
|
time_t theNow;
|
||||||
struct tm *theNow_tm;
|
|
||||||
struct tm theComparedTime;
|
struct tm theComparedTime;
|
||||||
int theHour, theMinute;
|
|
||||||
double theDiff;
|
double theDiff;
|
||||||
|
|
||||||
theNow = time (NULL);
|
theNow = time (NULL);
|
||||||
|
|
||||||
theNow_tm = localtime (&theNow);
|
|
||||||
theComparedTime = *localtime (&theNow);
|
theComparedTime = *localtime (&theNow);
|
||||||
|
|
||||||
theComparedTime.tm_hour = anEvent.getHour();
|
theComparedTime.tm_hour = anEvent.getHour();
|
||||||
|
|||||||
@@ -33,9 +33,16 @@
|
|||||||
*
|
*
|
||||||
* @brief Constructor of Timer Event Object.
|
* @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)
|
Event::~Event (void)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -129,7 +135,7 @@ void Event::Dump (void)
|
|||||||
*
|
*
|
||||||
* @brief return true if the Timer event is active.
|
* @brief return true if the Timer event is active.
|
||||||
*/
|
*/
|
||||||
bool Event::isActive (void)
|
bool Event::isActive (void) const
|
||||||
{
|
{
|
||||||
return mActive;
|
return mActive;
|
||||||
}
|
}
|
||||||
@@ -140,7 +146,7 @@ bool Event::isActive (void)
|
|||||||
*
|
*
|
||||||
* @brief return the capability of the Event.
|
* @brief return the capability of the Event.
|
||||||
*/
|
*/
|
||||||
std::string Event::getCapability (void)
|
std::string Event::getCapability (void) const
|
||||||
{
|
{
|
||||||
return mCapability;
|
return mCapability;
|
||||||
}
|
}
|
||||||
@@ -151,7 +157,7 @@ std::string Event::getCapability (void)
|
|||||||
*
|
*
|
||||||
* @brief return the ID of the Event.
|
* @brief return the ID of the Event.
|
||||||
*/
|
*/
|
||||||
uint16_t Event::getID (void)
|
uint16_t Event::getID (void) const
|
||||||
{
|
{
|
||||||
return mID;
|
return mID;
|
||||||
}
|
}
|
||||||
@@ -184,7 +190,7 @@ uint8_t Event::getMinute (void) const
|
|||||||
*
|
*
|
||||||
* @brief Return the Recurrency of the Event.
|
* @brief Return the Recurrency of the Event.
|
||||||
*/
|
*/
|
||||||
uint16_t Event::getRecurrence (void)
|
uint16_t Event::getRecurrence (void) const
|
||||||
{
|
{
|
||||||
return mRecurrence;
|
return mRecurrence;
|
||||||
}
|
}
|
||||||
@@ -195,7 +201,7 @@ uint16_t Event::getRecurrence (void)
|
|||||||
*
|
*
|
||||||
* @brief Return the Duration of the Event.
|
* @brief Return the Duration of the Event.
|
||||||
*/
|
*/
|
||||||
uint16_t Event::getDuration (void)
|
uint16_t Event::getDuration (void) const
|
||||||
{
|
{
|
||||||
return mDuration;
|
return mDuration;
|
||||||
}
|
}
|
||||||
@@ -206,7 +212,29 @@ uint16_t Event::getDuration (void)
|
|||||||
*
|
*
|
||||||
* @brief Return the Action of the Event.
|
* @brief Return the Action of the Event.
|
||||||
*/
|
*/
|
||||||
std::string Event::getAction (void)
|
std::string Event::getAction (void) const
|
||||||
{
|
{
|
||||||
return mAction;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,14 +50,18 @@ public:
|
|||||||
void Dump (void);
|
void Dump (void);
|
||||||
|
|
||||||
/* Getter */
|
/* Getter */
|
||||||
bool isActive (void);
|
bool isActive (void) const;
|
||||||
std::string getCapability (void);
|
std::string getCapability (void) const;
|
||||||
uint16_t getID (void);
|
uint16_t getID (void) const;
|
||||||
uint8_t getHour (void) const;
|
uint8_t getHour (void) const;
|
||||||
uint8_t getMinute (void) const;
|
uint8_t getMinute (void) const;
|
||||||
uint16_t getRecurrence (void);
|
uint16_t getRecurrence (void) const;
|
||||||
uint16_t getDuration (void);
|
uint16_t getDuration (void) const;
|
||||||
std::string getAction (void);
|
std::string getAction (void) const;
|
||||||
|
bool isInProgress (void) const;
|
||||||
|
|
||||||
|
/* Setter */
|
||||||
|
void setInProgress (bool aState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mActive;
|
bool mActive;
|
||||||
@@ -68,6 +72,7 @@ private:
|
|||||||
uint16_t mRecurrence;
|
uint16_t mRecurrence;
|
||||||
uint16_t mDuration;
|
uint16_t mDuration;
|
||||||
std::string mAction;
|
std::string mAction;
|
||||||
|
bool mInProgress;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _EVENT_H */
|
#endif /* _EVENT_H */
|
||||||
|
|||||||
@@ -139,12 +139,24 @@ int Timers::Expire (void)
|
|||||||
|
|
||||||
if ((*timer_evt).isActive()) {
|
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 {
|
else {
|
||||||
fprintf (stderr, "Time PAS identique\n");
|
|
||||||
|
if (theClock.isEqualToCurrentTime () {
|
||||||
|
|
||||||
|
(*timer_evt).setInProgress (true);
|
||||||
|
// Action START.
|
||||||
|
fprintf (stdout, "Timer Start\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user