2020-08-13 20:53:35 +02:00
|
|
|
#include "Countdown.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-12-15 23:00:30 +01:00
|
|
|
Countdown::Countdown(uint32_t initialTimeout): timeout(initialTimeout) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Countdown::~Countdown() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t Countdown::setTimeout(uint32_t miliseconds) {
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t return_value = Clock::getUptime( &startTime );
|
2016-06-15 23:48:41 +02:00
|
|
|
timeout = miliseconds;
|
|
|
|
return return_value;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Countdown::hasTimedOut() const {
|
|
|
|
uint32_t current_time;
|
2018-07-12 16:29:32 +02:00
|
|
|
Clock::getUptime( ¤t_time );
|
2016-06-15 23:48:41 +02:00
|
|
|
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);
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
void Countdown::timeOut() {
|
|
|
|
uint32_t current_time;
|
|
|
|
Clock::getUptime( ¤t_time );
|
|
|
|
startTime= current_time - timeout;
|
|
|
|
}
|