#include "espmega_iot_timer.hpp" void Timer::loop() { rtctime_t curtime = ESPMega_getTime(); if(today!=curtime.day) { today=curtime.day; timer_ran_today = false; ESPMega_FRAM.write8(fram_address,timer_ran_today); } if (!timer_ran_today && (hr < curtime.hours || (hr == curtime.hours && min <= curtime.minutes))) { timer_ran_today = true; ESPMega_FRAM.write8(fram_address,timer_ran_today); timer_callback(); } } Timer::Timer(uint8_t hour,uint8_t minute,void(*timer_callback)(), uint32_t fram_address) { rtctime_t curtime = ESPMega_getTime(); this-> today = curtime.day; this->hr = hour; this->min = minute; this->timer_callback = timer_callback; this->fram_address = fram_address; this-> timer_ran_today = ESPMega_FRAM.read8(fram_address); loop(); } void Timer::set(uint8_t hour,uint8_t minute) { rtctime_t curtime = ESPMega_getTime(); if ((hr < curtime.hours || (hr == curtime.hours && min <= curtime.minutes))) { this->timer_ran_today = true; ESPMega_FRAM.write8(fram_address,timer_ran_today); } else { this->timer_ran_today = false; ESPMega_FRAM.write8(fram_address,timer_ran_today); } hr = hour; min = minute; }