2020-09-10 19:51:17 +02:00
|
|
|
#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) {
|
2020-09-10 19:51:17 +02:00
|
|
|
if(resetAutomatically) {
|
|
|
|
counter = 0;
|
|
|
|
}
|
2020-09-19 01:17:43 +02:00
|
|
|
return opNecessary;
|
2020-09-10 19:51:17 +02:00
|
|
|
}
|
|
|
|
counter ++;
|
2020-09-19 01:17:43 +02:00
|
|
|
return opNecessary;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool PeriodicOperationDivider::check() {
|
|
|
|
if(counter >= divider) {
|
|
|
|
return true;
|
|
|
|
}
|
2020-09-10 19:51:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-19 01:17:43 +02:00
|
|
|
|
|
|
|
|
2020-09-10 19:51:17 +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;
|
|
|
|
}
|