simplify the clock object.
This commit is contained in:
@@ -47,17 +47,6 @@ Clock::~Clock(void)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
|
||||||
* @fn set
|
|
||||||
*
|
|
||||||
* @brief Set a time (hour/minute) to the Clock.
|
|
||||||
*/
|
|
||||||
int Clock::set(void)
|
|
||||||
{
|
|
||||||
m_now = time(NULL);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! ----------------------------------------------------------------------------
|
/*! ----------------------------------------------------------------------------
|
||||||
* @fn is_equal_to_timer
|
* @fn is_equal_to_timer
|
||||||
@@ -69,17 +58,18 @@ bool Clock::is_equal_to_timer(const Timer &a_timer)
|
|||||||
struct tm the_compared_time;
|
struct tm the_compared_time;
|
||||||
double the_diff;
|
double the_diff;
|
||||||
|
|
||||||
the_compared_time = *localtime(&m_now);
|
time_t the_time = time(NULL);
|
||||||
|
|
||||||
printf ("=>Hour: %.2d h %.2d\n", the_compared_time.tm_hour, the_compared_time.tm_min);
|
the_compared_time = *localtime(&the_time);
|
||||||
|
|
||||||
|
printf ("=>Timer: (%.2d h %.2d) Now: (%.2d h %.2d)\n", a_timer.get_hour(),a_timer.get_minute(),
|
||||||
|
the_compared_time.tm_hour, the_compared_time.tm_min);
|
||||||
|
|
||||||
the_compared_time.tm_hour = a_timer.get_hour();
|
the_compared_time.tm_hour = a_timer.get_hour();
|
||||||
the_compared_time.tm_min = a_timer.get_minute();
|
the_compared_time.tm_min = a_timer.get_minute();
|
||||||
|
|
||||||
the_diff = difftime(m_now, mktime(&the_compared_time));
|
the_diff = difftime(the_time, mktime(&the_compared_time));
|
||||||
|
// printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
|
||||||
printf ("=>Timer: %.2d h %.2d\n", a_timer.get_hour(),a_timer.get_minute());
|
|
||||||
printf ("%.f seconds of diff between current time and Timer time.\n", the_diff);
|
|
||||||
|
|
||||||
if (the_diff == 0)
|
if (the_diff == 0)
|
||||||
return true;
|
return true;
|
||||||
@@ -98,14 +88,15 @@ bool Clock::is_expired(uint16_t a_duration)
|
|||||||
struct tm the_compared_time;
|
struct tm the_compared_time;
|
||||||
double the_diff;
|
double the_diff;
|
||||||
|
|
||||||
the_compared_time = *localtime(&m_now);
|
time_t the_time = time(NULL);
|
||||||
|
the_compared_time = *localtime(&the_time);
|
||||||
|
|
||||||
// the_compared_time.tm_hour = m_hour;
|
// the_compared_time.tm_hour = m_hour;
|
||||||
// the_compared_time.tm_min = m_minute;
|
// the_compared_time.tm_min = m_minute;
|
||||||
|
|
||||||
the_expired = mktime(&the_compared_time) + (a_duration * 60);
|
the_expired = mktime(&the_compared_time) + (a_duration * 60);
|
||||||
|
|
||||||
the_diff = difftime(m_now, the_expired);
|
the_diff = difftime(the_time, the_expired);
|
||||||
|
|
||||||
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);
|
//printf ("%.f seconds of diff between %lld and %lld.\n", theDiff, mNow, theExpired);
|
||||||
|
|
||||||
|
|||||||
@@ -44,13 +44,8 @@ class Clock
|
|||||||
Clock(void);
|
Clock(void);
|
||||||
~Clock(void);
|
~Clock(void);
|
||||||
|
|
||||||
int set(void);
|
static bool is_equal_to_timer(const Timer &a_timer);
|
||||||
|
static bool is_expired(uint16_t a_duration);
|
||||||
bool is_equal_to_timer(const Timer &a_timer);
|
|
||||||
bool is_expired(uint16_t a_duration);
|
|
||||||
|
|
||||||
private:
|
|
||||||
time_t m_now;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _CLOCK_H */
|
#endif /* _CLOCK_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user