fsfw/timemanager/Countdown.cpp

39 lines
775 B
C++
Raw Normal View History

2020-09-22 02:12:02 +02:00
#include "Countdown.h"
2020-08-28 18:33:29 +02:00
2020-09-22 02:12:02 +02:00
Countdown::Countdown(uint32_t initialTimeout): startTime(0),
timeout(initialTimeout) {
2020-08-28 18:33:29 +02:00
}
Countdown::~Countdown() {
}
ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) {
ReturnValue_t return_value = Clock::getUptime( &startTime );
timeout = miliseconds;
return return_value;
}
bool Countdown::hasTimedOut() const {
uint32_t current_time;
Clock::getUptime( &current_time );
if ( uint32_t(current_time - startTime) >= timeout) {
return true;
} else {
return false;
}
}
bool Countdown::isBusy() const {
return !hasTimedOut();
}
ReturnValue_t Countdown::resetTimer() {
return setTimeout(timeout);
}
void Countdown::timeOut() {
uint32_t current_time;
Clock::getUptime( &current_time );
startTime= current_time - timeout;
}