fsfw/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp

45 lines
942 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),
counter(divider), divider(divider) {
2020-09-10 19:53:52 +02:00
}
bool PeriodicOperationDivider::checkAndIncrement() {
bool opNecessary = check();
if(opNecessary) {
if(resetAutomatically) {
2021-09-17 13:07:43 +02:00
counter = 1;
}
2021-09-20 18:29:57 +02:00
return opNecessary;
}
2021-09-17 13:07:43 +02:00
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
}
2020-12-01 17:08:46 +01:00
2020-09-10 19:53:52 +02:00
void PeriodicOperationDivider::resetCounter() {
counter = 0;
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
}