simplegui/DemoProc/src/List.c

288 lines
10 KiB
C
Raw Normal View History

/*************************************************************************/
/** Copyright. **/
/** FileName: List.c **/
/** Author: Polarix **/
/** Version: 1.0.0.0 **/
/** Description: HMI demo for list control interface. **/
/*************************************************************************/
//=======================================================================//
//= Include files. =//
//=======================================================================//
#include "DemoProc.h"
#include "SGUI_List.h"
#include "HMI_Engine.h"
//=======================================================================//
//= User Macro definition. =//
//=======================================================================//
#define NOTICE_TEXT_BUFFER_SIZE (64)
//=======================================================================//
//= Static function declaration. =//
//=======================================================================//
static HMI_ENGINE_RESULT HMI_DemoList_Initialize(SGUI_IF_OBJ* pstIFObj);
static HMI_ENGINE_RESULT HMI_DemoList_Prepare(SGUI_IF_OBJ* pstIFObj, const void* pstParameters);
static HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(SGUI_IF_OBJ* pstIFObj, const void* pstParameters);
static HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_IF_OBJ* pstIFObj, HMI_EVENT_TYPE eEvent, const HMI_EVENT* pstEvent);
static HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_IF_OBJ* pstIFObj, SGUI_INT iActionResult);
//=======================================================================//
//= Static variable declaration. =//
//=======================================================================//
static SGUI_CSZSTR s_szListTitle = DEMO_LIST_TITLE;
static SGUI_CSZSTR s_arrszNoticeType[] = { DEMO_LIST_ITEM_NOTICE_TEXT, DEMO_LIST_ITEM_NOTICE_TIME};
static SGUI_CSZSTR s_arrszEnumedValue[] = { DEMO_LIST_ITEM_ENUM_VALUE1, DEMO_LIST_ITEM_ENUM_VALUE2, DEMO_LIST_ITEM_ENUM_VALUE3};
static SGUI_List_ITEM s_arrstTestListItems[] = { DEMO_LIST_ITEM_0,
DEMO_LIST_ITEM_1,
DEMO_LIST_ITEM_2,
DEMO_LIST_ITEM_3,
DEMO_LIST_ITEM_4,
DEMO_LIST_ITEM_5,
DEMO_LIST_ITEM_6,
};
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
static SGUI_List_ITEM s_arrstAppendListItems[] = { DEMO_LIST_ITEM_7,
DEMO_LIST_ITEM_8,
DEMO_LIST_ITEM_9
};
#endif
HMI_SCREEN_ACTION s_stDemoListActions = { HMI_DemoList_Initialize,
HMI_DemoList_Prepare,
HMI_DemoList_RefreshScreen,
HMI_DemoList_ProcessEvent,
HMI_DemoList_PostProcess
};
static SGUI_List_STRUCT s_stDemoListObject;
static char s_szNoticeTextBuffer[NOTICE_TEXT_BUFFER_SIZE] = {0x00};
//=======================================================================//
//= Global variable declaration. =//
//=======================================================================//
HMI_SCREEN_OBJECT g_stHMIDemo_List = { HMI_SCREEN_ID_DEMO_LIST,
&s_stDemoListActions
};
//=======================================================================//
//= Function define. =//
//=======================================================================//
HMI_ENGINE_RESULT HMI_DemoList_Initialize(SGUI_IF_OBJ* pstIFObj)
{
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
/*----------------------------------*/
/* Variable Declaration */
/*----------------------------------*/
uint32_t i;
#endif
/*----------------------------------*/
/* Process */
/*----------------------------------*/
// Initialize list data.
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);
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
s_stDemoListObject.Data.Items = NULL;
s_stDemoListObject.Data.Count = 0;
// Insert list item.
for(i=0; i<(sizeof(s_arrstTestListItems)/sizeof(SGUI_List_ITEM)); i++)
{
SGUI_List_InsertItem(&s_stDemoListObject, &s_arrstTestListItems[i], s_stDemoListObject.Data.Count);
}
#else
s_stDemoListObject.Data.Items = s_arrstTestListItems;
s_stDemoListObject.Data.Count = sizeof(s_arrstTestListItems)/sizeof(SGUI_List_ITEM);
#endif
//Initialize list object.
SGUI_List_InitializeListData(&s_stDemoListObject);
return HMI_RET_NORMAL;
}
HMI_ENGINE_RESULT HMI_DemoList_Prepare (SGUI_IF_OBJ* pstIFObj, const void* pstParameters)
{
/*----------------------------------*/
/* Process */
/*----------------------------------*/
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
return HMI_RET_NORMAL;
}
HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(SGUI_IF_OBJ* pstIFObj, const void* pstParameters)
{
/*----------------------------------*/
/* Process */
/*----------------------------------*/
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
return HMI_RET_NORMAL;
}
HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_IF_OBJ* pstIFObj, HMI_EVENT_TYPE eEvent, const HMI_EVENT* pstEvent)
{
/*----------------------------------*/
/* Variable Declaration */
/*----------------------------------*/
HMI_ENGINE_RESULT eProcessResult;
SGUI_UINT16* parrKeyValue;
/*----------------------------------*/
/* Initialize */
/*----------------------------------*/
eProcessResult = HMI_RET_NORMAL;
/*----------------------------------*/
/* Process */
/*----------------------------------*/
if(eEvent == HMI_ENGINE_EVENT_ACTION)
{
if(NULL != pstEvent)
{
parrKeyValue = (SGUI_UINT16*)pstEvent->Data;
if(NULL != parrKeyValue)
{
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:
{
SGUI_List_SelectUpItem(pstIFObj, &s_stDemoListObject);
break;
}
case KEY_VALUE_DOWN:
{
SGUI_List_SelectDownItem(pstIFObj, &s_stDemoListObject);
break;
}
case KEY_VALUE_RIGHT:
{
if((*(parrKeyValue+0) & KEY_OPTION_SHIFT) != 0)
{
SGUI_List_SetListItemValue(pstIFObj, &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);
}
else
{
SGUI_List_SetListItemValue(pstIFObj, &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);
}
break;
}
case KEY_VALUE_LEFT:
{
if((*(parrKeyValue+0) & KEY_OPTION_SHIFT) != 0)
{
SGUI_List_SetListItemValue(pstIFObj, &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);
}
else
{
SGUI_List_SetListItemValue(pstIFObj, &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);
}
break;
}
#ifdef _SIMPLE_GUI_ENABLE_DYNAMIC_MEMORY_
case KEY_VALUE_F8:
{
SGUI_List_RemoveItem(&s_stDemoListObject, s_stDemoListObject.ControlVariable.SelectIndex);
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
break;
}
case KEY_VALUE_F9: // Insert to head.
{
SGUI_List_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[0], 0);
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
break;
}
case KEY_VALUE_F10: // Insert to intermediate.
{
SGUI_List_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[1], 5);
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
break;
}
case KEY_VALUE_F11: // Insert to end.
{
SGUI_List_InsertItem(&s_stDemoListObject, &s_arrstAppendListItems[2], s_stDemoListObject.Data.Count);
SGUI_List_Refresh(pstIFObj, &s_stDemoListObject);
break;
}
#endif
default:
{
break;
}
}
}
}
}
return eProcessResult;
}
HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_IF_OBJ* pstIFObj, SGUI_INT iActionResult)
{
uint32_t uiSelectListIndex;
SGUI_List_ITEM* pstSelectedItem;
int32_t iListItemParameterValue;
if(HMI_RET_CONFIRM == iActionResult)
{
uiSelectListIndex = s_stDemoListObject.ControlVariable.SelectIndex;
switch(SGUI_List_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex)->Sign)
{
case 1:
{
// Show notice.
pstSelectedItem = SGUI_List_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex);
iListItemParameterValue = pstSelectedItem->Valid.Value;
if(0 == iListItemParameterValue)
{
sprintf(s_szNoticeTextBuffer, DEMO_LIST_NOTICE_TEXT_FMT, uiSelectListIndex);
HMI_Goto(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer);
}
else
{
HMI_Goto(HMI_SCREEN_ID_DEMO_RTC_NOTICE, NULL);
}
break;
}
case 5:
{
HMI_Goto(HMI_SCREEN_ID_DEMO_VARIABLE_BOX, NULL);
break;
}
case 6:
{
HMI_Goto(HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, NULL);
break;
}
default:
{
sprintf(s_szNoticeTextBuffer, DEMO_LIST_NOTICE_TEXT_FMT, uiSelectListIndex);
HMI_Goto(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer);
break;
}
}
}
else if(HMI_RET_CANCEL == iActionResult)
{
HMI_GoBack(NULL);
}
return HMI_RET_NORMAL;
}