diff --git a/src/HomeGenie.cpp b/src/HomeGenie.cpp index 5e0c69d..cdd6c56 100644 --- a/src/HomeGenie.cpp +++ b/src/HomeGenie.cpp @@ -76,12 +76,16 @@ namespace Service { } #ifndef DISABLE_AUTOMATION + // init automation programs engine Automation::ProgramEngine::begin([this](void* sender, const char* apiCommand, ResponseCallback* callback){ this->onNetRequest(sender, apiCommand, callback); }); + // set scheduler callback Automation::Scheduler::setListener(this); + +#ifdef CONFIG_CREATE_AUTOMATION_TASK /* xTaskCreate( reinterpret_cast(Scheduler::loop), @@ -91,7 +95,6 @@ namespace Service { ESP_TASK_TIMER_PRIO - 1, nullptr );*/ - /* xTaskCreate( reinterpret_cast(ProgramEngine::worker), "ScheduledTask", @@ -100,7 +103,8 @@ namespace Service { tskIDLE_PRIORITY + 1, nullptr ); - //*/ +#endif + #endif Logger::info("READY."); diff --git a/src/automation/ProgramEngine.cpp b/src/automation/ProgramEngine.cpp index 43576e2..5bbfeb3 100644 --- a/src/automation/ProgramEngine.cpp +++ b/src/automation/ProgramEngine.cpp @@ -41,13 +41,16 @@ namespace Automation { std::function ProgramEngine::apiRequest = nullptr; ProgramEngine::ProgramEngine() { +#ifndef CONFIG_CREATE_AUTOMATION_TASK // setLoopInterval(100); +#endif }; void ProgramEngine::begin(std::function ar) { ProgramEngine::apiRequest = std::move(ar); } - /* + +#ifdef CONFIG_CREATE_AUTOMATION_TASK [[noreturn]] void ProgramEngine::worker() { for(;;) { auto jobs = &ProgramEngine::scheduleList; @@ -58,20 +61,20 @@ namespace Automation { vTaskDelay(portTICK_PERIOD_MS * 100); } } - //*/ - //* +#else void ProgramEngine::loop() { auto jobs = &ProgramEngine::scheduleList; - while (jobs->size() > 0) { + if (jobs->size() > 0) { ScheduledScript scheduledScript(jobs->shift()); scheduledScript.run(); } } - //*/ +#endif + void ProgramEngine::run(Schedule* schedule) { ProgramEngine::scheduleList.add(schedule); } } -#endif \ No newline at end of file +#endif diff --git a/src/automation/ProgramEngine.h b/src/automation/ProgramEngine.h index e1531e9..b52eb8c 100644 --- a/src/automation/ProgramEngine.h +++ b/src/automation/ProgramEngine.h @@ -43,13 +43,19 @@ namespace Automation { using namespace Net; class ProgramEngine +#ifndef CONFIG_CREATE_AUTOMATION_TASK : Task +#endif { public: ProgramEngine(); static void begin(std::function); -// [[noreturn]] static void worker(); + +#ifdef CONFIG_CREATE_AUTOMATION_TASK + [[noreturn]] static void worker(); +#else void loop() override; +#endif static void run(Schedule*); static std::function apiRequest; private: diff --git a/src/defs.h b/src/defs.h index 2df26fa..5e07463 100644 --- a/src/defs.h +++ b/src/defs.h @@ -38,7 +38,7 @@ #define DEBUGLOG_DEFAULT_LOG_LEVEL_ERROR -//#define DISABLE_AUTOMATION +#define CONFIG_CREATE_AUTOMATION_TASK #ifdef ESP8266 #define ESP_WIFI_STATUS WiFi.status()