Files
arduino/src/AgSchedule.cpp
2024-04-08 10:15:45 +07:00

27 lines
519 B
C++

#include "AgSchedule.h"
AgSchedule::AgSchedule(int period, void (*handler)(void))
: period(period), handler(handler) {}
AgSchedule::~AgSchedule() {}
void AgSchedule::run(void) {
uint32_t ms = (uint32_t)(millis() - count);
if (ms >= period) {
handler();
count = millis();
}
}
/**
* @brief Set schedule period
*
* @param period Period in ms
*/
void AgSchedule::setPeriod(int period) { this->period = period; }
/**
* @brief Update period
*/
void AgSchedule::update(void) { count = millis(); }