From b227f9d07473d596541ba6d435c56d9d19449b3e Mon Sep 17 00:00:00 2001 From: Eduard Dlabal Date: Sun, 18 May 2025 16:37:47 +0200 Subject: [PATCH] Refactor main.c for improved readability and update display cursor positions --- Core/Src/main.c | 55 ++++++++++++++++++++-------------------- build/Debug/.ninja_deps | Bin 26988 -> 28220 bytes build/Debug/.ninja_log | 8 ++++++ 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/Core/Src/main.c b/Core/Src/main.c index 59702c7..816583a 100644 --- a/Core/Src/main.c +++ b/Core/Src/main.c @@ -76,9 +76,9 @@ void parseIncommingPacket(uint8_t *_packet, incomming_data_t *_data); /* USER CODE END 0 */ /** - * @brief The application entry point. - * @retval int - */ + * @brief The application entry point. + * @retval int + */ int main(void) { @@ -205,27 +205,27 @@ int main(void) if (R_Data.state == 1) { HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET); - HD44780_SetCursor(1, 0); + HD44780_SetCursor(3, 0); HD44780_PrintStr("Prichod OK"); HD44780_SetCursor(0, 1); - char name[15]; - sprintf(name, "%10s,%1s.", R_Data.surname, R_Data.name); + char name[17]; + snprintf(name, sizeof(name), "%.*s,%.*s.", 13, R_Data.surname, 1, R_Data.name); HD44780_PrintStr(name); } else if (R_Data.state == 2) { HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET); - HD44780_SetCursor(1, 0); + HD44780_SetCursor(3, 0); HD44780_PrintStr("Odchod OK"); HD44780_SetCursor(0, 1); - char name[15]; - sprintf(name, "%10s,%1s.", R_Data.surname, R_Data.name); + char name[17]; + snprintf(name, sizeof(name), "%.*s,%.*s.", 13, R_Data.surname, 1, R_Data.name); HD44780_PrintStr(name); } else if (R_Data.state == 0) { HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET); - HD44780_SetCursor(1, 0); + HD44780_SetCursor(4, 0); HD44780_PrintStr("Chyba"); HD44780_SetCursor(0, 1); HD44780_PrintStr("Zkuste to znovu"); @@ -255,17 +255,17 @@ int main(void) } /** - * @brief System Clock Configuration - * @retval None - */ + * @brief System Clock Configuration + * @retval None + */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; /** Initializes the RCC Oscillators according to the specified parameters - * in the RCC_OscInitTypeDef structure. - */ + * in the RCC_OscInitTypeDef structure. + */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; @@ -279,9 +279,8 @@ void SystemClock_Config(void) } /** Initializes the CPU, AHB and APB buses clocks - */ - RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK - |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2; + */ + RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; @@ -380,9 +379,9 @@ PUTCHAR_PROTOTYPE /* USER CODE END 4 */ /** - * @brief This function is executed in case of error occurrence. - * @retval None - */ + * @brief This function is executed in case of error occurrence. + * @retval None + */ void Error_Handler(void) { /* USER CODE BEGIN Error_Handler_Debug */ @@ -391,14 +390,14 @@ void Error_Handler(void) /* USER CODE END Error_Handler_Debug */ } -#ifdef USE_FULL_ASSERT +#ifdef USE_FULL_ASSERT /** - * @brief Reports the name of the source file and the source line number - * where the assert_param error has occurred. - * @param file: pointer to the source file name - * @param line: assert_param error line source number - * @retval None - */ + * @brief Reports the name of the source file and the source line number + * where the assert_param error has occurred. + * @param file: pointer to the source file name + * @param line: assert_param error line source number + * @retval None + */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ diff --git a/build/Debug/.ninja_deps b/build/Debug/.ninja_deps index 5a726e7e4952932deeb1dcf53aa45823c3233041..c5a4bb1d8a648106291e850a9675e2e03281f76a 100644 GIT binary patch delta 89 zcmaEJiE+;z#tk`{dkiAQg9dIE4Y~&{a delta 9 QcmdmUhw;rN#tk`{02+e?-T(jq diff --git a/build/Debug/.ninja_log b/build/Debug/.ninja_log index 9ef15b8..86b7e7f 100644 --- a/build/Debug/.ninja_log +++ b/build/Debug/.ninja_log @@ -57,3 +57,11 @@ 27 243 1747578320796622150 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c.obj 4a83760c6970da49 5 284 1747578320836229032 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_i2c.c.obj c0e6a05b8bf26b38 284 341 1747578320892496514 LightTAM_RFID_Reader.elf 9d2867053cc90835 +0 72 1747578651608456255 CMakeFiles/LightTAM_RFID_Reader.dir/Core/Src/main.c.obj c2dc3f2732657e0d +72 126 1747578651660961016 LightTAM_RFID_Reader.elf 9d2867053cc90835 +1 86 1747578723903939202 CMakeFiles/LightTAM_RFID_Reader.dir/Core/Src/main.c.obj c2dc3f2732657e0d +86 143 1747578723959352794 LightTAM_RFID_Reader.elf 9d2867053cc90835 +1 76 1747578794545109526 CMakeFiles/LightTAM_RFID_Reader.dir/Core/Src/main.c.obj c2dc3f2732657e0d +76 137 1747578794604722166 LightTAM_RFID_Reader.elf 9d2867053cc90835 +0 76 1747578865865574378 CMakeFiles/LightTAM_RFID_Reader.dir/Core/Src/main.c.obj c2dc3f2732657e0d +76 131 1747578865918977708 LightTAM_RFID_Reader.elf 9d2867053cc90835