52 lines
1.3 KiB
C
52 lines
1.3 KiB
C
#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!");
|
|
}
|
|
}
|
|
} |