diff --git a/DemoProc/src/Basic.c b/DemoProc/src/Basic.c index 84adbef..f043d84 100644 --- a/DemoProc/src/Basic.c +++ b/DemoProc/src/Basic.c @@ -1,4 +1,4 @@ -/*************************************************************************/ +/*************************************************************************/ /** Copyright. **/ /** FileName: RTCNotice.c **/ /** Author: Polarix **/ @@ -65,10 +65,17 @@ HMI_ENGINE_RESULT HMI_DemoBasic_RefreshScreen(SGUI_SCR_DEV* pstDeviceIF, const v /*----------------------------------*/ /* Process */ /*----------------------------------*/ - SGUI_Basic_DrawLine(pstDeviceIF, 0, 10, 96, 10, SGUI_COLOR_FRGCLR); - SGUI_Basic_DrawRectangle(pstDeviceIF, 5, 5, 50, 50, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); - SGUI_Basic_DrawCircle(pstDeviceIF, 32, 32, 20, SGUI_COLOR_FRGCLR, SGUI_COLOR_FRGCLR); - SGUI_Basic_DrawCircle(pstDeviceIF, 96, 32, 20, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); + SGUI_Basic_DrawRectangle(pstDeviceIF, 5, 16, 40, 40, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); + SGUI_Basic_DrawCircle(pstDeviceIF, 30, 30, 12, SGUI_COLOR_FRGCLR, SGUI_COLOR_FRGCLR); + SGUI_Basic_DrawCircle(pstDeviceIF, 96, 40, 20, SGUI_COLOR_FRGCLR, SGUI_COLOR_TRANS); + + // GrayScale Demos + SGUI_Basic_DrawLine(pstDeviceIF, 0, 2, 50, 2, 0x02); + SGUI_Basic_DrawLine(pstDeviceIF, 0, 4, 60, 4, 0x04); + SGUI_Basic_DrawLine(pstDeviceIF, 0, 6, 70, 6, 0x06); + SGUI_Basic_DrawLine(pstDeviceIF, 0, 8, 80, 8, 0x08); + SGUI_Basic_DrawLine(pstDeviceIF, 0, 10, 90, 10, 0x0B); + SGUI_Basic_DrawLine(pstDeviceIF, 0, 12, 100, 12, 0x0E); return HMI_RET_NORMAL; } diff --git a/DemoProc/src/DemoProc.c b/DemoProc/src/DemoProc.c index 91adb17..c8311a0 100644 --- a/DemoProc/src/DemoProc.c +++ b/DemoProc/src/DemoProc.c @@ -1,399 +1,401 @@ -/*************************************************************************/ -/** Copyright. **/ -/** FileName: DemoProc.c **/ -/** Author: Polarix **/ -/** Description: User operation interface. **/ -/*************************************************************************/ -//=======================================================================// -//= Include files. =// -//=======================================================================// -#include "DemoProc.h" - -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ -#include "SDKInterface.h" -#include "SGUI_FontResource.h" -#else -#include "screen.h" -#include "usart.h" -#include "rtc.h" -#include "base_timer.h" -#include "DemoActions.h" -#include "trigger_flags.h" -#include "keyboard.h" -#endif - -//=======================================================================// -//= Static variable declaration. =// -//=======================================================================// -SGUI_SCR_DEV g_stDeviceInterface; -HMI_SCREEN_OBJECT* g_arrpstScreenObjs[] = - { - &g_stHMIDemo_List, - &g_stHMIDemo_TextPaint, - &g_stHMIDemo_VariableBox, - &g_stHMIDemo_RealtimeGraph, - &g_stHMIDemo_Menu, - &g_stHMIDemo_Notice, - &g_stHMIDemo_BasicPaint, - &g_stHMIDemo_Curve - }; -HMI_ENGINE_OBJECT g_stDemoEngine; - -//=======================================================================// -//= Static function declare. =// -//=======================================================================// -static void KeyPressEventProc(void); -static void RTCEventProc(void); -static void SysTickTimerEventProc(void); -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ -static bool CheckEventFlag(ENV_FLAG_INDEX eIndex); -#endif //_SIMPLE_GUI_IN_VIRTUAL_SDK_ - -//=======================================================================// -//= Function define. =// -//=======================================================================// - -/*****************************************************************************/ -/** Function Name: InitializeHMIEngineObj **/ -/** Purpose: Simple GUI HMI engine and interface demo process. **/ -/** Parameters: None. **/ -/** Return: HMI_ENGINE_RESULT. **/ -/** Notice: This function demonstrates how to use the interface and **/ -/** HMI engine of Simple GUI. **/ -/*****************************************************************************/ -HMI_ENGINE_RESULT InitializeHMIEngineObj(void) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_ENGINE_RESULT eProcessResult; - int iIndex; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - eProcessResult = HMI_RET_NORMAL; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - /* Clear structure. */ - SGUI_SystemIF_MemorySet(&g_stDeviceInterface, 0x00, sizeof(SGUI_SCR_DEV)); - SGUI_SystemIF_MemorySet(&g_stDemoEngine, 0x00, sizeof(HMI_ENGINE_OBJECT)); -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - /* Initialize display size. */ - g_stDeviceInterface.stSize.iWidth = 128; - g_stDeviceInterface.stSize.iHeight = 64; - /* Initialize interface object. */ - g_stDeviceInterface.fnSetPixel = SGUI_SDK_SetPixel; - g_stDeviceInterface.fnGetPixel = SGUI_SDK_GetPixel; - g_stDeviceInterface.fnClear = SGUI_SDK_ClearDisplay; - g_stDeviceInterface.fnSyncBuffer = SGUI_SDK_RefreshDisplay; -#else - #error Add screen device object initialize process here. -#endif - do - { - /* Prepare HMI engine object. */ - g_stDemoEngine.ScreenCount = sizeof(g_arrpstScreenObjs)/sizeof(*g_arrpstScreenObjs); - g_stDemoEngine.ScreenObjPtr = g_arrpstScreenObjs; - g_stDemoEngine.Interface = &g_stDeviceInterface; - - /* Initialize all screen object. */ - if(NULL != g_stDemoEngine.ScreenObjPtr) - { - for(iIndex=0; iIndexpstActions) - && (NULL != g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize) - ) - { - g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize(&g_stDeviceInterface); - g_stDemoEngine.ScreenObjPtr[iIndex]->pstPrevious = NULL; - } - } - } - else - { - - } - /* Active engine object. */ - eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_LIST); - //eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_ITEMS_BASE); - 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; -} - -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ -/*****************************************************************************/ -/** Function Name: CheckEventFlag **/ -/** Purpose: Check SimpleGUI virtual SDK event trigger flag and **/ -/** reset for next trigger and check. **/ -/** Parameters: **/ -/** @ eIndex[in]: Checked flag index. **/ -/** Return: true for event is trigger, false for not. **/ -/** Notice: This function only used in SimpleGUI virtual SDK **/ -/*****************************************************************************/ -bool CheckEventFlag(ENV_FLAG_INDEX eIndex) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - bool bReturn; - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - bReturn = SGUI_SDK_GetEventSyncFlag(eIndex); - - if(true == bReturn) - { - SGUI_SDK_SetEvnetSyncFlag(eIndex, false); - } - - return bReturn; -} -#endif // _SIMPLE_GUI_VIRTUAL_ENVIRONMENT_SIMULATOR_ - -/*****************************************************************************/ -/** Function Name: DemoMainProcess **/ -/** Purpose: It is a dummy main function for SimpleGUI Virtual SDK, **/ -/** or run demo process in demo process. **/ -/** Parameters: None. **/ -/** Return: Terminal code, seam as main function return code. **/ -/** Notice: None. **/ -/*****************************************************************************/ -void DemoMainProcess(void) -{ - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - // Initialize HMI Engine. - InitializeHMIEngineObj(); - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - while(1) - { - // Check and process heart-beat timer event. - if(true == SysTickTimerTriggered()) - { - SysTickTimerEventProc(); - } - // Check and process key press event. - if(true == UserEventTriggered()) - { - KeyPressEventProc(); - } - // Check and process RTC event. - if(true == RTCTimerTriggered()) - { - RTCEventProc(); - } - } -} - -/*****************************************************************************/ -/** Function Name: KeyPressEventProc **/ -/** Purpose: Deal with user key process in demo process. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: The button is just abstract, and the message may come **/ -/** from a touch screen, a serial port, and so on. **/ -/*****************************************************************************/ -void KeyPressEventProc(void) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - KEY_PRESS_EVENT stEvent; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - HMI_EVENT_INIT(stEvent); - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - stEvent.Head.iType = EVENT_TYPE_ACTION; - stEvent.Head.iID = EVENT_ID_KEY_PRESS; -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - stEvent.Data.uiKeyValue = SGUI_SDK_GetKeyEventData(); -#else - #error Add key event data prepare process here. -#endif - // Post key press event. - HMI_ProcessEvent((HMI_EVENT_BASE*)(&stEvent)); -} - -/*****************************************************************************/ -/** Function Name: SysTickTimerEventProc **/ -/** Purpose: Deal with heartbeat timer event in demo process. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: It is usually used to simulate ADC or other sensors. **/ -/*****************************************************************************/ -void SysTickTimerEventProc(void) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - DATA_EVENT stEvent; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - HMI_EVENT_INIT(stEvent); - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - stEvent.Head.iType = EVENT_TYPE_DATA; - stEvent.Head.iID = EVENT_ID_TIMER; - stEvent.Data.iValue = (rand() % 200)-100; - // Post timer event. - HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); -} - -/*****************************************************************************/ -/** Function Name: RTCEventProc **/ -/** Purpose: Deal with RTC timer event in demo process. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: It is usually used to simulate ADC or other sensors. **/ -/*****************************************************************************/ -void RTCEventProc(void) -{ - /*----------------------------------*/ - /* Variable Declaration */ - /*----------------------------------*/ - HMI_GENERAL_EVENT stEvent; - - /*----------------------------------*/ - /* Initialize */ - /*----------------------------------*/ - HMI_EVENT_INIT(stEvent); - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ - stEvent.Head.iType = EVENT_TYPE_DATA; - stEvent.Head.iID = EVENT_ID_RTC; - // Post RTC update message to a screen. - HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); -} - -/*****************************************************************************/ -/** Function Name: SysTickTimerTriggered **/ -/** Purpose: Check sys-tick timer interrupt is triggered. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*****************************************************************************/ -bool SysTickTimerTriggered(void) -{ - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - return CheckEventFlag(ENV_FLAG_IDX_SDK_TIM_EVENT); -#else - #error Add sys-tick timer trigger process here. -#endif -} - -/*****************************************************************************/ -/** Function Name: RTCTimerTriggered **/ -/** Purpose: Check RTC timer interrupt is triggered. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*****************************************************************************/ -bool RTCTimerTriggered(void) -{ - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - return CheckEventFlag(ENV_FLAG_IDX_SDK_RTC_EVENT); -#else - #error Add RTC timer trigger process here. -#endif -} - -/*****************************************************************************/ -/** Function Name: UserEventTriggered **/ -/** Purpose: Check user event is triggered. **/ -/** Parameters: None. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*****************************************************************************/ -bool UserEventTriggered(void) -{ - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - return CheckEventFlag(ENV_FLAG_IDX_SDK_KEY_EVENT); -#else - #error Add user event trigger process here. -#endif -} - -/*****************************************************************************/ -/** Function Name: SysTickTimerEnable **/ -/** Purpose: Enable or disable sys-tick timer. **/ -/** Parameters: **/ -/** @ bEnable[in]: True for enable sys-tick timer, false for disable. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*****************************************************************************/ -void SysTickTimerEnable(bool bEnable) -{ - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - (void)SGUI_SDK_ConfigHearBeatTimer(bEnable?DEMO_HEART_BEAT_INTERVAL_MS:0); -#else - #error Add sys-tick timer enable/disable process here. -#endif -} - -/*****************************************************************************/ -/** Function Name: RTCTimerEnable **/ -/** Purpose: Enable or disable RTC timer. **/ -/** Parameters: **/ -/** @ bEnable[in]: True for enable RTC timer, false for disable. **/ -/** Return: None. **/ -/** Notice: None. **/ -/*****************************************************************************/ -void RTCTimerEnable(bool bEnable) -{ - - /*----------------------------------*/ - /* Process */ - /*----------------------------------*/ -#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ - (void)SGUI_SDK_EnableRTCInterrupt(bEnable); -#else - #error Add RTC timer enable/disable process here. -#endif -} - +/*************************************************************************/ +/** Copyright. **/ +/** FileName: DemoProc.c **/ +/** Author: Polarix **/ +/** Description: User operation interface. **/ +/*************************************************************************/ +//=======================================================================// +//= Include files. =// +//=======================================================================// +#include "DemoProc.h" + +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ +#include "Common.h" +#include "SDKInterface.h" +#include "SGUI_FontResource.h" +#else +#include "screen.h" +#include "usart.h" +#include "rtc.h" +#include "base_timer.h" +#include "DemoActions.h" +#include "trigger_flags.h" +#include "keyboard.h" +#endif + +//=======================================================================// +//= Static variable declaration. =// +//=======================================================================// +SGUI_SCR_DEV g_stDeviceInterface; +HMI_SCREEN_OBJECT* g_arrpstScreenObjs[] = + { + &g_stHMIDemo_List, + &g_stHMIDemo_TextPaint, + &g_stHMIDemo_VariableBox, + &g_stHMIDemo_RealtimeGraph, + &g_stHMIDemo_Menu, + &g_stHMIDemo_Notice, + &g_stHMIDemo_BasicPaint, + &g_stHMIDemo_Curve + }; +HMI_ENGINE_OBJECT g_stDemoEngine; + +//=======================================================================// +//= Static function declare. =// +//=======================================================================// +static void KeyPressEventProc(void); +static void RTCEventProc(void); +static void SysTickTimerEventProc(void); +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ +static bool CheckEventFlag(ENV_FLAG_INDEX eIndex); +#endif //_SIMPLE_GUI_IN_VIRTUAL_SDK_ + +//=======================================================================// +//= Function define. =// +//=======================================================================// + +/*****************************************************************************/ +/** Function Name: InitializeHMIEngineObj **/ +/** Purpose: Simple GUI HMI engine and interface demo process. **/ +/** Parameters: None. **/ +/** Return: HMI_ENGINE_RESULT. **/ +/** Notice: This function demonstrates how to use the interface and **/ +/** HMI engine of Simple GUI. **/ +/*****************************************************************************/ +HMI_ENGINE_RESULT InitializeHMIEngineObj(void) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + HMI_ENGINE_RESULT eProcessResult; + int iIndex; + + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + eProcessResult = HMI_RET_NORMAL; + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + /* Clear structure. */ + SGUI_SystemIF_MemorySet(&g_stDeviceInterface, 0x00, sizeof(SGUI_SCR_DEV)); + SGUI_SystemIF_MemorySet(&g_stDemoEngine, 0x00, sizeof(HMI_ENGINE_OBJECT)); +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + /* Initialize display size. */ + g_stDeviceInterface.stSize.iWidth = PARAM_DEFAULT_PIXEL_NUM_H; + g_stDeviceInterface.stSize.iHeight = PARAM_DEFAULT_PIXEL_NUM_V; + g_stDeviceInterface.uiDepthBits = PARAM_DEFAULT_PIXEL_DEPTH; + /* Initialize interface object. */ + g_stDeviceInterface.fnSetPixel = SGUI_SDK_SetPixel; + g_stDeviceInterface.fnGetPixel = SGUI_SDK_GetPixel; + g_stDeviceInterface.fnClear = SGUI_SDK_ClearDisplay; + g_stDeviceInterface.fnSyncBuffer = SGUI_SDK_RefreshDisplay; +#else + #error Add screen device object initialize process here. +#endif + do + { + /* Prepare HMI engine object. */ + g_stDemoEngine.ScreenCount = sizeof(g_arrpstScreenObjs)/sizeof(*g_arrpstScreenObjs); + g_stDemoEngine.ScreenObjPtr = g_arrpstScreenObjs; + g_stDemoEngine.Interface = &g_stDeviceInterface; + + /* Initialize all screen object. */ + if(NULL != g_stDemoEngine.ScreenObjPtr) + { + for(iIndex=0; iIndexpstActions) + && (NULL != g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize) + ) + { + g_stDemoEngine.ScreenObjPtr[iIndex]->pstActions->Initialize(&g_stDeviceInterface); + g_stDemoEngine.ScreenObjPtr[iIndex]->pstPrevious = NULL; + } + } + } + else + { + + } + /* Active engine object. */ + eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_LIST); + //eProcessResult = HMI_ActiveEngine(&g_stDemoEngine, HMI_SCREEN_ID_DEMO_ITEMS_BASE); + 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; +} + +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ +/*****************************************************************************/ +/** Function Name: CheckEventFlag **/ +/** Purpose: Check SimpleGUI virtual SDK event trigger flag and **/ +/** reset for next trigger and check. **/ +/** Parameters: **/ +/** @ eIndex[in]: Checked flag index. **/ +/** Return: true for event is trigger, false for not. **/ +/** Notice: This function only used in SimpleGUI virtual SDK **/ +/*****************************************************************************/ +bool CheckEventFlag(ENV_FLAG_INDEX eIndex) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + bool bReturn; + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + bReturn = SGUI_SDK_GetEventSyncFlag(eIndex); + + if(true == bReturn) + { + SGUI_SDK_SetEvnetSyncFlag(eIndex, false); + } + + return bReturn; +} +#endif // _SIMPLE_GUI_VIRTUAL_ENVIRONMENT_SIMULATOR_ + +/*****************************************************************************/ +/** Function Name: DemoMainProcess **/ +/** Purpose: It is a dummy main function for SimpleGUI Virtual SDK, **/ +/** or run demo process in demo process. **/ +/** Parameters: None. **/ +/** Return: Terminal code, seam as main function return code. **/ +/** Notice: None. **/ +/*****************************************************************************/ +void DemoMainProcess(void) +{ + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + // Initialize HMI Engine. + InitializeHMIEngineObj(); + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + while(1) + { + // Check and process heart-beat timer event. + if(true == SysTickTimerTriggered()) + { + SysTickTimerEventProc(); + } + // Check and process key press event. + if(true == UserEventTriggered()) + { + KeyPressEventProc(); + } + // Check and process RTC event. + if(true == RTCTimerTriggered()) + { + RTCEventProc(); + } + } +} + +/*****************************************************************************/ +/** Function Name: KeyPressEventProc **/ +/** Purpose: Deal with user key process in demo process. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: The button is just abstract, and the message may come **/ +/** from a touch screen, a serial port, and so on. **/ +/*****************************************************************************/ +void KeyPressEventProc(void) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + KEY_PRESS_EVENT stEvent; + + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + HMI_EVENT_INIT(stEvent); + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + stEvent.Head.iType = EVENT_TYPE_ACTION; + stEvent.Head.iID = EVENT_ID_KEY_PRESS; +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + stEvent.Data.uiKeyValue = SGUI_SDK_GetKeyEventData(); +#else + #error Add key event data prepare process here. +#endif + // Post key press event. + HMI_ProcessEvent((HMI_EVENT_BASE*)(&stEvent)); +} + +/*****************************************************************************/ +/** Function Name: SysTickTimerEventProc **/ +/** Purpose: Deal with heartbeat timer event in demo process. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: It is usually used to simulate ADC or other sensors. **/ +/*****************************************************************************/ +void SysTickTimerEventProc(void) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + DATA_EVENT stEvent; + + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + HMI_EVENT_INIT(stEvent); + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + stEvent.Head.iType = EVENT_TYPE_DATA; + stEvent.Head.iID = EVENT_ID_TIMER; + stEvent.Data.iValue = (rand() % 200)-100; + // Post timer event. + HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); +} + +/*****************************************************************************/ +/** Function Name: RTCEventProc **/ +/** Purpose: Deal with RTC timer event in demo process. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: It is usually used to simulate ADC or other sensors. **/ +/*****************************************************************************/ +void RTCEventProc(void) +{ + /*----------------------------------*/ + /* Variable Declaration */ + /*----------------------------------*/ + HMI_GENERAL_EVENT stEvent; + + /*----------------------------------*/ + /* Initialize */ + /*----------------------------------*/ + HMI_EVENT_INIT(stEvent); + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ + stEvent.Head.iType = EVENT_TYPE_DATA; + stEvent.Head.iID = EVENT_ID_RTC; + // Post RTC update message to a screen. + HMI_ProcessEvent((HMI_EVENT_BASE*)&stEvent); +} + +/*****************************************************************************/ +/** Function Name: SysTickTimerTriggered **/ +/** Purpose: Check sys-tick timer interrupt is triggered. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: None. **/ +/*****************************************************************************/ +bool SysTickTimerTriggered(void) +{ + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + return CheckEventFlag(ENV_FLAG_IDX_SDK_TIM_EVENT); +#else + #error Add sys-tick timer trigger process here. +#endif +} + +/*****************************************************************************/ +/** Function Name: RTCTimerTriggered **/ +/** Purpose: Check RTC timer interrupt is triggered. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: None. **/ +/*****************************************************************************/ +bool RTCTimerTriggered(void) +{ + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + return CheckEventFlag(ENV_FLAG_IDX_SDK_RTC_EVENT); +#else + #error Add RTC timer trigger process here. +#endif +} + +/*****************************************************************************/ +/** Function Name: UserEventTriggered **/ +/** Purpose: Check user event is triggered. **/ +/** Parameters: None. **/ +/** Return: None. **/ +/** Notice: None. **/ +/*****************************************************************************/ +bool UserEventTriggered(void) +{ + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + return CheckEventFlag(ENV_FLAG_IDX_SDK_KEY_EVENT); +#else + #error Add user event trigger process here. +#endif +} + +/*****************************************************************************/ +/** Function Name: SysTickTimerEnable **/ +/** Purpose: Enable or disable sys-tick timer. **/ +/** Parameters: **/ +/** @ bEnable[in]: True for enable sys-tick timer, false for disable. **/ +/** Return: None. **/ +/** Notice: None. **/ +/*****************************************************************************/ +void SysTickTimerEnable(bool bEnable) +{ + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + (void)SGUI_SDK_ConfigHearBeatTimer(bEnable?DEMO_HEART_BEAT_INTERVAL_MS:0); +#else + #error Add sys-tick timer enable/disable process here. +#endif +} + +/*****************************************************************************/ +/** Function Name: RTCTimerEnable **/ +/** Purpose: Enable or disable RTC timer. **/ +/** Parameters: **/ +/** @ bEnable[in]: True for enable RTC timer, false for disable. **/ +/** Return: None. **/ +/** Notice: None. **/ +/*****************************************************************************/ +void RTCTimerEnable(bool bEnable) +{ + + /*----------------------------------*/ + /* Process */ + /*----------------------------------*/ +#ifdef _SIMPLE_GUI_IN_VIRTUAL_SDK_ + (void)SGUI_SDK_EnableRTCInterrupt(bEnable); +#else + #error Add RTC timer enable/disable process here. +#endif +} + diff --git a/GUI/inc/SGUI_Typedef.h b/GUI/inc/SGUI_Typedef.h index d06b377..5afaa01 100644 --- a/GUI/inc/SGUI_Typedef.h +++ b/GUI/inc/SGUI_Typedef.h @@ -61,6 +61,15 @@ typedef SGUI_UINT32 SGUI_ROM_ADDRESS; #define SGUI_FALSE (0) #define SGUI_TRUE (!SGUI_FALSE) +#define SGUI_COLOR_TRANS (-1) +/****** + * Deprecated! + * Prepared to delete this guy! + * DO NOT USE THIS MACRO ANY MORE! + */ +#define SGUI_COLOR_FRGCLR (0x0A) +#define SGUI_COLOR_BKGCLR (0) + typedef struct { SGUI_INT iX; @@ -87,12 +96,7 @@ typedef struct SGUI_INT iMax; }SGUI_RANGE; -typedef enum -{ - SGUI_COLOR_BKGCLR = 0, - SGUI_COLOR_FRGCLR = 1, - SGUI_COLOR_TRANS = 2, -}SGUI_COLOR; +typedef SGUI_INT16 SGUI_COLOR ; typedef enum { @@ -127,6 +131,8 @@ typedef struct { //Screen display area size in pixel. SGUI_AREA_SIZE stSize; + // Screen display pixel depth in bit count(eg. 4(bits) means 16 grayscale) + SGUI_UINT8 uiDepthBits; //Bitmap data buffer. SGUI_BYTE arrBmpDataBuffer[SGUI_BMP_DATA_BUFFER_SIZE]; //Engine & device initialize function. diff --git a/GUI/src/SGUI_Basic.c b/GUI/src/SGUI_Basic.c index 9bd2d59..1ed8837 100644 --- a/GUI/src/SGUI_Basic.c +++ b/GUI/src/SGUI_Basic.c @@ -41,13 +41,9 @@ void SGUI_Basic_DrawPoint(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiCoordinateX, SG { /* Action function is unspecified, no actions. */ } - else if(SGUI_COLOR_FRGCLR == eColor) + else { - pstDeviceIF->fnSetPixel(uiCoordinateX, uiCoordinateY, 1); - } - else if(SGUI_COLOR_BKGCLR == eColor) - { - pstDeviceIF->fnSetPixel(uiCoordinateX, uiCoordinateY, 0); + pstDeviceIF->fnSetPixel(uiCoordinateX,uiCoordinateY,eColor); } } } @@ -68,13 +64,11 @@ SGUI_COLOR SGUI_Basic_GetPoint(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiCoordinate /* Variable Declaration */ /*----------------------------------*/ SGUI_COLOR eColor; - SGUI_UINT uiPixValue; /*----------------------------------*/ /* Initialize */ /*----------------------------------*/ eColor = SGUI_COLOR_BKGCLR; - uiPixValue = 0; /*----------------------------------*/ /* Process */ @@ -87,16 +81,8 @@ SGUI_COLOR SGUI_Basic_GetPoint(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiCoordinate } else { - uiPixValue = pstDeviceIF->fnGetPixel(uiCoordinateX, uiCoordinateY); - if(0 == uiPixValue) - { - eColor = SGUI_COLOR_BKGCLR; - } - else - { - eColor = SGUI_COLOR_FRGCLR; - } - } + eColor = pstDeviceIF->fnGetPixel(uiCoordinateX, uiCoordinateY); + } } return eColor; @@ -440,15 +426,16 @@ void SGUI_Basic_DrawCircle(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiCx, SGUI_UINT // Fill the circle if((uiRadius > 1) && (eFillColor != SGUI_COLOR_TRANS) && (uiPosXOffset_Old != uiPosXOffset)) { - SGUI_Basic_DrawLine(pstDeviceIF, uiCx-uiPosXOffset, uiCy-uiYOffset+1, uiCx-uiPosXOffset, uiCy+uiYOffset-1, eFillColor); SGUI_Basic_DrawLine(pstDeviceIF, uiCx+uiPosXOffset, uiCy-uiYOffset+1, uiCx+uiPosXOffset, uiCy+uiYOffset-1, eFillColor); uiPosXOffset_Old = uiPosXOffset; } - SGUI_Basic_DrawLine(pstDeviceIF, uiCx-uiYOffset, uiCy-uiPosXOffset+1, uiCx-uiYOffset, uiCy+uiPosXOffset-1, eFillColor); - SGUI_Basic_DrawLine(pstDeviceIF, uiCx+uiYOffset, uiCy-uiPosXOffset+1, uiCx+uiYOffset, uiCy+uiPosXOffset-1, eFillColor); - uiYOffset_Old = uiYOffset; - + if ((uiRadius > 1) && (eFillColor != SGUI_COLOR_TRANS) && (uiYOffset_Old != uiYOffset)) + { + SGUI_Basic_DrawLine(pstDeviceIF, uiCx-uiYOffset, uiCy-uiPosXOffset+1, uiCx-uiYOffset, uiCy+uiPosXOffset-1, eFillColor); + SGUI_Basic_DrawLine(pstDeviceIF, uiCx+uiYOffset, uiCy-uiPosXOffset+1, uiCx+uiYOffset, uiCy+uiPosXOffset-1, eFillColor); + uiYOffset_Old = uiYOffset; + } // Draw edge. SGUI_Basic_DrawPoint(pstDeviceIF, uiCx+uiPosXOffset, uiCy+uiYOffset, eEdgeColor); SGUI_Basic_DrawPoint(pstDeviceIF, uiCx-uiPosXOffset, uiCy+uiYOffset, eEdgeColor); @@ -490,6 +477,8 @@ void SGUI_Basic_ReverseBlockColor(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiStartX, /* Variable Declaration */ /*----------------------------------*/ SGUI_UINT i_W, i_H; + SGUI_COLOR clsOriginColor; + SGUI_UINT16 uiDepthTotal=1<uiDepthBits; /*----------------------------------*/ /* Process */ @@ -498,14 +487,8 @@ void SGUI_Basic_ReverseBlockColor(SGUI_SCR_DEV* pstDeviceIF, SGUI_UINT uiStartX, { for(i_H=0; i_H![SimpleGUI在SSD1306主控制器的OLED显示屏上的显示效果](https://images.gitee.com/uploads/images/2018/0725/220230_cfc1d5f8_769424.jpeg "SimpleGUI_1.jpg") diff --git a/VirtualSDK/Common/inc/Common.h b/VirtualSDK/Common/inc/Common.h index ad9f2b2..67c0218 100644 --- a/VirtualSDK/Common/inc/Common.h +++ b/VirtualSDK/Common/inc/Common.h @@ -28,12 +28,20 @@ #define LCD_COLOR_OBJ_PIX (0xFF258562) #define LCD_COLOR_OBJ_BKG (0xFF2BEEDE) #define LCD_COLOR_OBJ_GRID (0xFF38E3D0) +// White LCD +/* +#define LCD_COLOR_OBJ_PIX (0xFFFFFFFF) +#define LCD_COLOR_OBJ_BKG (0x00000000) +#define LCD_COLOR_OBJ_GRID (0xFFCC1209) +*/ #define PARAM_DEFAULT_PIXEL_NUM_H (128) #define PARAM_DEFAULT_PIXEL_NUM_V (64) #define PARAM_DEFAULT_PANEL_BORDER_WIDTH (8) #define PARAM_DEFAULT_PIXEL_WIDTH (3) #define PARAM_DEFAULT_PIXEL_HEIGHT (3) +#define PARAM_DEFAULT_PIXEL_DEPTH_BITS (4) +#define PARAM_DEFAULT_PIXEL_DEPTH (1<PanelColor = LCD_COLOR_OBJ_BKG; pstParameter->PixelColor = LCD_COLOR_OBJ_PIX; pstParameter->GridColor = LCD_COLOR_OBJ_GRID; + pstParameter->PixelUnitDepth = PARAM_DEFAULT_PIXEL_DEPTH; } } diff --git a/VirtualSDK/Controls/inc/wxLCD.h b/VirtualSDK/Controls/inc/wxLCD.h index 86e029d..e30b596 100644 --- a/VirtualSDK/Controls/inc/wxLCD.h +++ b/VirtualSDK/Controls/inc/wxLCD.h @@ -17,6 +17,8 @@ class wxLCD: public wxLCDBase private: wxColour m_clsPixelHColour; wxColour m_clsPixelLColour; + wxColour* m_clsPixelPalette; + int m_iPixelDepth; protected: @@ -29,6 +31,7 @@ class wxLCD: public wxLCDBase void CleanScreen(void); void SetPanelColour(const wxColour& clsPanelColour, bool bRefreshNow = true); void SetPixelColour(const wxColour& clsPixelColour, bool bRefreshNow = true); + void SetPixelDepth(const int depth); // Prepare to remove. void SetParameter(PixelPanelParameter* pstPanelParameter); diff --git a/VirtualSDK/Controls/src/wxLCD.cpp b/VirtualSDK/Controls/src/wxLCD.cpp index 8343e9f..fe08fd2 100644 --- a/VirtualSDK/Controls/src/wxLCD.cpp +++ b/VirtualSDK/Controls/src/wxLCD.cpp @@ -8,7 +8,8 @@ //= Include files. =// //=======================================================================// #include "wxLCD.h" - +#include "SGUI_Typedef.h" +#include //=======================================================================// //= Function define. =// //=======================================================================// @@ -17,6 +18,7 @@ wxLCDBase(pclsParent, iWinID, clsPosition, clsSizeInPixel) { m_clsPixelLColour.Set(0x00000000); m_clsPixelHColour.Set(0x00000000); + m_clsPixelPalette=NULL; } wxLCD::~wxLCD(void) @@ -56,32 +58,111 @@ void wxLCD::SetPixelColour(const wxColour& clsPixelColour, bool bRefreshNow) } } +void wxLCD::SetPixelDepth(const int depth) +{ + this->m_iPixelDepth=depth; + if(this->m_clsPixelPalette != NULL) + { + free(m_clsPixelPalette); + m_clsPixelPalette=NULL; + } + // Generate a scaled Palette bettween the BackgroundColor and PixelColor + m_clsPixelPalette = new wxColor[depth]; + unsigned char ucRH=this->m_clsPixelHColour.Red(); + unsigned char ucGH=this->m_clsPixelHColour.Green(); + unsigned char ucBH=this->m_clsPixelHColour.Blue(); + + unsigned char ucRL=m_clsPixelLColour.Red(); + unsigned char ucGL=m_clsPixelLColour.Green(); + unsigned char ucBL=m_clsPixelLColour.Blue(); + + double dbRDiff=(ucRH-ucRL)*1.0/depth; + double dbGDiff=(ucGH-ucGL)*1.0/depth; + double dbBDiff=(ucBH-ucBL)*1.0/depth; + + double dbR=(int)ucRL*1.0; + double dbG=(int)ucGL*1.0; + double dbB=(int)ucBL*1.0; + + for(int i=0; i=clsTargetColor.Red() && clsTargetColor.Red()>clsMidColor.Red())) + { + iRight=iMid-1; + continue; + } + else if((clsRightColor.Red()>=clsTargetColor.Red() && clsTargetColor.Red()>clsMidColor.Red())|| + (clsRightColor.Red()<=clsTargetColor.Red() && clsTargetColor.Red()=clsTargetColor.Green() && clsTargetColor.Green()>clsMidColor.Green())) + { + iRight=iMid-1; + continue; + } + else if((clsRightColor.Green()>=clsTargetColor.Green() && clsTargetColor.Green()>clsMidColor.Green())|| + (clsRightColor.Green()<=clsTargetColor.Green() && clsTargetColor.Green()=clsTargetColor.Blue() && clsTargetColor.Blue()>clsMidColor.Blue())) + { + iRight=iMid-1; + continue; + } + else if((clsRightColor.Blue()>=clsTargetColor.Blue() && clsTargetColor.Blue()>clsMidColor.Blue())|| + (clsRightColor.Blue()<=clsTargetColor.Blue() && clsTargetColor.Blue()PixelColor), false); SetPanelColour(wxColor(pstPanelParameter->PanelColor), false); SetGridColor(wxColor(pstPanelParameter->GridColor)); + SetPixelDepth(pstPanelParameter->PixelUnitDepth); Layout(); } diff --git a/VirtualSDK/Project/CodeBlocks/VirtualSDK_wx31.cbp b/VirtualSDK/Project/CodeBlocks/VirtualSDK_wx31.cbp index 1f0cb4f..dfea864 100644 --- a/VirtualSDK/Project/CodeBlocks/VirtualSDK_wx31.cbp +++ b/VirtualSDK/Project/CodeBlocks/VirtualSDK_wx31.cbp @@ -100,6 +100,9 @@ + +