diff --git a/Core/Inc/gbk_text.h b/Core/Inc/gbk_text.h index 0b21f1f..dd4a7dd 100644 --- a/Core/Inc/gbk_text.h +++ b/Core/Inc/gbk_text.h @@ -27,11 +27,11 @@ extern const uint8_t text_massage_ended_GBK[]; // GBK文本长度宏(预计算,不含\0) #define text_device_name_LEN (10) -#define text_device_loading_LEN (16) -#define text_start_massage_LEN (8) -#define text_start_heating_LEN (8) -#define text_stop_massage_LEN (8) -#define text_stop_heating_LEN (8) +#define text_device_loading_LEN (20) +#define text_start_massage_LEN (10) +#define text_start_heating_LEN (10) +#define text_stop_massage_LEN (10) +#define text_stop_heating_LEN (10) #define text_massage_gear_1_LEN (13) #define text_massage_gear_2_LEN (13) #define text_massage_gear_3_LEN (13) @@ -41,11 +41,11 @@ extern const uint8_t text_massage_ended_GBK[]; #define text_massage_time_30_LEN (16) #define text_massage_time_cont_LEN (14) #define text_remaining_time_LEN (18) -#define text_heating_on_LEN (10) -#define text_heating_off_LEN (10) -#define text_massage_running_LEN (6) -#define text_massage_paused_LEN (10) -#define text_massage_ended_LEN (10) +#define text_heating_on_LEN (12) +#define text_heating_off_LEN (12) +#define text_massage_running_LEN (8) +#define text_massage_paused_LEN (12) +#define text_massage_ended_LEN (12) // 兼容旧代码的别名 #define text_device_name text_device_name_GBK diff --git a/Core/Inc/screen.h b/Core/Inc/screen.h index b11ceca..d51c359 100644 --- a/Core/Inc/screen.h +++ b/Core/Inc/screen.h @@ -84,7 +84,7 @@ void Screen_DrawText32V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t le void Screen_DrawText48_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color,uint8_t transparent); - +void Screen_ClearContent(void); #ifdef __cplusplus } #endif diff --git a/Core/Inc/stm32f1xx_it.h b/Core/Inc/stm32f1xx_it.h index d663de4..4e8eda7 100644 --- a/Core/Inc/stm32f1xx_it.h +++ b/Core/Inc/stm32f1xx_it.h @@ -52,6 +52,7 @@ void MemManage_Handler(void); void BusFault_Handler(void); void UsageFault_Handler(void); void DebugMon_Handler(void); +void USART3_IRQHandler(void); void TIM8_UP_IRQHandler(void); /* USER CODE BEGIN EFP */ diff --git a/Core/Src/freertos.c b/Core/Src/freertos.c index c9ed2d3..10d6253 100644 --- a/Core/Src/freertos.c +++ b/Core/Src/freertos.c @@ -19,14 +19,14 @@ /* Includes ------------------------------------------------------------------*/ #include "FreeRTOS.h" -#include "cmsis_os.h" -#include "gbk_text.h" -#include "main.h" #include "task.h" +#include "main.h" +#include "cmsis_os.h" /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ #include "elog.h" +#include "gbk_text.h" #include "motor_driver.h" #include "screen.h" #include "tim.h" @@ -36,7 +36,6 @@ #include #include - /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ @@ -79,37 +78,49 @@ static uint8_t time_state = 0; /* TIME_KEY 时间状态 */ /* Definitions for defaultTask */ osThreadId_t defaultTaskHandle; const osThreadAttr_t defaultTask_attributes = { - .name = "defaultTask", - .stack_size = 128 * 4, - .priority = (osPriority_t)osPriorityNormal, + .name = "defaultTask", + .stack_size = 128 * 4, + .priority = (osPriority_t) osPriorityNormal, }; /* Definitions for KeyTask */ osThreadId_t KeyTaskHandle; const osThreadAttr_t KeyTask_attributes = { - .name = "KeyTask", - .stack_size = 512 * 4, - .priority = (osPriority_t)osPriorityRealtime, + .name = "KeyTask", + .stack_size = 512 * 4, + .priority = (osPriority_t) osPriorityRealtime, }; /* Definitions for Sensor_Task */ osThreadId_t Sensor_TaskHandle; const osThreadAttr_t Sensor_Task_attributes = { - .name = "Sensor_Task", - .stack_size = 512 * 4, - .priority = (osPriority_t)osPriorityHigh7, + .name = "Sensor_Task", + .stack_size = 512 * 4, + .priority = (osPriority_t) osPriorityHigh7, }; /* Definitions for Motor_Task */ osThreadId_t Motor_TaskHandle; const osThreadAttr_t Motor_Task_attributes = { - .name = "Motor_Task", - .stack_size = 512 * 4, - .priority = (osPriority_t)osPriorityNormal1, + .name = "Motor_Task", + .stack_size = 512 * 4, + .priority = (osPriority_t) osPriorityNormal1, }; /* Definitions for Screen_Tsak */ osThreadId_t Screen_TsakHandle; const osThreadAttr_t Screen_Tsak_attributes = { - .name = "Screen_Tsak", - .stack_size = 1024 * 4, - .priority = (osPriority_t)osPriorityNormal, + .name = "Screen_Tsak", + .stack_size = 1024 * 4, + .priority = (osPriority_t) osPriorityNormal, +}; +/* Definitions for MP3_Play_Task */ +osThreadId_t MP3_Play_TaskHandle; +const osThreadAttr_t MP3_Play_Task_attributes = { + .name = "MP3_Play_Task", + .stack_size = 512 * 4, + .priority = (osPriority_t) osPriorityNormal, +}; +/* Definitions for init_ok */ +osEventFlagsId_t init_okHandle; +const osEventFlagsAttr_t init_ok_attributes = { + .name = "init_ok" }; /* Private function prototypes -----------------------------------------------*/ @@ -122,14 +133,15 @@ void Key(void *argument); void Sensor(void *argument); void Motor(void *argument); void Screen(void *argument); +void MP3(void *argument); void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */ /** - * @brief FreeRTOS initialization - * @param None - * @retval None - */ + * @brief FreeRTOS initialization + * @param None + * @retval None + */ void MX_FREERTOS_Init(void) { /* USER CODE BEGIN Init */ easylogger_init(); /* 初始化 EasyLogger */ @@ -155,8 +167,7 @@ void MX_FREERTOS_Init(void) { /* Create the thread(s) */ /* creation of defaultTask */ - defaultTaskHandle = - osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); + defaultTaskHandle = osThreadNew(StartDefaultTask, NULL, &defaultTask_attributes); /* creation of KeyTask */ KeyTaskHandle = osThreadNew(Key, NULL, &KeyTask_attributes); @@ -170,13 +181,21 @@ void MX_FREERTOS_Init(void) { /* creation of Screen_Tsak */ Screen_TsakHandle = osThreadNew(Screen, NULL, &Screen_Tsak_attributes); + /* creation of MP3_Play_Task */ + MP3_Play_TaskHandle = osThreadNew(MP3, NULL, &MP3_Play_Task_attributes); + /* USER CODE BEGIN RTOS_THREADS */ /* add threads, ... */ /* USER CODE END RTOS_THREADS */ + /* Create the event(s) */ + /* creation of init_ok */ + init_okHandle = osEventFlagsNew(&init_ok_attributes); + /* USER CODE BEGIN RTOS_EVENTS */ - /* add events, ... */ + /* USER CODE END RTOS_EVENTS */ + } /* USER CODE BEGIN Header_StartDefaultTask */ @@ -186,53 +205,37 @@ void MX_FREERTOS_Init(void) { * @retval None */ /* USER CODE END Header_StartDefaultTask */ -void StartDefaultTask(void *argument) { +void StartDefaultTask(void *argument) +{ /* USER CODE BEGIN StartDefaultTask */ - Screen_Init(); + Screen_Init(); - Screen_DrawText16_GBK(1, 30, text_device_loading,text_device_loading_LEN, TEXT_COLOR); - // 初始化命令 - uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00, - 0x00, 0x1E, 0xFE, 0xD7, 0xEF}; // 开启声音 - uint8_t init_cmd2[] = {0x7E, 0xFF, 0x06, 0x09, 0x00, - 0x00, 0x02, 0xFE, 0xF0, 0xEF}; // 指定播放设备为TF卡 + Screen_DrawText16_GBK(1, 30, text_device_loading, text_device_loading_LEN, + TEXT_COLOR); + - // 定义测试指令数据 - uint8_t test_cmd[] = {0x7E, 0xFF, 0x06, 0x12, 0x00, - 0x00, 0x01, 0xFE, 0xE8, 0xEF}; + // 等待bit0+bit1+bit2都被设置(所有模块初始化完成) + uint32_t flags = osEventFlagsWait( + init_okHandle, // 目标事件标志组 + (1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4), // 要等待的bit位(多个用|拼接) + osFlagsWaitAll, // 等待所有bit都被设置 + osWaitForever // 永久等待(直到满足条件) + ); + + if(flags == ((1<<0)|(1<<1)|(1<<2)|(1<<3)|(1<<4))) { + Screen_ClearContent(); + // 所有初始化完成,开始执行按摩逻辑 + Screen_DrawText16V_GBK(1, 30, text_stop_massage, text_stop_massage_LEN, 15); + } - // 先让模块稳定 - osDelay(2000); - - // 初始化:先发送开启声音指令,再发送指定播放设备指令 - HAL_UART_Transmit(&huart3, init_cmd1, sizeof(init_cmd1), 1000); - elog_d("MP3", - "发送的消息是:%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", - init_cmd1[0], init_cmd1[1], init_cmd1[2], init_cmd1[3], init_cmd1[4], - init_cmd1[5], init_cmd1[6], init_cmd1[7], init_cmd1[8], init_cmd1[9]); - osDelay(1500); // 重要:等待模块响应 - - HAL_UART_Transmit(&huart3, init_cmd2, sizeof(init_cmd2), 1000); - elog_d("MP3", - "发送的消息是:%02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", - init_cmd2[0], init_cmd2[1], init_cmd2[2], init_cmd2[3], init_cmd2[4], - init_cmd2[5], init_cmd2[6], init_cmd2[7], init_cmd2[8], init_cmd2[9]); - osDelay(1500); // 重要:等待初始化完成 + elog_d("Init","完成所有的初始化"); /* Infinite loop */ for (;;) { - // 直接整包发送测试指令 - HAL_UART_Transmit(&huart3, test_cmd, sizeof(test_cmd), 1000); - // 把发送的数据打印出来 - elog_d("mp3_cmd", - "发送测试指令: %02X %02X %02X %02X %02X %02X %02X %02X %02X %02X", - test_cmd[0], test_cmd[1], test_cmd[2], test_cmd[3], test_cmd[4], - test_cmd[5], test_cmd[6], test_cmd[7], test_cmd[8], test_cmd[9]); + // 可选:等待发送完成 // while(__HAL_UART_GET_FLAG(&huart3, UART_FLAG_TC) == RESET); - HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin); - osDelay(10000); // 延时1秒 } /* USER CODE END StartDefaultTask */ @@ -245,8 +248,10 @@ void StartDefaultTask(void *argument) { * @retval None */ /* USER CODE END Header_Key */ -void Key(void *argument) { +void Key(void *argument) +{ /* USER CODE BEGIN Key */ + elog_d("Init", "Key task started"); /* 防抖轮询实现四个低电平有效按键检测 */ GPIO_TypeDef *key_ports[4] = {M__KEY_GPIO_Port, M__KEYC7_GPIO_Port, HOT_KEY_GPIO_Port, TIME_KEY_GPIO_Port}; @@ -258,6 +263,8 @@ void Key(void *argument) { uint8_t pressed[4] = {0}; const uint8_t THRESH = 3; /* 3 * 10ms = 30ms 防抖 */ + osEventFlagsSet(init_okHandle, 1<<0); // 设置初始化完成标志 + for (;;) { for (int i = 0; i < 4; i++) { GPIO_PinState level = HAL_GPIO_ReadPin(key_ports[i], key_pins[i]); @@ -289,9 +296,13 @@ void Key(void *argument) { * @retval None */ /* USER CODE END Header_Sensor */ -void Sensor(void *argument) { +void Sensor(void *argument) +{ /* USER CODE BEGIN Sensor */ + elog_d("Init", "Sensor task started"); /* 按键处理任务 - 按键状态切换控制 */ + osEventFlagsSet(init_okHandle, 1<<1); + /* Infinite loop */ for (;;) { @@ -349,12 +360,18 @@ void Sensor(void *argument) { * @retval None */ /* USER CODE END Header_Motor */ -void Motor(void *argument) { +void Motor(void *argument) +{ /* USER CODE BEGIN Motor */ + elog_d("Init", "Motor task started"); /* 电机驱动初始化 */ Motor_Init(); + osEventFlagsSet(init_okHandle, 1<<2); + + + /* Infinite loop */ for (;;) { /* 电机任务主要功能: @@ -367,6 +384,7 @@ void Motor(void *argument) { uint8_t current_gear = Motor_GetGear(); elog_i("Motor", "当前档位: %u (0=停止,1=低,2=中,3=高)", current_gear); + HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin); osDelay(1000); } /* USER CODE END Motor */ @@ -379,18 +397,69 @@ void Motor(void *argument) { * @retval None */ /* USER CODE END Header_Screen */ -void Screen(void *argument) { +void Screen(void *argument) +{ /* USER CODE BEGIN Screen */ + elog_d("Init", "Screen task started"); + + osEventFlagsSet(init_okHandle, 1<<3); // HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY); /* Infinite loop */ for (;;) { - } /* USER CODE END Screen */ } +/* USER CODE BEGIN Header_MP3 */ + + + + +/** +* @brief Function implementing the MP3_Play_Task thread. +* @param argument: Not used +* @retval None +*/ +/* USER CODE END Header_MP3 */ +void MP3(void *argument) +{ + /* USER CODE BEGIN MP3 */ + elog_d("Init", "MP3 task started"); + uint8_t init_cmd1[] = {0x7E, 0xFF, 0x06, 0x06, 0x00, 0x00, 0x1E, 0xFE, 0xD7, 0xEF}; // 开启声音 + uint8_t init_cmd2[] = {0x7E, 0xFF, 0x06, 0x09, 0x00, 0x00, 0x02, 0xFE, 0xF0, 0xEF}; // TF卡 + uint8_t play_cmd[] = {0x7E, 0xFF, 0x06, 0x12, 0x00, 0x00, 0x01, 0xFE, 0xE8, 0xEF}; // 播放文件1 + + + + // 等待模块上电稳定 + osDelay(2000); + + // 发送初始化命令1,等待模块 ACK + HAL_UART_Transmit(&huart3, init_cmd1, sizeof(init_cmd1), 100); + + + // 发送初始化命令2 + HAL_UART_Transmit(&huart3, init_cmd2, sizeof(init_cmd2), 100); + + + elog_i("MP3", "模块初始化完成"); + osEventFlagsSet(init_okHandle, 1<<4); + + + /* Infinite loop */ + for(;;) + { + // 发送播放命令 + HAL_UART_Transmit(&huart3, play_cmd, sizeof(play_cmd), 100); + + osDelay(10000); + } + /* USER CODE END MP3 */ +} + /* Private application code --------------------------------------------------*/ /* USER CODE BEGIN Application */ /* USER CODE END Application */ + diff --git a/Core/Src/gbk_text.c b/Core/Src/gbk_text.c index 5c1e019..5b51c2b 100644 --- a/Core/Src/gbk_text.c +++ b/Core/Src/gbk_text.c @@ -4,25 +4,25 @@ // 对应GBK编码:0xD6, 0xC7, 0xC4, 0xDC, 0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xC7 const uint8_t text_device_name_GBK[] = {0xD6, 0xC7, 0xC4, 0xDC, 0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xC7}; -// 对应文本(UTF8):设备加载中请稍候 -// 对应GBK编码:0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2 -const uint8_t text_device_loading_GBK[] = {0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2}; +// 对应文本(UTF8):设备加载中,请稍候! +// 对应GBK编码:0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xA3, 0xAC, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2, 0xA3, 0xA1 +const uint8_t text_device_loading_GBK[] = {0xC9, 0xE8, 0xB1, 0xB8, 0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0, 0xA3, 0xAC, 0xC7, 0xEB, 0xC9, 0xD4, 0xBA, 0xF2, 0xA3, 0xA1}; -// 对应文本(UTF8):开始按摩 -// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6 -const uint8_t text_start_massage_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6}; +// 对应文本(UTF8):开始按摩! +// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6, 0xA3, 0xA1 +const uint8_t text_start_massage_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xB0, 0xB4, 0xC4, 0xA6, 0xA3, 0xA1}; -// 对应文本(UTF8):开始加热 -// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8 -const uint8_t text_start_heating_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8}; +// 对应文本(UTF8):开始加热! +// 对应GBK编码:0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8, 0xA3, 0xA1 +const uint8_t text_start_heating_GBK[] = {0xBF, 0xAA, 0xCA, 0xBC, 0xBC, 0xD3, 0xC8, 0xC8, 0xA3, 0xA1}; -// 对应文本(UTF8):停止按摩 -// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6 -const uint8_t text_stop_massage_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6}; +// 对应文本(UTF8):停止按摩! +// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6, 0xA3, 0xA1 +const uint8_t text_stop_massage_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xB0, 0xB4, 0xC4, 0xA6, 0xA3, 0xA1}; -// 对应文本(UTF8):停止加热 -// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8 -const uint8_t text_stop_heating_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8}; +// 对应文本(UTF8):停止加热! +// 对应GBK编码:0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8, 0xA3, 0xA1 +const uint8_t text_stop_heating_GBK[] = {0xCD, 0xA3, 0xD6, 0xB9, 0xBC, 0xD3, 0xC8, 0xC8, 0xA3, 0xA1}; // 对应文本(UTF8):按摩档位:1级 // 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x31, 0xBC, 0xB6 @@ -60,23 +60,23 @@ const uint8_t text_massage_time_cont_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1 // 对应GBK编码:0xCA, 0xA3, 0xD3, 0xE0, 0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xCE, 0xAA, 0xA3, 0xBA, 0x25, 0x64 const uint8_t text_remaining_time_GBK[] = {0xCA, 0xA3, 0xD3, 0xE0, 0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xCE, 0xAA, 0xA3, 0xBA, 0x25, 0x64}; -// 对应文本(UTF8):加热已开启 -// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4 -const uint8_t text_heating_on_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4}; +// 对应文本(UTF8):加热已开启! +// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4, 0xA3, 0xA1 +const uint8_t text_heating_on_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xBF, 0xAA, 0xC6, 0xF4, 0xA3, 0xA1}; -// 对应文本(UTF8):加热已关闭 -// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5 -const uint8_t text_heating_off_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5}; +// 对应文本(UTF8):加热已关闭! +// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5, 0xA3, 0xA1 +const uint8_t text_heating_off_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xD2, 0xD1, 0xB9, 0xD8, 0xB1, 0xD5, 0xA3, 0xA1}; -// 对应文本(UTF8):按摩中 -// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0 -const uint8_t text_massage_running_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0}; +// 对应文本(UTF8):按摩中! +// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0, 0xA3, 0xA1 +const uint8_t text_massage_running_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD6, 0xD0, 0xA3, 0xA1}; -// 对应文本(UTF8):按摩已暂停 -// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3 -const uint8_t text_massage_paused_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3}; +// 对应文本(UTF8):按摩已暂停! +// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3, 0xA3, 0xA1 +const uint8_t text_massage_paused_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3, 0xA3, 0xA1}; -// 对应文本(UTF8):按摩已结束 -// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8 -const uint8_t text_massage_ended_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8}; +// 对应文本(UTF8):按摩已结束! +// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8, 0xA3, 0xA1 +const uint8_t text_massage_ended_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8, 0xA3, 0xA1}; diff --git a/Core/Src/screen.c b/Core/Src/screen.c index 0caf853..b475005 100644 --- a/Core/Src/screen.c +++ b/Core/Src/screen.c @@ -15,6 +15,7 @@ #include #include #include "gbk_text.h" +#include "elog.h" /* 发送缓冲 */ static uint8_t txbuf[512]; @@ -320,4 +321,17 @@ void Screen_Ver(void) uint16_t p=0; p=buf_str(p,"VER();\r\n"); send_buf(p); -} \ No newline at end of file +} + +/** + * @brief 清除内容区(保留标题和边框) + * @note 假设屏幕分辨率 128x128,标题高度28像素,边框占1像素 + */ +void Screen_ClearContent(void) +{ + elog_i("Screen", "Clearing screen content..."); + // 内容区域坐标: + // 左上角 x=1, y=28(标题下方一行) + // 右下角 x=126, y=127(屏幕右下角) + Screen_BoxFill(1, 28, 126, 127, BG_COLOR); +} diff --git a/Core/Src/stm32f1xx_it.c b/Core/Src/stm32f1xx_it.c index abfd5ba..45a30ce 100644 --- a/Core/Src/stm32f1xx_it.c +++ b/Core/Src/stm32f1xx_it.c @@ -55,6 +55,7 @@ /* USER CODE END 0 */ /* External variables --------------------------------------------------------*/ +extern UART_HandleTypeDef huart3; extern TIM_HandleTypeDef htim8; /* USER CODE BEGIN EV */ @@ -159,6 +160,20 @@ void DebugMon_Handler(void) /* please refer to the startup file (startup_stm32f1xx.s). */ /******************************************************************************/ +/** + * @brief This function handles USART3 global interrupt. + */ +void USART3_IRQHandler(void) +{ + /* USER CODE BEGIN USART3_IRQn 0 */ + + /* USER CODE END USART3_IRQn 0 */ + HAL_UART_IRQHandler(&huart3); + /* USER CODE BEGIN USART3_IRQn 1 */ + + /* USER CODE END USART3_IRQn 1 */ +} + /** * @brief This function handles TIM8 update interrupt. */ diff --git a/Core/Src/usart.c b/Core/Src/usart.c index fc8b0d9..39d06eb 100644 --- a/Core/Src/usart.c +++ b/Core/Src/usart.c @@ -197,6 +197,9 @@ void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle) GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + /* USART3 interrupt Init */ + HAL_NVIC_SetPriority(USART3_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(USART3_IRQn); /* USER CODE BEGIN USART3_MspInit 1 */ /* USER CODE END USART3_MspInit 1 */ @@ -258,6 +261,8 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* uartHandle) */ HAL_GPIO_DeInit(GPIOB, GPIO_PIN_10|GPIO_PIN_11); + /* USART3 interrupt Deinit */ + HAL_NVIC_DisableIRQ(USART3_IRQn); /* USER CODE BEGIN USART3_MspDeInit 1 */ /* USER CODE END USART3_MspDeInit 1 */ diff --git a/Development_Docs/Serial_Screen_Docs/UTF8-GBK/text_utf8.txt b/Development_Docs/Serial_Screen_Docs/UTF8-GBK/text_utf8.txt index 0d1c2d7..e699196 100644 --- a/Development_Docs/Serial_Screen_Docs/UTF8-GBK/text_utf8.txt +++ b/Development_Docs/Serial_Screen_Docs/UTF8-GBK/text_utf8.txt @@ -1,10 +1,10 @@ # 按摩仪核心文本 text_device_name=智能按摩仪 -text_device_loading=设备加载中请稍候 -text_start_massage=开始按摩 -text_start_heating=开始加热 -text_stop_massage=停止按摩 -text_stop_heating=停止加热 +text_device_loading=设备加载中,请稍候! +text_start_massage=开始按摩! +text_start_heating=开始加热! +text_stop_massage=停止按摩! +text_stop_heating=停止加热! text_massage_gear_1=按摩档位:1级 text_massage_gear_2=按摩档位:2级 text_massage_gear_3=按摩档位:3级 @@ -16,8 +16,8 @@ text_massage_time_cont=按摩时间:持续 text_remaining_time=剩余按摩时间为:%d # 补充辅助文本) -text_heating_on=加热已开启 -text_heating_off=加热已关闭 -text_massage_running=按摩中 -text_massage_paused=按摩已暂停 -text_massage_ended=按摩已结束 +text_heating_on=加热已开启! +text_heating_off=加热已关闭! +text_massage_running=按摩中! +text_massage_paused=按摩已暂停! +text_massage_ended=按摩已结束! diff --git a/anmo.ioc b/anmo.ioc index a9d4f1f..3a431e3 100644 --- a/anmo.ioc +++ b/anmo.ioc @@ -2,9 +2,10 @@ CAD.formats= CAD.pinconfig= CAD.provider= +FREERTOS.Events01=init_ok,Dynamic,NULL FREERTOS.FootprintOK=true -FREERTOS.IPParameters=Tasks01,FootprintOK,configTOTAL_HEAP_SIZE -FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;KeyTask,48,512,Key,Default,NULL,Dynamic,NULL,NULL;Sensor_Task,47,512,Sensor,Default,NULL,Dynamic,NULL,NULL;Motor_Task,25,512,Motor,Default,NULL,Dynamic,NULL,NULL;Screen_Tsak,24,1024,Screen,Default,NULL,Dynamic,NULL,NULL +FREERTOS.IPParameters=Tasks01,FootprintOK,configTOTAL_HEAP_SIZE,Events01 +FREERTOS.Tasks01=defaultTask,24,128,StartDefaultTask,Default,NULL,Dynamic,NULL,NULL;KeyTask,48,512,Key,Default,NULL,Dynamic,NULL,NULL;Sensor_Task,47,512,Sensor,Default,NULL,Dynamic,NULL,NULL;Motor_Task,25,512,Motor,Default,NULL,Dynamic,NULL,NULL;Screen_Tsak,24,1024,Screen,Default,NULL,Dynamic,NULL,NULL;MP3_Play_Task,24,512,MP3,Default,NULL,Dynamic,NULL,NULL FREERTOS.configTOTAL_HEAP_SIZE=15000 File.Version=6 GPIO.groupedBy=Group By Peripherals @@ -68,6 +69,7 @@ NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:false\:true\:false\:true\:false NVIC.TIM8_UP_IRQn=true\:15\:0\:false\:false\:true\:false\:false\:true\:true NVIC.TimeBase=TIM8_UP_IRQn NVIC.TimeBaseIP=TIM8 +NVIC.USART3_IRQn=true\:5\:0\:false\:false\:true\:true\:true\:true\:true NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false\:false PA10.Locked=true PA10.Mode=Asynchronous