2017-05-31 12:35:32 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Copyright. **/
|
2017-06-02 12:33:13 +00:00
|
|
|
/** FileName: HMI_Demo02_List.c **/
|
2017-05-31 12:35:32 +00:00
|
|
|
/** Author: Polarix **/
|
|
|
|
/** Version: 1.0.0.0 **/
|
|
|
|
/** Description: HMI demo for list control interface. **/
|
|
|
|
/*************************************************************************/
|
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Include files. =//
|
|
|
|
//=======================================================================//
|
2017-06-02 12:33:13 +00:00
|
|
|
#include "HMI_Demo02_List.h"
|
2017-05-31 12:35:32 +00:00
|
|
|
#include "GUI_List.h"
|
|
|
|
#include "HMI_Process.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2017-06-07 13:50:51 +00:00
|
|
|
//=======================================================================//
|
|
|
|
//= User Macro definition. =//
|
|
|
|
//=======================================================================//
|
|
|
|
#define NOTICE_TEXT_BUFFER_SIZE (64)
|
|
|
|
|
2017-05-31 12:35:32 +00:00
|
|
|
//=======================================================================//
|
|
|
|
//= Static function declaration. =//
|
|
|
|
//=======================================================================//
|
|
|
|
static int32_t HMI_DemoList_Initialize(void);
|
2017-06-07 13:50:51 +00:00
|
|
|
static int32_t HMI_DemoList_PreProcess(const void* pstParameters);
|
|
|
|
static int32_t HMI_DemoList_RefreshScreen(void);
|
2017-07-31 13:29:09 +00:00
|
|
|
static int32_t HMI_DemoList_InternalEvent(uint32_t uiScreenID, const void* pstParameters);
|
|
|
|
static int32_t HMI_DemoList_ExternalEvent(uint32_t uiScreenID, const void* pstParameters);
|
2017-05-31 12:35:32 +00:00
|
|
|
static int32_t HMI_DemoList_PostProcess(int32_t iActionResult);
|
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Static variable declaration. =//
|
|
|
|
//=======================================================================//
|
2017-06-02 12:33:13 +00:00
|
|
|
static const char* arrszNoticeType[] = { "文字消息", "系统时间"};
|
2017-07-31 13:29:09 +00:00
|
|
|
static GUI_LIST_ITEM arrstTestListItems[] = { {0, "简单列表项", LIST_ITEM_NORMAL, {0}, {0, 0, 0}, NULL},
|
|
|
|
{1, "枚举类型列表项", LIST_ITEM_ENUM, {0, 0, 1}, {0, 0, 0}, arrszNoticeType},
|
|
|
|
{2, "数字列表项", LIST_ITEM_DIGIT, {0, -50, 50}, {0, 0, 3}, NULL},
|
|
|
|
{3, "带小数的数字列表项", LIST_ITEM_DIGIT, {1, -50, 50}, {2, 0, 5}, NULL},
|
|
|
|
{4, "超长文字的简单列表项", LIST_ITEM_NORMAL, {0, 0, 0}, {0, 0, 0}, NULL},
|
|
|
|
{5, "列表项", LIST_ITEM_NORMAL, {0, 0, 0}, {0, 0, 0}, NULL},
|
|
|
|
{6, "曲线图", LIST_ITEM_NORMAL, {0, 0, 0}, {0, 0, 0}, NULL},
|
|
|
|
{7, "编辑框", LIST_ITEM_NORMAL, {0, 0, 0}, {0, 0, 0}, NULL},
|
2017-05-31 12:35:32 +00:00
|
|
|
};
|
2017-07-31 13:29:09 +00:00
|
|
|
|
|
|
|
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
static GUI_LIST_ITEM arrstAppendListItems[] = { {8, "添加项1", LIST_ITEM_NORMAL, {0}, {0, 0, 0}, NULL},
|
|
|
|
{9, "添加项2", LIST_ITEM_ENUM, {0, 0, 1}, {0, 0, 0}, arrszNoticeType},
|
|
|
|
{10, "添加项3", LIST_ITEM_DIGIT, {0, -50, 50}, {0, 0, 3}, NULL},
|
|
|
|
};
|
|
|
|
#endif // _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
|
|
|
|
|
|
|
|
#if _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
static GUI_LIST_STRUCT stTestList = { {"测试列表", 8, NULL}};
|
|
|
|
#else
|
2017-06-07 13:50:51 +00:00
|
|
|
static GUI_LIST_STRUCT stTestList = { {"测试列表", 8, arrstTestListItems}};
|
2017-07-31 13:29:09 +00:00
|
|
|
#endif // _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
|
2017-06-07 13:50:51 +00:00
|
|
|
static char szNoticeTextBuffer[NOTICE_TEXT_BUFFER_SIZE] = {0x00};
|
|
|
|
|
2017-05-31 12:35:32 +00:00
|
|
|
//=======================================================================//
|
|
|
|
//= Global variable declaration. =//
|
|
|
|
//=======================================================================//
|
2017-06-02 12:33:13 +00:00
|
|
|
HMI_SCREEN_ACTION stHMI_DemoListActions = { HMI_DemoList_Initialize,
|
|
|
|
HMI_DemoList_PreProcess,
|
2017-06-07 13:50:51 +00:00
|
|
|
HMI_DemoList_RefreshScreen,
|
2017-07-31 13:29:09 +00:00
|
|
|
HMI_DemoList_InternalEvent,
|
|
|
|
HMI_DemoList_ExternalEvent,
|
2017-06-02 12:33:13 +00:00
|
|
|
HMI_DemoList_PostProcess
|
|
|
|
};
|
2017-06-05 13:01:34 +00:00
|
|
|
HMI_SCREEN g_stHMI_DemoList = { HMI_SCREEN_ID_ANY,
|
2017-06-02 12:33:13 +00:00
|
|
|
&stHMI_DemoListActions
|
|
|
|
};
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Function implementation. =//
|
|
|
|
//=======================================================================//
|
|
|
|
int32_t HMI_DemoList_Initialize(void)
|
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
GUI_List_InitializeListData(&stTestList);
|
|
|
|
return HMI_RESULT_NORMAL;
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:50:51 +00:00
|
|
|
int32_t HMI_DemoList_PreProcess(const void* pstParameters)
|
2017-06-02 12:33:13 +00:00
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
|
|
|
uint32_t i;
|
|
|
|
|
2017-06-02 12:33:13 +00:00
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-07-31 13:29:09 +00:00
|
|
|
for(i=0; i<(sizeof(arrstTestListItems)/sizeof(GUI_LIST_ITEM)); i++)
|
|
|
|
{
|
|
|
|
GUI_List_InsertItem(&stTestList, &arrstTestListItems[i], stTestList.Data.Count);
|
|
|
|
}
|
|
|
|
GUI_List_RefreshList(&stTestList);
|
|
|
|
#endif // _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
2017-06-02 12:33:13 +00:00
|
|
|
return HMI_RESULT_NORMAL;
|
|
|
|
}
|
|
|
|
|
2017-06-07 13:50:51 +00:00
|
|
|
int32_t HMI_DemoList_RefreshScreen(void)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-06-07 13:50:51 +00:00
|
|
|
GUI_List_RefreshList(&stTestList);
|
2017-05-31 12:35:32 +00:00
|
|
|
return HMI_RESULT_NORMAL;
|
|
|
|
}
|
|
|
|
|
2017-07-31 13:29:09 +00:00
|
|
|
int32_t HMI_DemoList_InternalEvent(uint32_t uiScreenID, const void* pstParameters)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
|
|
|
return HMI_RESULT_NORMAL;
|
|
|
|
}
|
|
|
|
|
2017-07-31 13:29:09 +00:00
|
|
|
int32_t HMI_DemoList_ExternalEvent(uint32_t uiScreenID, const void* pstParameters)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
|
|
|
int32_t iProcessResult;
|
2017-06-05 13:01:34 +00:00
|
|
|
USER_ACT_KEYPRESS* pstUserEvent;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-06-05 13:01:34 +00:00
|
|
|
iProcessResult = HMI_RESULT_NORMAL;
|
|
|
|
pstUserEvent = (USER_ACT_KEYPRESS*)pstParameters;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-06-05 13:01:34 +00:00
|
|
|
switch(pstUserEvent->KeyValue[0])
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
|
|
|
case KEY_VALUE_SPACE:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_ENTER:
|
|
|
|
{
|
2017-06-02 12:33:13 +00:00
|
|
|
iProcessResult = HMI_RESULT_CONFIRM;
|
2017-05-31 12:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_ESC:
|
|
|
|
{
|
2017-06-02 12:33:13 +00:00
|
|
|
iProcessResult = HMI_RESULT_CANCEL;
|
2017-05-31 12:35:32 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_UP:
|
|
|
|
{
|
|
|
|
GUI_List_SelectUpItem(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_DOWN:
|
|
|
|
{
|
|
|
|
GUI_List_SelectDownItem(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_RIGHT:
|
|
|
|
{
|
2017-06-05 13:01:34 +00:00
|
|
|
if((pstUserEvent->Options & KEY_OPTION_SHIFT) != 0)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
GUI_List_SetListItemValue(&stTestList, stTestList.ControlVariable.SelectIndex, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Valid.Value, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Decimal.Value-1);
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
GUI_List_SetListItemValue(&stTestList, stTestList.ControlVariable.SelectIndex, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Valid.Value+1, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Decimal.Value);
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_LEFT:
|
|
|
|
{
|
2017-06-05 13:01:34 +00:00
|
|
|
if((pstUserEvent->Options & KEY_OPTION_SHIFT) != 0)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
GUI_List_SetListItemValue(&stTestList, stTestList.ControlVariable.SelectIndex, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Valid.Value, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Decimal.Value+1);
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-07-31 13:29:09 +00:00
|
|
|
GUI_List_SetListItemValue(&stTestList, stTestList.ControlVariable.SelectIndex, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Valid.Value-1, GUI_List_GetListItemPtr(&stTestList, stTestList.ControlVariable.SelectIndex)->Decimal.Value);
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-07-31 13:29:09 +00:00
|
|
|
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
|
|
|
case KEY_VALUE_F8:
|
|
|
|
{
|
|
|
|
GUI_List_RemoveItem(&stTestList, stTestList.ControlVariable.SelectIndex);
|
|
|
|
GUI_List_RefreshList(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F9: // Insert to head.
|
|
|
|
{
|
|
|
|
GUI_List_InsertItem(&stTestList, &arrstAppendListItems[0], 0);
|
|
|
|
GUI_List_RefreshList(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F10: // Insert to end.
|
|
|
|
{
|
|
|
|
GUI_List_InsertItem(&stTestList, &arrstAppendListItems[1], 5);
|
|
|
|
GUI_List_RefreshList(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F11: // Insert to intermediate.
|
|
|
|
{
|
|
|
|
GUI_List_InsertItem(&stTestList, &arrstAppendListItems[2], stTestList.Data.Count);
|
|
|
|
GUI_List_RefreshList(&stTestList);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif //_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
|
2017-05-31 12:35:32 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iProcessResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t HMI_DemoList_PostProcess(int32_t iActionResult)
|
|
|
|
{
|
|
|
|
uint32_t uiSelectListIndex;
|
2017-06-02 12:33:13 +00:00
|
|
|
GUI_LIST_ITEM* pstSelectedItem;
|
|
|
|
int32_t iListItemParameterValue;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
if(HMI_RESULT_CONFIRM == iActionResult)
|
|
|
|
{
|
|
|
|
uiSelectListIndex = stTestList.ControlVariable.SelectIndex;
|
2017-07-31 13:29:09 +00:00
|
|
|
switch(GUI_List_GetListItemPtr(&stTestList, uiSelectListIndex)->Sign)
|
2017-06-02 12:33:13 +00:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// Show notice.
|
2017-07-31 13:29:09 +00:00
|
|
|
pstSelectedItem = GUI_List_GetListItemPtr(&stTestList, uiSelectListIndex);
|
2017-06-02 12:33:13 +00:00
|
|
|
iListItemParameterValue = pstSelectedItem->Valid.Value;
|
|
|
|
if(0 == iListItemParameterValue)
|
|
|
|
{
|
2017-06-07 13:50:51 +00:00
|
|
|
sprintf(szNoticeTextBuffer, "选择列表项%u.", uiSelectListIndex);
|
|
|
|
HMI_Action_Goto(3, szNoticeTextBuffer);
|
2017-06-02 12:33:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-05 13:01:34 +00:00
|
|
|
HMI_Action_Goto(2, NULL);
|
2017-06-02 12:33:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-06-07 13:50:51 +00:00
|
|
|
case 6:
|
|
|
|
{
|
|
|
|
HMI_Action_Goto(4, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
{
|
|
|
|
HMI_Action_Goto(5, NULL);
|
|
|
|
break;
|
|
|
|
}
|
2017-06-02 12:33:13 +00:00
|
|
|
default:
|
|
|
|
{
|
2017-06-07 13:50:51 +00:00
|
|
|
sprintf(szNoticeTextBuffer, "选择列表项%u.", uiSelectListIndex);
|
|
|
|
HMI_Action_Goto(3, szNoticeTextBuffer);
|
2017-06-02 12:33:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(HMI_RESULT_CANCEL == iActionResult)
|
|
|
|
{
|
|
|
|
HMI_Action_GoBack();
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|