```
refactor(gbk_text): 重构GBK文本常量定义并优化命名 移除过时的文本定义,使用更简洁通用的名称替换原有特定功能的文本 常量,并更新相应的长度定义和别名映射。 BREAKING CHANGE: 原有的特定功能文本常量已被移除,需使用新的通 用名称进行访问。 ```
This commit is contained in:
@@ -5,68 +5,47 @@
|
||||
|
||||
// GBK文本数组声明(定义在gbk_text.c中)
|
||||
extern const uint8_t text_device_name_GBK[];
|
||||
extern const uint8_t text_device_loading_GBK[];
|
||||
extern const uint8_t text_start_massage_GBK[];
|
||||
extern const uint8_t text_start_heating_GBK[];
|
||||
extern const uint8_t text_stop_massage_GBK[];
|
||||
extern const uint8_t text_stop_heating_GBK[];
|
||||
extern const uint8_t text_massage_gear_1_GBK[];
|
||||
extern const uint8_t text_massage_gear_2_GBK[];
|
||||
extern const uint8_t text_massage_gear_3_GBK[];
|
||||
extern const uint8_t text_massage_time_10_GBK[];
|
||||
extern const uint8_t text_massage_time_15_GBK[];
|
||||
extern const uint8_t text_massage_time_20_GBK[];
|
||||
extern const uint8_t text_massage_time_30_GBK[];
|
||||
extern const uint8_t text_massage_time_cont_GBK[];
|
||||
extern const uint8_t text_remaining_time_GBK[];
|
||||
extern const uint8_t text_heating_on_GBK[];
|
||||
extern const uint8_t text_heating_off_GBK[];
|
||||
extern const uint8_t text_massage_running_GBK[];
|
||||
extern const uint8_t text_massage_paused_GBK[];
|
||||
extern const uint8_t text_massage_ended_GBK[];
|
||||
extern const uint8_t text_loading_GBK[];
|
||||
extern const uint8_t text_massage_on_GBK[];
|
||||
extern const uint8_t text_massage_off_GBK[];
|
||||
extern const uint8_t text_heat_on_GBK[];
|
||||
extern const uint8_t text_heat_off_GBK[];
|
||||
extern const uint8_t text_gear_GBK[];
|
||||
extern const uint8_t text_time_GBK[];
|
||||
extern const uint8_t text_cont_GBK[];
|
||||
extern const uint8_t text_remaining_GBK[];
|
||||
extern const uint8_t text_running_GBK[];
|
||||
extern const uint8_t text_paused_GBK[];
|
||||
extern const uint8_t text_ended_GBK[];
|
||||
|
||||
// GBK文本长度宏(预计算,不含\0)
|
||||
#define text_device_name_LEN (10)
|
||||
#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)
|
||||
#define text_massage_time_10_LEN (16)
|
||||
#define text_massage_time_15_LEN (16)
|
||||
#define text_massage_time_20_LEN (16)
|
||||
#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 (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_loading_LEN (6)
|
||||
#define text_massage_on_LEN (8)
|
||||
#define text_massage_off_LEN (8)
|
||||
#define text_heat_on_LEN (8)
|
||||
#define text_heat_off_LEN (8)
|
||||
#define text_gear_LEN (4)
|
||||
#define text_time_LEN (6)
|
||||
#define text_cont_LEN (4)
|
||||
#define text_remaining_LEN (8)
|
||||
#define text_running_LEN (6)
|
||||
#define text_paused_LEN (6)
|
||||
#define text_ended_LEN (6)
|
||||
|
||||
// 兼容旧代码的别名
|
||||
#define text_device_name text_device_name_GBK
|
||||
#define text_device_loading text_device_loading_GBK
|
||||
#define text_start_massage text_start_massage_GBK
|
||||
#define text_start_heating text_start_heating_GBK
|
||||
#define text_stop_massage text_stop_massage_GBK
|
||||
#define text_stop_heating text_stop_heating_GBK
|
||||
#define text_massage_gear_1 text_massage_gear_1_GBK
|
||||
#define text_massage_gear_2 text_massage_gear_2_GBK
|
||||
#define text_massage_gear_3 text_massage_gear_3_GBK
|
||||
#define text_massage_time_10 text_massage_time_10_GBK
|
||||
#define text_massage_time_15 text_massage_time_15_GBK
|
||||
#define text_massage_time_20 text_massage_time_20_GBK
|
||||
#define text_massage_time_30 text_massage_time_30_GBK
|
||||
#define text_massage_time_cont text_massage_time_cont_GBK
|
||||
#define text_remaining_time text_remaining_time_GBK
|
||||
#define text_heating_on text_heating_on_GBK
|
||||
#define text_heating_off text_heating_off_GBK
|
||||
#define text_massage_running text_massage_running_GBK
|
||||
#define text_massage_paused text_massage_paused_GBK
|
||||
#define text_massage_ended text_massage_ended_GBK
|
||||
#define text_loading text_loading_GBK
|
||||
#define text_massage_on text_massage_on_GBK
|
||||
#define text_massage_off text_massage_off_GBK
|
||||
#define text_heat_on text_heat_on_GBK
|
||||
#define text_heat_off text_heat_off_GBK
|
||||
#define text_gear text_gear_GBK
|
||||
#define text_time text_time_GBK
|
||||
#define text_cont text_cont_GBK
|
||||
#define text_remaining text_remaining_GBK
|
||||
#define text_running text_running_GBK
|
||||
#define text_paused text_paused_GBK
|
||||
#define text_ended text_ended_GBK
|
||||
|
||||
#endif // __GBK_TEXT_H__
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file screen.h
|
||||
* @brief 串口屏驱动接口(用于 JC 系列串口屏,使用 USART1)
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file screen.h
|
||||
* @brief 串口屏驱动接口(用于 JC 系列串口屏,使用 USART1)
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#ifndef __SCREEN_H__
|
||||
@@ -15,10 +15,37 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
/* 颜色使用统一的标志 */
|
||||
#define TEXT_COLOR 15 /* 白色 */
|
||||
#define BG_COLOR 0 /* 黑色 */
|
||||
#define BG_COLOR 0 /* 黑色 */
|
||||
|
||||
|
||||
#define SCREEN_LEFT 1
|
||||
#define SCREEN_RIGHT 126
|
||||
|
||||
#define TITLE_LINE_Y 28
|
||||
#define ZONE1_LINE_Y 60
|
||||
#define ZONE2_LINE_Y 93
|
||||
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint16_t y_clear_start; // 清除区域起始
|
||||
uint16_t y_clear_end; // 清除区域结束
|
||||
uint16_t y_text; // 文本基线
|
||||
} ScreenZone_t;
|
||||
|
||||
|
||||
static const ScreenZone_t g_zones[3] =
|
||||
{
|
||||
{29, 60, 37}, // Zone1
|
||||
{61, 93, 69}, // Zone2
|
||||
{94, 126, 102} // Zone3
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -44,47 +71,71 @@ void Screen_DrawText16(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
/* 额外封装命令 */
|
||||
void Screen_SetRotation(uint8_t dir);
|
||||
void Screen_SetBaud(uint32_t baud);
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode);
|
||||
void Screen_DisplayImageByIndex(uint32_t index, uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint8_t mode);
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, uint8_t mode);
|
||||
void Screen_DisplayImageByIndex(uint32_t index, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, uint8_t mode);
|
||||
void Screen_Pixel(uint16_t x, uint16_t y, uint8_t color);
|
||||
void Screen_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color);
|
||||
void Screen_Box(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color);
|
||||
void Screen_BoxFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint8_t color);
|
||||
void Screen_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color);
|
||||
void Screen_Box(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color);
|
||||
void Screen_BoxFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color);
|
||||
void Screen_Circle(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
||||
void Screen_CircleFill(uint16_t x, uint16_t y, uint16_t r, uint8_t color);
|
||||
void Screen_SetBGColor(uint8_t color);
|
||||
void Screen_DrawText16V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk_buf, uint16_t gbk_len, uint8_t color);
|
||||
void Screen_DrawText16V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk_buf,
|
||||
uint16_t gbk_len, uint8_t color);
|
||||
/* 带/不带背景的文本 */
|
||||
void Screen_DrawText16V(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
void Screen_DrawText16V(uint16_t x, uint16_t y, const char *text,
|
||||
uint8_t color);
|
||||
void Screen_DrawText24(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
void Screen_DrawText24V(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
void Screen_DrawText24V(uint16_t x, uint16_t y, const char *text,
|
||||
uint8_t color);
|
||||
void Screen_DrawText32(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
void Screen_DrawText32V(uint16_t x, uint16_t y, const char *text, uint8_t color);
|
||||
void Screen_DrawText48(uint16_t x, uint16_t y, const char *text, uint8_t color, uint8_t transparent);
|
||||
void Screen_DrawText32V(uint16_t x, uint16_t y, const char *text,
|
||||
uint8_t color);
|
||||
void Screen_DrawText48(uint16_t x, uint16_t y, const char *text, uint8_t color,
|
||||
uint8_t transparent);
|
||||
|
||||
/* Button */
|
||||
void Screen_Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h, const char *label, uint8_t fontColor, uint8_t bgColor, uint8_t pressFlag, uint8_t style);
|
||||
void Screen_Button(uint16_t x, uint16_t y, uint16_t w, uint16_t h,
|
||||
const char *label, uint8_t fontColor, uint8_t bgColor,
|
||||
uint8_t pressFlag, uint8_t style);
|
||||
|
||||
/* Qrcode */
|
||||
void Screen_QRCode(uint16_t x, uint16_t y, const char *url);
|
||||
void Screen_QRCodeEx(uint16_t x, uint16_t y, const char *url, uint16_t size, uint8_t color);
|
||||
|
||||
/* 版本信息 */
|
||||
void Screen_Ver(void);
|
||||
void Screen_QRCodeEx(uint16_t x, uint16_t y, const char *url, uint16_t size,
|
||||
uint8_t color);
|
||||
|
||||
// GBK
|
||||
void Screen_DrawText16_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText16V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText16_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
void Screen_DrawText16V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
|
||||
void Screen_DrawText24_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText24V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText24_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
void Screen_DrawText24V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
|
||||
void Screen_DrawText32_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText32V_GBK(uint16_t x,uint16_t y,const uint8_t *gbk,uint16_t len,uint8_t color);
|
||||
void Screen_DrawText32_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
void Screen_DrawText32V_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color);
|
||||
|
||||
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_DrawText48_GBK(uint16_t x, uint16_t y, const uint8_t *gbk,
|
||||
uint16_t len, uint8_t color, uint8_t transparent);
|
||||
|
||||
// 清空屏幕相关
|
||||
void Screen_ClearZone(uint8_t zone);
|
||||
void Screen_ClearAllZones(void);
|
||||
|
||||
// 显示相关
|
||||
|
||||
void Screen_ShowInZone(uint8_t zone, const uint8_t * text,uint16_t text_len);
|
||||
|
||||
void Screen_ClearContent(void);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -32,12 +32,15 @@ extern "C" {
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern TIM_HandleTypeDef htim1;
|
||||
|
||||
extern TIM_HandleTypeDef htim4;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_TIM1_Init(void);
|
||||
void MX_TIM4_Init(void);
|
||||
|
||||
void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);
|
||||
|
||||
@@ -19,9 +19,10 @@
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "main.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "main.h"
|
||||
#include "task.h"
|
||||
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
@@ -78,50 +79,48 @@ 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,
|
||||
.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"
|
||||
};
|
||||
const osEventFlagsAttr_t init_ok_attributes = {.name = "init_ok"};
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* USER CODE BEGIN FunctionPrototypes */
|
||||
@@ -138,10 +137,10 @@ 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 */
|
||||
@@ -167,7 +166,8 @@ 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);
|
||||
@@ -195,7 +195,6 @@ void MX_FREERTOS_Init(void) {
|
||||
/* USER CODE BEGIN RTOS_EVENTS */
|
||||
|
||||
/* USER CODE END RTOS_EVENTS */
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_StartDefaultTask */
|
||||
@@ -205,30 +204,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 */
|
||||
|
||||
// 启动TIM1的PWM输出
|
||||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); // 启动PWM输出(加热)
|
||||
|
||||
Screen_Init();
|
||||
|
||||
Screen_DrawText16_GBK(1, 30, text_device_loading, text_device_loading_LEN,
|
||||
TEXT_COLOR);
|
||||
|
||||
// Screen_DrawText16_GBK(1, 30, text_device_loading, text_device_loading_LEN,
|
||||
// TEXT_COLOR);
|
||||
Screen_ShowInZone(1, text_loading, text_loading_LEN);
|
||||
|
||||
// 等待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);
|
||||
}
|
||||
// 等待bit0+bit1+bit2都被设置(所有模块初始化完成)
|
||||
uint32_t flags =
|
||||
osEventFlagsWait(init_okHandle, // 目标事件标志组
|
||||
(1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) |
|
||||
(1 << 4), // 要等待的bit位(多个用|拼接)
|
||||
osFlagsWaitAll, // 等待所有bit都被设置
|
||||
osWaitForever // 永久等待(直到满足条件)
|
||||
);
|
||||
|
||||
elog_d("Init","完成所有的初始化");
|
||||
if (flags == ((1 << 0) | (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4))) {
|
||||
|
||||
// 所有初始化完成,开始执行按摩逻辑
|
||||
// Screen_DrawText16V_GBK(1, 30, text_stop_massage, text_stop_massage_LEN, 15);
|
||||
Screen_ShowInZone(1, text_ended, text_ended_LEN);
|
||||
Screen_ShowInZone(2, text_massage_off, text_massage_off_LEN);
|
||||
Screen_ShowInZone(3, text_heat_off,text_heat_off_LEN);
|
||||
}
|
||||
|
||||
elog_d("Init", "完成所有的初始化");
|
||||
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
@@ -248,10 +254,9 @@ 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");
|
||||
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};
|
||||
@@ -263,7 +268,7 @@ void Key(void *argument)
|
||||
uint8_t pressed[4] = {0};
|
||||
const uint8_t THRESH = 3; /* 3 * 10ms = 30ms 防抖 */
|
||||
|
||||
osEventFlagsSet(init_okHandle, 1<<0); // 设置初始化完成标志
|
||||
osEventFlagsSet(init_okHandle, 1 << 0); // 设置初始化完成标志
|
||||
|
||||
for (;;) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@@ -296,13 +301,11 @@ 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);
|
||||
|
||||
osEventFlagsSet(init_okHandle, 1 << 1);
|
||||
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
@@ -332,9 +335,13 @@ void Sensor(void *argument)
|
||||
if (key_pressed & (1 << 2)) {
|
||||
/* HOT_KEY 按下:切换热功能 */
|
||||
hot_state = !hot_state;
|
||||
elog_d("HOT", "加热的状态: %d", hot_state);
|
||||
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin,
|
||||
hot_state ? GPIO_PIN_SET : GPIO_PIN_RESET);
|
||||
if (hot_state) {
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 300);
|
||||
elog_d("Hot", "设置PWM为300");
|
||||
} else {
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, 0); /* 关闭加热 */
|
||||
elog_d("Hot", "设置PWM为0");
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== TIME_KEY (bit3) 控制 ===== */
|
||||
@@ -360,17 +367,14 @@ 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);
|
||||
|
||||
|
||||
osEventFlagsSet(init_okHandle, 1 << 2);
|
||||
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
@@ -397,61 +401,55 @@ 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);
|
||||
osEventFlagsSet(init_okHandle, 1 << 3);
|
||||
|
||||
// HAL_UART_Transmit(&huart1, (uint8_t *)buf, strlen(buf), HAL_MAX_DELAY);
|
||||
/* Infinite loop */
|
||||
for (;;) {
|
||||
if (hot_state) {
|
||||
}
|
||||
}
|
||||
/* USER CODE END Screen */
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Header_MP3 */
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Function implementing the MP3_Play_Task thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
* @brief Function implementing the MP3_Play_Task thread.
|
||||
* @param argument: Not used
|
||||
* @retval None
|
||||
*/
|
||||
/* USER CODE END Header_MP3 */
|
||||
void MP3(void *argument)
|
||||
{
|
||||
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
|
||||
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);
|
||||
|
||||
// 等待模块上电稳定
|
||||
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);
|
||||
// 发送初始化命令2
|
||||
HAL_UART_Transmit(&huart3, init_cmd2, sizeof(init_cmd2), 100);
|
||||
|
||||
elog_i("MP3", "模块初始化完成");
|
||||
osEventFlagsSet(init_okHandle, 1 << 4);
|
||||
|
||||
/* Infinite loop */
|
||||
for(;;)
|
||||
{
|
||||
for (;;) {
|
||||
// 发送播放命令
|
||||
HAL_UART_Transmit(&huart3, play_cmd, sizeof(play_cmd), 100);
|
||||
HAL_UART_Transmit(&huart3, play_cmd, sizeof(play_cmd), 100);
|
||||
|
||||
osDelay(10000);
|
||||
}
|
||||
@@ -462,4 +460,3 @@ void MP3(void *argument)
|
||||
/* USER CODE BEGIN Application */
|
||||
|
||||
/* USER CODE END Application */
|
||||
|
||||
|
||||
@@ -4,79 +4,51 @@
|
||||
// 对应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, 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编码:0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0
|
||||
const uint8_t text_loading_GBK[] = {0xBC, 0xD3, 0xD4, 0xD8, 0xD6, 0xD0};
|
||||
|
||||
// 对应文本(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编码:0xB0, 0xB4, 0xC4, 0xA6, 0xC6, 0xF4, 0xB6, 0xAF
|
||||
const uint8_t text_massage_on_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xC6, 0xF4, 0xB6, 0xAF};
|
||||
|
||||
// 对应文本(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编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCD, 0xA3, 0xD6, 0xB9
|
||||
const uint8_t text_massage_off_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCD, 0xA3, 0xD6, 0xB9};
|
||||
|
||||
// 对应文本(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编码:0xBC, 0xD3, 0xC8, 0xC8, 0xC6, 0xF4, 0xB6, 0xAF
|
||||
const uint8_t text_heat_on_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xC6, 0xF4, 0xB6, 0xAF};
|
||||
|
||||
// 对应文本(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):加热停止
|
||||
// 对应GBK编码:0xBC, 0xD3, 0xC8, 0xC8, 0xCD, 0xA3, 0xD6, 0xB9
|
||||
const uint8_t text_heat_off_GBK[] = {0xBC, 0xD3, 0xC8, 0xC8, 0xCD, 0xA3, 0xD6, 0xB9};
|
||||
|
||||
// 对应文本(UTF8):按摩档位:1级
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x31, 0xBC, 0xB6
|
||||
const uint8_t text_massage_gear_1_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x31, 0xBC, 0xB6};
|
||||
// 对应文本(UTF8):%d级
|
||||
// 对应GBK编码:0x25, 0x64, 0xBC, 0xB6
|
||||
const uint8_t text_gear_GBK[] = {0x25, 0x64, 0xBC, 0xB6};
|
||||
|
||||
// 对应文本(UTF8):按摩档位:2级
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x32, 0xBC, 0xB6
|
||||
const uint8_t text_massage_gear_2_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x32, 0xBC, 0xB6};
|
||||
// 对应文本(UTF8):%d分钟
|
||||
// 对应GBK编码:0x25, 0x64, 0xB7, 0xD6, 0xD6, 0xD3
|
||||
const uint8_t text_time_GBK[] = {0x25, 0x64, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||
|
||||
// 对应文本(UTF8):按摩档位:3级
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x33, 0xBC, 0xB6
|
||||
const uint8_t text_massage_gear_3_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xB5, 0xB5, 0xCE, 0xBB, 0xA3, 0xBA, 0x33, 0xBC, 0xB6};
|
||||
// 对应文本(UTF8):持续
|
||||
// 对应GBK编码:0xB3, 0xD6, 0xD0, 0xF8
|
||||
const uint8_t text_cont_GBK[] = {0xB3, 0xD6, 0xD0, 0xF8};
|
||||
|
||||
// 对应文本(UTF8):按摩时间:10分钟
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||
const uint8_t text_massage_time_10_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||
// 对应文本(UTF8):剩余%d分
|
||||
// 对应GBK编码:0xCA, 0xA3, 0xD3, 0xE0, 0x25, 0x64, 0xB7, 0xD6
|
||||
const uint8_t text_remaining_GBK[] = {0xCA, 0xA3, 0xD3, 0xE0, 0x25, 0x64, 0xB7, 0xD6};
|
||||
|
||||
// 对应文本(UTF8):按摩时间:15分钟
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x35, 0xB7, 0xD6, 0xD6, 0xD3
|
||||
const uint8_t text_massage_time_15_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x31, 0x35, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||
// 对应文本(UTF8):运行中
|
||||
// 对应GBK编码:0xD4, 0xCB, 0xD0, 0xD0, 0xD6, 0xD0
|
||||
const uint8_t text_running_GBK[] = {0xD4, 0xCB, 0xD0, 0xD0, 0xD6, 0xD0};
|
||||
|
||||
// 对应文本(UTF8):按摩时间:20分钟
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x32, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||
const uint8_t text_massage_time_20_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x32, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||
// 对应文本(UTF8):已暂停
|
||||
// 对应GBK编码:0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3
|
||||
const uint8_t text_paused_GBK[] = {0xD2, 0xD1, 0xD4, 0xDD, 0xCD, 0xA3};
|
||||
|
||||
// 对应文本(UTF8):按摩时间:30分钟
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x33, 0x30, 0xB7, 0xD6, 0xD6, 0xD3
|
||||
const uint8_t text_massage_time_30_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0x33, 0x30, 0xB7, 0xD6, 0xD6, 0xD3};
|
||||
|
||||
// 对应文本(UTF8):按摩时间:持续
|
||||
// 对应GBK编码:0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0xB3, 0xD6, 0xD0, 0xF8
|
||||
const uint8_t text_massage_time_cont_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xCA, 0xB1, 0xBC, 0xE4, 0xA3, 0xBA, 0xB3, 0xD6, 0xD0, 0xF8};
|
||||
|
||||
// 对应文本(UTF8):剩余按摩时间为:%d
|
||||
// 对应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, 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, 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, 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, 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, 0xA3, 0xA1
|
||||
const uint8_t text_massage_ended_GBK[] = {0xB0, 0xB4, 0xC4, 0xA6, 0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8, 0xA3, 0xA1};
|
||||
// 对应文本(UTF8):已结束
|
||||
// 对应GBK编码:0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8
|
||||
const uint8_t text_ended_GBK[] = {0xD2, 0xD1, 0xBD, 0xE1, 0xCA, 0xF8};
|
||||
|
||||
|
||||
@@ -53,9 +53,6 @@ void MX_GPIO_Init(void)
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOB, RUN_LED_Pin|ERR_LED_Pin, GPIO_PIN_SET);
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(HOT_GPIO_Port, HOT_Pin, GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : RUN_LED_Pin ERR_LED_Pin */
|
||||
GPIO_InitStruct.Pin = RUN_LED_Pin|ERR_LED_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
@@ -69,13 +66,6 @@ void MX_GPIO_Init(void)
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : HOT_Pin */
|
||||
GPIO_InitStruct.Pin = HOT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(HOT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
@@ -94,6 +94,7 @@ int main(void)
|
||||
MX_USART1_UART_Init();
|
||||
MX_USART3_UART_Init();
|
||||
MX_TIM4_Init();
|
||||
MX_TIM1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file screen.c
|
||||
* @brief 串口屏驱动实现(JC系列),使用 USART1
|
||||
******************************************************************************
|
||||
*/
|
||||
******************************************************************************
|
||||
* @file screen.c
|
||||
* @brief 串口屏驱动实现(JC系列),使用 USART1
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
#include "screen.h"
|
||||
#include "cmsis_os.h"
|
||||
#include "cmsis_os2.h"
|
||||
#include "elog.h"
|
||||
#include "gbk_text.h"
|
||||
#include "main.h"
|
||||
#include "usart.h"
|
||||
#include "cmsis_os.h"
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include "gbk_text.h"
|
||||
#include "elog.h"
|
||||
#include <string.h>
|
||||
|
||||
/* 发送缓冲 */
|
||||
static uint8_t txbuf[512];
|
||||
@@ -25,28 +25,33 @@ static uint8_t txbuf[512];
|
||||
========================================================= */
|
||||
|
||||
/* 将字符串复制到发送缓冲区 */
|
||||
static uint16_t buf_str(uint16_t p,const char *s)
|
||||
{
|
||||
while(*s) txbuf[p++]=*s++;
|
||||
return p;
|
||||
static uint16_t buf_str(uint16_t p, const char *s) {
|
||||
while (*s)
|
||||
txbuf[p++] = *s++;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* 将32位无符号整数转换为字符串并复制到发送缓冲区 */
|
||||
static uint16_t buf_u32(uint16_t p,uint32_t v)
|
||||
{
|
||||
char tmp[12];
|
||||
int i=0;
|
||||
if(v==0){ txbuf[p++]='0'; return p; }
|
||||
while(v){ tmp[i++]=v%10+'0'; v/=10; }
|
||||
while(i--) txbuf[p++]=tmp[i];
|
||||
static uint16_t buf_u32(uint16_t p, uint32_t v) {
|
||||
char tmp[12];
|
||||
int i = 0;
|
||||
if (v == 0) {
|
||||
txbuf[p++] = '0';
|
||||
return p;
|
||||
}
|
||||
while (v) {
|
||||
tmp[i++] = v % 10 + '0';
|
||||
v /= 10;
|
||||
}
|
||||
while (i--)
|
||||
txbuf[p++] = tmp[i];
|
||||
return p;
|
||||
}
|
||||
|
||||
/* 发送指定长度的数据 */
|
||||
static void send_buf(uint16_t len)
|
||||
{
|
||||
HAL_UART_Transmit(&huart1,txbuf,len,HAL_MAX_DELAY);
|
||||
osDelay(100);
|
||||
static void send_buf(uint16_t len) {
|
||||
HAL_UART_Transmit(&huart1, txbuf, len, HAL_MAX_DELAY);
|
||||
osDelay(100);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
@@ -54,26 +59,26 @@ static void send_buf(uint16_t len)
|
||||
========================================================= */
|
||||
|
||||
/* 发送数据缓冲区 */
|
||||
int Screen_SendBuf(const uint8_t *buf,uint16_t len)
|
||||
{
|
||||
if(!buf||!len) return -1;
|
||||
HAL_StatusTypeDef st=HAL_UART_Transmit(&huart1,(uint8_t*)buf,len,HAL_MAX_DELAY);
|
||||
osDelay(20);
|
||||
return (st==HAL_OK)?0:-2;
|
||||
int Screen_SendBuf(const uint8_t *buf, uint16_t len) {
|
||||
if (!buf || !len)
|
||||
return -1;
|
||||
HAL_StatusTypeDef st =
|
||||
HAL_UART_Transmit(&huart1, (uint8_t *)buf, len, HAL_MAX_DELAY);
|
||||
osDelay(20);
|
||||
return (st == HAL_OK) ? 0 : -2;
|
||||
}
|
||||
|
||||
/* 发送命令字符串 */
|
||||
int Screen_SendCmd(const char *cmd)
|
||||
{
|
||||
if(!cmd) return -1;
|
||||
return Screen_SendBuf((uint8_t*)cmd,strlen(cmd));
|
||||
int Screen_SendCmd(const char *cmd) {
|
||||
if (!cmd)
|
||||
return -1;
|
||||
return Screen_SendBuf((uint8_t *)cmd, strlen(cmd));
|
||||
}
|
||||
|
||||
/* 发送命令并等待确认(当前未实现超时机制) */
|
||||
int Screen_SendCmdWaitOK(const char *cmd,uint32_t timeout_ms)
|
||||
{
|
||||
(void)timeout_ms;
|
||||
return Screen_SendCmd(cmd);
|
||||
int Screen_SendCmdWaitOK(const char *cmd, uint32_t timeout_ms) {
|
||||
(void)timeout_ms;
|
||||
return Screen_SendCmd(cmd);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
@@ -81,17 +86,33 @@ int Screen_SendCmdWaitOK(const char *cmd,uint32_t timeout_ms)
|
||||
========================================================= */
|
||||
|
||||
/* 屏幕初始化函数 */
|
||||
void Screen_Init(void)
|
||||
{
|
||||
osDelay(1000);
|
||||
Screen_Clear(BG_COLOR);
|
||||
osDelay(200);
|
||||
Screen_SetBGColor(BG_COLOR);
|
||||
Screen_SetBrightness(0);
|
||||
osDelay(200);
|
||||
Screen_Box(0,0,127,127,TEXT_COLOR);
|
||||
Screen_DrawText24_GBK(5,1,text_device_name,text_device_name_LEN,TEXT_COLOR);
|
||||
Screen_Line(0, 27, 127, 27, TEXT_COLOR);
|
||||
void Screen_Init(void) {
|
||||
osDelay(1000);
|
||||
Screen_Clear(BG_COLOR);
|
||||
osDelay(200);
|
||||
Screen_SetBGColor(BG_COLOR);
|
||||
Screen_SetBrightness(0);
|
||||
osDelay(200);
|
||||
|
||||
// 绘制外边框
|
||||
Screen_Box(0, 0, 127, 127, TEXT_COLOR);
|
||||
|
||||
// 绘制标题(24号字体高度约为24-26像素,留一点边距)
|
||||
Screen_DrawText24_GBK(5, 2, text_device_name, text_device_name_LEN,
|
||||
TEXT_COLOR);
|
||||
|
||||
// 标题线(在标题下方,y=28位置)
|
||||
Screen_Line(1, 28, 126, 28, TEXT_COLOR);
|
||||
|
||||
// 将剩余区域(28-127)等分为3份
|
||||
// 第1个等分区域:29-60
|
||||
Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 第1条分隔线
|
||||
|
||||
// 第2个等分区域:61-93
|
||||
Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 第2条分隔线
|
||||
|
||||
// 第3个等分区域:94-126
|
||||
// 底部区域不需要画线,因为已经有边框了
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
@@ -99,164 +120,180 @@ void Screen_Init(void)
|
||||
========================================================= */
|
||||
|
||||
/* 清除指定图层 */
|
||||
void Screen_Clear(uint8_t layer)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"DIR(1);CLR(");
|
||||
p=buf_u32(p,layer);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_Clear(uint8_t layer) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "DIR(1);CLR(");
|
||||
p = buf_u32(p, layer);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 显示指定地址的图片 */
|
||||
void Screen_DisplayImage(uint32_t addr)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"DIR(1);FSIMG(");
|
||||
p=buf_u32(p,addr);
|
||||
p=buf_str(p,",0,0,128,128,0);\r\n");
|
||||
send_buf(p);
|
||||
void Screen_DisplayImage(uint32_t addr) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "DIR(1);FSIMG(");
|
||||
p = buf_u32(p, addr);
|
||||
p = buf_str(p, ",0,0,128,128,0);\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 设置屏幕亮度 */
|
||||
void Screen_SetBrightness(uint8_t val)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"BL(");
|
||||
p=buf_u32(p,val);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_SetBrightness(uint8_t val) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "BL(");
|
||||
p = buf_u32(p, val);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 设置屏幕旋转方向 */
|
||||
void Screen_SetRotation(uint8_t dir)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"DIR(");
|
||||
p=buf_u32(p,dir);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_SetRotation(uint8_t dir) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "DIR(");
|
||||
p = buf_u32(p, dir);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 设置串口波特率 */
|
||||
void Screen_SetBaud(uint32_t baud)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"BPS(");
|
||||
p=buf_u32(p,baud);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_SetBaud(uint32_t baud) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "BPS(");
|
||||
p = buf_u32(p, baud);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 在指定位置显示图片 */
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"FSIMG(");
|
||||
p=buf_u32(p,addr); txbuf[p++]=',';
|
||||
p=buf_u32(p,x); txbuf[p++]=',';
|
||||
p=buf_u32(p,y); txbuf[p++]=',';
|
||||
p=buf_u32(p,w); txbuf[p++]=',';
|
||||
p=buf_u32(p,h); txbuf[p++]=',';
|
||||
p=buf_u32(p,mode);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_DisplayImageAtAddr(uint32_t addr, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, uint8_t mode) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "FSIMG(");
|
||||
p = buf_u32(p, addr);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, x);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, w);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, h);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, mode);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 通过索引显示图片 */
|
||||
void Screen_DisplayImageByIndex(uint32_t index,uint16_t x,uint16_t y,uint16_t w,uint16_t h,uint8_t mode)
|
||||
{
|
||||
Screen_DisplayImageAtAddr(index,x,y,w,h,mode);
|
||||
void Screen_DisplayImageByIndex(uint32_t index, uint16_t x, uint16_t y,
|
||||
uint16_t w, uint16_t h, uint8_t mode) {
|
||||
Screen_DisplayImageAtAddr(index, x, y, w, h, mode);
|
||||
}
|
||||
|
||||
/* 绘制单个像素点 */
|
||||
void Screen_Pixel(uint16_t x,uint16_t y,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"PS(");
|
||||
p=buf_u32(p,x); txbuf[p++]=',';
|
||||
p=buf_u32(p,y); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_Pixel(uint16_t x, uint16_t y, uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "PS(");
|
||||
p = buf_u32(p, x);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 绘制直线 */
|
||||
void Screen_Line(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"PL(");
|
||||
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_Line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "PL(");
|
||||
p = buf_u32(p, x1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, x2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 绘制矩形框 */
|
||||
void Screen_Box(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"BOX(");
|
||||
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_Box(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "BOX(");
|
||||
p = buf_u32(p, x1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, x2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 绘制填充矩形 */
|
||||
void Screen_BoxFill(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"BOXF(");
|
||||
p=buf_u32(p,x1); txbuf[p++]=',';
|
||||
p=buf_u32(p,y1); txbuf[p++]=',';
|
||||
p=buf_u32(p,x2); txbuf[p++]=',';
|
||||
p=buf_u32(p,y2); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_BoxFill(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2,
|
||||
uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "BOXF(");
|
||||
p = buf_u32(p, x1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y1);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, x2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y2);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 绘制圆形 */
|
||||
void Screen_Circle(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"CIR(");
|
||||
p=buf_u32(p,x); txbuf[p++]=',';
|
||||
p=buf_u32(p,y); txbuf[p++]=',';
|
||||
p=buf_u32(p,r); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_Circle(uint16_t x, uint16_t y, uint16_t r, uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "CIR(");
|
||||
p = buf_u32(p, x);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, r);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 绘制填充圆形 */
|
||||
void Screen_CircleFill(uint16_t x,uint16_t y,uint16_t r,uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"CIRF(");
|
||||
p=buf_u32(p,x); txbuf[p++]=',';
|
||||
p=buf_u32(p,y); txbuf[p++]=',';
|
||||
p=buf_u32(p,r); txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_CircleFill(uint16_t x, uint16_t y, uint16_t r, uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "CIRF(");
|
||||
p = buf_u32(p, x);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, r);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 设置背景颜色 */
|
||||
void Screen_SetBGColor(uint8_t color)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"SBC(");
|
||||
p=buf_u32(p,color);
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
void Screen_SetBGColor(uint8_t color) {
|
||||
uint16_t p = 0;
|
||||
p = buf_str(p, "SBC(");
|
||||
p = buf_u32(p, color);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* =========================================================
|
||||
@@ -264,74 +301,270 @@ void Screen_SetBGColor(uint8_t color)
|
||||
========================================================= */
|
||||
|
||||
/* 绘制GBK文本的核心函数 */
|
||||
static void draw_gbk(const char *cmd,
|
||||
uint16_t x,uint16_t y,
|
||||
const uint8_t *gbk,uint16_t len,
|
||||
uint8_t color,
|
||||
uint8_t extra,
|
||||
uint8_t has_extra)
|
||||
{
|
||||
uint16_t p=0;
|
||||
static void draw_gbk(const char *cmd, uint16_t x, uint16_t y,
|
||||
const uint8_t *gbk, uint16_t len, uint8_t color,
|
||||
uint8_t extra, uint8_t has_extra) {
|
||||
uint16_t p = 0;
|
||||
|
||||
p=buf_str(p,cmd);
|
||||
txbuf[p++]='(';
|
||||
p=buf_u32(p,x); txbuf[p++]=',';
|
||||
p=buf_u32(p,y); txbuf[p++]=',';
|
||||
txbuf[p++]='\'';
|
||||
p = buf_str(p, cmd);
|
||||
txbuf[p++] = '(';
|
||||
p = buf_u32(p, x);
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, y);
|
||||
txbuf[p++] = ',';
|
||||
txbuf[p++] = '\'';
|
||||
|
||||
memcpy(&txbuf[p],gbk,len);
|
||||
p+=len;
|
||||
memcpy(&txbuf[p], gbk, len);
|
||||
p += len;
|
||||
|
||||
txbuf[p++]='\'';
|
||||
txbuf[p++]=',';
|
||||
p=buf_u32(p,color);
|
||||
txbuf[p++] = '\'';
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, color);
|
||||
|
||||
if(has_extra){
|
||||
txbuf[p++]=',';
|
||||
p=buf_u32(p,extra);
|
||||
}
|
||||
if (has_extra) {
|
||||
txbuf[p++] = ',';
|
||||
p = buf_u32(p, extra);
|
||||
}
|
||||
|
||||
p=buf_str(p,");\r\n");
|
||||
send_buf(p);
|
||||
p = buf_str(p, ");\r\n");
|
||||
send_buf(p);
|
||||
}
|
||||
|
||||
/* 16号字体GBK文本绘制 */
|
||||
void Screen_DrawText16_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC16",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText16V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV16",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText16_GBK(uint16_t x, uint16_t y, const uint8_t *g, uint16_t l,
|
||||
uint8_t c) {
|
||||
draw_gbk("DC16", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
void Screen_DrawText16V_GBK(uint16_t x, uint16_t y, const uint8_t *g,
|
||||
uint16_t l, uint8_t c) {
|
||||
draw_gbk("DCV16", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
|
||||
/* 24号字体GBK文本绘制 */
|
||||
void Screen_DrawText24_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC24",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText24V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV24",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText24_GBK(uint16_t x, uint16_t y, const uint8_t *g, uint16_t l,
|
||||
uint8_t c) {
|
||||
draw_gbk("DC24", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
void Screen_DrawText24V_GBK(uint16_t x, uint16_t y, const uint8_t *g,
|
||||
uint16_t l, uint8_t c) {
|
||||
draw_gbk("DCV24", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
|
||||
/* 32号字体GBK文本绘制 */
|
||||
void Screen_DrawText32_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DC32",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText32V_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c){draw_gbk("DCV32",x,y,g,l,c,0,0);}
|
||||
void Screen_DrawText32_GBK(uint16_t x, uint16_t y, const uint8_t *g, uint16_t l,
|
||||
uint8_t c) {
|
||||
draw_gbk("DC32", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
void Screen_DrawText32V_GBK(uint16_t x, uint16_t y, const uint8_t *g,
|
||||
uint16_t l, uint8_t c) {
|
||||
draw_gbk("DCV32", x, y, g, l, c, 0, 0);
|
||||
}
|
||||
|
||||
/* 48号字体GBK文本绘制 */
|
||||
void Screen_DrawText48_GBK(uint16_t x,uint16_t y,const uint8_t *g,uint16_t l,uint8_t c,uint8_t t)
|
||||
{draw_gbk("DC48",x,y,g,l,c,t,1);}
|
||||
|
||||
/* =========================================================
|
||||
版本查询
|
||||
========================================================= */
|
||||
|
||||
/* 查询屏幕版本信息 */
|
||||
void Screen_Ver(void)
|
||||
{
|
||||
uint16_t p=0;
|
||||
p=buf_str(p,"VER();\r\n");
|
||||
send_buf(p);
|
||||
void Screen_DrawText48_GBK(uint16_t x, uint16_t y, const uint8_t *g, uint16_t l,
|
||||
uint8_t c, uint8_t t) {
|
||||
draw_gbk("DC48", x, y, g, l, c, t, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
// /**
|
||||
// * @brief 清空指定的等分区域
|
||||
// * @param zone 区域编号(1-3)
|
||||
// * @param redraw_line 是否重新绘制区域分隔线
|
||||
// */
|
||||
// void Screen_ClearZoneEx(uint8_t zone, bool redraw_line)
|
||||
// {
|
||||
// if (zone < 1 || zone > 3) {
|
||||
// elog_e("Screen", "Invalid zone number: %d", zone);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// elog_i("Screen", "Clearing zone %d (redraw_line=%d)...", zone,
|
||||
// redraw_line);
|
||||
|
||||
// int16_t y_start, y_end;
|
||||
|
||||
// // 区域定义
|
||||
// const struct {
|
||||
// int16_t y_start;
|
||||
// int16_t y_end;
|
||||
// } zones[] = {
|
||||
// {29, 60}, // 区域1
|
||||
// {61, 93}, // 区域2
|
||||
// {94, 126} // 区域3
|
||||
// };
|
||||
|
||||
// y_start = zones[zone-1].y_start;
|
||||
// y_end = zones[zone-1].y_end;
|
||||
|
||||
// // 清空指定区域
|
||||
// Screen_BoxFill(1, y_start, 126, y_end, BG_COLOR);
|
||||
|
||||
// // 重新绘制分隔线(如果需要)
|
||||
// if (redraw_line) {
|
||||
// switch(zone) {
|
||||
// case 1:
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 区域1下边界线
|
||||
// break;
|
||||
// case 2:
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 区域1下边界线
|
||||
// Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 区域2下边界线
|
||||
// break;
|
||||
// case 3:
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 区域1下边界线
|
||||
// Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 区域2下边界线
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 清空所有内容区域(保留标题和边框)
|
||||
// */
|
||||
// void Screen_ClearAllZones(void)
|
||||
// {
|
||||
// elog_i("Screen", "Clearing all zones...");
|
||||
|
||||
// // 一次性清空所有内容区域(从标题线下方到底部)
|
||||
// Screen_BoxFill(1, 29, 126, 126, BG_COLOR);
|
||||
|
||||
// // 重新绘制所有分隔线
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 第1条分隔线
|
||||
// Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 第2条分隔线
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 清空指定的等分区域
|
||||
// * @param zone 区域编号(1-3)
|
||||
// * @note 区域划分:
|
||||
// * 区域1:y坐标 29-60(高度32像素)
|
||||
// * 区域2:y坐标 61-93(高度33像素)
|
||||
// * 区域3:y坐标 94-126(高度33像素)
|
||||
// */
|
||||
// void Screen_ClearZone(uint8_t zone)
|
||||
// {
|
||||
// if (zone < 1 || zone > 3) {
|
||||
// elog_e("Screen", "Invalid zone number: %d", zone);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// elog_i("Screen", "Clearing zone %d...", zone);
|
||||
|
||||
// int16_t y_start, y_end;
|
||||
|
||||
// switch(zone) {
|
||||
// case 1:
|
||||
// y_start = 29;
|
||||
// y_end = 60;
|
||||
// break;
|
||||
// case 2:
|
||||
// y_start = 61;
|
||||
// y_end = 93;
|
||||
// break;
|
||||
// case 3:
|
||||
// y_start = 94;
|
||||
// y_end = 126;
|
||||
// break;
|
||||
// default:
|
||||
// return;
|
||||
// }
|
||||
|
||||
// // 清空指定区域(x从1到126,避开左右边框)
|
||||
// Screen_BoxFill(1, y_start, 126, y_end, BG_COLOR);
|
||||
// }
|
||||
|
||||
// // 在指定区域显示内容(适应多行文字)
|
||||
// void Screen_ShowInZone(uint8_t zone, const uint8_t *text, uint16_t text_len)
|
||||
// {
|
||||
// // 区域定义(扩大清空范围,确保完全清除)
|
||||
// const struct {
|
||||
// int16_t y_start_clear; // 清空起始Y(向上多清空一点)
|
||||
// int16_t y_end_clear; // 清空结束Y(向下多清空一点)
|
||||
// int16_t y_text; // 文字起始Y
|
||||
// } zones[] = {
|
||||
// {30, 61, 35}, // 区域1:清空30-61(从Y=30开始,避免清除标题线)
|
||||
// {60, 94, 67}, // 区域2:清空60-94(包含上下边界线)
|
||||
// {93, 127, 100} // 区域3:清空93-127(包含上边界线和底边框)
|
||||
// };
|
||||
|
||||
// if (zone < 1 || zone > 3) {
|
||||
// elog_e("Screen", "Invalid zone number: %d", zone);
|
||||
// return;
|
||||
// }
|
||||
|
||||
// elog_i("Screen", "Showing text in zone %d (multi-line support)...",
|
||||
// zone);
|
||||
|
||||
// // 扩大清空范围,确保完全清除两行文字(X从1开始到126)
|
||||
// Screen_BoxFill(1, zones[zone-1].y_start_clear, 126,
|
||||
// zones[zone-1].y_end_clear, BG_COLOR);
|
||||
|
||||
// // 重新绘制边界线(X从1开始到126)
|
||||
// switch(zone) {
|
||||
// case 1:
|
||||
// Screen_Line(1, 28, 126, 28, TEXT_COLOR); // 标题线(保持在28)
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 区域1下边界线
|
||||
// break;
|
||||
// case 2:
|
||||
// Screen_Line(1, 60, 126, 60, TEXT_COLOR); // 区域1下边界线
|
||||
// Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 区域2下边界线
|
||||
// break;
|
||||
// case 3:
|
||||
// Screen_Line(1, 93, 126, 93, TEXT_COLOR); // 区域2下边界线
|
||||
// // 区域3下边界线是屏幕边框,不需要重绘
|
||||
// break;
|
||||
// }
|
||||
|
||||
// // 显示文字(X从1开始,Y使用调整后的坐标)
|
||||
// Screen_DrawText16_GBK(2, zones[zone-1].y_text, text, text_len,
|
||||
// TEXT_COLOR);
|
||||
// }
|
||||
|
||||
static void Screen_DrawZoneLines(void) {
|
||||
Screen_Line(SCREEN_LEFT, TITLE_LINE_Y, SCREEN_RIGHT, TITLE_LINE_Y,
|
||||
TEXT_COLOR);
|
||||
Screen_Line(SCREEN_LEFT, ZONE1_LINE_Y, SCREEN_RIGHT, ZONE1_LINE_Y,
|
||||
TEXT_COLOR);
|
||||
Screen_Line(SCREEN_LEFT, ZONE2_LINE_Y, SCREEN_RIGHT, ZONE2_LINE_Y,
|
||||
TEXT_COLOR);
|
||||
}
|
||||
|
||||
void Screen_ClearZone(uint8_t zone) {
|
||||
if (zone < 1 || zone > 3)
|
||||
return;
|
||||
|
||||
const ScreenZone_t *z = &g_zones[zone - 1];
|
||||
|
||||
Screen_BoxFill(SCREEN_LEFT, z->y_clear_start, SCREEN_RIGHT, z->y_clear_end,
|
||||
BG_COLOR);
|
||||
}
|
||||
|
||||
void Screen_ClearAllZones(void) {
|
||||
Screen_BoxFill(SCREEN_LEFT, g_zones[0].y_clear_start, SCREEN_RIGHT,
|
||||
g_zones[2].y_clear_end, BG_COLOR);
|
||||
|
||||
Screen_DrawZoneLines();
|
||||
}
|
||||
|
||||
#define MAX_CHARS_PER_LINE 8
|
||||
#define GBK_BYTES_PER_CHAR 2
|
||||
#define MAX_LINE_BYTES (MAX_CHARS_PER_LINE * GBK_BYTES_PER_CHAR)
|
||||
|
||||
void Screen_ShowInZone(uint8_t zone, const uint8_t *text, uint16_t text_len) {
|
||||
if (zone < 1 || zone > 3)
|
||||
return;
|
||||
|
||||
const ScreenZone_t *z = &g_zones[zone - 1];
|
||||
|
||||
// 1️⃣ 清空整个zone
|
||||
Screen_ClearZone(zone);
|
||||
|
||||
Screen_DrawZoneLines();
|
||||
|
||||
// 2️⃣ 强制裁剪长度
|
||||
uint16_t len = text_len;
|
||||
if (len > MAX_LINE_BYTES)
|
||||
len = MAX_LINE_BYTES;
|
||||
|
||||
// 3️⃣ 单行绘制(不允许自动换行)
|
||||
Screen_DrawText16_GBK(2, z->y_text, text, len, TEXT_COLOR);
|
||||
}
|
||||
|
||||
113
Core/Src/tim.c
113
Core/Src/tim.c
@@ -24,8 +24,69 @@
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
TIM_HandleTypeDef htim1;
|
||||
TIM_HandleTypeDef htim4;
|
||||
|
||||
/* TIM1 init function */
|
||||
void MX_TIM1_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 0 */
|
||||
|
||||
/* USER CODE END TIM1_Init 0 */
|
||||
|
||||
TIM_MasterConfigTypeDef sMasterConfig = {0};
|
||||
TIM_OC_InitTypeDef sConfigOC = {0};
|
||||
TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN TIM1_Init 1 */
|
||||
|
||||
/* USER CODE END TIM1_Init 1 */
|
||||
htim1.Instance = TIM1;
|
||||
htim1.Init.Prescaler = 71;
|
||||
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||
htim1.Init.Period = 999;
|
||||
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||
htim1.Init.RepetitionCounter = 0;
|
||||
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
|
||||
if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
|
||||
sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
|
||||
if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sConfigOC.OCMode = TIM_OCMODE_PWM1;
|
||||
sConfigOC.Pulse = 0;
|
||||
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
|
||||
sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
|
||||
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
|
||||
sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
|
||||
sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
|
||||
if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
|
||||
sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
|
||||
sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
|
||||
sBreakDeadTimeConfig.DeadTime = 0;
|
||||
sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
|
||||
sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_HIGH;
|
||||
sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
|
||||
if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN TIM1_Init 2 */
|
||||
|
||||
/* USER CODE END TIM1_Init 2 */
|
||||
HAL_TIM_MspPostInit(&htim1);
|
||||
|
||||
}
|
||||
/* TIM4 init function */
|
||||
void MX_TIM4_Init(void)
|
||||
{
|
||||
@@ -93,6 +154,22 @@ void MX_TIM4_Init(void)
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_PWM_MspInit(TIM_HandleTypeDef* tim_pwmHandle)
|
||||
{
|
||||
|
||||
if(tim_pwmHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 0 */
|
||||
/* TIM1 clock enable */
|
||||
__HAL_RCC_TIM1_CLK_ENABLE();
|
||||
/* USER CODE BEGIN TIM1_MspInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
@@ -112,7 +189,25 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||
{
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
if(timHandle->Instance==TIM4)
|
||||
if(timHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 0 */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
/**TIM1 GPIO Configuration
|
||||
PA8 ------> TIM1_CH1
|
||||
*/
|
||||
GPIO_InitStruct.Pin = HOT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_MEDIUM;
|
||||
HAL_GPIO_Init(HOT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* USER CODE BEGIN TIM1_MspPostInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspPostInit 1 */
|
||||
}
|
||||
else if(timHandle->Instance==TIM4)
|
||||
{
|
||||
/* USER CODE BEGIN TIM4_MspPostInit 0 */
|
||||
|
||||
@@ -137,6 +232,22 @@ void HAL_TIM_MspPostInit(TIM_HandleTypeDef* timHandle)
|
||||
|
||||
}
|
||||
|
||||
void HAL_TIM_PWM_MspDeInit(TIM_HandleTypeDef* tim_pwmHandle)
|
||||
{
|
||||
|
||||
if(tim_pwmHandle->Instance==TIM1)
|
||||
{
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_TIM1_CLK_DISABLE();
|
||||
/* USER CODE BEGIN TIM1_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END TIM1_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user