Timer();
~Timer();
- /**
- * @brief Sets timer's amount of hours
- *
- * This value is added to the whole timer's countdown time.
- * After it reaches 0, the timer's ring alarm is called.
- *
- * @param[in] hour The hour to be set
- */
- void SetHour(int hour);
-
- /**
- * @brief Sets timer's amount of minutes
- *
- * This value is added to the whole timer's countdown time.
- * After it reaches 0, the timer's ring alarm is called.
- *
- * @param[in] minute The minute to be set
- */
- void SetMinute(int minute);
-
- /**
- * @brief Sets timer's amount of seconds
- *
- * This value is added to the whole timer's countdown time.
- * After it reaches 0, the timer's ring alarm is called.
- *
- * @param[in] second The second to be set
- */
- void SetSecond(int second);
-
- /**
- * @brief Gets timer's hour
- *
- * @return Number of timer's hours
- */
- unsigned GetHour(void) const;
-
- /**
- * @brief Gets timer's minutes
- *
- * @return Number of timer's minutes
- */
- unsigned GetMinute(void) const;
-
- /**
- * @brief Gets timer's seconds
- *
- * @return Number of timer's seconds
- */
- unsigned GetSecond(void) const;
-
/**
* @brief Sets total timer's countdown time
*
- * @param[in] hour The timer's hour
- * @param[in] minute The timer's minute
- * @param[in] second The timer's second
+ * @param[in] time Time in seconds
*/
- void SetTime(int hour, int minute, int second);
+ void SetTime(seconds time);
/**
* @brief Activates alarm after delay.
*/
seconds GetRemainingTime(void);
private:
- unsigned hour_;
- unsigned minute_;
- unsigned second_;
+ seconds remaining_time_ = seconds(0);
- int alarm_id_;
+ int alarm_id_ = 0;
static app_control_h CreateAppControl(void);
};
namespace model {
-Timer::Timer() : hour_(0), minute_(0), second_(0), alarm_id_(0)
+Timer::Timer()
{
}
{
}
-void Timer::SetHour(int hour)
+void Timer::SetTime(seconds time)
{
- if (hour > 99)
- hour = 0;
- else if (hour < 0)
- hour = 99;
-
- hour_ = hour;
-}
-
-void Timer::SetMinute(int minute)
-{
- if (minute > 59)
- minute = 0;
- else if (minute < 0)
- minute = 59;
-
- minute_ = minute;
-}
-
-void Timer::SetSecond(int second)
-{
- if (second > 59)
- second = 0;
- else if (second < 0)
- second = 59;
-
- second_ = second;
-}
-
-void Timer::SetTime(int hour, int minute, int second)
-{
- SetHour(hour);
- SetMinute(minute);
- SetSecond(second);
-}
-
-unsigned Timer::GetHour(void) const
-{
- return hour_;
-}
-
-unsigned Timer::GetMinute(void) const
-{
- return minute_;
-}
-
-unsigned Timer::GetSecond(void) const
-{
- return second_;
+ remaining_time_ = time;
}
seconds Timer::GetRemainingTime(void)
{
- seconds time = seconds(hour_ * 3600 + minute_ * 60 + second_);
-
- return time - GetTime();
+ return remaining_time_ - Counter::GetTime();
}
app_control_h Timer::CreateAppControl()
int hour = 0, minute = 0, second = 0;
view_->GetTime(&hour, &minute, &second);
-
- DBG("hour: %d min: %d src: %d", hour, minute, second);
-
- model_->SetTime(hour, minute, second);
+ model_->SetTime(std::chrono::seconds(hour * 3600 + minute * 60 + second));
if (!model_->Run())
return;