2024-04-03 07:04:55 +07:00
|
|
|
#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
|
2024-04-08 10:15:45 +07:00
|
|
|
*
|
2024-04-03 07:04:55 +07:00
|
|
|
* @param period Period in ms
|
|
|
|
*/
|
|
|
|
void AgSchedule::setPeriod(int period) { this->period = period; }
|
2024-04-08 10:15:45 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Update period
|
|
|
|
*/
|
|
|
|
void AgSchedule::update(void) { count = millis(); }
|