fsfw/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp

42 lines
894 B
C++
Raw Normal View History

2021-07-13 20:22:54 +02:00
#include "fsfw/globalfunctions/PeriodicOperationDivider.h"
2020-09-10 19:53:52 +02:00
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
bool resetAutomatically): resetAutomatically(resetAutomatically),
divider(divider) {
2020-09-10 19:53:52 +02:00
}
bool PeriodicOperationDivider::checkAndIncrement() {
bool opNecessary = check();
if(opNecessary and resetAutomatically) {
resetCounter();
}
else {
counter++;
}
return opNecessary;
2020-12-01 17:08:46 +01:00
}
bool PeriodicOperationDivider::check() {
if(counter >= divider) {
return true;
}
return false;
2020-09-10 19:53:52 +02:00
}
void PeriodicOperationDivider::resetCounter() {
counter = 1;
2020-09-10 19:53:52 +02:00
}
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
divider = newDivider;
2020-09-10 19:53:52 +02:00
}
uint32_t PeriodicOperationDivider::getCounter() const {
return counter;
2020-09-10 19:53:52 +02:00
}
uint32_t PeriodicOperationDivider::getDivider() const {
return divider;
2020-09-10 19:53:52 +02:00
}