[C] 纯文本查看 复制代码
/*
*********************************************************************************************************
*
* 模块名称 : GUI界面主函数
* 文件名称 : MainTask.c
* 版 本 : V1.0
* 说 明 : emWin测试。
*
* 修改记录 :
* 版本号 日期 作者 说明
* V1.0 2021-02-06 Eric2013 首版
*
* Copyright (C), 2021-2030, 安富莱电子 [url]www.armfly.com[/url]
*
*********************************************************************************************************
*/
#include "bsp.h"
#include "MainTask.h"
#define ID_WINDOW_0 (GUI_ID_USER + 0x00)
#define ID_BUTTON_0 (GUI_ID_USER + 0x01)
#define ID_BUTTON_1 (GUI_ID_USER + 0x02)
#define ID_BUTTON_2 (GUI_ID_USER + 0x03)
#define ID_BUTTON_3 (GUI_ID_USER + 0x04)
#define ID_BUTTON_4 (GUI_ID_USER + 0x05)
#define ID_BUTTON_5 (GUI_ID_USER + 0x06)
#define ID_BUTTON_6 (GUI_ID_USER + 0x07)
#define ID_BUTTON_7 (GUI_ID_USER + 0x08)
#define ID_EDIT_0 (GUI_ID_USER + 0x09)
#define ID_EDIT_1 (GUI_ID_USER + 0x0A)
#define ID_TEXT_0 (GUI_ID_USER + 0x0B)
#define ID_TEXT_1 (GUI_ID_USER + 0x0C)
#define ID_TEXT_2 (GUI_ID_USER + 0x0D)
static const GUI_WIDGET_CREATE_INFO _aDialogCreate1[] = {
{ WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button1", ID_BUTTON_0, 18, 87, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button2", ID_BUTTON_1, 130, 87, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button3", ID_BUTTON_2, 245, 87, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button4", ID_BUTTON_3, 361, 87, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button5", ID_BUTTON_4, 18, 161, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button6", ID_BUTTON_5, 130, 161, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button7", ID_BUTTON_6, 245, 161, 88, 44, 0, 0x0, 0 },
{ BUTTON_CreateIndirect, "Button8", ID_BUTTON_7, 361, 161, 88, 44, 0, 0x0, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_0, 48, 239, 80, 26, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_0, 370, 2, 112, 20, 0, 0x0, 0 },
{ TEXT_CreateIndirect, "Text", ID_TEXT_1, 368, 24, 112, 20, 0, 0x0, 0 },
{ EDIT_CreateIndirect, "Edit", ID_EDIT_1, 348, 239, 80, 26, 0, 0x64, 0 },
{ TEXT_CreateIndirect, "Frt", ID_TEXT_2, 109, 1, 237, 20, 0, 0x0, 0 },
// USER START (Optionally insert additional widgets)
// USER END
};
/*********************************************************************
*
* Static code
*
**********************************************************************
*/
// USER START (Optionally insert additional static code)
// USER END
/*********************************************************************
*
* _cbDialog
*/
static void _cbDialog1(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int NCode;
int Id;
char buf[20];
RTC_TimeTypeDef RTC_TimeStruct;
RTC_DateTypeDef RTC_DateStruct;// //显示日期
// USER START (Optionally insert additional variables)
// USER END
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
//
// Initialization of 'Edit'
//
GUI_SetFont(GUI_FONT_8X18);
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_0);
EDIT_SetText(hItem, "12345678");
//
// Initialization of 'Edit'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_EDIT_1);
EDIT_SetText(hItem, "123456.78");
//
// Initialization of 'Frist'
//
hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_2);
TEXT_SetFont(hItem, GUI_FONT_16B_ASCII);
TEXT_SetTextAlign(hItem, GUI_TA_HCENTER | GUI_TA_VCENTER);
// USER START (Optionally insert additional code for further widget initialization)
// USER END
break;
/* 定时器消息 */
case WM_TIMER: //--------------(1)
// //显示日期
// //HAL_RTC_GetDate(&hrtc,&RTC_DateStruct,RTC_FORMAT_BIN);//获取日期
// sprintf((char*)buf,"20%02d-%02d-%02d",RTC_DateStruct.Year,RTC_DateStruct.Month,RTC_DateStruct.Date);
// TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_0), (const char*)buf);
// //显示时间
// HAL_RTC_GetTime(&hrtc,&RTC_TimeStruct,RTC_FORMAT_BIN);//获取时间
// sprintf((char*)buf,"%02d:%02d:%02d",RTC_TimeStruct.Hours,RTC_TimeStruct.Minutes,RTC_TimeStruct.Seconds);
// TEXT_SetText(WM_GetDialogItem(pMsg->hWin, ID_TEXT_1), (const char*)buf);
WM_RestartTimer(pMsg->Data.v, 1000);
break;
case WM_KEY:
switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key)
{
case GUI_KEY_ESCAPE:
GUI_EndDialog(pMsg->hWin, 1);
break;
case GUI_KEY_TAB:
WM_SetFocusOnNextChild(pMsg->hWin);
break;
}
break;
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch(Id) {
case ID_BUTTON_0: // Notifications sent by 'Button1'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
GUI_EndDialog(pMsg->hWin, 0);
//reateSECOND();
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_1: // Notifications sent by 'Button2'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_2: // Notifications sent by 'Button3'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_3: // Notifications sent by 'Button4'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_4: // Notifications sent by 'Button5'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_5: // Notifications sent by 'Button6'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_6: // Notifications sent by 'Button7'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_BUTTON_7: // Notifications sent by 'Button8'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_EDIT_0: // Notifications sent by 'Edit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_VALUE_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
case ID_EDIT_1: // Notifications sent by 'Edit'
switch(NCode) {
case WM_NOTIFICATION_CLICKED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_RELEASED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
case WM_NOTIFICATION_VALUE_CHANGED:
// USER START (Optionally insert code for reacting on notification message)
// USER END
break;
// USER START (Optionally insert additional code for further notification handling)
// USER END
}
break;
// USER START (Optionally insert additional code for further Ids)
// USER END
}
break;
// USER START (Optionally insert additional message handling)
// USER END
default:
WM_DefaultProc(pMsg);
break;
}
}
/*********************************************************************
*
* Public code
*
**********************************************************************
*/
/*********************************************************************
*
* CreateWindow
*/
WM_HWIN CreateWindow(void) {
WM_HWIN hWin;
WM_HTIMER hTimer;
hWin = GUI_CreateDialogBox(_aDialogCreate1, GUI_COUNTOF(_aDialogCreate1), _cbDialog1, WM_HBKWIN, 0, 0);
WM_SetFocus(hWin);
/* 给对话框hDlg创建定时器,溢出时间是100ms */
hTimer = WM_CreateTimer(hWin, 0, 1000, 0); //--------------(2)
return hWin;
}
/*
*********************************************************************************************************
* 函 数 名: MainTask
* 功能说明: GUI主函数
* 形 参: 无
* 返 回 值: 无
*********************************************************************************************************
*/
void MainTask(void)
{
/* 初始化 */
GUI_Init();
/*
关于多缓冲和窗口内存设备的设置说明
1. 使能多缓冲是调用的如下函数,用户要在LCDConf_Lin_Template.c文件中配置了多缓冲,调用此函数才有效:
WM_MULTIBUF_Enable(1);
2. 窗口使能使用内存设备是调用函数:WM_SetCreateFlags(WM_CF_MEMDEV);
3. 如果emWin的配置多缓冲和窗口内存设备都支持,二选一即可,且务必优先选择使用多缓冲,实际使用
STM32H7 + 32位SDRAM + RGB565/RGB888平台测试,多缓冲可以有效的降低窗口移动或者滑动时的撕裂
感,并有效的提高流畅性,通过使能窗口使用内存设备是做不到的。
4. 所有emWin例子默认是开启三缓冲。
*/
WM_MULTIBUF_Enable(1);
/*
触摸校准函数默认是注释掉的,电阻屏需要校准,电容屏无需校准。如果用户需要校准电阻屏的话,执行
此函数即可,会将触摸校准参数保存到EEPROM里面,以后系统上电会自动从EEPROM里面加载。
TOUCH_Calibration(2); 参数为2表示两点校准
TOUCH_Calibration(4); 参数为4表示四点校准
*/
#if 0
LCD_SetBackLight(255);
TOUCH_Calibration(2);
#endif
/* 设置桌面窗口的背景色是白色,并且支持重绘 */
WM_SetDesktopColor(GUI_BLUE);
CreateWindow();
/* 屏幕显示后点亮,有效防止瞬间高亮 */
GUI_Delay(200);
LCD_SetBackLight(255);
while(1)
{
GUI_Delay(10);
}
}
/***************************** 安富莱电子 [url]www.armfly.com[/url] (END OF FILE) *********************************/