备份-封装函数

This commit is contained in:
王绪洁 2025-07-30 16:56:57 +08:00
parent 768f66dd16
commit 465d561044
6 changed files with 1051 additions and 875 deletions

View File

@ -306,7 +306,7 @@ void start_lcd_task(void const *argument)
for (;;)
{
uart_lcd_makecurve_test();
vTaskDelay(300);
vTaskDelay(30);
}
/* USER CODE END start_lcd_task */
}

View File

@ -776,7 +776,6 @@ void dma_usart_send(UART_HandleTypeDef *huart, uint8_t *buf, uint8_t len)
while (uart_lcd_state.lcd_flag != 0)
{
}
uart_lcd_state.lcd_flag = 1; // 设置标志位,表示正在发送数据
if (HAL_UART_Transmit_DMA(huart, buf, len) != HAL_OK)
{

View File

@ -190,6 +190,21 @@
<WinNumber>1</WinNumber>
<ItemText>test_num</ItemText>
</Ww>
<Ww>
<count>8</count>
<WinNumber>1</WinNumber>
<ItemText>lcd_set_button1_data</ItemText>
</Ww>
<Ww>
<count>9</count>
<WinNumber>1</WinNumber>
<ItemText>uart_lcd_button_data</ItemText>
</Ww>
<Ww>
<count>10</count>
<WinNumber>1</WinNumber>
<ItemText>lcd_set_button1_data</ItemText>
</Ww>
</WatchWindow1>
<Tracepoint>
<THDelay>0</THDelay>

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,11 @@
/*
* @Author: wangxujie wangxujie@wuxismart.com
* @Date: 2025-03-10 15:05:20
* @LastEditors: wangxujie wangxujie@wuxismart.com
* @LastEditTime: 2025-07-30 16:54:34
* @FilePath: \signal_generator\User\driver\uart_lcd.c
* @Description: ,`customMade`, koroFileHeader查看配置 : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
#include "uart_lcd.h"
#include "usart.h"
#include "lwip.h"
@ -5,34 +13,96 @@
extern ip4_addr_t ipaddr;
uart_lcd_t uart_lcd_state = {0};
lcd_makecurve_t lcd_makecurve_data = {0};
lcd_set_button_t lcd_set_button1_data = {0}; // 输出通道文本按钮界面ID 0控件ID 1
lcd_set_button_t lcd_set_button2_data = {0}; // 第一路AO输出箭头按钮界面ID 0控件ID 2
lcd_set_button_t lcd_set_button3_data = {0}; // 第二路AO输出箭头按钮界面ID 0控件ID 3
lcd_set_button_t lcd_set_button4_data = {0}; // SW1状态按钮界面ID 1控件ID 1
lcd_set_button_t lcd_set_button5_data = {0}; // SW2状态按钮界面ID 1控件ID 2
lcd_set_txt_t lcd_set_txt_data = {0}; // 文本设置数据
lcd_set_progress_t lcd_set_progress_data = {0}; // 进度条设置数据
lcd_switchscreen_t lcd_switchscreen_data = {0}; // 切换画面数据
extern float current_buff[2];
uint8_t uart_lcd_data[24] = {0xEE, 0xB1, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x01, 0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
static void uart_lcd_page_init(lcd_switchscreen_t *screen_data);
static void uart_lcd_button_init(lcd_set_button_t *button_data, uint16_t screen_id, uint16_t ctrl_id);
static void uart_lcd_current_channel1(void);
static void uart_lcd_current_channel2(void);
static void uart_lcd_page_init(lcd_switchscreen_t *screen_data)
{
screen_data->cmd_head = LCD_CMD_HEAD;
screen_data->cmd_type = LCD_CMD_TYPE;
screen_data->cmd_ctrl_type = LCD_CMD_CTRL_TYPE_SWITCH_SCREEN;
screen_data->cmd_screen_id = 0x0000; // 默认切换到主界面
screen_data->cmd_tail = LCD_CMD_TAIL;
}
static void uart_lcd_button_init(lcd_set_button_t *button_data, uint16_t screen_id, uint16_t ctrl_id)
{
button_data->cmd_head = LCD_CMD_HEAD;
button_data->cmd_type = LCD_CMD_TYPE;
button_data->cmd_ctrl_type = LCD_CMD_CTRL_TYPE_SET_BUTTON;
button_data->cmd_screen_id = screen_id;
button_data->cmd_ctrl_id = ctrl_id;
button_data->cmd_button_status = 0; // 默认按钮状态为未按下
button_data->cmd_tail = LCD_CMD_TAIL;
}
/**
* @brief LCD按钮状态
*
* LCD上的按钮状态
*
* @param button_data
*/
static void uart_lcd_set_button_status(lcd_set_button_t *button_data)
{
if (button_data == NULL)
{
return;
}
while (uart_lcd_state.lcd_flag != 0)
{
}
static uint8_t uart_lcd_button_data[sizeof(lcd_set_button_t)] = {0};
uart_lcd_button_data[0] = button_data->cmd_head; // 帧头
uart_lcd_button_data[1] = button_data->cmd_type; // 命令类型
uart_lcd_button_data[2] = button_data->cmd_ctrl_type; // 控制类型
uart_lcd_button_data[3] = (button_data->cmd_screen_id >> 8) & 0xFF; // 画面ID高位
uart_lcd_button_data[4] = button_data->cmd_screen_id & 0xFF; // 画面ID低位
uart_lcd_button_data[5] = (button_data->cmd_ctrl_id >> 8) & 0xFF; // 控件ID高位
uart_lcd_button_data[6] = button_data->cmd_ctrl_id & 0xFF; // 控件ID低位
uart_lcd_button_data[7] = button_data->cmd_button_status; // 按钮状态
uart_lcd_button_data[8] = (button_data->cmd_tail >> 24) & 0xFF; // 帧尾
uart_lcd_button_data[9] = (button_data->cmd_tail >> 16) & 0xFF; // 帧尾
uart_lcd_button_data[10] = (button_data->cmd_tail >> 8) & 0xFF; // 帧尾
uart_lcd_button_data[11] = button_data->cmd_tail & 0xFF; // 帧尾
// 大小端转换
dma_usart_send(&huart4, uart_lcd_button_data, sizeof(lcd_set_button_t));
}
static void uart_lcd_current_channel1(void)
{
dma_usart_send(&huart4, uart_lcd_data, ARRAY_LEN(uart_lcd_data));
// 输出文本按钮状态0第一路AO状态1第二路AO状态0
lcd_set_button1_data.cmd_button_status = 0; // 第一路AO输出文本按钮状态为未按下
uart_lcd_set_button_status(&lcd_set_button1_data);
lcd_set_button2_data.cmd_button_status = 1; // 第一路AO输出箭头按钮状态为按下
uart_lcd_set_button_status(&lcd_set_button2_data);
lcd_set_button3_data.cmd_button_status = 0; // 第二路AO输出箭头按钮状态为未按下
uart_lcd_set_button_status(&lcd_set_button3_data);
}
uint8_t uart_lcd_data2[24] = {0xEE, 0xB1, 0x12, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x01, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x01, 0x01, 0xFF, 0xFC, 0xFF, 0xFF};
static void uart_lcd_current_channel2(void)
{
dma_usart_send(&huart4, uart_lcd_data2, ARRAY_LEN(uart_lcd_data2));
}
uint8_t uart_lcd_data3[9] = {0xEE, 0xB1, 0x00, 0x00, 0x00, 0xFF, 0xFC, 0xFF, 0xFF};
static void uart_lcd_page1(void)
{
uart_lcd_state.page_num = 0;
dma_usart_send(&huart4, uart_lcd_data3, ARRAY_LEN(uart_lcd_data3));
}
uint8_t uart_lcd_data4[9] = {0xEE, 0xB1, 0x00, 0x00, 0x01, 0xFF, 0xFC, 0xFF, 0xFF};
static void uart_lcd_page2(void)
{
uart_lcd_state.page_num = 1;
dma_usart_send(&huart4, uart_lcd_data4, ARRAY_LEN(uart_lcd_data4));
// 输出文本按钮状态1第一路AO状态0第二路AO状态1
lcd_set_button1_data.cmd_button_status = 1;
uart_lcd_set_button_status(&lcd_set_button1_data);
lcd_set_button2_data.cmd_button_status = 0;
uart_lcd_set_button_status(&lcd_set_button2_data);
lcd_set_button3_data.cmd_button_status = 1;
uart_lcd_set_button_status(&lcd_set_button3_data);
}
/**
* @brief UART向LCD屏幕绘制IP地址
*
@ -62,15 +132,23 @@ void uart_lcd_draw_ipaddr(void)
void uart_lcd_init(void)
{
// 初始化屏幕
uart_lcd_state.page_num = 0;
uart_lcd_page_init(&lcd_switchscreen_data); // 初始化页面数据
uart_lcd_page_switch(uart_lcd_state.page_num); // 切换到第一个页面
uart_lcd_state.key_state[0] = 0;
uart_lcd_state.key_state[1] = 1;
uart_lcd_state.key_state[2] = 0;
// 初始化按钮
uart_lcd_button_init(&lcd_set_button1_data, 0, 1);
uart_lcd_button_init(&lcd_set_button2_data, 0, 2);
uart_lcd_button_init(&lcd_set_button3_data, 0, 3);
uart_lcd_button_init(&lcd_set_button4_data, 1, 1);
uart_lcd_button_init(&lcd_set_button5_data, 1, 2);
uart_lcd_state.current_out_channel = 0;
uart_lcd_state.current_value[0] = 0;
uart_lcd_state.current_value[1] = 0;
uart_lcd_channel_switch(uart_lcd_state.key_state[0]);
uart_lcd_channel_switch(uart_lcd_state.current_out_channel);
HAL_Delay(10);
uart_lcd_current_out(0);
HAL_Delay(10);
@ -78,7 +156,7 @@ void uart_lcd_init(void)
lcd_makecurve_data.cmd_head = 0xEE; // 帧头
lcd_makecurve_data.cmd_type = 0xB1; // 命令类型
lcd_makecurve_data.cmd_ctrl_type = 0x32; // 写曲线数据
lcd_makecurve_data.cmd_page_id = 0x01; // 画面ID
lcd_makecurve_data.cmd_screen_id = 0x01; // 画面ID
lcd_makecurve_data.cmd_ctrl_id = 0x0E; // 控件ID
lcd_makecurve_data.cmd_curve_channel = 0x00; // 曲线通道
lcd_makecurve_data.cmd_tail = 0xFFFCFFFF; // 帧尾
@ -120,20 +198,21 @@ void uart_lcd_channel_switch(uint8_t channel)
void uart_lcd_page_switch(uint8_t page)
{
switch (page)
while (uart_lcd_state.lcd_flag != 0)
{
case 0:
uart_lcd_page1();
break;
case 1:
uart_lcd_page2();
break;
default:
uart_lcd_page1();
break;
}
// HAL_Delay(100);
static uint8_t uart_switchscreen_data[sizeof(lcd_switchscreen_t)] = {0};
lcd_switchscreen_data.cmd_screen_id = (uint16_t)page; // 更新当前页面状态
uart_switchscreen_data[0] = lcd_switchscreen_data.cmd_head; // 帧头
uart_switchscreen_data[1] = lcd_switchscreen_data.cmd_type; // 命令类型
uart_switchscreen_data[2] = lcd_switchscreen_data.cmd_ctrl_type; // 控制类型
uart_switchscreen_data[3] = (lcd_switchscreen_data.cmd_screen_id >> 8) & 0xFF; // 画面ID高位地址
uart_switchscreen_data[4] = lcd_switchscreen_data.cmd_screen_id & 0xFF; // 画面ID低位地址
uart_switchscreen_data[5] = (lcd_switchscreen_data.cmd_tail >> 24) & 0xFF; // 帧尾
uart_switchscreen_data[6] = (lcd_switchscreen_data.cmd_tail >> 16) & 0xFF; // 帧尾
uart_switchscreen_data[7] = (lcd_switchscreen_data.cmd_tail >> 8) & 0xFF; // 帧尾
uart_switchscreen_data[8] = lcd_switchscreen_data.cmd_tail & 0xFF; // 帧尾
dma_usart_send(&huart4, uart_switchscreen_data, sizeof(lcd_switchscreen_t)); // 发送切换画面数据
}
void uart_lcd_ecll_control_current_out(void)
{
@ -156,21 +235,17 @@ void uart_lcd_ecll_control_current_out(void)
ec11_data.confirm_key_flag_last++;
if (ec11_data.confirm_key_flag_last > 2)
{
if (uart_lcd_state.key_state[0] == 1)
if (uart_lcd_state.current_out_channel == 1)
{
uart_lcd_state.key_state[0] = 0;
uart_lcd_state.key_state[1] = 1;
uart_lcd_state.key_state[2] = 0;
uart_lcd_state.current_out_channel = 0;
}
else if (uart_lcd_state.key_state[0] == 0)
else if (uart_lcd_state.current_out_channel == 0)
{
uart_lcd_state.key_state[0] = 1;
uart_lcd_state.key_state[1] = 0;
uart_lcd_state.key_state[2] = 1;
uart_lcd_state.current_out_channel = 1;
}
ec11_data.confirm_key_flag_last = 0;
ec11_data.confirm_key_flag = 0;
uart_lcd_channel_switch(uart_lcd_state.key_state[0]);
uart_lcd_channel_switch(uart_lcd_state.current_out_channel);
}
}
else if (ec11_data.confirm_key_flag == 3) // 切换界面
@ -199,7 +274,7 @@ void uart_lcd_ec11_control_current(void)
if ((ec11_data.direction == 0) && (ec11_data.encode_num > ec11_data.encode_num_last))
{
if (uart_lcd_state.key_state[0] == 0)
if (uart_lcd_state.current_out_channel == 0)
{
uart_lcd_state.current_value[0] += 1;
if (uart_lcd_state.current_value[0] > 20)
@ -207,7 +282,7 @@ void uart_lcd_ec11_control_current(void)
uart_lcd_state.current_value[0] = 20;
}
}
else if (uart_lcd_state.key_state[0] == 1)
else if (uart_lcd_state.current_out_channel == 1)
{
uart_lcd_state.current_value[1] += 1;
if (uart_lcd_state.current_value[1] > 20)
@ -215,11 +290,11 @@ void uart_lcd_ec11_control_current(void)
uart_lcd_state.current_value[1] = 20;
}
}
uart_lcd_current_out(uart_lcd_state.key_state[0]);
uart_lcd_current_out(uart_lcd_state.current_out_channel);
}
if ((ec11_data.direction == 1) && (ec11_data.encode_num < ec11_data.encode_num_last))
{
if (uart_lcd_state.key_state[0] == 0)
if (uart_lcd_state.current_out_channel == 0)
{
if (uart_lcd_state.current_value[0] < 2)
{
@ -230,7 +305,7 @@ void uart_lcd_ec11_control_current(void)
uart_lcd_state.current_value[0] -= 1;
}
}
else if (uart_lcd_state.key_state[0] == 1)
else if (uart_lcd_state.current_out_channel == 1)
{
if (uart_lcd_state.current_value[1] < 2)
{
@ -241,21 +316,21 @@ void uart_lcd_ec11_control_current(void)
uart_lcd_state.current_value[1] -= 1;
}
}
uart_lcd_current_out(uart_lcd_state.key_state[0]);
uart_lcd_current_out(uart_lcd_state.current_out_channel);
}
ec11_data.encode_num_last = ec11_data.encode_num;
}
}
uint8_t uart_makecurve_data[128] = {0};
void uart_lcd_makecurvet(lcd_makecurve_t *makecurve_data)
{
static uint8_t uart_makecurve_data[256] = {0}; // 发送数据缓冲区最大长度为256字节
uart_makecurve_data[0] = makecurve_data->cmd_head; // 帧头
uart_makecurve_data[1] = makecurve_data->cmd_type; // 命令类型
uart_makecurve_data[2] = makecurve_data->cmd_ctrl_type; // 控制类型
uart_makecurve_data[3] = (makecurve_data->cmd_page_id >> 8) & 0xFF; // 画面ID高位地址
uart_makecurve_data[4] = makecurve_data->cmd_page_id & 0xFF; // 画面ID低位地址
uart_makecurve_data[3] = (makecurve_data->cmd_screen_id >> 8) & 0xFF; // 画面ID高位地址
uart_makecurve_data[4] = makecurve_data->cmd_screen_id & 0xFF; // 画面ID低位地址
uart_makecurve_data[5] = (makecurve_data->cmd_ctrl_id >> 8) & 0xFF; // 控件ID高位地址
uart_makecurve_data[6] = makecurve_data->cmd_ctrl_id & 0xFF; // 控件ID低位地址
uart_makecurve_data[7] = makecurve_data->cmd_curve_channel; // 曲线通道
@ -273,15 +348,10 @@ void uart_lcd_makecurvet(lcd_makecurve_t *makecurve_data)
void uart_lcd_makecurve_test(void)
{
lcd_makecurve_data.cmd_data_len = 1; // 假设数据长度为1
static uint8_t test_num = 0;
// if (uart_lcd_state.page_num == 1)
{
test_num++;
if (test_num > 100)
{
test_num = 0; // 重置计数器
}
lcd_makecurve_data.cmd_data[0] = test_num / 10 * 10; // 填充数据内容
lcd_makecurve_data.cmd_data[0] = (current_buff[1] - 4) * 100 / 16; // 填充数据内容
uart_lcd_makecurvet(&lcd_makecurve_data); // 调用函数发送数据
}

View File

@ -2,7 +2,7 @@
* @Author: wangxujie wangxujie@wuxismart.com
* @Date: 2025-03-10 15:05:20
* @LastEditors: wangxujie wangxujie@wuxismart.com
* @LastEditTime: 2025-07-29 15:28:31
* @LastEditTime: 2025-07-30 16:50:15
* @FilePath: \signal_generator\User\driver\uart_lcd.h
* @Description: ,`customMade`, koroFileHeader查看配置 : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
@ -10,12 +10,28 @@
#define __UART_LCD_H__
#include "main.h"
#define LCD_CMD_HEAD 0xEE // LCD指令帧头
#define LCD_CMD_TYPE 0xB1 // LCD指令类型对控件操作基本都为0xB1具体查询手册
#define LCD_CMD_CTRL_TYPE_SWITCH_SCREEN 0x00 // 切换屏幕命令
#define LCD_CMD_CTRL_TYPE_SET_BUTTON 0x10 // 设置按钮状态命令
#define LCD_CMD_CTRL_TYPE_SET_TXT 0x10 // 设置文本命令
#define LCD_CMD_CTRL_TYPE_SET_PROGRESS 0x10 // 设置进度条命令
#define LCD_CMD_CTRL_TYPE_MAKE_CURVE 0x30 // 绘制曲线命令
#define LCD_CMD_TAIL 0xFFFCFFFF
#define LCD_SCREEN_ID_CRUUENT 0x00 // 电流输出界面ID
#define LCD_SCREEN_ID_CURVE 0x01 // 绘制曲线界面ID
#define LCD_CMD_SET_BUTTON_LEN 0x0C // 设置按钮状态命令长度
#pragma pack(1)
typedef struct
{
uint8_t cmd_head; // 帧头
uint8_t cmd_type; // 命令类型
uint8_t cmd_ctrl_type; // 控制类型
uint16_t cmd_page_id; // 画面ID
uint16_t cmd_screen_id; // 画面ID
uint16_t cmd_ctrl_id; // 控件ID
uint8_t cmd_curve_channel; // 曲线通道
@ -24,11 +40,70 @@ typedef struct
uint32_t cmd_tail; // 帧尾
} lcd_makecurve_t; // lcd绘制曲线结构体
#pragma pack()
extern lcd_makecurve_t lcd_makecurve_data;
#pragma pack(1)
typedef struct
{
uint8_t cmd_head; // 帧头
uint8_t cmd_type; // 命令类型
uint8_t cmd_ctrl_type; // 控制类型
uint16_t cmd_screen_id; // 画面ID
uint16_t cmd_ctrl_id; // 控件ID
uint8_t cmd_button_status; // 按钮状态
uint32_t cmd_tail; // 帧尾
} lcd_set_button_t; // lcd设置按钮状态结构体
#pragma pack()
extern lcd_set_button_t lcd_set_button1_data;
extern lcd_set_button_t lcd_set_button2_data;
extern lcd_set_button_t lcd_set_button3_data;
extern lcd_set_button_t lcd_set_button4_data;
extern lcd_set_button_t lcd_set_button5_data;
typedef struct
{
uint8_t cmd_head; // 帧头
uint8_t cmd_type; // 命令类型
uint8_t cmd_ctrl_type; // 控制类型
uint16_t cmd_screen_id; // 画面ID
uint16_t cmd_ctrl_id; // 控件ID
float cmd_txt_data; // 文本内容应该为字符串形式且长度不定当前项目中只需要上传浮点需要浮点转ASCII码
uint32_t cmd_tail; // 帧尾
} lcd_set_txt_t; // lcd设置按钮状态结构体
extern lcd_set_txt_t lcd_set_txt_data;
typedef struct
{
uint8_t cmd_head; // 帧头
uint8_t cmd_type; // 命令类型
uint8_t cmd_ctrl_type; // 控制类型
uint16_t cmd_screen_id; // 画面ID
uint16_t cmd_ctrl_id; // 控件ID
uint32_t cmd_progress_value; // 按钮状态
uint32_t cmd_tail; // 帧尾
} lcd_set_progress_t; // lcd设置按钮状态结构体
extern lcd_set_progress_t lcd_set_progress_data;
#pragma pack(1)
typedef struct
{
uint8_t cmd_head; // 帧头
uint8_t cmd_type; // 命令类型
uint8_t cmd_ctrl_type; // 控制类型
uint16_t cmd_screen_id; // 画面ID
uint32_t cmd_tail; // 帧尾
} lcd_switchscreen_t; // 切换画面
#pragma pack()
extern lcd_switchscreen_t lcd_switchscreen_data;
typedef struct
{
uint8_t page_num;
uint8_t key_state[3];
uint8_t current_out_channel; // 当前输出通道
uint8_t current_value[2];
uint8_t lcd_flag;
} uart_lcd_t;