From d1bcf7e3602c707c3b1d2f8a8547dbe9570cbb9f Mon Sep 17 00:00:00 2001 From: Mysteo91 Date: Tue, 1 Aug 2023 11:24:26 +0300 Subject: [PATCH] ---vl6180dr --- App/app.cpp | 16 ++++++++-------- main_prog/Core/Src/gpio.c | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/App/app.cpp b/App/app.cpp index fe2360a..7d8a1ea 100644 --- a/App/app.cpp +++ b/App/app.cpp @@ -75,7 +75,7 @@ void AppInit(void) uint8_t temp[2]; uint32_t controlPinMs = 0; uint8_t controlPinFlag = 0; -uint8_t controlPinHighStart = 0; +uint32_t controlPinDetectedMs = 0; uint8_t updateMode = 0; void zummerOff (void) @@ -153,15 +153,15 @@ void AppTask(void) lightStartMs = 0; lightingOff(); } - if (HAL_GPIO_ReadPin(CONTROL_PIN_GPIO_Port, CONTROL_PIN_Pin) == GPIO_PIN_SET) { - if (controlPinFlag == 0) - { - controlPinHighStart = HAL_GetTick(); + if (HAL_GPIO_ReadPin(CONTROL_PIN_GPIO_Port, CONTROL_PIN_Pin) == GPIO_PIN_RESET && controlPinFlag == 0) { + controlPinDetectedMs = HAL_GetTick(); controlPinFlag = 1; - } - } else if (controlPinFlag == 1) { + } else if (controlPinFlag == 1 && HAL_GPIO_ReadPin(CONTROL_PIN_GPIO_Port, CONTROL_PIN_Pin) == GPIO_PIN_SET ) { controlPinFlag = 0; - uint32_t ms = HAL_GetTick() - controlPinHighStart; + uint32_t ms = 0; + if (controlPinDetectedMs != 0) + ms = HAL_GetTick() - controlPinDetectedMs; + controlPinDetectedMs = 0; if (ms >= 5000 && ms < 5200) { ////////Update mode HAL_UART_DeInit(&huart1); diff --git a/main_prog/Core/Src/gpio.c b/main_prog/Core/Src/gpio.c index a4c73d9..5f957ce 100644 --- a/main_prog/Core/Src/gpio.c +++ b/main_prog/Core/Src/gpio.c @@ -74,7 +74,7 @@ void MX_GPIO_Init(void) /*Configure GPIO pin : PtPin */ GPIO_InitStruct.Pin = CONTROL_PIN_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; - GPIO_InitStruct.Pull = GPIO_PULLDOWN; + GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(CONTROL_PIN_GPIO_Port, &GPIO_InitStruct); /* EXTI interrupt init*/