cron timer implemented
This commit is contained in:
parent
cabef176aa
commit
1612c0a830
|
|
@ -23,7 +23,9 @@
|
||||||
#include "AppConfiguration.h"
|
#include "AppConfiguration.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
static cron_job *jobs[CRON_TIMERS_NUMBER];
|
#define TAG "CRON_TIMER"
|
||||||
|
|
||||||
|
static cron_job *JobsList[CRON_TIMERS_NUMBER];
|
||||||
|
|
||||||
void custom_cron_job_callback(cron_job *job)
|
void custom_cron_job_callback(cron_job *job)
|
||||||
{
|
{
|
||||||
|
|
@ -31,7 +33,7 @@ void custom_cron_job_callback(cron_job *job)
|
||||||
int obj = ((cron_timer_t*) job->data)->obj;
|
int obj = ((cron_timer_t*) job->data)->obj;
|
||||||
char *name = ((cron_timer_t*) job->data)->name;
|
char *name = ((cron_timer_t*) job->data)->name;
|
||||||
//here call all timers jobs depends on object and action
|
//here call all timers jobs depends on object and action
|
||||||
ESP_LOGI("CRON_TIMER", "Executed timer '%s' action %d under object %d", name, act, obj);
|
ESP_LOGI(TAG, "Executed timer '%s' action %d under object %d", name, act, obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,33 +45,23 @@ esp_err_t InitCronSheduler()
|
||||||
|
|
||||||
esp_err_t ReloadCronSheduler()
|
esp_err_t ReloadCronSheduler()
|
||||||
{
|
{
|
||||||
static bool isStarted = false;
|
//remove all jobs
|
||||||
esp_err_t res = ESP_OK;
|
ESP_LOGI(TAG,"Cron stop call result %d",cron_stop());
|
||||||
bool isJobsPresents = false;
|
cron_job_clear_all();
|
||||||
|
//check if we have jobs to run
|
||||||
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
for (int i = 0; i < CRON_TIMERS_NUMBER; i++)
|
||||||
{
|
{
|
||||||
if (jobs[i] != NULL)
|
|
||||||
{
|
|
||||||
cron_job_destroy(jobs[i]);
|
|
||||||
jobs[i] = NULL;
|
|
||||||
}
|
|
||||||
if (!GetAppConf()->Timers[i].del && GetAppConf()->Timers[i].enab)
|
if (!GetAppConf()->Timers[i].del && GetAppConf()->Timers[i].enab)
|
||||||
{
|
{
|
||||||
|
JobsList[i] = cron_job_create(GetAppConf()->Timers[i].cron, custom_cron_job_callback,
|
||||||
jobs[i] = cron_job_create(GetAppConf()->Timers[i].cron, custom_cron_job_callback,
|
(void*) &GetAppConf()->Timers[i]);
|
||||||
(void*) &GetAppConf()->Timers[i]);
|
|
||||||
isJobsPresents = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
int jobs_num = cron_job_node_count();
|
||||||
|
ESP_LOGI(TAG, "In config presents %d jobs", jobs_num);
|
||||||
|
|
||||||
|
if (jobs_num > 0)
|
||||||
if (isJobsPresents && !isStarted)
|
ESP_LOGI(TAG,"Cron start call result %d",cron_start());
|
||||||
{
|
return ESP_OK;
|
||||||
cron_start();
|
|
||||||
isStarted = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user