fsfw/src/fsfw/timemanager/Countdown.h

81 lines
1.8 KiB
C
Raw Normal View History

2020-12-15 23:00:30 +01:00
#ifndef FSFW_TIMEMANAGER_COUNTDOWN_H_
#define FSFW_TIMEMANAGER_COUNTDOWN_H_
#include "Clock.h"
/**
2021-09-27 19:57:42 +02:00
*
* Countdown keeps track of a timespan.
*
* Countdown::resetTimer restarts the timer.
* Countdown::setTimeout sets a new countdown duration and resets.
*
* Can be checked with Countdown::hasTimedOut or
* Countdown::isBusy.
*
* Countdown::timeOut will force the timer to time out.
*
*/
class Countdown {
public:
2021-09-27 19:57:42 +02:00
/**
* Constructor which sets the countdown duration in milliseconds
*
* It does not start the countdown!
* Call resetTimer or setTimeout before usage!
* Otherwise a call to hasTimedOut might return True.
*
* @param initialTimeout Countdown duration in milliseconds
*/
Countdown(uint32_t initialTimeout = 0);
~Countdown();
2021-09-27 19:57:42 +02:00
/**
* Call to set a new countdown duration.
*
* Resets the countdown!
*
* @param milliseconds new countdown duration in milliseconds
* @return Returnvalue from Clock::getUptime
*/
ReturnValue_t setTimeout(uint32_t milliseconds);
/**
* Returns true if the countdown duration has passed.
*
* @return True if the countdown has passed
* False if it is still running
*/
bool hasTimedOut() const;
2021-09-27 19:57:42 +02:00
/**
* Complementary to hasTimedOut.
*
* @return True if the countdown is till running
* False if it is still running
*/
bool isBusy() const;
2021-09-27 19:57:42 +02:00
/**
* Uses last set timeout value and restarts timer.
*/
2020-12-15 23:00:30 +01:00
ReturnValue_t resetTimer();
2021-09-27 19:57:42 +02:00
/**
* Returns the remaining milliseconds (0 if timeout)
*/
uint32_t getRemainingMillis() const;
/**
* Makes hasTimedOut() return true
*/
2020-12-15 23:00:30 +01:00
void timeOut();
2021-09-27 19:57:42 +02:00
/**
* Internal countdown duration in milliseconds
*/
uint32_t timeout;
2020-12-15 23:00:30 +01:00
private:
2021-09-27 19:57:42 +02:00
/**
* Last time the timer was started (uptime)
*/
2020-12-15 23:00:30 +01:00
uint32_t startTime = 0;
2021-09-27 19:57:42 +02:00
uint32_t getCurrentTime() const;
};
2020-12-15 23:00:30 +01:00
#endif /* FSFW_TIMEMANAGER_COUNTDOWN_H_ */