Refactor main.c for improved readability and update display cursor positions

This commit is contained in:
2025-05-18 16:37:47 +02:00
parent 344d0000fa
commit b227f9d074
3 changed files with 35 additions and 28 deletions
+27 -28
View File
@@ -76,9 +76,9 @@ void parseIncommingPacket(uint8_t *_packet, incomming_data_t *_data);
/* USER CODE END 0 */ /* USER CODE END 0 */
/** /**
* @brief The application entry point. * @brief The application entry point.
* @retval int * @retval int
*/ */
int main(void) int main(void)
{ {
@@ -205,27 +205,27 @@ int main(void)
if (R_Data.state == 1) if (R_Data.state == 1)
{ {
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET); 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_PrintStr("Prichod OK");
HD44780_SetCursor(0, 1); HD44780_SetCursor(0, 1);
char name[15]; char name[17];
sprintf(name, "%10s,%1s.", R_Data.surname, R_Data.name); snprintf(name, sizeof(name), "%.*s,%.*s.", 13, R_Data.surname, 1, R_Data.name);
HD44780_PrintStr(name); HD44780_PrintStr(name);
} }
else if (R_Data.state == 2) else if (R_Data.state == 2)
{ {
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET); 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_PrintStr("Odchod OK");
HD44780_SetCursor(0, 1); HD44780_SetCursor(0, 1);
char name[15]; char name[17];
sprintf(name, "%10s,%1s.", R_Data.surname, R_Data.name); snprintf(name, sizeof(name), "%.*s,%.*s.", 13, R_Data.surname, 1, R_Data.name);
HD44780_PrintStr(name); HD44780_PrintStr(name);
} }
else if (R_Data.state == 0) else if (R_Data.state == 0)
{ {
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET); 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_PrintStr("Chyba");
HD44780_SetCursor(0, 1); HD44780_SetCursor(0, 1);
HD44780_PrintStr("Zkuste to znovu"); HD44780_PrintStr("Zkuste to znovu");
@@ -255,17 +255,17 @@ int main(void)
} }
/** /**
* @brief System Clock Configuration * @brief System Clock Configuration
* @retval None * @retval None
*/ */
void SystemClock_Config(void) void SystemClock_Config(void)
{ {
RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
/** Initializes the RCC Oscillators according to the specified parameters /** 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.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1; RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
@@ -279,9 +279,8 @@ void SystemClock_Config(void)
} }
/** Initializes the CPU, AHB and APB buses clocks /** Initializes the CPU, AHB and APB buses clocks
*/ */
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
@@ -380,9 +379,9 @@ PUTCHAR_PROTOTYPE
/* USER CODE END 4 */ /* USER CODE END 4 */
/** /**
* @brief This function is executed in case of error occurrence. * @brief This function is executed in case of error occurrence.
* @retval None * @retval None
*/ */
void Error_Handler(void) void Error_Handler(void)
{ {
/* USER CODE BEGIN Error_Handler_Debug */ /* USER CODE BEGIN Error_Handler_Debug */
@@ -391,14 +390,14 @@ void Error_Handler(void)
/* USER CODE END Error_Handler_Debug */ /* 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 * @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred. * where the assert_param error has occurred.
* @param file: pointer to the source file name * @param file: pointer to the source file name
* @param line: assert_param error line source number * @param line: assert_param error line source number
* @retval None * @retval None
*/ */
void assert_failed(uint8_t *file, uint32_t line) void assert_failed(uint8_t *file, uint32_t line)
{ {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
Binary file not shown.
+8
View File
@@ -57,3 +57,11 @@
27 243 1747578320796622150 cmake/stm32cubemx/CMakeFiles/STM32_Drivers.dir/__/__/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_uart.c.obj 4a83760c6970da49 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 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 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