diff --git a/DemoProc/inc/DemoProc.h b/DemoProc/inc/DemoProc.h index 307d456..b8c23d7 100644 --- a/DemoProc/inc/DemoProc.h +++ b/DemoProc/inc/DemoProc.h @@ -20,7 +20,7 @@ // HMI action type typedef enum { - EVENT_ID_UNKNOW = 0, + EVENT_ID_UNKNOW = 0, // User defined action type. EVENT_ID_KEY_PRESS, EVENT_ID_TIMER, @@ -29,6 +29,21 @@ typedef enum EVENT_ID_MAX }EVENT_ID; +// HMI event type. +typedef enum +{ + EVENT_TYPE_ANY = 0, + EVENT_TYPE_ACTION, + EVENT_TYPE_DATA, +}EVENT_TYPE; + +enum DEMO_PROC_ACTION_ID +{ + HMI_DEMO_PROC_NO_ACT = 0, + HMI_DEMO_PROC_CONFIRM = 1, + HMI_DEMO_PROC_CANCEL = 2, +}; + typedef struct { SGUI_UINT16 uiKeyValue; @@ -54,8 +69,10 @@ HMI_EVENT_TYPE_DECLARE(DATA_EVENT, DUMMY_DATA_EVENT_DATA); //=======================================================================// //= Public variable declaration. =// -//=======================================================================// -extern HMI_ENGINE_OBJECT g_stDemoEngine; +//=======================================================================// +/* HMI engine object. */ +extern HMI_ENGINE_OBJECT g_stDemoEngine; +/* Screen display objects. */ extern HMI_SCREEN_OBJECT g_stHMIDemo_ScrollingText; extern HMI_SCREEN_OBJECT g_stHMIDemo_List; extern HMI_SCREEN_OBJECT g_stHMIDemo_TextNotice; @@ -70,7 +87,6 @@ extern "C" { #endif /* __cplusplus */ HMI_ENGINE_RESULT InitializeEngine(void); -HMI_ENGINE_RESULT EventProcess(const HMI_EVENT_BASE* pstEvent); int DemoMainProcess(void); #ifdef __cplusplus diff --git a/DemoProc/src/DemoProc.c b/DemoProc/src/DemoProc.c index f67cfcf..564d926 100644 --- a/DemoProc/src/DemoProc.c +++ b/DemoProc/src/DemoProc.c @@ -20,8 +20,17 @@ //=======================================================================// //= Static variable declaration. =// //=======================================================================// -HMI_ENGINE_OBJECT g_stDemoEngine; SGUI_SCR_DEV g_stDeviceInterface; +HMI_SCREEN_OBJECT* g_arrpstScreenObjs[] = + { + &g_stHMIDemo_ScrollingText, + &g_stHMIDemo_List, + &g_stHMIDemo_TextNotice, + &g_stHMIDemo_RTCNotice, + &g_stHMIDemo_VariableBox, + &g_stHMI_DemoRealtimeGraph, + }; +HMI_ENGINE_OBJECT g_stDemoEngine; //=======================================================================// //= Static function declare. =// @@ -48,6 +57,7 @@ HMI_ENGINE_RESULT InitializeEngine(void) /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; + int iIndex; /*----------------------------------*/ /* Initialize */ @@ -79,81 +89,49 @@ HMI_ENGINE_RESULT InitializeEngine(void) g_stDeviceInterface.stActions.fnClearScreen = OLED_ClearDisplay; g_stDeviceInterface.stActions.fnRefreshScreen = OLED_RefreshScreen; #endif - g_stDemoEngine.Interface = &g_stDeviceInterface; - /* Configure HMI engine. */ - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) + do { - eProcessResult = HMI_PrepareEngine(&g_stDemoEngine); - } + /* Prepare HMI engine object. */ + g_stDemoEngine.ScreenCount = sizeof(g_arrpstScreenObjs)/sizeof(*g_arrpstScreenObjs); + g_stDemoEngine.ScreenObjPtr = g_arrpstScreenObjs; + g_stDemoEngine.Interface = &g_stDeviceInterface; - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMIDemo_ScrollingText, SGUI_TRUE); - } - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMIDemo_List, SGUI_TRUE); - } - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMIDemo_TextNotice, SGUI_TRUE); - } - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMIDemo_RTCNotice, SGUI_TRUE); - } - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMIDemo_VariableBox, SGUI_TRUE); - } - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - eProcessResult = HMI_AddScreen(&g_stDemoEngine, &g_stHMI_DemoRealtimeGraph, SGUI_TRUE); - } + /* Initialize all screen object. */ + if(NULL != g_stDemoEngine.ScreenObjPtr) + { + for(iIndex=0; iIndexpstActions) + && (g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize) + ) + { + g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize(&g_stDeviceInterface); + g_stDemoEngine.ScreenObjPtr[iIndex]->pstPrevious = NULL; + } + } + } + else + { - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { + } + /* Active engine object. */ eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_SCROLLING_TEXT); - } - - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { + if(HMI_PROCESS_FAILED(eProcessResult)) + { + /* Active engine failed. */ + break; + } + /* Start engine process. */ eProcessResult = HMI_StartEngine(NULL); - } + if(HMI_PROCESS_FAILED(eProcessResult)) + { + /* Start engine failed. */ + break; + } + }while(0); - return eProcessResult; -} - -/*****************************************************************************/ -/** Function Name: EventProcess **/ -/** Purpose: Process posted event. **/ -/** Parameters: **/ -/** @ pstEvent[in]: HMI event data. **/ -/** Return: HMI_ENGINE_RESULT. **/ -/** Notice: This function must be called when initialize. **/ -/*****************************************************************************/ -HMI_ENGINE_RESULT EventProcess(const HMI_EVENT_BASE* pstEvent) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_ENGINE_RESULT eProcessResult; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - eProcessResult = HMI_RET_NORMAL; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - - eProcessResult = HMI_ProcessEvent(pstEvent); - if(HMI_PROCESS_SUCCESSFUL(eProcessResult)) - { - HMI_PostProcess(eProcessResult); - } return eProcessResult; } @@ -209,11 +187,11 @@ void KeyPressEventProc(void) /*----------------------------------*/ /* Process */ /*----------------------------------*/ - stEvent.Head.eType = HMI_ENGINE_EVENT_ACTION; + stEvent.Head.iType = EVENT_TYPE_ACTION; stEvent.Head.iID = EVENT_ID_KEY_PRESS; stEvent.Data.uiKeyValue = SGUI_SDK_GetKeyEventData(); // Post key press event. - EventProcess((HMI_EVENT_BASE*)(&stEvent)); + HMI_ProcessEvent((HMI_EVENT_BASE*)(&stEvent)); } void SysTickTimerEventProc(void) @@ -231,11 +209,11 @@ void SysTickTimerEventProc(void) /*----------------------------------*/ /* Process */ /*----------------------------------*/ - stEvent.Head.eType = HMI_ENGINE_EVENT_DATA; + stEvent.Head.iType = EVENT_TYPE_DATA; stEvent.Head.iID = EVENT_ID_TIMER; stEvent.Data.iValue = (rand() % 200)-100; // Post timer event. - EventProcess((HMI_EVENT_BASE*)&stEvent); + HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); } @@ -254,9 +232,9 @@ void RTCEventProc(void) /*----------------------------------*/ /* Process */ /*----------------------------------*/ - stEvent.Head.eType = HMI_ENGINE_EVENT_DATA; + stEvent.Head.iType = EVENT_TYPE_DATA; stEvent.Head.iID = EVENT_ID_RTC; // Post RTC update message to a screen. - EventProcess((HMI_EVENT_BASE*)&stEvent); + HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); } diff --git a/DemoProc/src/List.c b/DemoProc/src/List.c index 190de3f..734b10c 100644 --- a/DemoProc/src/List.c +++ b/DemoProc/src/List.c @@ -24,8 +24,8 @@ static HMI_ENGINE_RESULT HMI_DemoList_Initialize(SGUI_SCR_DEV* pstIFObj); static HMI_ENGINE_RESULT HMI_DemoList_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); //=======================================================================// //= Static variable declaration. =// @@ -130,7 +130,7 @@ HMI_ENGINE_RESULT HMI_DemoList_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* return HMI_RET_NORMAL; } -HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ @@ -139,18 +139,20 @@ HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EV SGUI_UINT16 uiKeyCode; SGUI_UINT16 uiKeyValue; SGUI_UINT16 uiOptionCode; - KEY_PRESS_EVENT* pstKeyEvent; + KEY_PRESS_EVENT* pstKeyEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; pstKeyEvent = (KEY_PRESS_EVENT*)pstEvent; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ /*----------------------------------*/ - if(pstEvent->eType == HMI_ENGINE_EVENT_ACTION) + if(pstEvent->iType == EVENT_TYPE_ACTION) { // Check event is valid. if(SGUI_FALSE == HMI_EVENT_SIZE_CHK(*pstKeyEvent, KEY_PRESS_EVENT)) @@ -167,12 +169,12 @@ HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EV { case KEY_VALUE_ENTER: { - eProcessResult = HMI_RET_CONFIRM; + iProcessAction = HMI_DEMO_PROC_CONFIRM; break; } case KEY_VALUE_ESC: { - eProcessResult = HMI_RET_CANCEL; + iProcessAction = HMI_DEMO_PROC_CANCEL; break; } case KEY_VALUE_UP: @@ -242,19 +244,24 @@ HMI_ENGINE_RESULT HMI_DemoList_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EV } } } + if(NULL != piActionID) + { + *piActionID = iProcessAction; + } + return eProcessResult; } -HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { uint32_t uiSelectListIndex; SGUI_List_ITEM* pstSelectedItem; int32_t iListItemParameterValue; - if(HMI_RET_CONFIRM == iActionResult) + if(HMI_DEMO_PROC_CONFIRM == iActionID) { uiSelectListIndex = s_stDemoListObject.ControlVariable.SelectIndex; - switch(SGUI_List_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex)->Sign) + switch(SGUI_List_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex)->ItemID) { case 1: { @@ -264,36 +271,37 @@ HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iAct if(0 == iListItemParameterValue) { sprintf(s_szNoticeTextBuffer, DEMO_LIST_NOTICE_TEXT_FMT, uiSelectListIndex); - HMI_Goto(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer); + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer); } else { - HMI_Goto(HMI_SCREEN_ID_DEMO_RTC_NOTICE, NULL); + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_RTC_NOTICE, NULL); } break; } case 5: { - HMI_Goto(HMI_SCREEN_ID_DEMO_VARIABLE_BOX, NULL); + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_VARIABLE_BOX, NULL); break; } case 6: { - HMI_Goto(HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, NULL); + HMI_SwitchScreen(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); + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer); break; } } } - else if(HMI_RET_CANCEL == iActionResult) + else if(HMI_DEMO_PROC_CANCEL == iActionID) { HMI_GoBack(NULL); } + return HMI_RET_NORMAL; } diff --git a/DemoProc/src/RTCNotice.c b/DemoProc/src/RTCNotice.c index 4f657c5..0d292a1 100644 --- a/DemoProc/src/RTCNotice.c +++ b/DemoProc/src/RTCNotice.c @@ -21,17 +21,16 @@ //=======================================================================// //= Static function declaration. =// //=======================================================================// -static HMI_ENGINE_RESULT HMI_DemoRTCNotice_Initialize(SGUI_SCR_DEV* pstIFObj); static HMI_ENGINE_RESULT HMI_DemoRTCNotice_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoRTCNotice_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoRTCNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoRTCNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); //=======================================================================// //= Static variable declaration. =// //=======================================================================// static char s_szRTCNoticeText[NOTICE_RTC_BUFFER_SIZE+1] = {0x00}; -HMI_SCREEN_ACTION s_stDemoRTCNoticeActions = { HMI_DemoRTCNotice_Initialize, +HMI_SCREEN_ACTION s_stDemoRTCNoticeActions = { NULL, HMI_DemoRTCNotice_Prepare, HMI_DemoRTCNotice_RefreshScreen, HMI_DemoRTCNotice_ProcessEvent, @@ -47,15 +46,10 @@ HMI_SCREEN_OBJECT g_stHMIDemo_RTCNotice = { HMI_SCREEN_ID_DEMO_RTC_NOTIC //=======================================================================// //= Function define. =// //=======================================================================// -HMI_ENGINE_RESULT HMI_DemoRTCNotice_Initialize(SGUI_SCR_DEV* pstIFObj) -{ - SGUI_SystemIF_MemorySet(s_szRTCNoticeText, 0x00, sizeof(SGUI_CHAR)*(NOTICE_RTC_BUFFER_SIZE+1)); - return HMI_RET_NORMAL; -} - HMI_ENGINE_RESULT HMI_DemoRTCNotice_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters) { SGUI_SDK_EnableRTCInterrupt(true); + SGUI_SystemIF_MemorySet(s_szRTCNoticeText, 0x00, sizeof(SGUI_CHAR)*(NOTICE_RTC_BUFFER_SIZE+1)); HMI_DemoRTCNotice_RefreshScreen(pstIFObj, NULL); return HMI_RET_NORMAL; } @@ -78,7 +72,7 @@ HMI_ENGINE_RESULT HMI_DemoRTCNotice_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const return HMI_RET_NORMAL; } -HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ @@ -86,19 +80,21 @@ HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H HMI_ENGINE_RESULT eProcessResult; SGUI_TIME stRTCTime; SGUI_UINT16 uiKeyValue; - KEY_PRESS_EVENT* pstKeyEvent; + KEY_PRESS_EVENT* pstKeyEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ /*----------------------------------*/ if(NULL != pstEvent) { - if(HMI_ENGINE_EVENT_ACTION == pstEvent->eType) + if(EVENT_TYPE_ACTION == pstEvent->iType) { if(EVENT_ID_KEY_PRESS == pstEvent->iID) { @@ -109,13 +105,13 @@ HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H case KEY_VALUE_ENTER: case KEY_VALUE_ESC: { - eProcessResult = HMI_RET_CANCEL; + iProcessAction = HMI_DEMO_PROC_CANCEL; break; } } } } - else if(HMI_ENGINE_EVENT_DATA == pstEvent->eType) + else if(EVENT_TYPE_DATA == pstEvent->iType) { if(EVENT_ID_RTC == pstEvent->iID) { @@ -124,26 +120,28 @@ HMI_ENGINE_RESULT HMI_DemoRTCNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H stRTCTime.Year, stRTCTime.Month, stRTCTime.Day, stRTCTime.Hour, stRTCTime.Minute, stRTCTime.Second); SGUI_Notice_Refresh(pstIFObj, s_szRTCNoticeText, 0, SGUI_ICON_INFORMATION); - eProcessResult = HMI_RET_NOACTION; - } } } - else + if(NULL != piActionID) { - eProcessResult = HMI_RET_NOACTION; + *piActionID = iProcessAction; } return eProcessResult; } -HMI_ENGINE_RESULT HMI_DemoRTCNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoRTCNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { - if(HMI_RET_CANCEL == iActionResult) + if(HMI_PROCESS_SUCCESSFUL(eProcResult)) { - SGUI_SDK_EnableRTCInterrupt(false); - HMI_GoBack(NULL); + if(HMI_DEMO_PROC_CANCEL == iActionID) + { + SGUI_SDK_EnableRTCInterrupt(false); + HMI_GoBack(NULL); + } } + return HMI_RET_NORMAL; } diff --git a/DemoProc/src/RealtimeGraph.c b/DemoProc/src/RealtimeGraph.c index c203f23..e0a8988 100644 --- a/DemoProc/src/RealtimeGraph.c +++ b/DemoProc/src/RealtimeGraph.c @@ -18,25 +18,25 @@ static HMI_ENGINE_RESULT HMI_DemoRealGraph_Initialize(SGUI_SCR_DEV* pstIFObj); static HMI_ENGINE_RESULT HMI_DemoRealGraph_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoRealGraph_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoRealGraph_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); //=======================================================================// //= Static variable declaration. =// //=======================================================================// -SGUI_RTGRAPH_CONTROL s_stRealtimeGraphControl = {50, -50, SGUI_TRUE, 3, 0}; -SGUI_RTGRAPH_DATA s_stRealtimeGraphData = {{1, 9, 126, 46}, {0}, {0}, {0}, 0, 0}; -SGUI_RTGRAPH s_stRealtimeGraph = {&s_stRealtimeGraphData, &s_stRealtimeGraphControl}; +SGUI_RTGRAPH_CONTROL s_stRealtimeGraphControl = {50, -50, SGUI_TRUE, 3, 0}; +SGUI_RTGRAPH_DATA s_stRealtimeGraphData = {{1, 9, 126, 46}, {0}, {0}, {0}, 0, 0}; +SGUI_RTGRAPH s_stRealtimeGraph = {&s_stRealtimeGraphData, &s_stRealtimeGraphControl}; //=======================================================================// //= Global variable declaration. =// //=======================================================================// -HMI_SCREEN_ACTION s_stDemoRealtimeGraphActions = { HMI_DemoRealGraph_Initialize, +static HMI_SCREEN_ACTION s_stDemoRealtimeGraphActions = { HMI_DemoRealGraph_Initialize, HMI_DemoRealGraph_Prepare, HMI_DemoRealGraph_RefreshScreen, HMI_DemoRealGraph_ProcessEvent, HMI_DemoRealGraph_PostProcess, }; -HMI_SCREEN_OBJECT g_stHMI_DemoRealtimeGraph = { HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, +HMI_SCREEN_OBJECT g_stHMI_DemoRealtimeGraph = { HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, &s_stDemoRealtimeGraphActions }; @@ -92,7 +92,7 @@ HMI_ENGINE_RESULT HMI_DemoRealGraph_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const return HMI_RET_NORMAL; } -HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ @@ -103,11 +103,13 @@ HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H SGUI_UINT16 uiKeyValue; KEY_PRESS_EVENT* pstKeyEvent; DATA_EVENT* pstDataEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ @@ -129,11 +131,7 @@ HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H if(KEY_VALUE_ESC == uiKeyValue) { - eProcessResult = HMI_RET_CANCEL; - } - else - { - eProcessResult = HMI_RET_NOACTION; + iProcessAction = HMI_DEMO_PROC_CANCEL; } } break; @@ -156,25 +154,34 @@ HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const H } default: { - eProcessResult = HMI_RET_NOACTION; + /* No process. */ break; } } + if(NULL != piActionID) + { + *piActionID = iProcessAction; + } + return eProcessResult; } -HMI_ENGINE_RESULT HMI_DemoRealGraph_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoRealGraph_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { /*----------------------------------*/ /* Process */ /*----------------------------------*/ - if(HMI_RET_CANCEL == iActionResult) + if(HMI_PROCESS_SUCCESSFUL(eProcResult)) { - // Stop heart-beat timer. - SGUI_SDK_ConfigHearBeatTimer(0); - // Go back to last screen. - HMI_GoBack(NULL); + if(HMI_DEMO_PROC_CANCEL == iActionID) + { + // Stop heart-beat timer. + SGUI_SDK_ConfigHearBeatTimer(0); + // Go back to last screen. + HMI_GoBack(NULL); + } } + return HMI_RET_NORMAL; } diff --git a/DemoProc/src/ScrollingText.c b/DemoProc/src/ScrollingText.c index a08fd65..48ad2ae 100644 --- a/DemoProc/src/ScrollingText.c +++ b/DemoProc/src/ScrollingText.c @@ -11,7 +11,6 @@ //=======================================================================// #include "DemoProc.h" #include "SGUI_Text.h" -#include "SGUI_Frame.h" #include "HMI_Engine.h" //=======================================================================// @@ -34,8 +33,9 @@ static HMI_ENGINE_RESULT HMI_DemoScrollingText_Initialize(SGUI_SCR_DEV* Interface); static HMI_ENGINE_RESULT HMI_DemoScrollingText_Prepare(SGUI_SCR_DEV* Interface, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoScrollingText_RefreshScreen(SGUI_SCR_DEV* Interface, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoScrollingText_PostProcess(SGUI_SCR_DEV* Interface, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoScrollingText_PostProcess(SGUI_SCR_DEV* Interface, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); +static void HMI_DemoScrollingText_DrawFrame(SGUI_SCR_DEV* Interface); //=======================================================================// //= Static variable declaration. =// @@ -47,9 +47,6 @@ static int32_t s_iTextOffset; static SGUI_INT s_iTextHeight; static SGUI_RECT_AREA s_stTextDisplayArea; -static SGUI_BOX_FRAME_STRUCT s_stTextFrame = { {HMI_TEXT_DEMO_FRAME_EDGE_LAYERS, SGUI_FONT_SIZE_H12}, - {NULL} - }; static HMI_SCREEN_ACTION s_stDemoScrollingTextActions = { HMI_DemoScrollingText_Initialize, HMI_DemoScrollingText_Prepare, @@ -98,7 +95,7 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_Initialize(SGUI_SCR_DEV* Interface) HMI_ENGINE_RESULT HMI_DemoScrollingText_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters) { // Paint frame edge. - SGUI_Frame_DrawFullScreenFrame(pstIFObj, &s_stTextFrame); + HMI_DemoScrollingText_DrawFrame(pstIFObj); // Start dummy heart-beat timer. SGUI_SDK_ConfigHearBeatTimer(SDK_DEFAULT_HEART_BEAT_INTERVAL_MS); return HMI_RET_NORMAL; @@ -114,7 +111,7 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_Prepare(SGUI_SCR_DEV* pstIFObj, const vo /*****************************************************************************/ HMI_ENGINE_RESULT HMI_DemoScrollingText_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters) { - SGUI_Frame_DrawFullScreenFrame(pstIFObj, &s_stTextFrame); + HMI_DemoScrollingText_DrawFrame(pstIFObj); SGUI_Text_DrawMultipleLinesText(pstIFObj, s_szDemoText, SGUI_FONT_SIZE_H12, &s_stTextDisplayArea, s_iTextOffset, SGUI_DRAW_NORMAL); return HMI_RET_NORMAL; } @@ -130,19 +127,21 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_RefreshScreen(SGUI_SCR_DEV* pstIFObj, co /** Limitation: Parameter pointer is a void type, convert to the **/ /** appropriate type before use. **/ /*****************************************************************************/ -HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; SGUI_UINT16 uiKeyValue; - KEY_PRESS_EVENT* pstKeyEvent; + KEY_PRESS_EVENT* pstKeyEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ @@ -156,17 +155,12 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* pstIFObj, con if(KEY_VALUE_SPACE == uiKeyValue) { - eProcessResult = HMI_RET_FOLLOWUP; - } - else - { - eProcessResult = HMI_RET_NOACTION; + iProcessAction = HMI_DEMO_PROC_CONFIRM; } break; } case EVENT_ID_TIMER: { - //SGUI_Frame_DrawFullScreenFrame(pstIFObj, &s_stTextFrame); SGUI_Text_DrawMultipleLinesText(pstIFObj, s_szDemoText, SGUI_FONT_SIZE_H12, &s_stTextDisplayArea, s_iTextOffset, SGUI_DRAW_NORMAL); if(s_iTextOffset + s_iTextHeight == 0) { @@ -176,15 +170,19 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* pstIFObj, con { s_iTextOffset--; } - eProcessResult = HMI_RET_NOACTION; break; } default: { - eProcessResult = HMI_RET_NOACTION; + /* No process. */ break; } } + if(NULL != piActionID) + { + *piActionID = iProcessAction; + } + return eProcessResult; } @@ -193,18 +191,39 @@ HMI_ENGINE_RESULT HMI_DemoScrollingText_ProcessEvent(SGUI_SCR_DEV* pstIFObj, con /** Purpose: Do something after user action or update screen. **/ /** Resources: List data structure and bind data if existed. **/ /** Parameters: **/ -/** @iActionResult[in]: User action or system action process result. **/ +/** @ iActionResult[in]: User action or system action process result. **/ /** Return: Post process result. **/ /** Limitation: None. **/ /*****************************************************************************/ -HMI_ENGINE_RESULT HMI_DemoScrollingText_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoScrollingText_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { - if(HMI_RET_FOLLOWUP == iActionResult) + if(HMI_PROCESS_SUCCESSFUL(eProcResult)) { - // Stop heart-beat timer. - SGUI_SDK_ConfigHearBeatTimer(0); - // Go to main list. - HMI_Goto(HMI_SCREEN_ID_DEMO_LIST, NULL); + if(HMI_DEMO_PROC_CONFIRM == iActionID) + { + // Stop heart-beat timer. + SGUI_SDK_ConfigHearBeatTimer(0); + // Go to main list. + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_LIST, NULL); + } } + return HMI_RET_NORMAL; } + +/*****************************************************************************/ +/** Function Name: HMI_DemoScrollingText_DrawFrame **/ +/** Purpose: Draw frame edge for scroll text screen. **/ +/** Parameters: **/ +/** @ Interface[in]: Device driver object. **/ +/** Return: None. **/ +/** Limitation: None. **/ +/*****************************************************************************/ +void HMI_DemoScrollingText_DrawFrame(SGUI_SCR_DEV* Interface) +{ + if(NULL != Interface) + { + SGUI_Basic_DrawRectangle(Interface, 0, 0, RECT_WIDTH(Interface->stSize), RECT_HEIGHT(Interface->stSize), SGUI_COLOR_FRGCLR, SGUI_COLOR_BKGCLR); + SGUI_Basic_DrawRectangle(Interface, 2, 2, RECT_WIDTH(Interface->stSize)-4, RECT_HEIGHT(Interface->stSize)-4, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); + } +} diff --git a/DemoProc/src/TextNotice.c b/DemoProc/src/TextNotice.c index ca8c794..7ddc7c7 100644 --- a/DemoProc/src/TextNotice.c +++ b/DemoProc/src/TextNotice.c @@ -23,8 +23,8 @@ static HMI_ENGINE_RESULT HMI_DemoTextNotice_Initialize(SGUI_SCR_DEV* pstIFObj); static HMI_ENGINE_RESULT HMI_DemoTextNotice_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoTextNotice_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoTextNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoTextNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoTextNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoTextNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); //=======================================================================// //= Static variable declaration. =// @@ -78,24 +78,26 @@ HMI_ENGINE_RESULT HMI_DemoTextNotice_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const return HMI_RET_NORMAL; } -HMI_ENGINE_RESULT HMI_DemoTextNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoTextNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; SGUI_UINT16 uiKeyValue; - KEY_PRESS_EVENT* pstKeyEvent; + KEY_PRESS_EVENT* pstKeyEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ /*----------------------------------*/ - if(HMI_ENGINE_EVENT_ACTION == pstEvent->eType) + if(EVENT_TYPE_ACTION == pstEvent->iType) { if(EVENT_ID_KEY_PRESS == pstEvent->iID) { @@ -107,24 +109,31 @@ HMI_ENGINE_RESULT HMI_DemoTextNotice_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const case KEY_VALUE_ENTER: case KEY_VALUE_ESC: { - eProcessResult = HMI_RET_CANCEL; + iProcessAction = HMI_DEMO_PROC_CANCEL; break; } } } } + if(NULL != piActionID) + { + *piActionID = iProcessAction; + } return eProcessResult; } -HMI_ENGINE_RESULT HMI_DemoTextNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoTextNotice_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { /*----------------------------------*/ /* Process */ /*----------------------------------*/ - if(HMI_RET_CANCEL == iActionResult) + if(HMI_PROCESS_SUCCESSFUL(eProcResult)) { - HMI_GoBack(NULL); + if(HMI_DEMO_PROC_CANCEL == iActionID) + { + HMI_GoBack(NULL); + } } return HMI_RET_NORMAL; } diff --git a/DemoProc/src/VariableBox.c b/DemoProc/src/VariableBox.c index d744e73..8b2ad2a 100644 --- a/DemoProc/src/VariableBox.c +++ b/DemoProc/src/VariableBox.c @@ -9,7 +9,6 @@ //= Include files. =// //=======================================================================// #include "DemoProc.h" -#include "SGUI_Frame.h" #include "SGUI_Notice.h" #include "SGUI_VariableBox.h" @@ -28,8 +27,8 @@ static HMI_ENGINE_RESULT HMI_DemoVariableBox_Initialize(SGUI_SCR_DEV* pstIFObj); static HMI_ENGINE_RESULT HMI_DemoVariableBox_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); static HMI_ENGINE_RESULT HMI_DemoVariableBox_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); -static HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent); -static HMI_ENGINE_RESULT HMI_DemoVariableBox_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult); +static HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoVariableBox_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); static void HMI_DemoVariableBox_DrawFrame(SGUI_SCR_DEV* pstIFObj, SGUI_SZSTR szTitle); //=======================================================================// @@ -113,26 +112,28 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_RefreshScreen(SGUI_SCR_DEV* pstIFObj, cons return HMI_RET_NORMAL; } -HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent) +HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) { /*----------------------------------*/ /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; SGUI_UINT16 uiKeyValue; - KEY_PRESS_EVENT* pstKeyEvent; + KEY_PRESS_EVENT* pstKeyEvent; + SGUI_INT iProcessAction; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; + iProcessAction = HMI_DEMO_PROC_NO_ACT; /*----------------------------------*/ /* Process */ /*----------------------------------*/ if(s_uiAutoConfirmTimer > 0) { - if(HMI_ENGINE_EVENT_ACTION == pstEvent->eType) + if(EVENT_TYPE_ACTION == pstEvent->iType) { if(EVENT_ID_KEY_PRESS == pstEvent->iID) { @@ -146,7 +147,7 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const } } } - else if(HMI_ENGINE_EVENT_DATA == pstEvent->eType) + else if(EVENT_TYPE_DATA == pstEvent->iType) { if(EVENT_ID_RTC == pstEvent->iID) { @@ -161,8 +162,6 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const eProcessResult = HMI_DemoVariableBox_RefreshScreen(pstIFObj, NULL); SGUI_SDK_EnableRTCInterrupt(false); } - - eProcessResult = HMI_RET_NOACTION; } else { @@ -186,12 +185,11 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const SGUI_IntegerVariableBox_Refresh(pstIFObj, &s_stNumberVariableBox, SGUI_CENTER, SGUI_DRAW_NORMAL); SGUI_TextVariableBox_Refresh(pstIFObj, &s_stTextVariableBox, SGUI_DRAW_REVERSE); } - eProcessResult = HMI_RET_NOACTION; break; } case KEY_VALUE_ESC: { - eProcessResult = HMI_RET_CANCEL; + iProcessAction = HMI_DEMO_PROC_CANCEL; break; } case KEY_VALUE_LEFT: @@ -204,7 +202,6 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const SGUI_TextVariableBox_ChangeCharacter(pstIFObj, &s_stTextVariableBox, SGUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NONE); } } - eProcessResult = HMI_RET_NOACTION; break; } case KEY_VALUE_UP: @@ -218,7 +215,6 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const s_stNumberVariableBox.Value++; SGUI_IntegerVariableBox_Refresh(pstIFObj, &s_stNumberVariableBox, SGUI_CENTER, SGUI_DRAW_REVERSE); } - eProcessResult = HMI_RET_NOACTION; break; } case KEY_VALUE_RIGHT: @@ -231,7 +227,6 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const SGUI_TextVariableBox_ChangeCharacter(pstIFObj, &s_stTextVariableBox, SGUI_DRAW_REVERSE, GUI_TEXT_ASCII, SGUI_TXT_VARBOX_OPT_NONE); } } - eProcessResult = HMI_RET_NOACTION; break; } case KEY_VALUE_DOWN: @@ -245,7 +240,6 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const s_stNumberVariableBox.Value--; SGUI_IntegerVariableBox_Refresh(pstIFObj, &s_stNumberVariableBox, SGUI_CENTER, SGUI_DRAW_REVERSE); } - eProcessResult = HMI_RET_NOACTION; break; } case KEY_VALUE_ENTER: @@ -265,22 +259,30 @@ HMI_ENGINE_RESULT HMI_DemoVariableBox_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const } default: { - eProcessResult = HMI_RET_NOACTION; + /* No process. */ break; } } } } + if(NULL != piActionID) + { + *piActionID = iProcessAction; + } + return eProcessResult; } -HMI_ENGINE_RESULT HMI_DemoVariableBox_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_DemoVariableBox_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) { - if(HMI_RET_CANCEL == iActionResult) + if(HMI_PROCESS_SUCCESSFUL(eProcResult)) { - s_uiAutoConfirmTimer = 5; - HMI_GoBack(NULL); + if(HMI_DEMO_PROC_CANCEL == iActionID) + { + s_uiAutoConfirmTimer = 5; + HMI_GoBack(NULL); + } } return HMI_RET_NORMAL; @@ -291,18 +293,27 @@ void HMI_DemoVariableBox_DrawFrame(SGUI_SCR_DEV* pstIFObj, SGUI_SZSTR szTitle) /*----------------------------------*/ /* Variable Declaration */ /*----------------------------------*/ - SGUI_BOX_FRAME_STRUCT stFrameData; + SGUI_RECT_AREA stTextDisplayArea; + SGUI_RECT_AREA stTextDataArea; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ - stFrameData.Parameter.EdgeLayers = 2; - stFrameData.Parameter.FontSize = SGUI_FONT_SIZE_H12; - stFrameData.Data.Title = szTitle; + stTextDisplayArea.PosX = 4; + stTextDisplayArea.PosY = 4; + stTextDisplayArea.Width = 120; + stTextDisplayArea.Height = 12; + stTextDataArea.PosX = 0; + stTextDataArea.PosY = 0; /*----------------------------------*/ /* Process */ /*----------------------------------*/ - // Draw frame - SGUI_Frame_DrawFullScreenFrame(pstIFObj, &stFrameData); + if(NULL != pstIFObj) + { + SGUI_Basic_DrawRectangle(pstIFObj, 0, 0, RECT_WIDTH(pstIFObj->stSize), RECT_HEIGHT(pstIFObj->stSize), SGUI_COLOR_FRGCLR, SGUI_COLOR_BKGCLR); + SGUI_Basic_DrawRectangle(pstIFObj, 2, 2, RECT_WIDTH(pstIFObj->stSize)-4, RECT_HEIGHT(pstIFObj->stSize)-4, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); + SGUI_Basic_DrawLine(pstIFObj, 3, 17, 124, 17, SGUI_COLOR_FRGCLR); + SGUI_Text_DrawSingleLineText(pstIFObj, szTitle, SGUI_FONT_SIZE_H12, &stTextDisplayArea, &stTextDataArea, SGUI_DRAW_NORMAL); + } } diff --git a/Documents/Files/Docs/Dependencies.xlsx b/Documents/Files/Docs/Dependencies.xlsx new file mode 100644 index 0000000..9bf6901 Binary files /dev/null and b/Documents/Files/Docs/Dependencies.xlsx differ diff --git a/Documents/HMI简要说明.pdf b/Documents/HMI简要说明.pdf deleted file mode 100644 index 01bb6d1..0000000 Binary files a/Documents/HMI简要说明.pdf and /dev/null differ diff --git a/Documents/wxWidgets3.1.2编译错误的解决办法.md b/Documents/How to build wxWidgets3.1.2 with MinGW in windows.md similarity index 100% rename from Documents/wxWidgets3.1.2编译错误的解决办法.md rename to Documents/How to build wxWidgets3.1.2 with MinGW in windows.md diff --git a/Documents/字库制作简述.md b/Documents/How to create font data.md similarity index 99% rename from Documents/字库制作简述.md rename to Documents/How to create font data.md index a505063..e0bbeb1 100644 --- a/Documents/字库制作简述.md +++ b/Documents/How to create font data.md @@ -263,5 +263,5 @@ SGUI_SIZE SGUI_Text_GetCharacterTableIndex(SGUI_UINT16 uiCharacterCode) >SimpleGUI@开源中国:https://www.oschina.net/p/simplegui >SimpleGUI@码云:https://gitee.com/Polarix/simplegui -  本人并不是全职的开源开发者,依然有工作及家庭的琐碎事务要处理,所以对于大家的需求和疑问反馈的可能并不及时,多有怠慢,敬请谅解。 +  本人并不是全职的开源开发者,依然有工作及家庭的琐碎事务要处理,所以对于大家的需求和疑问反馈的可能并不及时,多有怠慢,敬请谅解。   最后,再次感谢您的支持。 diff --git a/Documents/SimpleGUI user manual.md b/Documents/SimpleGUI user manual.md new file mode 100644 index 0000000..0e1eb9f --- /dev/null +++ b/Documents/SimpleGUI user manual.md @@ -0,0 +1,621 @@ +

目录

+ +* [1. 概述](#1) +* [2. GUI](#2) +* [3. HMI](#3) +* [4. 其他应用技巧](#4) +* [5. 使用限制](#5) +* [6. 联系开发者](#6) +------- +

1. 概述

+ +  本文将详细介绍SimpleGUI各个机能模块的组成、依赖关系与实现原理,方便用户根据自己的具体需求对SimpleGUI进行必要的修改、剪裁或二次开发。 +  SimpleGUI分为GUI和HMI两部分,GUI部分负责显示和绘图控制,HMI则提供了一种构件和管理界面的逻辑关系的手段,方便开发者分离业务逻辑和画面显示,更有利于编写和维护。如果不需要,HMI可不使用。 + +<返回到[目录](#0)/[标题](#1)> + +

2. GUI

+ +### 2.1. 基本数据类型 +  为避免在因不同平台、不同编译器下对不同基本数据类型的定义不同导致的可能潜在的问题,SimpleGUI单独使用了一个名为SGUI_Typedef.h的文件,对SimpleGUI的数据类型进行了重新封装,以避免因为不同数据类型的表达范围、指针等问题导致难以调查的系统异常。 + +### 2.2. 设备驱动 +  SimpleGUI对显示设备和资源的使用是通过SGUI_SCR_DEV(SimpleGUI Screen Device)结构体实例来实现的,结构体的定义为: + +```c++ +typedef struct +{ + //Screen display area size in pixel. + SGUI_AREA_SIZE stSize; + //Bitmap data buffer. + SGUI_BYTE arrBmpDataBuffer[SGUI_BMP_DATA_BUFFER_SIZE]; + //Engine & device initialize function. + SGUI_FN_IF_INITIALIZE fnInitialize; + //Clear screen function. + SGUI_FN_IF_CLEAR fnClearScreen; + //Set pixel value function. + SGUI_FN_IF_SET_POINT fnSetPixel; + //Get pixel value function. + SGUI_FN_IF_GET_POINT fnGetPixel; + // Refresh screen display. + SGUI_FN_IF_REFRESH fnRefreshScreen; +}SGUI_SCR_DEV; +``` +  此数据结构的定义位于SGUI_Typedef.h文件中,包含若干函数指针,用户需要声明一个此类型的结构体,然后按照结构体中函数指针的数据类型设计和实现相应功能的设备驱动函数,并将对应的函数指针注册到结构体实例,然后在调用SimpleGUI绘图函数时,将该结构体的指针作为参数传入函数(通常是参数表的第一个参数)。 +  结构体各成员的功能描述如下: +|指针|函数功能|参数表|返回值| +|:--|:--|:--|:--| +|stSize|保存屏幕设备的现实尺寸,单位为像素。|-|-| +|arrBmpDataBuffer|字节数组,用于在位图绘制(包括文字绘制)时读取位图数据。|-|-| +|fnInitialize|设备初始化,通常由HMI部分调用。|void|SGUI_INT| +|fnClearScreen|清除屏幕显示,如果使用了显示缓存,同时清除缓存。|void|void| +|fnSetPixel|设定像素值,0为灭1为亮。|SGUI_INT, SGUI_INT, SGUI_INT|void| +|fnGetPixel|读取像素值,0为灭1为亮。|SGUI_INT, SGUI_INT|SGUI_INT| +|fnRefreshScreen|更新屏幕显示,通常指将显示缓存的数据同步到设备。|void|void| + +  具体的数据类型定义请参考SGUI_Typedef.h文件的内容。 +  在使用SimpleGUI之前,首先需要您实现您目标平台上对屏幕设备的操作函数。实现内容至少包括设备初始化、读像素和写像素三个接口。 +  如果不考虑执行效率,以上三个函数实现后就,SimpleGUi就可以工作了,当然,如果想更有效的绘图,还需根据驱动程序的逻辑结构、缓存的数据结构、硬件特性等因素实现其他的接口函数,如清除屏幕、更新屏幕、水平线绘制、垂直线绘制等,如果使用了显示缓存,那么还有必要实现缓存同步函数,以实现将缓存内容同步到屏幕的功能。 +  以下为演示例程中对该结构体实例的声明和使用。 +```c++ +SGUI_SCR_DEV g_stDeviceInterface; + +SGUI_SystemIF_MemorySet(&g_stDeviceInterface, 0x00, sizeof(SGUI_SCR_DEV)); +/* Initialize display size. */ +g_stDeviceInterface.stSize.Width = 128; +g_stDeviceInterface.stSize.Height = 64; +/* Initialize interface object. */ +g_stDeviceInterface.stActions.fnSetPixel = OLED_SetPixel; +g_stDeviceInterface.stActions.fnGetPixel = OLED_GetPixel; +g_stDeviceInterface.stActions.fnClearScreen = OLED_ClearDisplay; +g_stDeviceInterface.stActions.fnRefreshScreen = OLED_RefreshScreen; +``` + +### 2.3. 功能函数 + +  SimpleGUI的所有功能函数可以简单的划分为“平台接口”、“共通机能”、“基础绘图”和“控件”四部分。 +####   平台接口 +  此部分接口的实现位于SGUI_Interface.c文件中,封装或实现包括内存块复制(memcpy)、赋值(memset)、申请与释放(malloc/free)字符串的复制(strcpy/strncpy)、长度测量(strlen)以及时间(RTC时间)的获取、Flash(包括内部和外部)中数据的获取等依赖于系统平台的机能实现。 +####   共通机能 +  此部分接口的实现位于SGUI_Common.c文件中,封装或实现了包括数字与字符串之间的格式化转换、以及小数点的插入等。由于SimpleGUI中全程避免使用浮点数,所以小数点基本上都是通过格式化字符串得来,请悉知。 +####   基础绘图 +  此部分接口的实现位于SGUI_Basic.c文件中,封装或实现了点、线、圆形、矩形以及位图的绘制,以及区域反色、屏幕内容的更新(仅在使用显示缓存时有用)与清除等。 +####   控件 +  此部分也可被称为“组件”,实现于多个文件中,提供了多种方便使用的函数。 + +|文件名|功能概要| +|:--|:-- | +|SGUI_Text.c|提供封装好的文字绘制功能、包括单行、多行以及绘制文字前需要的部分预演算等。| +|SGUI_Frame.c|边框绘制功能,用于绘制屏幕边框,例如列表和实时曲线的窗口边框等。| +|SGUI_Notice.c|用于显示消息提示框,提示一些文字内容,可带图标,类似Windows中的MessageBox。| +|SGUI_ScrollBar.c|提供显示水平或垂直滚动条的功能。| +|SGUI_ProcessBar.c|提供进度条的显示功能,支持上、下、左、右四个生长方向。| +|SGUI_List|提供列表显示功能,可以显示一个列表,列表项目可以为枚举字符串型、整数型、小数型或不带参数的普通型。| +|SGUI_VariableBox.c|提供数值输入和字符串输入两种输入框接口。| +|SGUI_RealtimeGraph.c|提供封装好的实时曲线界面接口,可以在屏幕上根据用户输入的点数据绘制和现实一条实时曲线。| + +  以上文件均提供同名的头文件(.h),可以直接包含和调用。 + +  所有的控件的实例在显示和操作中,均使用一个结构体进行数据和参数的保存,同时,所有的控件均提供画面更新接口(SGUI_XXX_Refresh函数),用以在任何需要的时候恢复控件在屏幕设备上的显示。此方法的设计意在在绝大多数情况下可以取代图层的概念。 + +### 2.4. 依赖关系 + +  SimpleGUI为了可以在一定程度上实现剪裁,将代码设计为前文描述的四部分,四部分从高到低,大体呈依赖关系,例如控件的实现依赖基础绘图、基础绘图的实现依赖共通机能、共通机能的实现一定程度上依赖平台接口。以最常用的列表为例,列表的实现、依赖Text、ScrollBar两个控件、Text中的文本绘制功能、以及基础绘图的区域反色功能。 +  截至目前,SimpleGUI的所有功能模块之间的依赖关系请参照“Dependencies.xlsx”文件。在开发时可依照此文档对SimpleGUI进行适当剪裁以避免资源浪费。 + +<返回到[目录](#0)/[标题](#2)> + + +

3. HMI

+ +### 3.1 HMI概述 +  HMI模型作为SimpleGUI的附加组件存在,意在使用相对固定的数据格式及代码逻辑,帮助开发者方便的编写和完成便于维护和拓展的用户交互动作。 +  HMI主要分为“画面”和“交互引擎”两部分,交互引擎负责外来事件、数据的组织与预处理、并调用用户预先准备好的屏幕绘制函数更新屏幕显示。而屏幕显示的操作,则交由画面部分完成。 + +### 3.2 画面 +  HMI模型在在设计之初,虽然使用C语言的语法,但是使用了C++中“类”和“对象”的概念进行构建和管理,每一个画面都是一个对象,都具有画面动作,概念上类似于类的成员方法,包含“初始化”、“准备”、“事件处理”、“画面更新”、“后处理”五个部分,以下称为画面动作对象。 +  画面动作对象的数据格式定义如下: + +```c++ +// Screen action interface function pointer structure. +typedef struct +{ + // Initialize screen data and parameter. + HMI_ENGINE_RESULT (*Initialize) (SGUI_SCR_DEV* Interface); + // Do some thing before current screen display. + HMI_ENGINE_RESULT (*Prepare) (SGUI_SCR_DEV* Interface, const void* pstParameters); + // Repaint screen if needed. + HMI_ENGINE_RESULT (*Repaint) (SGUI_SCR_DEV* Interface, const void* pstParameters); + // Process event. + HMI_ENGINE_RESULT (*ProcessEvent) (SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); + // Post process. + HMI_ENGINE_RESULT (*PostProcess) (SGUI_SCR_DEV* Interface, SGUI_INT iActionID); +}HMI_SCREEN_ACTION; +``` + +  各个成员的功能说明如下: + +|变量名|功能概要| +|:--|:-- | +|Initialize|函数指针,指向画面的初始化函数。| +|Prepare|函数指针,指向画面对象的准备函数,通常用于画面显示前或事件处理前的一些预处理。| +|Repaint|函数指针,指向画面更新函数,意在必要时更新画面显示。| +|ProcessEvent|函数指针,指向画面的事件处理函数,用户的操作或设备、外部中断的信息在有必要更新显示时,通过此函数通知到画面并做相应处理。| +|PostProcess|函数指针,消息处理后的后续处理,例如需要变更到其他画面显示、返回等。| + +  而在一个系统中,不可能只有一个画面,所以画面对象除了包含画面动作对象外,还包含前指针以及画面ID的记录。画面对象数据格式的定义如下: + +```c++ +// Screen data structure. +typedef struct _T_HMI_SCREEN_OBJECT_ +{ + SGUI_INT iScreenID; + HMI_SCREEN_ACTION* pstActions; + struct _T_HMI_SCREEN_OBJECT_* pstPrevious; +}HMI_SCREEN_OBJECT; +``` + +  各个成员的功能说明如下: + +|变量名|功能概要| +|:--|:-- | +|iScreenID|画面ID,每一个画面应该有一个专用的、不重复的ID用于索引对象本身。| +|pstActions|画面动作对象指针,指向画面动作处理函数对象。| +|pstPrevious|前画面指针,默认情况下为NULL,当画面显示时,此指针将被修改为指向前一个画面的对象。| + +  此结构体才是用来操作“画面”的对象,所有的画面对象都以此格式声明和定义,使画面数据的操作、事件的响应统一化,进而方便画面的管理与扩充。在设计画面时,为了代码维护方便,推荐每个画面对应的处理都实现在单独的文件中,这样一来,每一个文件就被抽象成了一个“画面对象”,类似C++中类的实例。 +  接下来以实时曲线为例,简要说明一下画面的组织与构成。具体逻辑可以参照DemoProc文件夹下的src/RealtimeGraph.c文件。为讲解方便,讲解代码与演示工程的实例有所出入,请悉知。 + +  在RealtimeGraph.c文件中,对Action对象的声明和定义如下: +```c++ +static HMI_SCREEN_ACTION s_stDemoRealtimeGraphActions = { + HMI_DemoRealGraph_Initialize, + HMI_DemoRealGraph_Prepare, + HMI_DemoRealGraph_RefreshScreen, + HMI_DemoRealGraph_ProcessEvent, + HMI_DemoRealGraph_PostProcess, +}; +``` + +  对应的五个函数的原型声明如下: +```c++ +static HMI_DemoRealGraph_Initialize(SGUI_SCR_DEV* pstIFObj); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_Prepare(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_RefreshScreen(SGUI_SCR_DEV* pstIFObj, const void* pstParameters); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); +static HMI_ENGINE_RESULT HMI_DemoRealGraph_PostProcess(SGUI_SCR_DEV* pstIFObj, SGUI_INT iActionID); +``` + +   有了上述的函数和结构体对象定义,接下来,就可以定义画面对象了: + +```c++ +HMI_SCREEN_OBJECT g_stHMI_DemoRealtimeGraph = { + HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, + &s_stDemoRealtimeGraphActions +}; +``` + +  HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH为实时曲线画面对象的唯一ID,此对象需要全局引用,故此,在DemoProc.hw文件中,做了全局声明: + +```c++ +extern HMI_SCREEN_OBJECT g_stHMI_DemoRealtimeGraph; +``` + +  此时,就可以对这个画面对象进行操作了,例如在系统启动,对该画面对象进行初始化时,就可以这样进行操作: + +```c++ +g_stHMI_DemoRealtimeGraph.pstActions->Initialize(&g_stDeviceInterface); +``` + +  同理,需要显示前准备或者画面更新时也可以这样操作: + +```c++ +g_stHMI_DemoRealtimeGraph.pstActions->Prepare(&g_stDeviceInterface, pstData); +g_stHMI_DemoRealtimeGraph.pstActions->Repaint(&g_stDeviceInterface, NULL); +``` + +### 3.3 事件 + +  SimpleGUI的HMI模型中,画面对外部的响应是以一种被称为“事件”的处理方式进行的。画面对事件的响应,是通过画面动作对象的ProcessEvent指针指向的函数进行处理与响应的。每一个事件都含有一个事件头,事件头中包含了事件的Type、ID和Size三种信息,Type和ID均由用户自由定义,并在事件的发送和画面对象的事件处理过程中使用。HMI模型不参与Type与ID的定义、修改与判断。 +  事件头的数据结构定义如下。 + +```c++ +typedef struct +{ + HMI_EVENT_TYPE eType; + SGUI_INT iID; + SGUI_INT iSize; +}HMI_EVENT_BASE; +``` + +  HMI模型的事件分为两种,一种是通用事件,这种事件只有一个头部,包含着Type和ID信息,通常用来通知一些周期性事件,例如定时器、闹钟、固定的按键等等。 +  通用事件的数据结构定义如下。 + +```c++ +typedef struct +{ + HMI_EVENT_BASE Head; +}HMI_GENERAL_EVENT; +``` + +  另外一种叫做自定义事件,自定义事件除了普通的事件头信息外,还可以夹带一些用户自定义的数据,为了达成这种设计目的而不消耗过多内存,HMI提供了一下宏定义方便用户声明自定义的事件类型。 + +```c++ +#define HMI_EVENT_TYPE_DECLARE(NAME, DATA) \ +typedef struct \ +{ \ + HMI_EVENT_BASE Head; \ + DATA Data; \ +}NAME; +``` + +  其中NAME为新的事件类型名,DATA为新事件需要夹带的数据结构定义。 +  这样的好处就是,可以使用类似于C++中“继承”的概念。在画面对象的消息处理中,所有事件均可以先以事件头(HMI_EVENT_BASE)的格式进行解析,在正确的识别Type和ID后,再使用强制类型转换,对用户自定义的数据类型进行读取。 +  接下来依然以实时曲线为例,简要说明事件的使用方法。曲线数据来自一个定时器的周期性触发,每触发一次,都产生一个随机数(在VirtualSDK中),然后将这个数字作为数据发送到实时曲线画面对象。详细处理请参照DemoProc文件夹下的DemoProc.c和src/在RealtimeGraph.c文件。为讲解方便,讲解代码与演示工程的实例有所出入,请悉知。 + +  实时曲线数据事件类型定义如下: +```c++ +typedef struct +{ + SGUI_INT iValue; +}DUMMY_DATA_EVENT_DATA; + +HMI_EVENT_TYPE_DECLARE(DATA_EVENT, DUMMY_DATA_EVENT_DATA); +``` +  定时器触发的处理如下: +```c++ +DATA_EVENT stEvent; +SGUI_INT iAction; +HMI_EVENT_INIT(stEvent); + +stEvent.Head.eType = HMI_ENGINE_EVENT_DATA; +stEvent.Head.iID = EVENT_ID_TIMER; +stEvent.Data.iValue = (rand() % 200)-100; + +g_stHMI_DemoRealtimeGraph.pstActions->ProcessEvent(&g_stDeviceInterface, (HMI_EVENT_BASE*)&stEvent, &iAction); + +g_stDeviceInterface->fnRefreshScreen(); +``` +  在实时曲线的画面对象中,事件处理如下: +```c++ +HMI_ENGINE_RESULT HMI_DemoRealGraph_ProcessEvent(SGUI_SCR_DEV* pstIFObj, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID) +{ + DATA_EVENT* pstDataEvent; + + if((EVENT_ID_TIMER == pstEvent->iID) && (HMI_ENGINE_EVENT_DATA == pstEvent->eType)) + { + pstDataEvent = (DATA_EVENT*)pstEvent; + SGUI_RealtimeGraph_AppendValue(pstIFObj, &s_stRealtimeGraph, pstDataEvent->Data.iValue); + HMI_DemoRealGraph_RefreshScreen(pstIFObj, NULL); + } +} +``` +  这样,就完成了画面对于特定事件的响应,响应内容可以是用户操作、也可以是传感器或设备数据的更新。 + +### 3.4 HMI引擎 + +  在一个系统中往往有多个画面,尤其是一些控制系统,通常会包含一些列表之类。 +以列表为例,按照通常的逻辑,系统中的列表需要这样处理: +``` +选择操作() +{ + 选择项目 = 显示列表(); + switch(选择项目) + { + case 0: + ... + break; + case 1: + ... + break; + ... + default: + ... + } +} +``` +  这看起来没什么问题,但是如果存在多级列表呢? +``` +选择操作() +{ + 选择项目 = 显示列表(); + switch(选择项目) + { + case 0: + 显示二级列表1(); + break; + case 1: + 显示二级列表2(); + break; + ... + default: + ... + } +} +``` +  这看起来也没有什么问题,但是仔细想一下,一个列表选择完成后,如果选择操作不结束,那么这个函数永远都在运行中,如果是多级列表,那么未完成操作的函数都将驻留内存,这对内存资源,尤其是栈资源是一种极大的消耗。 +  解决多级画面内存开销大、方便多画面管理、尽可能隔离画面显示业务与数据处理业务,解决这三大问题才是SimpleGUI的HMI模型存在的真正意义。 +  以下HMI模型的设计逻辑: + + * 同一时刻,活动在内存中的画面对象只有一个。 + * 所有画面的逻辑级别一致,不存在层级区别。 + * 事件的投送不区别画面逻辑,统一发送给当前画面,是否予以响应由画面对象的事件处理函数决定。 + +  由于HMI模型中大量使用函数指针进行操作,理解起来可能会比较晦涩,但是如果充分理解以上三点,HMI模型的处理将会变得非常简单。 +  接下来将简要剖析VirtualSDK中的演示程序中对HMI模型的使用,以此讲解HMI模型的使用方法。 +  首先是HMI引擎的类型声明: +```c++ +typedef struct +{ + HMI_SCREEN_OBJECT** ScreenObjPtr; + SGUI_INT ScreenCount; + HMI_SCREEN_OBJECT* CurrentScreenObject; + SGUI_SCR_DEV* Interface; +}HMI_ENGINE_OBJECT; +``` + +  由上可知,一个HMI模型中包含以下四部分: + + * 画面对象列表。 + * 画面对象总数。 + * 当前活动画面对象指针。 + * 设备驱动对象指针。 + +  然后是DemoProc.c文件中对HMI引擎实例的声明,由于HMI引擎中也包含其他数据结构,所以所有HMI对象相关的声明都在这里: + +```c++ +SGUI_SCR_DEV g_stDeviceInterface; +HMI_SCREEN_OBJECT* g_arrpstScreenObjs[] = +{ + &g_stHMIDemo_ScrollingText, + &g_stHMIDemo_List, + &g_stHMIDemo_TextNotice, + &g_stHMIDemo_RTCNotice, + &g_stHMIDemo_VariableBox, + &g_stHMI_DemoRealtimeGraph, +}; +HMI_ENGINE_OBJECT g_stDemoEngine; +``` + +  接下来是DemoProc.c文件中的DemoMainProcess函数,该函数用于模拟在目标平台上的main函数,是演示历程的起点。 + +```c++ +int DemoMainProcess(void) +{ + // Initialize Engine. + InitializeEngine(); + while(1) + { + // Check and process heart-beat timer event. + if(true == SGUI_SDK_GetEventSyncFlag(ENV_FLAG_IDX_SDK_TIM_EVENT)) + { + SysTickTimerEventProc(); + SGUI_SDK_SetEvnetSyncFlag(ENV_FLAG_IDX_SDK_TIM_EVENT, false); + } + // Check and process key press event. + if(true == SGUI_SDK_GetEventSyncFlag(ENV_FLAG_IDX_SDK_KEY_EVENT)) + { + KeyPressEventProc(); + SGUI_SDK_SetEvnetSyncFlag(ENV_FLAG_IDX_SDK_KEY_EVENT, false); + } + // Check and process RTC event. + if(true == SGUI_SDK_GetEventSyncFlag(ENV_FLAG_IDX_SDK_RTC_EVENT)) + { + RTCEventProc(); + SGUI_SDK_SetEvnetSyncFlag(ENV_FLAG_IDX_SDK_RTC_EVENT, false); + } + } + return 0; +} +``` + +  然后进入InitializeEngine函数,此函数用于HMI引擎对象的初始化。之前声明的HMI引擎实例和相关的其他实例都将在这里初始化。首先是设备驱动对象: + +```c++ +SGUI_SystemIF_MemorySet(&g_stDeviceInterface, 0x00, sizeof(SGUI_SCR_DEV)); +/* Initialize display size. */ +g_stDeviceInterface.stSize.Width = 128; +g_stDeviceInterface.stSize.Height = 64; +/* Initialize interface object. */ +g_stDeviceInterface.fnSetPixel = SGUI_SDK_SetPixel; +g_stDeviceInterface.fnGetPixel = SGUI_SDK_GetPixel; +g_stDeviceInterface.fnClearScreen = SGUI_SDK_ClearDisplay; +g_stDeviceInterface.fnRefreshScreen = SGUI_SDK_RefreshDisplay; +``` + +  接下来是画面对象: + +```c++ +SGUI_SystemIF_MemorySet(&g_stDemoEngine, 0x00, sizeof(HMI_ENGINE_OBJECT)); +/* Prepare HMI engine object. */ +g_stDemoEngine.ScreenCount = sizeof(g_arrpstScreenObjs)/sizeof(*g_arrpstScreenObjs); +g_stDemoEngine.ScreenObjPtr = g_arrpstScreenObjs; +g_stDemoEngine.Interface = &g_stDeviceInterface; +``` + +  至此,HMI模型实例的相关初始化都已经完成,接下来,需要对所有的画面对象进行初始化,初始化方法区别于各个画面业务的不同有所不同,但都可以通过画面动作对象中的Initialize函数指针调用: + +```c++ +for(iIndex=0; iIndexpstActions) + && (g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize) + ) + { + g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize(&g_stDeviceInterface); + g_stDemoEngine.ScreenObjPtr[iIndex]->pstPrevious = NULL; + } +} +``` + +  这里有一个细节需要注意,每一个画面的pstPrevious成员都需要初始化为NULL。在画面业务处理中,此指针指向业务逻辑中当前画面的前一画面。如果此指针不为空,那么将不能切换至该画面(不可重入)。 +  这样设计是因为,如果画面迁移顺序为A->B->C->B->D->E,那么根据SimpleGUI的设计特性,每一个画面都有专门的对象记录相关数据,那么第二次进入B画面时,B画面的数据就会被修改,而返回上一画面时,数据也只能保留最后一次修改的数据。所以,在HMI中要求,只要业务逻辑不同,就不能使用同一个画面对象,即使这两个对象的显示效果完全一致。 +  在HMI引擎和所有画面对象都初始化完成后,就可以调用HMI_ActiveEngine函数登录并激活HMI引擎对象。 + +```c++ +/* Active engine object. */ +eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_SCROLLING_TEXT); +``` + +  激活时,可以通过参数指定哪一个画面为起始画面,如果指定的画面找不到,那么HMI将会以画面对象列表中的第一个画面对象为起始画面,同时,HMI引擎对象的CurrentScreenObject指针将会被设定,指向起始画面。 +  以上所有动作都完成后,调用HMI_StartEngine函数开始显示起始画面,如果画面显示时需要其他数据作为参量,可以通过参数将参量数据的指针传递至画面对象。 + +```c++ +/* Start engine process. */ +eProcessResult = HMI_StartEngine(NULL); +``` + +  至此,如果设备驱动程序正常,屏幕上将会显示第一个画面了。 +  由于之前HMI引擎的CurrentScreenObject成员已经在HMI_ActiveEngine函数中被设定,此后,所有的消息处理都将无视画面实例,直接操作这个指针成员。例程中的列表演示为例,假设我们当前正在列表画面中,这时键盘上的回车键按下,程序将会进入到KeyPressEventProc函数中。 + +```c++ +void KeyPressEventProc(void) +{ + KEY_PRESS_EVENT stEvent; + HMI_EVENT_INIT(stEvent); + + stEvent.Head.iType = EVENT_TYPE_ACTION; + stEvent.Head.iID = EVENT_ID_KEY_PRESS; + stEvent.Data.uiKeyValue = SGUI_SDK_GetKeyEventData(); + HMI_ProcessEvent((HMI_EVENT_BASE*)(&stEvent)); +} +``` + +  此函数将调用HMI_ProcessEvent函数,将按键事件传递到CurrentScreenObject指针指向的画面实例中。 + +```c++ +HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent) +{ + ...... + eProcessResult = pstCurrentScreen->pstActions->ProcessEvent(g_pstActivedEngineObject->Interface, pstEvent, &iActionID); + ...... + eProcessResult = pstCurrentScreen->pstActions->PostProcess(g_pstActivedEngineObject->Interface, eProcessResult, iActionID); + ...... + if( (NULL != g_pstActivedEngineObject->Interface) && + (NULL != g_pstActivedEngineObject->Interface->fnRefreshScreen)) + { + g_pstActivedEngineObject->Interface->fnRefreshScreen(); + } + ...... + return eProcessResult; +} +``` + +  上述代码只保留了关键部分,详细请参考HMI_Engine.c文件中HMI_ProcessEvent函数的实现。 +  由上述代码段可见,事件实例以指针的形式传递到了CurrentScreenObject指针指向的画面实例中,在事件处理函数ProcessEvent执行完毕后,又调用了PostProcess函数进行“后处理”,然后调用设备实例的fnRefreshScreen函数更新画面显示(更新画面显示的操作通常在显示设备使用显示缓存的情况下才需要实现并调用)。具体的事件响应处理,请参照前文针对事件的讲解,参考DemoProc文件夹中的src/List.c文件中事件处理函数HMI_DemoList_ProcessEventh的实现。 +  在事件处理完成后,HMI引擎同时调用了PostProcess指针,执行了画面的“后处理函数”。所谓“后处理”,就是根据事件的响应结果,执行一些h后续需要的处理,如画面切换、数据更新等等。 +  下面是事件处理和后处理函数的原型声明: + +```c++ +HMI_ENGINE_RESULT (*ProcessEvent)(SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); + +HMI_ENGINE_RESULT (*PostProcess)(SGUI_SCR_DEV* Interface, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); +``` + +  后处理函数的第一个参数为显示设备对象,不做过多解释。第二个参数eProcResult为事件处理函数的执行结果,如果没有发生异常,通常为HMI_RET_NORMAL, 第三个参数iActionID为用户自由使用的参数,来源为事件处理函数的最后一个出口参数piActionID,用来传递一些事件处理函数产生的结果。 +  以列表的演示代码为例,HMI_DemoList_PostProcessh函数的处理如下: + +```c++ +HMI_ENGINE_RESULT HMI_DemoList_PostProcess(SGUI_SCR_DEV* pstIFObj, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID) +{ + ...... + if(HMI_DEMO_PROC_CONFIRM == iActionID) + { + uiSelectListIndex = s_stDemoListObject.ControlVariable.SelectIndex; + switch(SGUI_List_GetListItemPtr(&s_stDemoListObject, uiSelectListIndex)->ItemID) + { + 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_SwitchScreen(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer); + } + else + { + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_RTC_NOTICE, NULL); + } + break; + } + case 5: + { + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_VARIABLE_BOX, NULL); + break; + } + case 6: + { + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_REAL_TIME_GRAPH, NULL); + break; + } + default: + { + sprintf(s_szNoticeTextBuffer, DEMO_LIST_NOTICE_TEXT_FMT, uiSelectListIndex); + HMI_SwitchScreen(HMI_SCREEN_ID_DEMO_TEXT_NOTICE, s_szNoticeTextBuffer); + break; + } + } + } + else if(HMI_DEMO_PROC_CANCEL == iActionID) + { + HMI_GoBack(NULL); + } + + return HMI_RET_NORMAL; +} +``` + +  由上可以看出,列表演示程序的后处理中,根据用户选择的列表项的不同,会调用HMI引擎的HMI_SwitchScreen函数切换到相应的画面显示,或调用HMI_GoBack函数返回之前的画面。 +  HMI_SwitchScreen函数的主要实现如下: +```c++ +HMI_ENGINE_RESULT HMI_SwitchScreen(SGUI_INT iDestScreenID, const void* pstParameters) +{ + ...... + pstDestScreen = HMI_GetScreenObjectInEngine(g_pstActivedEngineObject, iDestScreenID); + ...... + pstDestScreen->pstPrevious = g_pstActivedEngineObject->CurrentScreenObject; + ...... + g_pstActivedEngineObject->CurrentScreenObject = pstDestScreen; + ...... + eProcessResult = pstDestScreen->pstActions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); + ...... + return eProcessResult; +} +``` + +  HMI_SwitchScreen函数将根据用户指定的ID,查找相应的画面对象,将找到的画面对象的前画面指针指向当前画面,并将HMI实例的CurrentScreenObject指向新的画面实例,然后调用新实例的Prepare函数完成画面准备与切换,HMI_GoBack函数原理类似,不同点在于画面实例的指针来自于当前画面的pstPrevious成员而非通过ID查找新实例。 +  以上就是HMI引擎的工作原理,SimpleGUI的HMI引擎的特点就是画面的所有操作无需等待,运行后立即退出,不长期占用栈空间,对内存栈资源的开销相对较小。同时可以便捷的通过HMI引擎对画面和功能进行扩充,可维护性较强。 +  其他详细的函数处理与实现,请参考源代码。 + +<返回到[目录](#0)/[标题](#3)> + +

4. 其他应用技巧

+ +### 4.1 HMI引擎切换 +  在使用SimpleGUI的HMI引擎时,如果有必要在系统中依据不同的条件进入不同的交互系统时,可以创建多个HMI对象,并使用HMI_ActiveEngineh函数激活对应的HMI对象。 +  本质上,HMI引擎在HMI_Engine.c文件中声明了一个指向HMI_ENGINE_OBJECT类型实例的内部指针变量,指向的HMI引擎对象就是当前被激活的HMI引擎,通过HMI_ActiveEngine函数可以将这个指针重新设定并调用新指定HMI引擎中当前活动画面的Prepare方法。进行切换后的初次显示。 + +### 4.2 多显示设备 +  如果系统中需要支持多个显示屏时,可以针对不同的显示屏定义多个设备驱动对象。在需要切换不同的显示设备进行相应控制时,可以使用HMI引擎提供的HMI_SetDeviceObject函数为当前活动的HMI引擎设定新的设备驱动对象,从而实现在多屏环境下的区别控制。 + +<返回到[目录](#0)/[标题](#4)> + +

5. 使用限制

+ +  SimpleGUI的GUI部分和HMI部分目前均没有进行线程安全设计,在使用中强烈建议将SimpleGUi的额画面处理放在同一个线程中进行,避免多线程或在中断函数中调用GUI或HMI接口函数,除非在设计期间您可以严格保证使用SimpleGUI处理部分的绝对线程安全。 + + +<返回到[目录](#0)/[标题](#5)> + +

6. 联系开发者

+ +  首先,感谢您对SimpleGUI的赏识与支持。 +  虽然最早仅仅作为一套GUI接口库使用,但我最终希望SimpleGUI能够为您提供一套完整的单色屏GUI及交互设计解决方案,如果您有新的需求、提议亦或想法,欢迎在以下地址留言,或加入[QQ交流群799501887](https://jq.qq.com/?_wv=1027&k=5ahGPvK)留言交流。 +>SimpleGUI@开源中国:https://www.oschina.net/p/simplegui +>SimpleGUI@码云:https://gitee.com/Polarix/simplegui + +  本人并不是全职的开源开发者,依然有工作及家庭的琐碎事务要处理,所以对于大家的需求和疑问反馈的可能并不及时,多有怠慢,敬请谅解。 +  最后,再次感谢您的支持。 diff --git a/Documents/SimpleGUI结构介绍.md b/Documents/SimpleGUI结构介绍.md deleted file mode 100644 index 1aaf1fa..0000000 --- a/Documents/SimpleGUI结构介绍.md +++ /dev/null @@ -1,86 +0,0 @@ -SimpleGUI 结构介绍 ---- -## 1. 概述 - -  本文将详细介绍SimpleGUI各个机能模块的组成与依赖关系,方便用户根据自己的具体需求对SimpleGUI进行必要的剪裁,以实现资源消耗的最小化。 -  SimpleGUI分为GUI和HMI两部分,GUI部分负责显示和绘图控制,HMI则提供了一种构件和管理界面的逻辑关系的手段,方便开发者分离业务逻辑和画面显示,更有利于编写和维护。如果不需要,HMI可不使用。 - -## 2. GUI部分 - -### 2.1. 基本数据类型 -  为避免在因不同平台、不同编译器下对不同基本数据类型的定义不同导致的可能潜在的问题,SimpleGUI单独使用了一个名为SGUI_Typedef.h的文件,对SimpleGUI的数据类型进行了重新封装,以避免因为不同数据类型的表达范围、指针等问题导致难以调查的系统异常。 - -### 2.2. 设备驱动 -  在使用SimpleGUI之前,首先需要您实现您目标平台上对屏幕设备的操作函数。实现内容至少为: -|函数功能|参数表|返回值| -|:--|:--|:--| -|读取屏幕像素点|SGUI_INT iX, SGUI_INT iY|SGUI_INT| -|设定(写入)屏幕像素点|SGUI_INT iX, SGUI_INT iY, SGUI_INT iColor|void| - -  如果不考虑执行效率,以上两个函数实现后就,SimpleGUi就可以工作了,当然,如果想更有效的绘图,还需根据驱动程序的逻辑结构、缓存的数据结构、硬件特性等因素实现其他的接口函数,如清除屏幕、更新屏幕、水平线绘制、垂直线绘制等。 - -  SimpleGUI对显示设备的操作是通过一个名为SGUI_SCR_DEV(SimpleGUI Screen Device)的结构体实例来实现的,结构体的定义为: - -```c++ -typedef struct -{ - //Engine & device initialize function. - SGUI_ENGINE_ACTION_FN_INITIALIZE fnInitialize; - //Clear screen function. - SGUI_ENGINE_ACTION_FN_CLEAR fnClearScreen; - //Set pixel value function. - SGUI_ENGINE_ACTION_FN_SET_POINT fnSetPixel; - //Get pixel value function. - SGUI_ENGINE_ACTION_FN_GET_POINT fnGetPixel; - // Refresh screen display. - SGUI_ENGINE_ACTION_FN_REFRESH fnRefreshScreen; -}SGUI_SCR_DEV; -``` -  此数据结构的定义位于SGUI_Typedef.h文件中,包含若干函数指针,用户需要声明一个此类型的结构体,然后按照结构体中函数指针的数据类型设计和实现相应功能的设备驱动函数,并将对应的函数指针注册到结构体实例,然后在调用SimpleGUI绘图函数时,将该结构体的指针作为参数传入函数(通常是参数表的第一个参数)。 - -  除前文描述的像素点读写函数外,SGUI_SCR_DEV结构体中的其他函数通常只有在需要实现显示缓存时才可能用到,描述如下: -|指针|函数功能|参数表|返回值| -|:--|:--|:--|:--| -|fnInitialize|设备初始化,通常由HMI部分调用。|void|SGUI_INT| -|fnClearScreen|清除屏幕显示,如果使用了显示缓存,同时清除缓存。|void|void| -|fnRefreshScreen|更新屏幕显示,通常指将显示缓存的数据同步到设备。|void|void| - - -  其他具体的数据类型定义请参考SGUI_Typedef.h文件的内容。 - -### 2.3. 逻辑结构 - -  SimpleGUI的所有接口有着明确的包含关系,可以简单的划分为“平台接口”、“共通机能”、“基础绘图”和“控件”四部分。 - -####   平台接口 -  此部分接口的实现位于SGUI_Interface.c文件中,封装或实现包括内存块复制(memcpy)、赋值(memset)、申请与释放(malloc/free)字符串的复制(strcpy/strncpy)、长度测量(strlen)以及当前时间(RTC时间)的获取、Flash(包括内部和外部)中数据的获取等依赖于系统平台的机能实现。 -####   共通机能 -  此部分接口的实现位于SGUI_Common.c文件中,封装或实现了包括数字与字符串之间的格式化转换、以及小数点的插入等。由于SimpleGUI中全程避免使用浮点数,所以小数点基本上都是通过格式化字符串得来,请悉知。 -####   基础绘图 -  此部分接口的实现位于SGUI_Basic.c文件中,封装或实现了点、线、圆形、矩形以及位图的绘制,以及区域反色、屏幕内容的更新(仅在使用显示缓存时有用)与清除等。 -####   控件 -  此部分也可被称为“组件”,实现于多个文件中,提供了多种方便使用的接口组。 - -|文件名|功能概要| -|:--|:-- | -|SGUI_Text.c|提供封装好的文字绘制接口、包括单行、多行以及绘制文字前需要的部分预演算等。| -|SGUI_Frame.c|边框绘制接口,用于绘制屏幕边框,例如列表和实时曲线的窗口边框等。| -|SGUI_Notice.c|用于显示一个消息提示框,提示一些文字内容,可带图标,类似Windows中的MessageBox。| -|SGUI_ScrollBar.c|提供显示水平或垂直滚动条的接口。| -|SGUI_ProcessBar.c|提供进度条的显示接口,支持上、下、左、右四个生长方向。| -|SGUI_List|提供列表显示接口,可以显示一个列表,列表项目可以为枚举字符串型、整数型、小数型或不带参数的普通型。| -|SGUI_VariableBox.c|提供数值输入和字符串输入两种输入框接口。| -|SGUI_RealtimeGraph.c|提供封装好的实时曲线界面接口,可以在屏幕上根据用户输入的点数据绘制和现实一条实时曲线。| - -  以上文件均提供同名的头文件(.h),可以直接包含和调用。 - -  所有的控件的实例在显示和操作中,均使用一个结构体进行数据和参数的保存,同时,所有的控件均提供画面更新接口(SGUI_XXX_Refresh函数),用以在任何需要的时候恢复控件在屏幕设备上的显示。此方法的设计意在在绝大多数情况下可以取代图层的概念。 - -### 2.4. 依赖关系 - -  SimpleGUI为了可以在一定程度上实现剪裁,将代码设计为前文描述的四部分,四部分从高到低,大体呈依赖关系,例如控件的实现依赖基础绘图、基础绘图的实现依赖共通机能、共通机能的实现一定程度上依赖平台接口。 -  以最常用的列表为例,列表的实现、依赖Frame、ScrollBar两个控件、Text中的文本绘制功能、同时还依赖基础绘图的区域反色功能。 -   - - -## 3. HMI模型 diff --git a/Documents/Source/HMI简要说明.docx b/Documents/Source/HMI简要说明.docx deleted file mode 100644 index bcc8af8..0000000 Binary files a/Documents/Source/HMI简要说明.docx and /dev/null differ diff --git a/Documents/Source/Images/Image_0001.png b/Documents/Source/Images/Image_0001.png deleted file mode 100644 index 4c399a0..0000000 Binary files a/Documents/Source/Images/Image_0001.png and /dev/null differ diff --git a/Documents/Source/Images/Image_0002.png b/Documents/Source/Images/Image_0002.png deleted file mode 100644 index 7fb08bb..0000000 Binary files a/Documents/Source/Images/Image_0002.png and /dev/null differ diff --git a/Documents/VirtualSDK环境配置.md b/Documents/VirtualSDK user manual.md similarity index 98% rename from Documents/VirtualSDK环境配置.md rename to Documents/VirtualSDK user manual.md index c6fd455..5253a93 100644 --- a/Documents/VirtualSDK环境配置.md +++ b/Documents/VirtualSDK user manual.md @@ -1,184 +1,184 @@ -SimpleGUI Virtual SDK 使用说明 ---- -## 1. 概述 - -  为了方便开发者在自己的项目中使用SimpleGUI部署、开发或试开发GUI模块,作者特设计此模拟环境,用于进行不依赖硬件平台的学习或开发。 -  SimpleGUI Virtual SDK(以下简称SDK)使用C++语言开发,基于wxWidgets的GUI框架,工程建立于Code::Blocks集成开发环境中,可以于Windows XP或更高版本的操作系统中编译和运行。 - -## 2. 基于GCC和Code::Blocks的SDK环境搭建 - -#### 2.1. 下载Code::Blocks - -  请访问[Code::Blocks下载页面](http://www.codeblocks.org/downloads/binaries)下载Code::Blocks集成开发环境的可执行文件,截至本文档最后一次编辑,Code::Blocks集成开发环境的最新版本为17.12。 -  由于Code::Blocks开发环境本身可以适配多种编译器,所以可下载选项有很多,如果对编译器并不了解,可以选择下载“codeblocks-17.12mingw-setup.exe”或“codeblocks-17.12mingw-nosetup.zip”,这两个版本自带TDM-GCC 5.1.0版本编译器,区别为前者为安装版,会自动创建文件类型关联,后者为绿色版,解压即用。 -  后续讲解也以此编译器为例。 ->![01-Codeblocks下载页面](https://images.gitee.com/uploads/images/2019/0117/131725_1b7479df_769424.png) - -#### 2.2. 部署wxWidgets - -  请访问[wxWidgets下载页面](http://www.wxwidgets.org/downloads/),选择页面中“Latest Development Release: 3.1.2”或者“Latest Stable Release: 3.0.4”标题下“Binaries”中的“Download windows binaries”链接。 ->![02-wxWidgets下载页面](https://images.gitee.com/uploads/images/2019/0117/131820_a6ed6bf6_769424.png) - -  在弹出的列表中下载对应的编译器使用的库,本例中使用Codeblocks自带的TDM-GCC 5.1.0本编译器。所以选择下载“MinGW-TDM5.10”下的头文件(Header Files)和开发用库文件(Development Files)。 - ->![03-wxWidgets库的选择](https://images.gitee.com/uploads/images/2019/0117/232547_839319af_769424.png) ->   由于2018年12月10日wxWidgets3.1.2版本更新后,面向GCC编译器的Makefile无法在Windows环境下直接使用,所以从本次更新开始,仅讲解wxWidgets库文件的使用方法,不再详述wxWidgets库的编译过程,如果有这方面具体需求,请参考本人的博文[《wxWidgets3.1.2在Windows+TDM-GCC环境下编译错误的处理》](https://my.oschina.net/Polarix/blog/2996189)了解详细信息。 ->   3.1.1及更早版本的源代码仍然可以直接在Windows下使用TDM-GCC编译。 - -  下载后,请将下载的头文件和库文件解压在同一个文件夹中,解压的路径不宜太长,文件夹名中不要出现括号、下划线、空格等特殊字符,否则将可能导致程序编译时引用文件异常。本范例中部署路径为“E:\Workspace\Librarys\wxWidgets\ForTDM510”。解压后,请将库文件的目录名从“gccXXXXXX\_dll”修改为“gcc\_dll”。 -  部署后的目录结构应为: -``` - wxWidgets库目录 - ├─ include - │ ├─ msvc - │ │ └─ wx - │ │ └─ *.h - │ └─ wx - │ ├─ [DIR] - │ └─ *.h - └─ lib - ├─ gcc_dll - ├─ mswu - └─ *.a(库文件) -``` - - -#### 2.3. 配置Code::Blocks下的wxWidgets开发环境 - -  启动Code::Blocks,然后选择选择“Settings”(设置)菜单下的“Global variables”(全局变量)项目。 - ->![04-Global variables选项](https://images.gitee.com/uploads/images/2019/0117/131842_f2e41830_769424.png) - -  在打开的全局变量编辑窗口中,点击“New”按钮,新建一个全局变量“wxbin”。 - ->![05-新建全局变量](https://images.gitee.com/uploads/images/2019/0117/232846_b419f48d_769424.png) - -  然后将全局变量的根路径、包含路径和库路经分别设置为wxWidgets的根路径include路径和lib路径,其他留空即可,参考下图。 ->全局变量配置 ->![06-全局变量配置](https://images.gitee.com/uploads/images/2019/0117/232905_babc192c_769424.png) - -  然后点击“Close”关闭环境变量编辑窗口,至此,SimpleGUI模拟环境开发需要使用的Codeblocks+wxWidgets环境搭建完成。 - -### 3. 编译和使用Virtual SDK -#### 3.1. 工程环境结构 - -  您可以通过Git工具,从码云(Gitee)上将SimpleGUI的全部代码和资料同步到本地,如果您不想使用Git工具,也可以在[SimpleGUI工程页面](https://gitee.com/Polarix/simplegui)中点击“克隆/下载”按钮,在弹出的窗口中点击“下载ZIP”按钮下载整个工程的压缩包文件。 -  同步或下载解压SimpleGUI后,就可以使用SimpleGUI的Virtual SDK了,SimpleGUI的主目录结构和说明如下: - -|目录名|功能| -|:- |:- | -|DemoProc|SimpGUI的演示代码| -|DemoProject|SimpleGUI的演示工程| -|Documents|关于SimpleGUI的一些简要说明文档| -|GUI|SimpleGUI的代码实现部分| -|HMI|SimpleGUI的HMI模型实现部分| -|VirtualSDK|Virtual SDK的工程及源码| - -#### 3.2. 编译Virtual SDK工程 -  进入VirtualSDK\Project\CodeBlocks目录下,SimpleGUI.cbp文件夹即为模拟环境的工程文件,使用Code::Blocks打开。如果用户下载的是nosetup(绿色版)的Code::Blocks,需要手动建立关联才能直接用双击的方式打开cbp文件,否则,用户只能先打开Code::Blocks,然后从Code::Blocks中执行打开操作以打开工程文件。 -  点击工具栏上的编译按钮或按快捷键Ctrl+F9,开始编译模拟环境演示工程。 -  编译完成,显示无错误和警告,现在点击工具栏上的运行按钮或按快捷键Ctrl+F10就可以看到模拟环境的运行效果了。 ->![07-编译工程](https://images.gitee.com/uploads/images/2019/0117/131925_defb4a75_769424.png) - ->![08-运行效果](https://images.gitee.com/uploads/images/2019/0117/131942_a01e12c5_769424.png) - -#### 3.3. 配置Virtual SDK -  默认情况下,SimpleGUI的Virtual SDK中虚拟显示屏幕的配色方案为黄底黑字的LCD点阵显示屏,为最大程度上模拟真实情况下的视觉效果,方便创建和调试GUI元素,模拟环境的虚拟LCD面板可以通过修改配置定义修改颜色和尺寸。 -  打开Virtual SDK工程,进入VirtualSDK\Common\inc文件夹(对应工程路径/SimpleGUI/Headers/VirtualSDK/Common/inc),打开Common.h文件,找到以下宏定义: - -|宏定义名|功能| -|:- |:- | -|LCD_COLOR_OBJ_PIX|逻辑有效像素点颜色(前景颜色)| -|LCD_COLOR_OBJ_BKG|逻辑无效像素点颜色(背景颜色)| -|LCD_COLOR_OBJ_GRID|网格颜色| -|PARAM_DEFAULT_PIXEL_NUM_H|横向像素点数量| -|PARAM_DEFAULT_PIXEL_NUM_V|纵向像素点数量| -|PARAM_DEFAULT_PIXEL_WIDTH|屏幕像素单元宽度| -|PARAM_DEFAULT_PIXEL_HEIGHT|屏幕像素单元高度| - -  Virtual SDK默认状态下模拟的是黄底黑字的LCD显示屏,不显示像素网格。接下来以模拟黑底蓝字的OLED19264显示屏效果,简要介绍一下各个宏定义的使用方法: -> - 使用一张目标屏幕的照片,使用取色工具获取屏幕背景、像素以及边框颜色的RGB值,比如淘宝上的照片,就可以直接使用。 ->![09-实物照片](https://images.gitee.com/uploads/images/2019/0117/233447_91a32ff3_769424.png) -> - 将颜色的RGBA值分别更新入三个宏定义中,颜色使用32位无符号整数表示,从高至低四字节的意义分别为A、B、G、R。例如上图中屏幕背景色、像素色和边框色分别设定为0xFF070707、0xFFF1FA4F和0xFFC9652F,由于不需要显示网格,所以不需要修改网格颜色。 -> - 分别修改PARAM\_DEFAULT\_PIXEL\_NUM\_H和PARAM\_DEFAULT\_PIXEL\_NUM\_V的值为192和64。 -> - 修改\GUI\inc\SGUI_Common.h(对应工程路径/SimpleGUI/Headers/GUI/inc/SGUI_Common.h)文件中的SGUI_LCD_SIZE_WIDTH和SGUI_LCD_SIZE_HEIGHT的值为192和64。 -> - 重新编译工程。 - -  重新编译后,即可看到效果,此时已经模拟为黑底蓝字的OLED显示屏。 ->![10-Virtual SDK模拟OLED显示屏](https://images.gitee.com/uploads/images/2019/0117/132051_954fd5c7_769424.png) - -  上述的宏用于VirtualSDK\Common\src\Common.c(对应工程路径/SimpleGUI/Sources/VirtualSDK/Common/src/Common.c)文件中,载入设定参数的操作中。 - - void SetDefaultParameterData(PixelPanelParameter* pstParameter) - { - if(NULL != pstParameter) - { - // Appearance - pstParameter->HorizontalPixelNumber = PARAM_DEFAULT_PIXEL_NUM_H; - pstParameter->VerticalPixelNumber = PARAM_DEFAULT_PIXEL_NUM_V; - pstParameter->PixelUnitWidth = PARAM_DEFAULT_PIXEL_WIDTH; - pstParameter->PixelUnitHeight = PARAM_DEFAULT_PIXEL_HEIGHT; - pstParameter->EdgeWidth = PARAM_DEFAULT_EDGE_WIDTH; - pstParameter->EnableGrid = PARAM_DEFAULT_GRID_DISABLE; - - // ScreenColor - pstParameter->PanelColor.RGBA = LCD_COLOR_OBJ_BKG; - pstParameter->PixelColor.RGBA = LCD_COLOR_OBJ_PIX; - pstParameter->EdgeColor.RGBA = LCD_COLOR_OBJ_EDGE; - pstParameter->GridColor.RGBA = LCD_COLOR_OBJ_GRID; - } - } - -  此函数将在Virtual SDK启动时配置LCD面板的相关参数,如果想要使能像素网格,可以将: - - pstParameter->EnableGrid = PARAM_DEFAULT_GRID_DISABLE; - -修改为: - - pstParameter->EnableGrid = PARAM_DEFAULT_GRID_ENABLE; -同时修改屏幕像素尺寸为4或4以上 - - pstParameter->PixelSize = 4; - -重新编译后,效果如下: ->![11-Virtual SDK模拟OLED显示屏(带网格)](https://images.gitee.com/uploads/images/2019/0117/132125_7336e715_769424.png) - -  需要注意的是,由于网格线显示时占用1像素,为了避免画面显示失调,SimpleGUI的Virtual SDK仅在LCD像素点尺寸(也就是宏定义PARAM_DEFAULT_PIXEL_SIZE)的值大于4时,网格设定才会有效,在像素点尺寸小于4时,网格线将被强制关闭。 - -#### 3.4. 使用Virtual SDK -  SimpleGUI提供了一个虚拟入口,用于模拟SimpleGUI在目标平台下的简易动作。 -  Virtual SDK在VirtualSDK\Interface\src\SDKInterface.c(对应工程路径/SimpleGUI/Sources/VirtualSDK/Common/src/Common.c)文件中提供了以下接口。 - -|接口函数|功能概要| -|:--|:- | -|SGUI_SDK_DummyMainProc|Virtual SDK的虚拟主入口函数,模拟Main函数。| -|SGUI_SDK_SetEvnetSyncFlag|设定事件信号标记,通常由Virtual SDK自身调用,用于在模拟心跳定时器、RTC定时器或按键事件触发时设定标记用。| -|SGUI_SDK_SyncKeyEventData|同步按键事件,用于保存消息触发时的键值。| -|SGUI_SDK_GetEventSyncFlag|获取事件信号标记,通常由用户程序调用,用于读取和查询模拟心跳定时器、RTC定时器或按键是否触发。| -|SGUI_SDK_GetKeyEventData|获取按键事件触发的键值,通常由用户程序调用。| -|SGUI_SDK_Initialize|初始化Virtual SDK虚拟设备,通常由用户程序调用。| -|SGUI_SDK_ConfigHearBeatTimer|配置虚拟心跳定时器,通常由用户程序调用,单位毫秒,参数为0时定时器停止。| -|SGUI_SDK_EnableRTCInterrupt|配置虚拟RTC定时器使能。| -|SGUI_SDK_SetPixel|写LCD像素值(仅显示缓存)| -|SGUI_SDK_GetPixel|读LCD像素值(仅显示缓存)| -|SGUI_SDK_RefreshDisplay|更新显示内容| -|SGUI_SDK_ClearDisplay|清除屏幕显示| - -  Virtual SDK中除了虚拟的显示屏外,还提供了连个定时器可供使用,分别为“模拟心跳定时器”和 -“RTC”定时器。 - - - 模拟心跳定时器 -  受用户编写的模拟程序控制,以指定的时间间隔触发或停止,用于携带一些测试用模拟数据或实现简易动画效果等,例如演示历程起始画面中文字滚动的效果,以及实时曲线中曲线数据的携带都依赖此定时器实现。 - - 模拟RTC定时器 -  受用户编写的模拟程序控制,可启动或停止,每1秒触发一次,可用于秒级计时或更新系统时间用。 - -  各函数的详细使用方法请参照演示历程。 - -### 4. 联系开发者 -  首先,感谢您对SimpleGUI的赏识与支持。 -  虽然最早仅仅作为一套GUI接口库使用,但我最终希望SimpleGUI能够为您提供一套完整的单色屏GUI及交互设计解决方案,如果您有新的需求、提议亦或想法,欢迎在以下地址留言,或加入[QQ交流群799501887](https://jq.qq.com/?_wv=1027&k=5ahGPvK)留言交流。 ->SimpleGUI@开源中国:https://www.oschina.net/p/simplegui ->SimpleGUI@码云:https://gitee.com/Polarix/simplegui - -  本人并不是全职的开源开发者,依然有工作及家庭的琐碎事务要处理,所以对于大家的需求和疑问反馈的可能并不及时,多有怠慢,敬请谅解。 -  最后,再次感谢您的支持。 +SimpleGUI Virtual SDK 使用说明 +--- +## 1. 概述 + +  为了方便开发者在自己的项目中使用SimpleGUI部署、开发或试开发GUI模块,作者特设计此模拟环境,用于进行不依赖硬件平台的学习或开发。 +  SimpleGUI Virtual SDK(以下简称SDK)使用C++语言开发,基于wxWidgets的GUI框架,工程建立于Code::Blocks集成开发环境中,可以于Windows XP或更高版本的操作系统中编译和运行。 + +## 2. 基于GCC和Code::Blocks的SDK环境搭建 + +#### 2.1. 下载Code::Blocks + +  请访问[Code::Blocks下载页面](http://www.codeblocks.org/downloads/binaries)下载Code::Blocks集成开发环境的可执行文件,截至本文档最后一次编辑,Code::Blocks集成开发环境的最新版本为17.12。 +  由于Code::Blocks开发环境本身可以适配多种编译器,所以可下载选项有很多,如果对编译器并不了解,可以选择下载“codeblocks-17.12mingw-setup.exe”或“codeblocks-17.12mingw-nosetup.zip”,这两个版本自带TDM-GCC 5.1.0版本编译器,区别为前者为安装版,会自动创建文件类型关联,后者为绿色版,解压即用。 +  后续讲解也以此编译器为例。 +>![01-Codeblocks下载页面](https://images.gitee.com/uploads/images/2019/0117/131725_1b7479df_769424.png) + +#### 2.2. 部署wxWidgets + +  请访问[wxWidgets下载页面](http://www.wxwidgets.org/downloads/),选择页面中“Latest Development Release: 3.1.2”或者“Latest Stable Release: 3.0.4”标题下“Binaries”中的“Download windows binaries”链接。 +>![02-wxWidgets下载页面](https://images.gitee.com/uploads/images/2019/0117/131820_a6ed6bf6_769424.png) + +  在弹出的列表中下载对应的编译器使用的库,本例中使用Codeblocks自带的TDM-GCC 5.1.0本编译器。所以选择下载“MinGW-TDM5.10”下的头文件(Header Files)和开发用库文件(Development Files)。 + +>![03-wxWidgets库的选择](https://images.gitee.com/uploads/images/2019/0117/232547_839319af_769424.png) +>   由于2018年12月10日wxWidgets3.1.2版本更新后,面向GCC编译器的Makefile无法在Windows环境下直接使用,所以从本次更新开始,仅讲解wxWidgets库文件的使用方法,不再详述wxWidgets库的编译过程,如果有这方面具体需求,请参考本人的博文[《wxWidgets3.1.2在Windows+TDM-GCC环境下编译错误的处理》](https://my.oschina.net/Polarix/blog/2996189)了解详细信息。 +>   3.1.1及更早版本的源代码仍然可以直接在Windows下使用TDM-GCC编译。 + +  下载后,请将下载的头文件和库文件解压在同一个文件夹中,解压的路径不宜太长,文件夹名中不要出现括号、下划线、空格等特殊字符,否则将可能导致程序编译时引用文件异常。本范例中部署路径为“E:\Workspace\Librarys\wxWidgets\ForTDM510”。解压后,请将库文件的目录名从“gccXXXXXX\_dll”修改为“gcc\_dll”。 +  部署后的目录结构应为: +``` + wxWidgets库目录 + ├─ include + │ ├─ msvc + │ │ └─ wx + │ │ └─ *.h + │ └─ wx + │ ├─ [DIR] + │ └─ *.h + └─ lib + ├─ gcc_dll + ├─ mswu + └─ *.a(库文件) +``` + + +#### 2.3. 配置Code::Blocks下的wxWidgets开发环境 + +  启动Code::Blocks,然后选择选择“Settings”(设置)菜单下的“Global variables”(全局变量)项目。 + +>![04-Global variables选项](https://images.gitee.com/uploads/images/2019/0117/131842_f2e41830_769424.png) + +  在打开的全局变量编辑窗口中,点击“New”按钮,新建一个全局变量“wxbin”。 + +>![05-新建全局变量](https://images.gitee.com/uploads/images/2019/0117/232846_b419f48d_769424.png) + +  然后将全局变量的根路径、包含路径和库路经分别设置为wxWidgets的根路径include路径和lib路径,其他留空即可,参考下图。 +>全局变量配置 +>![06-全局变量配置](https://images.gitee.com/uploads/images/2019/0117/232905_babc192c_769424.png) + +  然后点击“Close”关闭环境变量编辑窗口,至此,SimpleGUI模拟环境开发需要使用的Codeblocks+wxWidgets环境搭建完成。 + +### 3. 编译和使用Virtual SDK +#### 3.1. 工程环境结构 + +  您可以通过Git工具,从码云(Gitee)上将SimpleGUI的全部代码和资料同步到本地,如果您不想使用Git工具,也可以在[SimpleGUI工程页面](https://gitee.com/Polarix/simplegui)中点击“克隆/下载”按钮,在弹出的窗口中点击“下载ZIP”按钮下载整个工程的压缩包文件。 +  同步或下载解压SimpleGUI后,就可以使用SimpleGUI的Virtual SDK了,SimpleGUI的主目录结构和说明如下: + +|目录名|功能| +|:- |:- | +|DemoProc|SimpGUI的演示代码| +|DemoProject|SimpleGUI的演示工程| +|Documents|关于SimpleGUI的一些简要说明文档| +|GUI|SimpleGUI的代码实现部分| +|HMI|SimpleGUI的HMI模型实现部分| +|VirtualSDK|Virtual SDK的工程及源码| + +#### 3.2. 编译Virtual SDK工程 +  进入VirtualSDK\Project\CodeBlocks目录下,SimpleGUI.cbp文件夹即为模拟环境的工程文件,使用Code::Blocks打开。如果用户下载的是nosetup(绿色版)的Code::Blocks,需要手动建立关联才能直接用双击的方式打开cbp文件,否则,用户只能先打开Code::Blocks,然后从Code::Blocks中执行打开操作以打开工程文件。 +  点击工具栏上的编译按钮或按快捷键Ctrl+F9,开始编译模拟环境演示工程。 +  编译完成,显示无错误和警告,现在点击工具栏上的运行按钮或按快捷键Ctrl+F10就可以看到模拟环境的运行效果了。 +>![07-编译工程](https://images.gitee.com/uploads/images/2019/0117/131925_defb4a75_769424.png) + +>![08-运行效果](https://images.gitee.com/uploads/images/2019/0117/131942_a01e12c5_769424.png) + +#### 3.3. 配置Virtual SDK +  默认情况下,SimpleGUI的Virtual SDK中虚拟显示屏幕的配色方案为黄底黑字的LCD点阵显示屏,为最大程度上模拟真实情况下的视觉效果,方便创建和调试GUI元素,模拟环境的虚拟LCD面板可以通过修改配置定义修改颜色和尺寸。 +  打开Virtual SDK工程,进入VirtualSDK\Common\inc文件夹(对应工程路径/SimpleGUI/Headers/VirtualSDK/Common/inc),打开Common.h文件,找到以下宏定义: + +|宏定义名|功能| +|:- |:- | +|LCD_COLOR_OBJ_PIX|逻辑有效像素点颜色(前景颜色)| +|LCD_COLOR_OBJ_BKG|逻辑无效像素点颜色(背景颜色)| +|LCD_COLOR_OBJ_GRID|网格颜色| +|PARAM_DEFAULT_PIXEL_NUM_H|横向像素点数量| +|PARAM_DEFAULT_PIXEL_NUM_V|纵向像素点数量| +|PARAM_DEFAULT_PIXEL_WIDTH|屏幕像素单元宽度| +|PARAM_DEFAULT_PIXEL_HEIGHT|屏幕像素单元高度| + +  Virtual SDK默认状态下模拟的是黄底黑字的LCD显示屏,不显示像素网格。接下来以模拟黑底蓝字的OLED19264显示屏效果,简要介绍一下各个宏定义的使用方法: +> - 使用一张目标屏幕的照片,使用取色工具获取屏幕背景、像素以及边框颜色的RGB值,比如淘宝上的照片,就可以直接使用。 +>![09-实物照片](https://images.gitee.com/uploads/images/2019/0117/233447_91a32ff3_769424.png) +> - 将颜色的RGBA值分别更新入三个宏定义中,颜色使用32位无符号整数表示,从高至低四字节的意义分别为A、B、G、R。例如上图中屏幕背景色、像素色和边框色分别设定为0xFF070707、0xFFF1FA4F和0xFFC9652F,由于不需要显示网格,所以不需要修改网格颜色。 +> - 分别修改PARAM\_DEFAULT\_PIXEL\_NUM\_H和PARAM\_DEFAULT\_PIXEL\_NUM\_V的值为192和64。 +> - 修改\GUI\inc\SGUI_Common.h(对应工程路径/SimpleGUI/Headers/GUI/inc/SGUI_Common.h)文件中的SGUI_LCD_SIZE_WIDTH和SGUI_LCD_SIZE_HEIGHT的值为192和64。 +> - 重新编译工程。 + +  重新编译后,即可看到效果,此时已经模拟为黑底蓝字的OLED显示屏。 +>![10-Virtual SDK模拟OLED显示屏](https://images.gitee.com/uploads/images/2019/0117/132051_954fd5c7_769424.png) + +  上述的宏用于VirtualSDK\Common\src\Common.c(对应工程路径/SimpleGUI/Sources/VirtualSDK/Common/src/Common.c)文件中,载入设定参数的操作中。 + + void SetDefaultParameterData(PixelPanelParameter* pstParameter) + { + if(NULL != pstParameter) + { + // Appearance + pstParameter->HorizontalPixelNumber = PARAM_DEFAULT_PIXEL_NUM_H; + pstParameter->VerticalPixelNumber = PARAM_DEFAULT_PIXEL_NUM_V; + pstParameter->PixelUnitWidth = PARAM_DEFAULT_PIXEL_WIDTH; + pstParameter->PixelUnitHeight = PARAM_DEFAULT_PIXEL_HEIGHT; + pstParameter->EdgeWidth = PARAM_DEFAULT_EDGE_WIDTH; + pstParameter->EnableGrid = PARAM_DEFAULT_GRID_DISABLE; + + // ScreenColor + pstParameter->PanelColor.RGBA = LCD_COLOR_OBJ_BKG; + pstParameter->PixelColor.RGBA = LCD_COLOR_OBJ_PIX; + pstParameter->EdgeColor.RGBA = LCD_COLOR_OBJ_EDGE; + pstParameter->GridColor.RGBA = LCD_COLOR_OBJ_GRID; + } + } + +  此函数将在Virtual SDK启动时配置LCD面板的相关参数,如果想要使能像素网格,可以将: + + pstParameter->EnableGrid = PARAM_DEFAULT_GRID_DISABLE; + +修改为: + + pstParameter->EnableGrid = PARAM_DEFAULT_GRID_ENABLE; +同时修改屏幕像素尺寸为4或4以上 + + pstParameter->PixelSize = 4; + +重新编译后,效果如下: +>![11-Virtual SDK模拟OLED显示屏(带网格)](https://images.gitee.com/uploads/images/2019/0117/132125_7336e715_769424.png) + +  需要注意的是,由于网格线显示时占用1像素,为了避免画面显示失调,SimpleGUI的Virtual SDK仅在LCD像素点尺寸(也就是宏定义PARAM_DEFAULT_PIXEL_SIZE)的值大于4时,网格设定才会有效,在像素点尺寸小于4时,网格线将被强制关闭。 + +#### 3.4. 使用Virtual SDK +  SimpleGUI提供了一个虚拟入口,用于模拟SimpleGUI在目标平台下的简易动作。 +  Virtual SDK在VirtualSDK\Interface\src\SDKInterface.c(对应工程路径/SimpleGUI/Sources/VirtualSDK/Common/src/Common.c)文件中提供了以下接口。 + +|接口函数|功能概要| +|:--|:- | +|SGUI_SDK_DummyMainProc|Virtual SDK的虚拟主入口函数,模拟Main函数。| +|SGUI_SDK_SetEvnetSyncFlag|设定事件信号标记,通常由Virtual SDK自身调用,用于在模拟心跳定时器、RTC定时器或按键事件触发时设定标记用。| +|SGUI_SDK_SyncKeyEventData|同步按键事件,用于保存消息触发时的键值。| +|SGUI_SDK_GetEventSyncFlag|获取事件信号标记,通常由用户程序调用,用于读取和查询模拟心跳定时器、RTC定时器或按键是否触发。| +|SGUI_SDK_GetKeyEventData|获取按键事件触发的键值,通常由用户程序调用。| +|SGUI_SDK_Initialize|初始化Virtual SDK虚拟设备,通常由用户程序调用。| +|SGUI_SDK_ConfigHearBeatTimer|配置虚拟心跳定时器,通常由用户程序调用,单位毫秒,参数为0时定时器停止。| +|SGUI_SDK_EnableRTCInterrupt|配置虚拟RTC定时器使能。| +|SGUI_SDK_SetPixel|写LCD像素值(仅显示缓存)| +|SGUI_SDK_GetPixel|读LCD像素值(仅显示缓存)| +|SGUI_SDK_RefreshDisplay|更新显示内容| +|SGUI_SDK_ClearDisplay|清除屏幕显示| + +  Virtual SDK中除了虚拟的显示屏外,还提供了连个定时器可供使用,分别为“模拟心跳定时器”和 +“RTC”定时器。 + + - 模拟心跳定时器 +  受用户编写的模拟程序控制,以指定的时间间隔触发或停止,用于携带一些测试用模拟数据或实现简易动画效果等,例如演示历程起始画面中文字滚动的效果,以及实时曲线中曲线数据的携带都依赖此定时器实现。 + - 模拟RTC定时器 +  受用户编写的模拟程序控制,可启动或停止,每1秒触发一次,可用于秒级计时或更新系统时间用。 + +  各函数的详细使用方法请参照演示历程。 + +### 4. 联系开发者 +  首先,感谢您对SimpleGUI的赏识与支持。 +  虽然最早仅仅作为一套GUI接口库使用,但我最终希望SimpleGUI能够为您提供一套完整的单色屏GUI及交互设计解决方案,如果您有新的需求、提议亦或想法,欢迎在以下地址留言,或加入[QQ交流群799501887](https://jq.qq.com/?_wv=1027&k=5ahGPvK)留言交流。 +>SimpleGUI@开源中国:https://www.oschina.net/p/simplegui +>SimpleGUI@码云:https://gitee.com/Polarix/simplegui + +  本人并不是全职的开源开发者,依然有工作及家庭的琐碎事务要处理,所以对于大家的需求和疑问反馈的可能并不及时,多有怠慢,敬请谅解。 +  最后,再次感谢您的支持。 diff --git a/GUI/inc/SGUI_Basic.h b/GUI/inc/SGUI_Basic.h index 3fad624..49d25e8 100644 --- a/GUI/inc/SGUI_Basic.h +++ b/GUI/inc/SGUI_Basic.h @@ -4,6 +4,7 @@ //= Include files. =// //=======================================================================// #include "SGUI_Common.h" +#include "SGUI_FlashData.h" //=======================================================================// //= Data type definition. =// @@ -39,6 +40,5 @@ void SGUI_Basic_DrawRectangle(SGUI_SCR_DEV* pstIFObj, SGUI_UINT uiStartX, SG void SGUI_Basic_DrawCircle(SGUI_SCR_DEV* pstIFObj, SGUI_UINT uiCx, SGUI_UINT uiCy, SGUI_UINT uiRadius, SGUI_COLOR eEdgeColor, SGUI_COLOR eFillColor); void SGUI_Basic_ReverseBlockColor(SGUI_SCR_DEV* pstIFObj, SGUI_UINT uiStartX, SGUI_UINT uiStartY, SGUI_UINT uiWidth, SGUI_UINT uiHeight); void SGUI_Basic_DrawBitMap(SGUI_SCR_DEV* pstIFObj, SGUI_RECT_AREA* pstDisplayArea, SGUI_RECT_AREA* pstDataArea, SGUI_FLASH_DATA_SOURCE eDataSource, SGUI_ROM_ADDRESS adDataStartAddr, SGUI_DRAW_MODE eDrawMode); -void SGUI_Basic_RefreshDisplay(SGUI_SCR_DEV* pstIFObj); #endif diff --git a/GUI/inc/SGUI_List.h b/GUI/inc/SGUI_List.h index cea83f5..3bb3cd2 100644 --- a/GUI/inc/SGUI_List.h +++ b/GUI/inc/SGUI_List.h @@ -30,8 +30,8 @@ typedef struct typedef struct _st_sgui_list_item_ { - SGUI_SIZE Sign; - SGUI_CSZSTR Text; + SGUI_SIZE ItemID; + SGUI_CSZSTR Text; SGUI_List_ITEM_TYPE Type; SGUI_List_PARAMETER_VALUE Valid; SGUI_List_PARAMETER_VALUE Decimal; diff --git a/GUI/inc/SGUI_Notice.h b/GUI/inc/SGUI_Notice.h index aab9085..48bbf21 100644 --- a/GUI/inc/SGUI_Notice.h +++ b/GUI/inc/SGUI_Notice.h @@ -5,6 +5,7 @@ //=======================================================================// #include "SGUI_Common.h" #include "SGUI_Basic.h" +#include "SGUI_Text.h" //=======================================================================// //= User Macro definition. =// diff --git a/GUI/inc/SGUI_ProcessBar.h b/GUI/inc/SGUI_ProcessBar.h index afce117..57ce990 100644 --- a/GUI/inc/SGUI_ProcessBar.h +++ b/GUI/inc/SGUI_ProcessBar.h @@ -4,6 +4,7 @@ //= Include files. =// //=======================================================================// #include "SGUI_Common.h" +#include "SGUI_Basic.h" //=======================================================================// //= Data type definition. =// diff --git a/GUI/inc/SGUI_ScrollBar.h b/GUI/inc/SGUI_ScrollBar.h index 697b61b..2e352b0 100644 --- a/GUI/inc/SGUI_ScrollBar.h +++ b/GUI/inc/SGUI_ScrollBar.h @@ -3,6 +3,7 @@ //=======================================================================// //= Include files. =// //=======================================================================// +#include "SGUI_Basic.h" #include "SGUI_Common.h" //=======================================================================// diff --git a/GUI/inc/SGUI_Typedef.h b/GUI/inc/SGUI_Typedef.h index 8e6eff2..18472a6 100644 --- a/GUI/inc/SGUI_Typedef.h +++ b/GUI/inc/SGUI_Typedef.h @@ -34,6 +34,8 @@ typedef uint32_t SGUI_UINT32; typedef int SGUI_INT; typedef unsigned int SGUI_UINT; +typedef long SGUI_LONG; +typedef unsigned long SGUI_ULONG; typedef unsigned char SGUI_BYTE; typedef const unsigned char SGUI_CBYTE; typedef size_t SGUI_SIZE; diff --git a/GUI/src/1.txt b/GUI/src/1.txt new file mode 100644 index 0000000..4bf2359 --- /dev/null +++ b/GUI/src/1.txt @@ -0,0 +1,13 @@ + hCu F ̃{[ x Work ł + {[ VAԍ EEB2-19FB ł + + F:\Workspace\39_Developement\06-Gitee\SimpleGUI_Working\GUI\src ̃fBNg + +[.] [..] 1.txt +Listfile.cmd SGUI_Basic.c SGUI_Common.c +SGUI_FlashData.c SGUI_Frame.c SGUI_Graph.c +SGUI_Interface.c SGUI_List.c SGUI_Notice.c +SGUI_ProcessBar.c SGUI_RealtimeGraph.c SGUI_ScrollBar.c +SGUI_Text.c SGUI_VariableBox.c + 15 ‚̃t@C 1,505,620 oCg + 2 ‚̃fBNg 84,545,929,216 oCg̋󂫗̈ diff --git a/GUI/src/Listfile.cmd b/GUI/src/Listfile.cmd new file mode 100644 index 0000000..34a8b84 --- /dev/null +++ b/GUI/src/Listfile.cmd @@ -0,0 +1,2 @@ +dir /w > 1.txt +pause \ No newline at end of file diff --git a/GUI/src/SGUI_Basic.c b/GUI/src/SGUI_Basic.c index d87deec..457bd8e 100644 --- a/GUI/src/SGUI_Basic.c +++ b/GUI/src/SGUI_Basic.c @@ -10,7 +10,6 @@ //= Include files. =// //=======================================================================// #include "SGUI_Basic.h" -#include "SGUI_FlashData.h" //=======================================================================// //= User Macro definition. =// @@ -155,7 +154,6 @@ void SGUI_Basic_ClearScreen(SGUI_SCR_DEV* pstIFObj) else { SGUI_Basic_DrawRectangle(pstIFObj, 0, 0, RECT_WIDTH(pstIFObj->stSize), RECT_HEIGHT(pstIFObj->stSize), SGUI_COLOR_BKGCLR, SGUI_COLOR_BKGCLR); - SGUI_Basic_RefreshDisplay(pstIFObj); } } } @@ -551,22 +549,3 @@ void SGUI_Basic_DrawBitMap(SGUI_SCR_DEV* pstIFObj, SGUI_RECT_AREA* pstDisplayAre } } } - -/*************************************************************************/ -/** Function Name: SGUI_Basic_RefreshDisplay **/ -/** Purpose: Sync display buffer to screen. **/ -/** Params: **/ -/** @ pstIFObj[in]: SimpleGUI object pointer. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*************************************************************************/ -void SGUI_Basic_RefreshDisplay(SGUI_SCR_DEV* pstIFObj) -{ - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - if(NULL != pstIFObj) - { - pstIFObj->fnRefreshScreen(); - } -} diff --git a/GUI/src/SGUI_List.c b/GUI/src/SGUI_List.c index 2f07ea4..e80c23d 100644 --- a/GUI/src/SGUI_List.c +++ b/GUI/src/SGUI_List.c @@ -8,12 +8,7 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Common.h" -#include "SGUI_Basic.h" -#include "SGUI_Text.h" -#include "SGUI_ScrollBar.h" #include "SGUI_List.h" -#include "SGUI_Frame.h" //=======================================================================// //= User Macro definition. =// diff --git a/GUI/src/SGUI_Notice.c b/GUI/src/SGUI_Notice.c index 3f20ca9..848b6f1 100644 --- a/GUI/src/SGUI_Notice.c +++ b/GUI/src/SGUI_Notice.c @@ -9,9 +9,6 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Common.h" -#include "SGUI_Basic.h" -#include "SGUI_Text.h" #include "SGUI_Notice.h" //=======================================================================// diff --git a/GUI/src/SGUI_ProcessBar.c b/GUI/src/SGUI_ProcessBar.c index dbe8d55..5507781 100644 --- a/GUI/src/SGUI_ProcessBar.c +++ b/GUI/src/SGUI_ProcessBar.c @@ -9,7 +9,6 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Basic.h" #include "SGUI_ProcessBar.h" //=======================================================================// diff --git a/GUI/src/SGUI_RealtimeGraph.c b/GUI/src/SGUI_RealtimeGraph.c index 521ef02..cbeb71a 100644 --- a/GUI/src/SGUI_RealtimeGraph.c +++ b/GUI/src/SGUI_RealtimeGraph.c @@ -9,8 +9,6 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Common.h" -#include "SGUI_Text.h" #include "SGUI_RealtimeGraph.h" //=======================================================================// diff --git a/GUI/src/SGUI_ScrollBar.c b/GUI/src/SGUI_ScrollBar.c index 89f6290..a3c9c2f 100644 --- a/GUI/src/SGUI_ScrollBar.c +++ b/GUI/src/SGUI_ScrollBar.c @@ -9,7 +9,6 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Basic.h" #include "SGUI_ScrollBar.h" //=======================================================================// diff --git a/GUI/src/SGUI_Text.c b/GUI/src/SGUI_Text.c index f11c040..6d4eb15 100644 --- a/GUI/src/SGUI_Text.c +++ b/GUI/src/SGUI_Text.c @@ -9,9 +9,7 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Common.h" #include "SGUI_Text.h" -#include "SGUI_Basic.h" //=======================================================================// //= Static variable declaration. =// diff --git a/GUI/src/SGUI_VariableBox.c b/GUI/src/SGUI_VariableBox.c index 89a1eae..3f700ca 100644 --- a/GUI/src/SGUI_VariableBox.c +++ b/GUI/src/SGUI_VariableBox.c @@ -9,9 +9,6 @@ //=======================================================================// //= Include files. =// //=======================================================================// -#include "SGUI_Common.h" -#include "SGUI_Basic.h" -#include "SGUI_Text.h" #include "SGUI_VariableBox.h" //=======================================================================// diff --git a/HMI/inc/HMI_Engine.h b/HMI/inc/HMI_Engine.h index 7ca67d4..ec276b9 100644 --- a/HMI/inc/HMI_Engine.h +++ b/HMI/inc/HMI_Engine.h @@ -10,12 +10,12 @@ //=======================================================================// // GoBack history size #define HMI_SCREEN_HISTORY_MAX (20) -#define HMI_SCREEN_LIST_MAX (20) #define HMI_EVENT_KEY_VALUE_LENGTH_MAX (4) // Parameter post label. #define HMI_SCREEN_ID_ANY (-1) // This label means parameter will posted to every screen. #define HMI_PROCESS_SUCCESSFUL(RESULT) (RESULT >= 0) +#define HMI_PROCESS_FAILED(RESULT) (!(HMI_PROCESS_SUCCESSFUL(RESULT))) // Start screen definition #define HMI_SCREEN_START (0) @@ -32,7 +32,7 @@ typedef struct \ { \ HMI_EVENT_DATA_MEMSET(EVENT); \ EVENT.Head.iSize = sizeof(EVENT); \ - EVENT.Head.eType = HMI_ENGINE_EVENT_ANY; \ + EVENT.Head.iType = EVENT_TYPE_ANY; \ } #define HMI_EVENT_SIZE_CHK(EVENT, TYPE) (((EVENT).Head.iSize == sizeof(TYPE))?SGUI_TRUE:SGUI_FALSE) @@ -44,43 +44,23 @@ typedef struct \ typedef enum { // Abnormal. - HMI_RET_ERROR = -1, + HMI_RET_ERROR = -3, HMI_RET_INVALID_DATA = -2, - HMI_RET_NO_SPACE = -3, - HMI_RET_MEMORY_ERR = -4, - HMI_RET_UNDEFINED_ACTION = -5, - HMI_RET_ERROR_STATE = -6, + HMI_RET_ERROR_STATE = -1, // Normal. - HMI_RET_NORMAL = 0, - HMI_RET_INITIALIZE, - HMI_RET_CONFIRM, - HMI_RET_CANCEL, - HMI_RET_FOLLOWUP, - HMI_RET_FALLBACK, - HMI_RET_INPROCESSING, - HMI_RET_NOACTION, + HMI_RET_ABNORMAL = 0, + HMI_RET_NORMAL = 1, }HMI_ENGINE_RESULT; -// HMI engine state. typedef enum { - HMI_ENGINE_STATE_UNINIT = 0, - HMI_ENGINE_STATE_READY, - HMI_ENGINE_STATE_INPROCESS, - HMI_ENGINE_STATE_ERROR, -}HMI_ENGINE_STATE; - -// HMI event type. -typedef enum -{ - HMI_ENGINE_EVENT_ANY = 0, - HMI_ENGINE_EVENT_ACTION, // Turn to a new screen. - HMI_ENGINE_EVENT_DATA, // Refresh screen display. -}HMI_EVENT_TYPE; + HMI_ENGINE_SCR_SWITCH = 0,// Switch screen and record to history. + HMI_ENGINE_SCR_POPUP, // Show up screen only. +}HMI_SCREEN_DISP_TYPE; typedef struct { - HMI_EVENT_TYPE eType; + SGUI_INT iType; SGUI_INT iID; SGUI_INT iSize; }HMI_EVENT_BASE; @@ -93,45 +73,40 @@ typedef struct // Screen action interface function pointer structure. typedef struct { - HMI_ENGINE_RESULT (*Initialize) (SGUI_SCR_DEV* Interface); // Initialize screen data and parameter. - HMI_ENGINE_RESULT (*Prepare) (SGUI_SCR_DEV* Interface, const void* pstParameters); // Do some thing before current screen display. - HMI_ENGINE_RESULT (*Repaint) (SGUI_SCR_DEV* Interface, const void* pstParameters); // Repaint screen if needed. - HMI_ENGINE_RESULT (*ProcessEvent) (SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent); // Process event. - HMI_ENGINE_RESULT (*PostProcess) (SGUI_SCR_DEV* Interface, SGUI_INT iActionResult); - //void* (*InstanceData)(void); // Get current screen instance data pointer. + // Initialize screen data and parameter. + HMI_ENGINE_RESULT (*Initialize) (SGUI_SCR_DEV* Interface); + // Do some thing before current screen display. + HMI_ENGINE_RESULT (*Prepare) (SGUI_SCR_DEV* Interface, const void* pstParameters); + // Repaint screen if needed. + HMI_ENGINE_RESULT (*Repaint) (SGUI_SCR_DEV* Interface, const void* pstParameters); + // Process event. + HMI_ENGINE_RESULT (*ProcessEvent) (SGUI_SCR_DEV* Interface, const HMI_EVENT_BASE* pstEvent, SGUI_INT* piActionID); + // Post process. + HMI_ENGINE_RESULT (*PostProcess) (SGUI_SCR_DEV* Interface, HMI_ENGINE_RESULT eProcResult, SGUI_INT iActionID); }HMI_SCREEN_ACTION; // Screen data structure. -typedef struct +typedef struct _T_HMI_SCREEN_OBJECT_ { - SGUI_INT ScreenID; - HMI_SCREEN_ACTION* Actions; + SGUI_INT iScreenID; + HMI_SCREEN_ACTION* pstActions; + struct _T_HMI_SCREEN_OBJECT_* pstPrevious; }HMI_SCREEN_OBJECT; typedef struct { - SGUI_INT TopIndex; - HMI_SCREEN_OBJECT* Item[HMI_SCREEN_HISTORY_MAX]; -}HMI_HISTORY_STACK; - -typedef struct -{ - HMI_SCREEN_OBJECT* Screen[HMI_SCREEN_LIST_MAX]; + HMI_SCREEN_OBJECT** ScreenObjPtr; SGUI_INT ScreenCount; HMI_SCREEN_OBJECT* CurrentScreenObject; - HMI_HISTORY_STACK History; - HMI_ENGINE_STATE State; SGUI_SCR_DEV* Interface; }HMI_ENGINE_OBJECT; //=======================================================================// //= Public function declaration. =// //=======================================================================// -HMI_ENGINE_RESULT HMI_PrepareEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject); -HMI_ENGINE_RESULT HMI_AddScreen(HMI_ENGINE_OBJECT* pstHMIEngineObject, HMI_SCREEN_OBJECT* pstScreenObject, SGUI_BOOL bInitializeScreenObject); HMI_ENGINE_RESULT HMI_ActiveEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject, SGUI_INT iScreenID); HMI_ENGINE_RESULT HMI_StartEngine(const void* pstParameters); -HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent); -HMI_ENGINE_RESULT HMI_PostProcess(SGUI_INT iActionResult); -HMI_ENGINE_RESULT HMI_Goto(SGUI_INT iDestScreenID, const void* pstParameters); +HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent); +HMI_ENGINE_RESULT HMI_SwitchScreen(SGUI_INT iDestScreenID, const void* pstParameters); HMI_ENGINE_RESULT HMI_GoBack(const void* pstParameters); +HMI_ENGINE_RESULT HMI_SetDeviceObject(SGUI_SCR_DEV* pstDeviceObj); #endif // __INCLUDE_HMI_ENGINE_H__ diff --git a/HMI/src/HMI_Engine.c b/HMI/src/HMI_Engine.c index b6b7b8a..9a2a398 100644 --- a/HMI/src/HMI_Engine.c +++ b/HMI/src/HMI_Engine.c @@ -10,8 +10,6 @@ //= Include files. =// //=======================================================================// #include "HMI_Engine.h" -#include "SGUI_Common.h" -#include "SGUI_Basic.h" //=======================================================================// //= Static variable declaration. =// @@ -21,113 +19,11 @@ static HMI_ENGINE_OBJECT* g_pstActivedEngineObject; //=======================================================================// //= Static function declaration. =// //=======================================================================// -static SGUI_INLINE HMI_SCREEN_OBJECT* HMI_GetScreenObjectInEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject, SGUI_INT iScreenID); +static HMI_SCREEN_OBJECT* HMI_GetScreenObjectInEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject, SGUI_INT iScreenID); //=======================================================================// //= Function define. =// //=======================================================================// -/*****************************************************************************/ -/** Function Name: HMI_PrepareEngine. **/ -/** Purpose: Initialize HMI engine object. **/ -/** Params: **/ -/** @pstHMIEngineObject[in]: Engine object pointer. **/ -/** @pstScreenObject[in]: Screen object pointer. **/ -/** Return: HMI_ENGINE_RESULT **/ -/** @HMI_RET_NORMAL: Add success. **/ -/** Notice: HMI engine object must prepared by this function before **/ -/** used. **/ -/*****************************************************************************/ -HMI_ENGINE_RESULT HMI_PrepareEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_ENGINE_RESULT eProcessResult; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - eProcessResult = HMI_RET_NORMAL; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - if(NULL != pstHMIEngineObject) - { - // Clean HMI engine object memory area. - // SGUI_Common_MemorySet(pstHMIEngineObject, 0x00, sizeof(HMI_ENGINE_OBJECT)); - - // Initialize engine object data, - pstHMIEngineObject->ScreenCount = 0; - pstHMIEngineObject->State = HMI_ENGINE_STATE_READY; - } - return eProcessResult; -} - -/*****************************************************************************/ -/** Function Name: HMI_AddScreen **/ -/** Purpose: Add a screen object to a existed HMI engine object. **/ -/** Params: **/ -/** @pstHMIEngineObject[in]: Engine object pointer. **/ -/** @pstScreenObject[in]: Screen object pointer. **/ -/** @bInitializeScreenObject[in]: Initialize or reinitialize screen object. **/ -/** Return: HMI_ENGINE_RESULT **/ -/** @HMI_RET_NORMAL: Add success. **/ -/** @HMI_RET_NO_SPACE: No blank element in engine object for new screen. **/ -/** Notice: The engine object only record pointer of the screen **/ -/** object, so please keep the memory area is usable during **/ -/** processing. **/ -/*****************************************************************************/ -HMI_ENGINE_RESULT HMI_AddScreen(HMI_ENGINE_OBJECT* pstHMIEngineObject, HMI_SCREEN_OBJECT* pstScreenObject, SGUI_BOOL bInitializeScreenObject) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_ENGINE_RESULT eProcessResult; - SGUI_INT iIndex; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - eProcessResult = HMI_RET_NORMAL; - iIndex = 0; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - if((NULL != pstHMIEngineObject) && (NULL != pstScreenObject)) - { - // Looking for the blank element in array. - while(iIndex < pstHMIEngineObject->ScreenCount) - { - if(NULL == pstHMIEngineObject->Screen) - { - break; - } - else - { - iIndex++; - } - } - if(iIndex < HMI_SCREEN_LIST_MAX) - { - if(SGUI_TRUE == bInitializeScreenObject) - { - pstScreenObject->Actions->Initialize(pstHMIEngineObject->Interface); - } - // Add screen object pointer to engine. - pstHMIEngineObject->Screen[iIndex] = pstScreenObject; - pstHMIEngineObject->ScreenCount++; - } - else - { - // No blank element in array, screen object add failed. - eProcessResult = HMI_RET_NO_SPACE; - } - } - return eProcessResult; -} - /*****************************************************************************/ /** Function Name: HMI_ActiveEngine **/ /** Purpose: Set a HMI engine object to the activated state. **/ @@ -162,32 +58,28 @@ HMI_ENGINE_RESULT HMI_ActiveEngine(HMI_ENGINE_OBJECT* pstHMIEngineObject, SGUI_I /*----------------------------------*/ /* Process */ /*----------------------------------*/ - if((NULL != g_pstActivedEngineObject) && (HMI_ENGINE_STATE_INPROCESS == g_pstActivedEngineObject->State)) + if(NULL != pstHMIEngineObject) { - // Current engine is already in processing, cannot active others. - eProcessResult = HMI_RET_ERROR_STATE; + if(HMI_SCREEN_ID_ANY != iScreenID) + { + pstScreenObject = HMI_GetScreenObjectInEngine(pstHMIEngineObject, iScreenID); + } + else + { + pstScreenObject = pstHMIEngineObject->ScreenObjPtr[0]; + } + if(NULL != pstScreenObject) + { + pstHMIEngineObject->CurrentScreenObject = pstScreenObject; + } + else + { + eProcessResult = HMI_RET_INVALID_DATA; + } } else { - if(NULL != pstHMIEngineObject) - { - if(HMI_SCREEN_ID_ANY != iScreenID) - { - pstScreenObject = HMI_GetScreenObjectInEngine(pstHMIEngineObject, iScreenID); - } - else - { - pstScreenObject = pstHMIEngineObject->Screen[0]; - } - if(NULL != pstScreenObject) - { - pstHMIEngineObject->CurrentScreenObject = pstScreenObject; - } - else - { - eProcessResult = HMI_RET_INVALID_DATA; - } - } + eProcessResult = HMI_RET_INVALID_DATA; } if(HMI_RET_NORMAL == eProcessResult) @@ -228,29 +120,18 @@ HMI_ENGINE_RESULT HMI_StartEngine(const void* pstParameters) /*----------------------------------*/ if(NULL != g_pstActivedEngineObject) { - if(HMI_ENGINE_STATE_READY != g_pstActivedEngineObject->State) - { - // Engine not initialized. - eProcessResult = HMI_RET_ERROR_STATE; - } - else - { - // Prepare and display screen. - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_INPROCESS; - pstStartScreen = g_pstActivedEngineObject->CurrentScreenObject; - if(NULL != pstStartScreen) - { - if(NULL != pstStartScreen->Actions) - { - if(NULL != pstStartScreen->Actions->Prepare) - { - pstStartScreen->Actions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); - SGUI_Basic_RefreshDisplay(g_pstActivedEngineObject->Interface); - } - } - } - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_READY; - } + pstStartScreen = g_pstActivedEngineObject->CurrentScreenObject; + if(NULL != pstStartScreen) + { + if(NULL != pstStartScreen->pstActions) + { + if(NULL != pstStartScreen->pstActions->Prepare) + { + eProcessResult = pstStartScreen->pstActions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); + g_pstActivedEngineObject->Interface->fnRefreshScreen(); + } + } + } } else { @@ -276,6 +157,7 @@ HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent) /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; HMI_SCREEN_OBJECT* pstCurrentScreen; + SGUI_INT iActionID; /*----------------------------------*/ /* Initialize */ @@ -288,33 +170,35 @@ HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent) /*----------------------------------*/ if(NULL != g_pstActivedEngineObject) { - if(HMI_ENGINE_STATE_READY != g_pstActivedEngineObject->State) - { - // Engine not initialized. - eProcessResult = HMI_RET_ERROR_STATE; - } - else - { - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_INPROCESS; - pstCurrentScreen = g_pstActivedEngineObject->CurrentScreenObject; - if(NULL == pstCurrentScreen) - { - // Screen ID is invalid or screen object is not in this engine. - eProcessResult = HMI_RET_INVALID_DATA; - } - else - { - if(NULL != pstCurrentScreen->Actions) - { - if(NULL != pstCurrentScreen->Actions->ProcessEvent) - { - eProcessResult = pstCurrentScreen->Actions->ProcessEvent(g_pstActivedEngineObject->Interface, pstEvent); - SGUI_Basic_RefreshDisplay(g_pstActivedEngineObject->Interface); - } - } - } - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_READY; - } + // Get current displayed screen object. + pstCurrentScreen = g_pstActivedEngineObject->CurrentScreenObject; + if( (NULL == pstCurrentScreen) || + (NULL == pstCurrentScreen->pstActions) || + (NULL == pstCurrentScreen->pstActions->ProcessEvent)) + { + // Screen ID is invalid or screen object is invalid. + eProcessResult = HMI_RET_INVALID_DATA; + + } + else + { + // Process event. + eProcessResult = pstCurrentScreen->pstActions->ProcessEvent(g_pstActivedEngineObject->Interface, pstEvent, &iActionID); + } + + // Run post process. + eProcessResult = pstCurrentScreen->pstActions->PostProcess(g_pstActivedEngineObject->Interface, eProcessResult, iActionID); + /* + if(HMI_PROCESS_FAILED(eProcResult)) + { + // Post process return failed. + } + */ + if( (NULL != g_pstActivedEngineObject->Interface) && + (NULL != g_pstActivedEngineObject->Interface->fnRefreshScreen)) + { + g_pstActivedEngineObject->Interface->fnRefreshScreen(); + } } else { @@ -326,22 +210,21 @@ HMI_ENGINE_RESULT HMI_ProcessEvent(const HMI_EVENT_BASE* pstEvent) } /*****************************************************************************/ -/** Function Name: HMI_PostProcess **/ -/** Purpose: Process after event process. **/ +/** Function Name: HMI_SwitchScreen **/ +/** Purpose: Turn to a screen with screen index. **/ /** Params: **/ -/** @iActionResult[in]: Event post result. **/ +/** @ iDestScreenID[in]: Screen ID witch will be going to. **/ +/** @ pstParameters[in]: Screen prepare data pointer. **/ /** Return: HMI_ENGINE_RESULT. **/ -/** @HMI_RET_NORMAL: Post process finished normally. **/ -/** @HMI_RET_INVALID_DATA: Screen object is error, post process function **/ -/** might be unspecified. **/ -/** Notice: None. **/ +/** Notice: Screen will only refresh when pstPreProcessData is NULL **/ /*****************************************************************************/ -HMI_ENGINE_RESULT HMI_PostProcess(SGUI_INT iActionResult) +HMI_ENGINE_RESULT HMI_SwitchScreen(SGUI_INT iDestScreenID, const void* pstParameters) { /*----------------------------------*/ /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; + HMI_SCREEN_OBJECT* pstDestScreen; /*----------------------------------*/ /* Initialize */ @@ -353,85 +236,30 @@ HMI_ENGINE_RESULT HMI_PostProcess(SGUI_INT iActionResult) /*----------------------------------*/ if(NULL != g_pstActivedEngineObject) { - if( (NULL != g_pstActivedEngineObject) && - (NULL != g_pstActivedEngineObject->CurrentScreenObject) && - (NULL != g_pstActivedEngineObject->CurrentScreenObject->Actions) && - (NULL != g_pstActivedEngineObject->CurrentScreenObject->Actions->PostProcess)) + pstDestScreen = HMI_GetScreenObjectInEngine(g_pstActivedEngineObject, iDestScreenID); + if(NULL == pstDestScreen) { - eProcessResult = g_pstActivedEngineObject->CurrentScreenObject->Actions->PostProcess(g_pstActivedEngineObject->Interface, iActionResult); - SGUI_Basic_RefreshDisplay(g_pstActivedEngineObject->Interface); + /* Not find screen object by ID. */ + eProcessResult = HMI_RET_INVALID_DATA; + } + else if(NULL != pstDestScreen->pstPrevious) + { + /* Cannot reenter to a screen object. */ + eProcessResult = HMI_RET_ERROR; } else { - eProcessResult = HMI_RET_INVALID_DATA; + pstDestScreen->pstPrevious = g_pstActivedEngineObject->CurrentScreenObject; + g_pstActivedEngineObject->CurrentScreenObject = pstDestScreen; + if(NULL != pstDestScreen->pstActions) + { + if(NULL != pstDestScreen->pstActions->Prepare) + { + eProcessResult = pstDestScreen->pstActions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); + } + } } - } - return eProcessResult; -} -/*****************************************************************************/ -/** Function Name: HMI_Goto **/ -/** Purpose: Turn to a screen with screen index. **/ -/** Params: **/ -/** @uiDestScreenID[in]: Screen ID witch will be going to. **/ -/** @pstParameters[in]: Screen prepare data pointer. **/ -/** Return: None. **/ -/** Notice: Screen will only refresh when pstPreProcessData is NULL **/ -/*****************************************************************************/ -HMI_ENGINE_RESULT HMI_Goto(SGUI_INT iDestScreenID, const void* pstParameters) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_ENGINE_RESULT eProcessResult; - HMI_SCREEN_OBJECT* pstCurrentScreen; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - eProcessResult = HMI_RET_NORMAL; - pstCurrentScreen = NULL; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - if(NULL != g_pstActivedEngineObject) - { - if(HMI_ENGINE_STATE_READY != g_pstActivedEngineObject->State) - { - // Engine not initialized or in processing. - eProcessResult = HMI_RET_ERROR_STATE; - } - else - { - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_INPROCESS; - pstCurrentScreen = g_pstActivedEngineObject->CurrentScreenObject; - if(NULL != pstCurrentScreen) - { - // Push current screen to history stack. - g_pstActivedEngineObject->History.Item[g_pstActivedEngineObject->History.TopIndex] = pstCurrentScreen; - g_pstActivedEngineObject->History.TopIndex++; - - // Set next screen information in engine. - pstCurrentScreen = HMI_GetScreenObjectInEngine(g_pstActivedEngineObject, iDestScreenID); - if(NULL != pstCurrentScreen) - { - g_pstActivedEngineObject->CurrentScreenObject = pstCurrentScreen; - if(NULL != pstCurrentScreen->Actions) - { - if(NULL != pstCurrentScreen->Actions->Prepare) - { - eProcessResult = pstCurrentScreen->Actions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); - } - } - } - else - { - eProcessResult = HMI_RET_INVALID_DATA; - } - } - g_pstActivedEngineObject->State = HMI_ENGINE_STATE_READY; - } } else { @@ -447,8 +275,8 @@ HMI_ENGINE_RESULT HMI_Goto(SGUI_INT iDestScreenID, const void* pstParameters) /** Purpose: Go back to previous screen in actions history. **/ /** Resources: Screen data structure and action process function. **/ /** Params: **/ -/** @pstPreProcessData[in]: Update screen data. **/ -/** Return: None. **/ +/** @pstPreProcessData[in]: Update screen data. **/ +/** Return: HMI_ENGINE_RESULT. **/ /** Notice: Screen will only refresh when pstPreProcessData is NULL **/ /*****************************************************************************/ HMI_ENGINE_RESULT HMI_GoBack(const void* pstParameters) @@ -457,46 +285,36 @@ HMI_ENGINE_RESULT HMI_GoBack(const void* pstParameters) /* Variable Declaration */ /*----------------------------------*/ HMI_ENGINE_RESULT eProcessResult; - HMI_SCREEN_OBJECT* pstCurrentScreen; + HMI_SCREEN_OBJECT* pstPreviousScreen; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eProcessResult = HMI_RET_NORMAL; - pstCurrentScreen = NULL; /*----------------------------------*/ /* Process */ /*----------------------------------*/ if(NULL != g_pstActivedEngineObject) { - if(HMI_ENGINE_STATE_READY != g_pstActivedEngineObject->State) - { - // Engine not initialized or in processing. - eProcessResult = HMI_RET_ERROR_STATE; - } - else - { - g_pstActivedEngineObject->History.TopIndex--; - pstCurrentScreen = g_pstActivedEngineObject->History.Item[g_pstActivedEngineObject->History.TopIndex]; - g_pstActivedEngineObject->History.Item[g_pstActivedEngineObject->History.TopIndex] = NULL; + pstPreviousScreen = g_pstActivedEngineObject->CurrentScreenObject->pstPrevious; + g_pstActivedEngineObject->CurrentScreenObject->pstPrevious = NULL; - if(NULL != pstCurrentScreen) - { - g_pstActivedEngineObject->CurrentScreenObject = pstCurrentScreen; - if(NULL != pstCurrentScreen->Actions) - { - if(NULL != pstCurrentScreen->Actions->Prepare) - { - eProcessResult = pstCurrentScreen->Actions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); - } - } - } - else - { - eProcessResult = HMI_RET_INVALID_DATA; - } - } + if(NULL != pstPreviousScreen) + { + g_pstActivedEngineObject->CurrentScreenObject = pstPreviousScreen; + if(NULL != pstPreviousScreen->pstActions) + { + if(NULL != pstPreviousScreen->pstActions->Prepare) + { + eProcessResult = pstPreviousScreen->pstActions->Prepare(g_pstActivedEngineObject->Interface, pstParameters); + } + } + } + else + { + eProcessResult = HMI_RET_INVALID_DATA; + } } else { @@ -541,9 +359,9 @@ HMI_SCREEN_OBJECT* HMI_GetScreenObjectInEngine(HMI_ENGINE_OBJECT* pstHMIEngineOb { while(iIndex < pstHMIEngineObject->ScreenCount) { - if(iScreenID == pstHMIEngineObject->Screen[iIndex]->ScreenID) + if(iScreenID == pstHMIEngineObject->ScreenObjPtr[iIndex]->iScreenID) { - pstScreenObject = pstHMIEngineObject->Screen[iIndex]; + pstScreenObject = pstHMIEngineObject->ScreenObjPtr[iIndex]; break; } else @@ -555,3 +373,39 @@ HMI_SCREEN_OBJECT* HMI_GetScreenObjectInEngine(HMI_ENGINE_OBJECT* pstHMIEngineOb return pstScreenObject; } + +/*****************************************************************************/ +/** Function Name: HMI_SetDeviceObject. **/ +/** Purpose: Set a new screen device interface object pointer to **/ +/** actived HMI object. **/ +/** Params: **/ +/** @ pstDeviceObj[in]: New device driver interface object pointer. **/ +/** Return: HMI_ENGINE_RESULT **/ +/** Notice: None. **/ +/*****************************************************************************/ +HMI_ENGINE_RESULT HMI_SetDeviceObject(SGUI_SCR_DEV* pstDeviceObj) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + HMI_ENGINE_RESULT eProcessResult; + + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + eProcessResult = HMI_RET_NORMAL; + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + if((NULL == pstDeviceObj) || (NULL == g_pstActivedEngineObject)) + { + eProcessResult = HMI_RET_INVALID_DATA; + } + else + { + g_pstActivedEngineObject->Interface = pstDeviceObj; + } + + return eProcessResult; +} diff --git a/VirtualSDK/Project/CodeBlocks/VirtualSDK.cbp b/VirtualSDK/Project/CodeBlocks/VirtualSDK.cbp index 88b2aa5..d399388 100644 --- a/VirtualSDK/Project/CodeBlocks/VirtualSDK.cbp +++ b/VirtualSDK/Project/CodeBlocks/VirtualSDK.cbp @@ -118,8 +118,6 @@ - - @@ -138,12 +136,6 @@ - - - -