control burner based on table
This commit is contained in:
parent
9dd525457e
commit
e314b1a5b4
115
main/control.c
115
main/control.c
@ -10,7 +10,7 @@
|
||||
#define PERIODIC_INTERVAL 1U // run control loop every 1sec
|
||||
|
||||
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_DAY 30.0
|
||||
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 20.0
|
||||
#define RETURN_FLOW_TEMPERATURE_LOWER_LIMIT_NIGHT 25.0
|
||||
#define CHAMPER_TEMPERATURE_TARGET 70.0
|
||||
|
||||
static const char *TAG = "smart-oil-heater-control-system-control";
|
||||
@ -27,6 +27,8 @@ static sControlDay aControlTable[] = {
|
||||
};
|
||||
|
||||
void taskControl(void *pvParameters);
|
||||
eControlWeekday getCurrentWeekday(void);
|
||||
sControlTemperatureEntry getCurrentTemperatureEntry(void);
|
||||
|
||||
void initControl(void)
|
||||
{
|
||||
@ -51,6 +53,7 @@ void initControl(void)
|
||||
|
||||
void taskControl(void *pvParameters)
|
||||
{
|
||||
bool bHeatingInAction = false;
|
||||
while (1)
|
||||
{
|
||||
vTaskDelay(PERIODIC_INTERVAL * 1000U / portTICK_PERIOD_MS);
|
||||
@ -69,20 +72,38 @@ void taskControl(void *pvParameters)
|
||||
continue;
|
||||
}
|
||||
|
||||
// TODO: control the burner based on controltable
|
||||
setCirculationPumpState(DISABLED);
|
||||
setBurnerState(ENABLED);
|
||||
setSafetyControlState(ENABLED);
|
||||
sControlTemperatureEntry currentControlEntry = getCurrentTemperatureEntry();
|
||||
ESP_LOGI(TAG, "Control Entry Hour: %i Minute: %i ChamberTemp: %lf ReturnFlowTemp: %lf", currentControlEntry.timestamp.hour, currentControlEntry.timestamp.minute, currentControlEntry.fChamberTemperature, currentControlEntry.fReturnFlowTemperature);
|
||||
|
||||
int numberOfDays = sizeof(aControlTable) / sizeof(aControlTable[0]);
|
||||
ESP_LOGI(TAG, "Number of days: %i", numberOfDays);
|
||||
|
||||
for (int i = 0; i < numberOfDays; i++)
|
||||
if (getChamberTemperature().fCurrentValue >= currentControlEntry.fChamberTemperature)
|
||||
{
|
||||
ESP_LOGI(TAG, "Day %d: %d", i + 1, aControlTable[i].day);
|
||||
bHeatingInAction = false;
|
||||
setCirculationPumpState(ENABLED);
|
||||
setBurnerState(DISABLED);
|
||||
setSafetyControlState(ENABLED);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (bHeatingInAction)
|
||||
{
|
||||
// TODO: Check burner fault signal here
|
||||
}
|
||||
}
|
||||
|
||||
int numberOfEntries = aControlTable[i].entryCount;
|
||||
ESP_LOGI(TAG, "Number of entries: %i", numberOfEntries);
|
||||
if (bHeatingInAction == false)
|
||||
{
|
||||
if (getReturnFlowTemperature().average60s.fValue <= currentControlEntry.fReturnFlowTemperature)
|
||||
{
|
||||
bHeatingInAction = true;
|
||||
setCirculationPumpState(ENABLED);
|
||||
setBurnerState(ENABLED);
|
||||
setSafetyControlState(ENABLED);
|
||||
sControlState = CONTROL_HEATING;
|
||||
}
|
||||
else
|
||||
{
|
||||
sControlState = CONTROL_RETURN_FLOW_TOO_WARM;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,3 +112,73 @@ eControlState getControlState(void)
|
||||
{
|
||||
return sControlState;
|
||||
}
|
||||
|
||||
eControlWeekday getCurrentWeekday(void)
|
||||
{
|
||||
time_t now;
|
||||
struct tm *timeinfo;
|
||||
|
||||
// Get the current time
|
||||
time(&now);
|
||||
timeinfo = localtime(&now); // Convert to local time
|
||||
|
||||
// Get the day of the week (0 = Sunday, 1 = Monday, ..., 6 = Saturday)
|
||||
int day = timeinfo->tm_wday;
|
||||
|
||||
// Adjust so that Monday = 0, Sunday = 6
|
||||
if (day == 0)
|
||||
{
|
||||
day = 6; // Sunday becomes 6
|
||||
}
|
||||
else
|
||||
{
|
||||
day -= 1; // Shift other days to make Monday = 0
|
||||
}
|
||||
|
||||
return (eControlWeekday)day;
|
||||
}
|
||||
|
||||
sControlTemperatureEntry getCurrentTemperatureEntry(void)
|
||||
{
|
||||
sControlTemperatureEntry result = aControlTable[0].aTemperatureEntries[0];
|
||||
eControlWeekday currentDay = getCurrentWeekday();
|
||||
time_t now;
|
||||
struct tm timeinfo;
|
||||
|
||||
// Get the current time
|
||||
time(&now);
|
||||
// Convert to local time structure
|
||||
localtime_r(&now, &timeinfo);
|
||||
// Extract hour and minute
|
||||
int hour = timeinfo.tm_hour; // Hour (0-23)
|
||||
int minute = timeinfo.tm_min; // Minute (0-59)u
|
||||
|
||||
// ESP_LOGI(TAG, "Current Day: %i Hour: %i Minute: %i", currentDay, hour, minute);
|
||||
|
||||
for (int i = 0; i < sizeof(aControlTable) / sizeof(aControlTable[0]); i++)
|
||||
{
|
||||
/// loops through days
|
||||
// ESP_LOGI(TAG, "Day %d: %d", i + 1, aControlTable[i].day);
|
||||
// int numberOfEntries = aControlTable[i].entryCount;
|
||||
// ESP_LOGI(TAG, "Number of entries: %i", numberOfEntries);
|
||||
|
||||
for (int j = 0; j < aControlTable[i].entryCount; j++)
|
||||
{
|
||||
// ESP_LOGI(TAG, "SET Return Control Entry Day: %i Hour: %i Minute: %i ChamberTemp: %lf ReturnFlowTemp: %lf", aControlTable[i].day, aControlTable[i].aTemperatureEntries[j].timestamp.hour, aControlTable[i].aTemperatureEntries[j].timestamp.minute, aControlTable[i].aTemperatureEntries[j].fChamberTemperature, aControlTable[i].aTemperatureEntries[j].fReturnFlowTemperature);
|
||||
result = aControlTable[i].aTemperatureEntries[j];
|
||||
|
||||
if (((aControlTable[i].day + 1) % 6) >= currentDay)
|
||||
{
|
||||
if (aControlTable[i].aTemperatureEntries[j].timestamp.hour >= hour)
|
||||
{
|
||||
if (aControlTable[i].aTemperatureEntries[j].timestamp.minute >= minute)
|
||||
{
|
||||
// ESP_LOGI(TAG, "MINUTE Return Control Entry Day: %i Hour: %i Minute: %i ChamberTemp: %lf ReturnFlowTemp: %lf", aControlTable[i].day, aControlTable[i].aTemperatureEntries[j].timestamp.hour, aControlTable[i].aTemperatureEntries[j].timestamp.minute, aControlTable[i].aTemperatureEntries[j].fChamberTemperature, aControlTable[i].aTemperatureEntries[j].fReturnFlowTemperature);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
@ -22,7 +22,6 @@ typedef enum _ControlWeekday
|
||||
FRIDAY,
|
||||
SATURDAY,
|
||||
SUNDAY,
|
||||
WEEKDAY_COUNT
|
||||
} eControlWeekday;
|
||||
|
||||
typedef struct _ControlTimestamp
|
||||
@ -46,4 +45,4 @@ typedef struct _ControlDay
|
||||
} sControlDay;
|
||||
|
||||
void initControl(void);
|
||||
eControlState getControlState(void);
|
||||
eControlState getControlState(void);
|
||||
|
Loading…
Reference in New Issue
Block a user