From c50f36d8a97cf97637dff9afd7937724efef258d35bad6dab0cd7d552d20fce5 Mon Sep 17 00:00:00 2001 From: localhorst <localhorst@mosad.xyz> Date: Wed, 25 Dec 2024 18:09:04 +0100 Subject: [PATCH] improve fault handling --- main/control.c | 16 ++++++++++++++++ main/inputs.c | 3 ++- main/safety.c | 13 +------------ 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/main/control.c b/main/control.c index 0806907..76ea7e7 100644 --- a/main/control.c +++ b/main/control.c @@ -62,6 +62,14 @@ void taskControl(void *pvParameters) { ESP_LOGW(TAG, "Control not possible due to safety fault!"); sControlState = CONTROL_FAULT_SAFETY; + if (bHeatingInAction == true) + { + ESP_LOGI(TAG, "Control not possible due to safety fault: Disable burner"); + bHeatingInAction = false; + setCirculationPumpState(ENABLED); + setBurnerState(DISABLED); + setSafetyControlState(ENABLED); + } continue; } @@ -69,6 +77,14 @@ void taskControl(void *pvParameters) { ESP_LOGW(TAG, "Control not possible due to sntp fault!"); sControlState = CONTROL_FAULT_SNTP; + if (bHeatingInAction == true) + { + ESP_LOGI(TAG, "Control not possible due to sntp fault: Disable burner"); + bHeatingInAction = false; + setCirculationPumpState(ENABLED); + setBurnerState(DISABLED); + setSafetyControlState(ENABLED); + } continue; } diff --git a/main/inputs.c b/main/inputs.c index 67c374e..c418164 100644 --- a/main/inputs.c +++ b/main/inputs.c @@ -7,7 +7,7 @@ #include "inputs.h" #define MAX_DN18B20_SENSORS 4U -#define ONE_WIRE_LOOPS 2U // try to read the 1-Wire sensors that often +#define ONE_WIRE_LOOPS 4U // try to read the 1-Wire sensors that often #define PERIODIC_INTERVAL 1U // read and compute the inputs every 1sec static const char *TAG = "smart-oil-heater-control-system-inputs"; @@ -163,6 +163,7 @@ void taskInput(void *pvParameters) if (ds18x20_measure_and_read_multi(uDS18B20Pin, uOneWireAddresses, sSensorCount, fDS18B20Temps) != ESP_OK) { ESP_LOGE(TAG, "1-Wire devices read error"); + vTaskDelay(PERIODIC_INTERVAL * 100U / portTICK_PERIOD_MS); //Wait 100ms if bus error occurred } else { diff --git a/main/safety.c b/main/safety.c index db60a87..4bfccd5 100644 --- a/main/safety.c +++ b/main/safety.c @@ -155,16 +155,5 @@ void getSensorSanityStates(sSensorSanityCheck *pSensorSanityChecks) eSafetyState getSafetyState(void) { - eSafetyState state = SAFETY_NO_ERROR; - if (xSemaphoreTakeRecursive(xMutexAccessSafety, pdMS_TO_TICKS(5000)) == pdTRUE) - { - state = sSafetyState; - xSemaphoreGiveRecursive(xMutexAccessSafety); - } - else - { - state = SAFETY_INTERNAL_ERROR; - ESP_LOGE(TAG, "Unable to take mutex: getSafetyState()"); - } - return state; + return sSafetyState; } \ No newline at end of file