修复bug,更新readme
This commit is contained in:
parent
4bb45d1f18
commit
345dcfa588
|
@ -1,8 +1,16 @@
|
|||
# referee
|
||||
|
||||
## referee运行流程
|
||||
|
||||
首先在chassis的初始化中调用裁判系统初始化函数,将要绘制的uidata的指针传递给接口,接口会返回裁判系统的反馈数据指针。然后,在refereeUItask里进行UI初始化,确定ui发送的目标并绘制初始化UI。完成后,uitask会以10hz的频率按顺序更新UI。
|
||||
|
||||
|
||||
## 如何绘制你的自定义UI?以绘制超级电容能量条为例:
|
||||
|
||||
UI的绘制包含初始化和TASK两个部分,初始化部分在`My_UI_init`函数中,TASK部分在`My_UI_Refresh`函数中。
|
||||
|
||||
## 初始化部分:
|
||||
### 初始化部分:
|
||||
|
||||
初始化部分的UI主要有两个目的:静态UI的绘制、为动态UI的绘制做准备。
|
||||
|
||||
分析超级电容能量条功能可知,此UI包含如下:
|
||||
|
@ -15,16 +23,19 @@ Power:xxx Power为静态不变的,冒号后的xxx为变化的量。
|
|||
绘制矩形方框内的初始能量条、绘制Power的初始值。
|
||||
|
||||
### 绘制字符“Power:”:
|
||||
|
||||
设置绘制用结构体,此处使用数组是因为需要绘制多个字符。本次绘制的字符为“Power:”,只是用到了第6个,即xxx[5]:
|
||||
|
||||
```c
|
||||
static String_Data_t UI_State_sta[6]; // 静态
|
||||
```
|
||||
|
||||
字符格式以及内容设置:
|
||||
|
||||
```c
|
||||
Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 7, UI_Color_Green, 18, 2, 620, 230, "Power:");
|
||||
```
|
||||
各参数意义如下,函数定义中有详细注释:
|
||||
|
||||
//各参数意义如下,函数定义中有详细注释:
|
||||
string String_Data类型变量指针,用于存放字符串数据
|
||||
stringname[3] 字符串名称,用于标识更改
|
||||
String_Operate 字符串操作,初始化时一般使用"UI_Graph_ADD"
|
||||
|
@ -34,38 +45,53 @@ Char_Draw(&UI_State_sta[5], "ss5", UI_Graph_ADD, 7, UI_Color_Green, 18, 2, 620,
|
|||
String_Width 字符串线宽
|
||||
Start_x、Start_y 开始坐标
|
||||
*stringdata 字符串数据
|
||||
设置完毕后,使用“Char_ReFresh”发送即可:
|
||||
```c
|
||||
|
||||
//设置完毕后,使用“Char_ReFresh”发送即可:
|
||||
Char_ReFresh(&referee_recv_info->referee_id, UI_State_sta[5]);
|
||||
```
|
||||
|
||||
|
||||
|
||||
### 绘制能量框:
|
||||
|
||||
定义一个图形类结构体,用于绘制能量框:
|
||||
|
||||
```c
|
||||
static Graph_Data_t UI_energy_line[3]; // 电容能量条
|
||||
```
|
||||
|
||||
能量框参数设置以及发送函数:
|
||||
|
||||
```c
|
||||
Rectangle_Draw(&UI_energy_line[0],"ss6", UI_Graph_ADD, 7, UI_Color_Green,20, 720, 220, 820, 240)
|
||||
UI_ReFresh(&referee_recv_info->referee_id, 1,UI_energy_line[0]);
|
||||
```
|
||||
|
||||
### 绘制power的初始值:
|
||||
|
||||
```c
|
||||
Float_Draw(&UI_Energy[1], "sd5", UI_Graph_ADD, 8, UI_Color_Green, 18, 2, 2, 750, 230, 24000);
|
||||
```
|
||||
|
||||
### 绘制能量条的初始值:
|
||||
|
||||
```c
|
||||
Line_Draw(&UI_Energy[2], "sd6", UI_Graph_ADD, 8, UI_Color_Pink, 30, 720, 160, 1020, 160);
|
||||
```
|
||||
|
||||
将两个图形打包发送
|
||||
|
||||
```
|
||||
UI_ReFresh(&referee_recv_info->referee_id, 2, UI_Energy[1], UI_Energy[2]);
|
||||
```
|
||||
|
||||
## TASK部分
|
||||
|
||||
task中UI处于动态变化,此时需要检测所画的UI是否发生变化,若发生变化,则刷新对应UI。
|
||||
### 添加变化检测:
|
||||
|
||||
绘制功率部分UI,我们需要的是`Chassis_Power_Data_s`中的数据,我们定义`Chassis_Power_Data_s Chassis_Power_Data;`和`Chassis_Power_Data_s Chassis_last_Power_Data;`分别存储此次和上次的对应数据,本次和上次对应检测变化的需求。
|
||||
|
||||
```c
|
||||
typedef struct
|
||||
{
|
||||
|
@ -88,7 +114,9 @@ typedef struct
|
|||
|
||||
} Referee_Interactive_info_t;
|
||||
```
|
||||
|
||||
添加功率变化标志位,`uint32_t Power_flag : 1;`,1为检测到变化,0为未检测到变换
|
||||
|
||||
```
|
||||
typedef struct
|
||||
{
|
||||
|
@ -121,6 +149,7 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data)
|
|||
}
|
||||
```
|
||||
### 根据功率的变化绘制UI:
|
||||
|
||||
在绘制变化的UI时,由于初始化时已经使用`UI_Graph_ADD`操作添加了UI,所以在绘制时,需要使用`UI_Graph_Change`操作,以便于刷新UI。
|
||||
|
||||
同时,完成UI刷新后,需要将对应的flag置0,以便于下次检测变化
|
||||
|
|
|
@ -218,57 +218,21 @@ static void My_UI_Refresh(referee_info_t *referee_recv_info, Referee_Interactive
|
|||
// shoot
|
||||
if (_Interactive_data->Referee_Interactive_Flag.shoot_flag == 1)
|
||||
{
|
||||
switch (_Interactive_data->shoot_mode)
|
||||
{
|
||||
case SHOOT_OFF:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650, "off");
|
||||
break;
|
||||
}
|
||||
case SHOOT_ON:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Orange, 15, 2, 270, 650, "on ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Char_Draw(&UI_State_dyn[2], "sd2", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 650, _Interactive_data->shoot_mode == SHOOT_ON ? "on " : "off");
|
||||
Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[2]);
|
||||
_Interactive_data->Referee_Interactive_Flag.shoot_flag = 0;
|
||||
}
|
||||
// friction
|
||||
if (_Interactive_data->Referee_Interactive_Flag.friction_flag == 1)
|
||||
{
|
||||
switch (_Interactive_data->friction_mode)
|
||||
{
|
||||
case FRICTION_OFF:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600, "off");
|
||||
break;
|
||||
}
|
||||
case FRICTION_ON:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600, "on ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Char_Draw(&UI_State_dyn[3], "sd3", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 600, _Interactive_data->friction_mode == FRICTION_ON ? "on " : "off");
|
||||
Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[3]);
|
||||
_Interactive_data->Referee_Interactive_Flag.friction_flag = 0;
|
||||
}
|
||||
// lid
|
||||
if (_Interactive_data->Referee_Interactive_Flag.lid_flag == 1)
|
||||
{
|
||||
switch (_Interactive_data->lid_mode)
|
||||
{
|
||||
case LID_CLOSE:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550, "close");
|
||||
break;
|
||||
}
|
||||
case LID_OPEN:
|
||||
{
|
||||
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550, "open ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
Char_Draw(&UI_State_dyn[4], "sd4", UI_Graph_Change, 8, UI_Color_Pink, 15, 2, 270, 550, _Interactive_data->lid_mode == LID_OPEN ? "open " : "close");
|
||||
Char_ReFresh(&referee_recv_info->referee_id, UI_State_dyn[4]);
|
||||
_Interactive_data->Referee_Interactive_Flag.lid_flag = 0;
|
||||
}
|
||||
|
@ -316,7 +280,7 @@ static void Mode_Change_Check(Referee_Interactive_info_t *_Interactive_data)
|
|||
|
||||
if (_Interactive_data->lid_mode != _Interactive_data->lid_last_mode)
|
||||
{
|
||||
_Interactive_data->Referee_Interactive_Flag.lid_flag = 1;
|
||||
_Interactive_data->Referee_Interactive_Flag.lid_flag= 1;
|
||||
_Interactive_data->lid_last_mode = _Interactive_data->lid_mode;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue