diff --git a/main/control.c b/main/control.c index 473a0f4..7e6b262 100644 --- a/main/control.c +++ b/main/control.c @@ -0,0 +1,52 @@ +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "esp_log.h" +#include "control.h" +#include "outputs.h" +#include "inputs.h" +#include "safety.h" + +#define PERIODIC_INTERVAL 1U // run safety checks every 1sec + +static const char *TAG = "smart-oil-heater-control-system-control"; + +void taskControl(void *pvParameters); + +void initControl(void) +{ + + BaseType_t taskCreated = xTaskCreate( + taskControl, // Function to implement the task + "taskControl", // Task name + 4096, // Stack size (in words, not bytes) + NULL, // Parameters to the task function (none in this case) + 5, // Task priority (higher number = higher priority) + NULL // Task handle (optional) + ); + + if (taskCreated == pdPASS) + { + ESP_LOGI(TAG, "Task created successfully!"); + } + else + { + ESP_LOGE(TAG, "Failed to create task"); + } +} + +void taskControl(void *pvParameters) +{ + while (1) + { + vTaskDelay(PERIODIC_INTERVAL * 1000U / portTICK_PERIOD_MS); + + if (getSafetyState() == SAFETY_NO_ERROR) + { + // TODO: control the burner based on timetable + } + else + { + ESP_LOGW(TAG, "Control not possible due to safety fault!"); + } + } +} \ No newline at end of file diff --git a/main/control.h b/main/control.h index 473a0f4..67170a0 100644 --- a/main/control.h +++ b/main/control.h @@ -0,0 +1,3 @@ +#pragma once + +void initControl(void); \ No newline at end of file