fsfw/globalfunctions/PeriodicOperationDivider.cpp

45 lines
841 B
C++
Raw Normal View History

#include "PeriodicOperationDivider.h"
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
bool resetAutomatically): resetAutomatically(resetAutomatically),
counter(divider), divider(divider) {
}
bool PeriodicOperationDivider::checkAndIncrement() {
2020-09-19 01:17:43 +02:00
bool opNecessary = check();
if(opNecessary) {
if(resetAutomatically) {
counter = 0;
}
2020-09-19 01:17:43 +02:00
return opNecessary;
}
counter ++;
2020-09-19 01:17:43 +02:00
return opNecessary;
}
bool PeriodicOperationDivider::check() {
if(counter >= divider) {
return true;
}
return false;
}
2020-09-19 01:17:43 +02:00
void PeriodicOperationDivider::resetCounter() {
counter = 0;
}
void PeriodicOperationDivider::setDivider(uint32_t newDivider) {
divider = newDivider;
}
uint32_t PeriodicOperationDivider::getCounter() const {
return counter;
}
uint32_t PeriodicOperationDivider::getDivider() const {
return divider;
}