Skip to content

Commit

Permalink
v1.2.8
Browse files Browse the repository at this point in the history
- Added separate FreeRTOS Task for ProgramEngine worker
- Fix errors when compiling for ESP8266
- Automatically add POST data to APIRequest Data field
- Added timezone support
- Added ProgramEngine for creating automation programs using JavaScript
- Added Scheduler API (partial implementation) with Cron expression support
- Added `DISABLE_AUTOMATION` flag to disable automation ProgramEngine and Scheduler
- Code cleanup and libs update
  • Loading branch information
genemars committed Apr 20, 2024
1 parent 418c0f6 commit 09ea3c6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/HomeGenie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<TaskFunction_t>(Scheduler::loop),
Expand All @@ -91,7 +95,6 @@ namespace Service {
ESP_TASK_TIMER_PRIO - 1,
nullptr
);*/
/*
xTaskCreate(
reinterpret_cast<TaskFunction_t>(ProgramEngine::worker),
"ScheduledTask",
Expand All @@ -100,7 +103,8 @@ namespace Service {
tskIDLE_PRIORITY + 1,
nullptr
);
//*/
#endif

#endif

Logger::info("READY.");
Expand Down
15 changes: 9 additions & 6 deletions src/automation/ProgramEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ namespace Automation {
std::function<void(void*, const char* , ResponseCallback*)> ProgramEngine::apiRequest = nullptr;

ProgramEngine::ProgramEngine() {
#ifndef CONFIG_CREATE_AUTOMATION_TASK
// setLoopInterval(100);
#endif
};

void ProgramEngine::begin(std::function<void(void*, const char* , ResponseCallback*)> ar) {
ProgramEngine::apiRequest = std::move(ar);
}
/*

#ifdef CONFIG_CREATE_AUTOMATION_TASK
[[noreturn]] void ProgramEngine::worker() {
for(;;) {
auto jobs = &ProgramEngine::scheduleList;
Expand All @@ -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
#endif
8 changes: 7 additions & 1 deletion src/automation/ProgramEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<void(void*, const char* , ResponseCallback*)>);
// [[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<void(void*, const char* , ResponseCallback*)> apiRequest;
private:
Expand Down
2 changes: 1 addition & 1 deletion src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 09ea3c6

Please sign in to comment.