diff --git a/firmware/components/sen5x/sen5x_app.c b/firmware/components/sen5x/sen5x_app.c index a72d4ca..0480181 100644 --- a/firmware/components/sen5x/sen5x_app.c +++ b/firmware/components/sen5x/sen5x_app.c @@ -244,6 +244,7 @@ static void sen5x_task_producer(void* arg) { } ESP_LOGI(TAG, "Producer stopping."); + g_task_prod = NULL; vTaskDelete(NULL); } @@ -259,6 +260,7 @@ esp_err_t sen5x_app_init(const sen5x_i2c_cfg_t* cfg) { // 1) I2C-Subsystem + // 2) HAL-Konfiguration struct esp32_i2c_config hal_cfg = { .addr = cfg->addr, @@ -306,32 +308,30 @@ void sen5x_app_deinit(void) { ESP_LOGI(TAG, "Deinitializing SEN5x app..."); - // Producer stoppen - g_run = false; + g_run = false; // Producer freundlich bitten zu stoppen - if (g_task_prod) { - vTaskDelete(g_task_prod); - g_task_prod = NULL; + // Warten, bis der Producer sich selbst beendet hat + for (int i = 0; i < 50 && g_task_prod; i++) { + vTaskDelay(pdMS_TO_TICKS(10)); } - // Influx worker stoppen net_influx_stop(); - // Device Tag if (g_device_tag) { free(g_device_tag); g_device_tag = NULL; } - // Sensor stoppen & HAL freigeben sen5x_stop_measurement(); sensirion_i2c_hal_free(); - i2cdev_done(); + + // i2cdev_done(); // NICHT hier, da Bus global genutzt wird g_inited = false; ESP_LOGI(TAG, "SEN5x app deinitialized."); } + /** * Kompatibilität zur bisherigen main.c: * Diese Task fungiert nun als "Launcher": startet Producer und beendet sich dann.