2017-05-31 12:35:32 +00:00
|
|
|
/*************************************************************************/
|
|
|
|
/** Copyright. **/
|
2017-10-11 10:59:56 +00:00
|
|
|
/** FileName: 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-10-08 16:03:05 +00:00
|
|
|
#include "DemoProc.h"
|
2017-08-02 14:24:26 +00:00
|
|
|
#include "SGUI_List.h"
|
2017-10-08 16:03:05 +00:00
|
|
|
#include "HMI_Engine.h"
|
2017-05-31 12:35:32 +00:00
|
|
|
|
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. =//
|
|
|
|
//=======================================================================//
|
2017-10-10 12:14:51 +00:00
|
|
|
static HMI_ENGINE_RESULT HMI_DemoList_Initialize(void);
|
|
|
|
static HMI_ENGINE_RESULT HMI_DemoList_Prepare(const void* pstParameters);
|
|
|
|
static HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(const void* pstParameters);
|
|
|
|
static HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(HMI_EVENT_TYPE eEvent, const HMI_EVENT* pstEvent);
|
|
|
|
static HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_INT iActionResult);
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
|
|
|
//= Static variable declaration. =//
|
|
|
|
//=======================================================================//
|
2017-10-11 10:59:56 +00:00
|
|
|
static SGUI_PCSZSTR s_szListTitle = "测试列表";
|
|
|
|
static SGUI_PCSZSTR s_arrszNoticeType[] = { "文字消息", "系统时间"};
|
|
|
|
static SGUI_LIST_ITEM s_arrstTestListItems[] = { { 0, "简单列表项", LIST_ITEM_NORMAL, {0}, {0, 0, 0}, NULL},
|
|
|
|
{ 1, "枚举类型列表项", LIST_ITEM_ENUM, {0, 0, 1}, {0, 0, 0}, s_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},
|
|
|
|
};
|
2017-07-31 13:29:09 +00:00
|
|
|
|
2017-09-22 14:09:36 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-10-11 10:59:56 +00:00
|
|
|
static SGUI_LIST_ITEM s_arrstAppendListItems[] = { { 8, "添加项1", LIST_ITEM_NORMAL, {0}, {0, 0, 0}, NULL},
|
|
|
|
{ 9, "添加项2", LIST_ITEM_ENUM, {0, 0, 1}, {0, 0, 0}, s_arrszNoticeType},
|
|
|
|
{10, "添加项3", LIST_ITEM_DIGIT, {0, -50, 50}, {0, 0, 3}, NULL}
|
|
|
|
};
|
2017-09-22 14:09:36 +00:00
|
|
|
#endif
|
2017-07-31 13:29:09 +00:00
|
|
|
|
2017-10-11 10:59:56 +00:00
|
|
|
HMI_SCREEN_ACTION s_stDemoListActions = { HMI_DemoList_Initialize,
|
|
|
|
HMI_DemoList_Prepare,
|
|
|
|
HMI_DemoList_RefreshScreen,
|
|
|
|
HMI_DemoList_ProcessEvent,
|
|
|
|
HMI_DemoList_PostProcess
|
|
|
|
};
|
2017-07-31 13:29:09 +00:00
|
|
|
|
2017-10-11 10:59:56 +00:00
|
|
|
static SGUI_LIST_STRUCT s_stDemoListObject;
|
|
|
|
|
|
|
|
static char s_szNoticeTextBuffer[NOTICE_TEXT_BUFFER_SIZE] = {0x00};
|
2017-06-07 13:50:51 +00:00
|
|
|
|
2017-05-31 12:35:32 +00:00
|
|
|
//=======================================================================//
|
|
|
|
//= Global variable declaration. =//
|
|
|
|
//=======================================================================//
|
2017-10-11 10:59:56 +00:00
|
|
|
HMI_SCREEN_OBJECT g_stHMIDemo_List = { HMI_SCREEN_ID_DEMO_LIST,
|
|
|
|
&s_stDemoListActions
|
|
|
|
};
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
//=======================================================================//
|
2017-12-27 12:03:30 +00:00
|
|
|
//= Function define. =//
|
2017-05-31 12:35:32 +00:00
|
|
|
//=======================================================================//
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT HMI_DemoList_Initialize(void)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
|
|
|
uint32_t i;
|
|
|
|
#endif
|
|
|
|
|
2017-05-31 12:35:32 +00:00
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-10-08 16:03:05 +00:00
|
|
|
// Initialize list data.
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_Common_MemorySet(&s_stDemoListObject, 0x00, sizeof(SGUI_LIST_STRUCT));
|
|
|
|
// Title and font size must set before initialize list object.
|
|
|
|
s_stDemoListObject.Data.Title = s_szListTitle;
|
|
|
|
s_stDemoListObject.FontSize = SGUI_FONT_SIZE_H12;
|
|
|
|
//Initialize list object.
|
|
|
|
SGUI_LIST_InitializeListData(&s_stDemoListObject);
|
2017-09-22 14:09:36 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-10-11 10:59:56 +00:00
|
|
|
s_stDemoListObject.Data.Items = NULL;
|
|
|
|
s_stDemoListObject.Data.Count = 0;
|
2017-10-10 12:14:51 +00:00
|
|
|
// Insert list item.
|
2017-10-11 10:59:56 +00:00
|
|
|
for(i=0; i<(sizeof(s_arrstTestListItems)/sizeof(SGUI_LIST_ITEM)); i++)
|
2017-07-31 13:29:09 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_InsertItem(&s_stDemoListObject, &s_arrstTestListItems[i], s_stDemoListObject.Data.Count);
|
2017-07-31 13:29:09 +00:00
|
|
|
}
|
2017-10-11 10:59:56 +00:00
|
|
|
#else
|
|
|
|
s_stDemoListObject.Data.Items = s_arrstTestListItems;
|
|
|
|
s_stDemoListObject.Data.Count = sizeof(s_arrstTestListItems)/sizeof(SGUI_LIST_ITEM);
|
2017-09-22 14:09:36 +00:00
|
|
|
#endif
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-02 12:33:13 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT HMI_DemoList_Prepare (const void* pstParameters)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(const void* pstParameters)
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-06-07 13:50:51 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(HMI_EVENT_TYPE eEvent, const HMI_EVENT* pstEvent)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Variable Declaration */
|
|
|
|
/*----------------------------------*/
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT eProcessResult;
|
|
|
|
SGUI_UINT16* parrKeyValue;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Initialize */
|
|
|
|
/*----------------------------------*/
|
2017-10-10 12:14:51 +00:00
|
|
|
eProcessResult = HMI_RET_NORMAL;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
|
|
|
/*----------------------------------*/
|
|
|
|
/* Process */
|
|
|
|
/*----------------------------------*/
|
2017-10-10 12:14:51 +00:00
|
|
|
if(eEvent == HMI_ENGINE_EVENT_ACTION)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
if(NULL != pstEvent)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
parrKeyValue = (SGUI_UINT16*)pstEvent->Data;
|
|
|
|
if(NULL != parrKeyValue)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
switch(*(parrKeyValue+1))
|
|
|
|
{
|
|
|
|
case KEY_VALUE_ENTER:
|
|
|
|
{
|
|
|
|
eProcessResult = HMI_RET_CONFIRM;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_ESC:
|
|
|
|
{
|
|
|
|
eProcessResult = HMI_RET_CANCEL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_UP:
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SelectUpItem(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_DOWN:
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SelectDownItem(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_RIGHT:
|
|
|
|
{
|
|
|
|
if((*(parrKeyValue+0) & KEY_OPTION_SHIFT) != 0)
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SetListItemValue(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Valid.Value, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Decimal.Value-1);
|
2017-10-10 12:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SetListItemValue(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Valid.Value+1, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Decimal.Value);
|
2017-10-10 12:14:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_LEFT:
|
|
|
|
{
|
|
|
|
if((*(parrKeyValue+0) & KEY_OPTION_SHIFT) != 0)
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SetListItemValue(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Valid.Value, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Decimal.Value+1);
|
2017-10-10 12:14:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_SetListItemValue(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Valid.Value-1, SGUI_LIST_GetListItemPtr(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex)->Decimal.Value);
|
2017-10-10 12:14:51 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-09-22 14:09:36 +00:00
|
|
|
#if (_SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_ > 0)
|
2017-10-10 12:14:51 +00:00
|
|
|
case KEY_VALUE_F8:
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_RemoveItem(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex);
|
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F9: // Insert to head.
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[0], 0);
|
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F10: // Insert to intermediate.
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[1], 5);
|
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case KEY_VALUE_F11: // Insert to end.
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
SGUI_LIST_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[2], s_stDemoListObject.Data.Count);
|
|
|
|
SGUI_LIST_RefreshList(&s_stDemoListObject);
|
2017-10-10 12:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-22 14:09:36 +00:00
|
|
|
#endif
|
2017-10-10 12:14:51 +00:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-10 12:14:51 +00:00
|
|
|
return eProcessResult;
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_INT iActionResult)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
|
|
|
uint32_t uiSelectListIndex;
|
2017-08-02 14:24:26 +00:00
|
|
|
SGUI_LIST_ITEM* pstSelectedItem;
|
2017-06-02 12:33:13 +00:00
|
|
|
int32_t iListItemParameterValue;
|
2017-05-31 12:35:32 +00:00
|
|
|
|
2017-10-08 16:03:05 +00:00
|
|
|
if(HMI_RET_CONFIRM == iActionResult)
|
2017-05-31 12:35:32 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
uiSelectListIndex = s_stDemoListObject.ControlVariable.SelectIndex;
|
|
|
|
switch(SGUI_LIST_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex)->Sign)
|
2017-06-02 12:33:13 +00:00
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
// Show notice.
|
2017-10-11 10:59:56 +00:00
|
|
|
pstSelectedItem = SGUI_LIST_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex);
|
2017-06-02 12:33:13 +00:00
|
|
|
iListItemParameterValue = pstSelectedItem->Valid.Value;
|
|
|
|
if(0 == iListItemParameterValue)
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
sprintf(s_szNoticeTextBuffer, "选择列表项%u.", uiSelectListIndex);
|
|
|
|
HMI_Goto(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer);
|
2017-06-02 12:33:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
HMI_Goto(HMI_SCREEN_ID_DEMO_RTC_NOTICE, NULL);
|
2017-06-02 12:33:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-10-11 10:59:56 +00:00
|
|
|
case 5:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
HMI_Goto(HMI_SCREEN_ID_DEMO_VARIABLE_BOX, NULL);
|
2017-06-07 13:50:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-10-11 10:59:56 +00:00
|
|
|
case 6:
|
2017-06-07 13:50:51 +00:00
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
HMI_Goto(HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, NULL);
|
2017-06-07 13:50:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-06-02 12:33:13 +00:00
|
|
|
default:
|
|
|
|
{
|
2017-10-11 10:59:56 +00:00
|
|
|
sprintf(s_szNoticeTextBuffer, "选择列表项%u.", uiSelectListIndex);
|
|
|
|
HMI_Goto(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer);
|
2017-06-02 12:33:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
else if(HMI_RET_CANCEL == iActionResult)
|
2017-06-02 12:33:13 +00:00
|
|
|
{
|
2017-10-10 12:14:51 +00:00
|
|
|
HMI_GoBack(NULL);
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
2017-10-08 16:03:05 +00:00
|
|
|
return HMI_RET_NORMAL;
|
2017-05-31 12:35:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|