From 6b8eb18df3778bac6262f44e3bc82185fb494d05 Mon Sep 17 00:00:00 2001 From: mooiweertje Date: Sat, 15 Nov 2025 20:23:16 +0100 Subject: [PATCH] heartBeat --- main/main.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/main/main.cpp b/main/main.cpp index d319148..e6643a2 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -64,6 +64,8 @@ static const int MEASURE_BAT_BIT = BIT7; static EventGroupHandle_t controlEventGroup; +volatile bool myTaskAlive = false; + enum messageHandlingResult { // We got a handoff back, so we get to send the next message CONTROL_TO_US, @@ -74,9 +76,17 @@ enum messageHandlingResult { }; static TimerHandle_t measureBatTimer; +TimerHandle_t healthCheckTimer ; static void measureBatTimerCallback(TimerHandle_t xTimer) { xEventGroupSetBits(controlEventGroup, MEASURE_BAT_BIT); } +static void checkMyTaskHealth(TimerHandle_t xTimer) { + if (!myTaskAlive) { + esp_restart(); + } + myTaskAlive = false; // Reset voor volgende check +} + static messageHandlingResult handleMotorMessage(ion_state * state) { messageType message = {}; readResult result; @@ -249,8 +259,10 @@ static void my_task(void *pvParameter) { initMotor(); measureBatTimer = xTimerCreate("measureBatTimer", (100 / portTICK_PERIOD_MS), pdTRUE, (void *)0, measureBatTimerCallback); - xTimerStart(measureBatTimer, 0); + + healthCheckTimer = xTimerCreate("healthCheckTimer", 60000 / portTICK_PERIOD_MS, pdTRUE, NULL, checkMyTaskHealth); + xTimerStart(healthCheckTimer, 0); ion_state state = { .state = IDLE, @@ -266,6 +278,8 @@ static void my_task(void *pvParameter) { while(true) { + myTaskAlive = true; // sign of life + // TODO: // More use of timeouts // See if we really need 8k stack (copying message structure a lot I guess)