fsfw/src/fsfw/globalfunctions/PeriodicOperationDivider.cpp

30 lines
835 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
2022-02-02 10:29:30 +01:00
PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider, bool resetAutomatically)
: resetAutomatically(resetAutomatically), divider(divider) {}
2020-09-10 19:53:52 +02:00
bool PeriodicOperationDivider::checkAndIncrement() {
2022-02-02 10:29:30 +01:00
bool opNecessary = check();
if (opNecessary and resetAutomatically) {
resetCounter();
} else {
counter++;
}
return opNecessary;
2020-12-01 17:08:46 +01:00
}
bool PeriodicOperationDivider::check() {
2022-02-02 10:29:30 +01:00
if (counter >= divider) {
return true;
}
return false;
2020-09-10 19:53:52 +02:00
}
2022-02-02 10:29:30 +01:00
void PeriodicOperationDivider::resetCounter() { counter = 1; }
2020-09-10 19:53:52 +02:00
2022-02-02 10:29:30 +01:00
void PeriodicOperationDivider::setDivider(uint32_t newDivider) { divider = newDivider; }
2020-09-10 19:53:52 +02:00
2022-02-02 10:29:30 +01:00
uint32_t PeriodicOperationDivider::getCounter() const { return counter; }
2020-09-10 19:53:52 +02:00
2022-02-02 10:29:30 +01:00
uint32_t PeriodicOperationDivider::getDivider() const { return divider; }