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 */
/**
* @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 */