fsfw/globalfunctions/PeriodicOperationDivider.cpp

45 lines
841 B
C++
Raw Normal View History

2020-09-10 19:53:52 +02:00
#include "PeriodicOperationDivider.h"
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider,
bool resetAutomatically): resetAutomatically(resetAutomatically),
counter(divider), divider(divider) {
}
bool PeriodicOperationDivider::checkAndIncrement() {
2020-12-01 17:08:46 +01:00
bool opNecessary = check();
if(opNecessary) {
2020-09-10 19:53:52 +02:00
if(resetAutomatically) {
counter = 0;
}
2020-12-01 17:08:46 +01:00
return opNecessary;
2020-09-10 19:53:52 +02:00
}
counter ++;
2020-12-01 17:08:46 +01:00
return opNecessary;
}
bool PeriodicOperationDivider::check() {
if(counter >= divider) {
return true;
}
2020-09-10 19:53:52 +02:00
return false;
}
2020-12-01 17:08:46 +01:00
2020-09-10 19:53:52 +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;
}