From a4fd5d26f5659d4a783b7ab0e321f8c2355cea88 Mon Sep 17 00:00:00 2001 From: "Jasper v. Blanckenburg" Date: Wed, 17 Jul 2024 16:42:32 +0200 Subject: [PATCH] Plausibility delay for SDC measurement --- Core/Src/main.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index c885119..7b49641 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -88,6 +88,16 @@ static void loop_delay() { } last_loop = HAL_GetTick(); } + +static void update_sdc() { + static int last[2] = {0, 0}; + int current = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == GPIO_PIN_SET; + if (last[0] == last[1] && last[0] == current) { + sdc_closed = current; + } + last[0] = last[1]; + last[1] = current; +} /* USER CODE END 0 */ /** @@ -138,8 +148,7 @@ int main(void) /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ - sdc_closed = HAL_GPIO_ReadPin(SDC_VOLTAGE_GPIO_Port, SDC_VOLTAGE_Pin) == - GPIO_PIN_SET; + update_sdc(); slaves_check(); shunt_check();