Ucgui Interface Design & amp; entity key driver, ucgui

Source: Internet
Author: User

Ucgui Interface Design & entity key driver, ucgui

Ucgui Interface Design & entity key driver


For more information, see http://blog.csdn.net/jdh99, :jdh.


Environment:

HOST: WIN8

Development Environment: MDK4.72

Ucgui version: 3.90

Mcu: stm32f103VE


Note:

This program designs an interface based on the ucgui dialog box mechanism and controls the interface with six solid buttons.


:


Source code:

Gui_main.h

/*************************************** * ****************************** Header file of the main interface module * (c) copyright 2014, jdh * All Right Reserved * Creation Time: by jdh ************************************* * *******************************/# ifndef _ GUI_MAIN_H _# define _ GUI_MAIN_H _/*********************************** * *********************************** header file **** **************************************** * *************************/# include "world. h "/************************************* ****** **************************************** ************************//************** **************************************** * ***************** work interval * Unit: ms *************************************** * *****************************/# define INTERVAL_GUI_MAIN100 /**** **************************************** ************* **************************************** *****************//********************* **************************************** ***************************** **************************************** */void gui_main_load (void ); /*************************************** ******* **************************************** * *********************/void gui_main_run (void ); /*************************************** * ****************************** set the display status * parameter: enable: 0: Disable display, 1: open the display ************************************** * *****************************/void gui_main_show (uint8_t enable ); /*************************************** * ****************************** get the current display status * return: 0: Disable display. 1: open the display ************************************** * *****************************/uint8_t gui_main_get_show (void ); # endif

Gui_main.c

/*************************************** * ******************************* Main file of the main interface module * (c) copyright 2014, jdh * All Right Reserved * Creation Time: by jdh ************************************* *********************************//***** **************************************** * ************************ header file ************** **************************************** * **************/# include "gui_main.h "/***************** **************************************** ************************** **************************************** * ***/# define ID_FRAMEWIN (GUI_ID_USER + 0x10) # define ID_BUTTON_ OK (rows + 0x11) # define aggregate (GUI_ID_USER + 0x12) # define ID_BUTTON_UP (rows + 0x13) # define ID_BUTTON_DOWN (GUI_ID_USER + 0x14) # define ID_BUTTON_LEFT (rows + 0x15) # define ID_BUTTON_RIGHT (rows + 0x16) # define ID_TEXT_MATCH (rows + 0x17) # define id_text_arg (GUI_ID_USER + 0x18) # define ID_LISTBOX_FUNC (GUI_ID_USER + 0x19) /*************************************** ******* **************************************** ***********************//*************** **************************************** *********************** **************************************** * *****/struct _ Key_State {uint8_t OK; uint8_t cancel; uint8_t up; uint8_t down; uint8_t left; uint8_t right ;}; /*************************************** * ****************************** static variables ******* **************************************** ***********************//*************** **************************************** *********************** **************************************** * *****/static WM_HWIN Handle_Gui; /*************************************** * ****************************** resource table ******* **************************************** * ********************/static const GUI_WIDGET_CREATE_INFO _ aDialogCreate [] = {FRAMEWIN_CreateIndirect, "Frame3", ID_FRAMEWIN, 0, 0,240,320, 0, 0x0}, {BUTTON_CreateIndirect, "OK", ID_BUTTON_ OK, 5,255, 40, 20, 0, 0x0 }, {BUTTON_CreateIndirect, "Button", ID_BUTTON_DOWN, 95,280, 40, 20, 0, 0x0}, {BUTTON_CreateIndirect, "UP", ID_BUTTON_UP, 95,255, 40, 20, 0, 0x0 },{ BUTTON_CreateIndirect, "CANCEL", ID_BUTTON_CANCEL, 185,255, 40, 20, 0, 0x0 },{ BUTTON_CreateIndirect, "RIGHT", ID_BUTTON_RIGHT, 140,270, 40, 20, 0, 0x0}, {BUTTON_CreateIndirect, "LEFT", ID_BUTTON_LEFT, 50,270, 40, 20, 0, 0x0}, {TEXT_CreateIndirect, "Match", ID_TEXT_MATCH, 140, 15, 80, 20, 0, 0x0}, {TEXT_CreateIndirect, "reported", id_text_reported, 140, 40, 80, 20, 0, 0x0 }, {LISTBOX_CreateIndirect, "Listbox", ID_LISTBOX_FUNC, 5, 10,120,220, 0, 0x0}, // user start (Optionally insert additional widgets) // user end }; /*************************************** ****** **************************************** * *********************/static struct _ Time Time_Last = {. s = 0 ,. ms = 0 ,. us = 0 }; /*************************************** ******* **************************************** * ********************/static struct _ Key_State = {. OK = 0 ,. cancel = 0 ,. up = 0 ,. down = 0 ,. left = 0 ,. right = 0 }; /*************************************** * ******************************* the current display status ** 0: not displayed, 1 ************************************** * *****************************/static uint8_t State_Show = 1; /*************************************** ******* **************************************** ***********************//*************** **************************************** *********************** **************************************** * *****/static void _ cbDialog (WM_MESSAGE * pMsg ); /*************************************** * ****************************** scheduled work ******* **************************************** * *********************/static void slot_tick (void ); /*************************************** ******* **************************************** * *********************/static void deal_key (void ); /*************************************** ******** **************************************** **********************//**************** **************************************** ************************ **************************************** * *****/void gui_main_load (void) {// Handle_Gui = GUI_CreateDialogBox (_ aDialogCreate, GUI_COUNTOF (_ aDialogCreate), _ cbDialog, WM_HBKWIN, 0, 0 );} /*************************************** ******* **************************************** * *********************/void gui_main_run (void) {struct _ Time time; // determine whether the current display is if (State_Show = 0) {return;} // get the current time get_time (& Time ); // determine whether the work time is reached if (sub_time (time, Time_Last)> = INTERVAL_GUI_MAIN * 1000) {// Update time Time_Last = time; // timed work slot_tick ();}} /*************************************** * ****************************** set the display status * parameter: enable: 0: Disable display, 1: open the display ************************************** * *****************************/void gui_main_show (uint8_t enable) {State_Show = enable; if (enable) {WM_ShowWindow (Handle_Gui);} else {WM_HideWindow (Handle_Gui );}} /*************************************** * ****************************** get the current display status * return: 0: Disable display. 1: open the display ************************************** * *****************************/uint8_t gui_main_get_show (void) {return State_Show ;} /*************************************** * ****************************** scheduled work ******* **************************************** * *********************/static void slot_tick (void) {// press the key to process deal_key ();} /*************************************** ******* **************************************** * *********************/static void deal_key (void) {WM_HWIN hItem; // key scan // inf_key_scan (); // determines whether the key is pressed if (inf_key_detect_hold (KEY_CANCEL) {if (Key_State.cancel = 0) {Key_State.cancel = 1; // press hItem = WM_GetDialogItem (Handle_Gui, ID_BUTTON_CANCEL); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS | BUTTON_STATE_PRESSED); // shutdown inf_power_set (OFF );}} else {if (Key_State.cancel = 1) {Key_State.cancel = 0; // The initialization key hItem = keys (Handle_Gui, ID_BUTTON_CANCEL); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS ); // enable inf_power_set (ON) ;}// determine whether to press the next key if (inf_key_detect_hold (KEY_DOWN) {if (Key_State.down = 0) {Key_State.down = 1; // initialize the key hItem = handler (Handle_Gui, ID_BUTTON_DOWN); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS | priority); // send the key signal wm_policyparent (hItem, wm_icationication_clicked );}} else {if (Key_State.down = 1) {Key_State.down = 0; // The initialization key hItem = keys (Handle_Gui, ID_BUTTON_DOWN); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS );}} // determine whether the upper key is pressed if (then (KEY_UP) {if (Key_State.up = 0) {Key_State.up = 1; // The initialization key hItem = WM_GetDialogItem (Handle_Gui, ID_BUTTON_UP ); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS | fail); // send the key signal wm_policyparent (hItem, WM_NOTIFICATION_CLICKED);} else {if (Key_State.up = 1) {Key_State.up = 0; // initialize hItem = WM_GetDialogItem (Handle_Gui, ID_BUTTON_UP); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS) ;}// judge whether the test key is pressed if (KEY_ OK )) {if (Key_State. OK = 0) {Key_State. OK = 1; // The initialization key hItem = handler (Handle_Gui, ID_BUTTON_ OK); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS | BUTTON_STATE_PRESSED ); // send the key signal wm_policyparent (hItem, WM_NOTIFICATION_CLICKED);} else {if (Key_State. OK = 1) {Key_State. OK = 0; // initialize the key hItem = wm_getalodigitem (Handle_Gui, ID_BUTTON_ OK); BUTTON_SetState (hItem, BUTTON_STATE_HASFOCUS );}}} /*************************************** * ****************************** callback function ******* **************************************** * *********************/static void _ cbDialog (WM_MESSAGE * pMsg) {WM_HWIN hItem; int NCode; int Id; // user start (Optionally insert additional variables) // USER ENDchar str [20] = {0}; switch (pMsg-> MsgId) {case when: {// initialize the form // Add a small key FRAMEWIN_AddCloseButton (pMsg-> hWin, FRAMEWIN_BUTTON_RIGHT, 0); FRAMEWIN_AddMaxButton (pMsg-> hWin, FRAMEWIN_BUTTON_RIGHT, 1 ); FRAMEWIN_AddMinButton (pMsg-> hWin, FRAMEWIN_BUTTON_RIGHT, 2); FRAMEWIN_SetFont (pMsg-> hWin, & GUI_FontHZ12); sprintf (str, "feet Testing System Ver % d by jdh ", VERSION_SOFT); FRAMEWIN_SetText (pMsg-> hWin, str); // initialization list box hItem = WM_GetDialogItem (pMsg-> hWin, ID_LISTBOX_FUNC); // set the focus to WM_SetFocus (hItem ); // set the content LISTBOX_SetFont (hItem, & GUI_FontHZ12); LISTBOX_AddString (hItem, "bind Code"); LISTBOX_AddString (hItem, "Select Frequency"); LISTBOX_AddString (hItem, "Call test"); LISTBOX_AddString (hItem, "GPRS test"); LISTBOX_AddString (hItem, "GPS test"); LISTBOX_AddString (hItem, "125K test"); SCROLLBAR_CreateAttached (hItem, optional); // The initialization key hItem = WM_GetDialogItem (pMsg-> hWin, ID_BUTTON_ OK); BUTTON_SetFont (hItem, & GUI_FontHZ12); BUTTON_SetText (hItem, "test "); hItem = WM_GetDialogItem (pMsg-> hWin, response); BUTTON_SetFont (hItem, & response); BUTTON_SetText (hItem, "shutdown"); hItem = WM_GetDialogItem (pMsg-> hWin, ID_BUTTON_UP); BUTTON_SetFont (hItem, & response); BUTTON_SetText (hItem, "upper"); hItem = encrypt (pMsg-> hWin, ID_BUTTON_DOWN); BUTTON_SetFont (hItem, & response ); BUTTON_SetText (hItem, ""); hItem = WM_GetDialogItem (pMsg-> hWin, ID_BUTTON_LEFT); BUTTON_SetFont (hItem, & signature); BUTTON_SetText (hItem ,""); hItem = WM_GetDialogItem (pMsg-> hWin, ID_BUTTON_RIGHT); BUTTON_SetFont (hItem, & GUI_FontHZ12); BUTTON_SetText (hItem ,""); // initialize the text hItem = WM_GetDialogItem (pMsg-> hWin, ID_TEXT_MATCH); TEXT_SetFont (hItem, & GUI_FontHZ12); TEXT_SetText (hItem, "not bound to the footer "); hItem = WM_GetDialogItem (pMsg-> hWin, id_text_arg); TEXT_SetFont (hItem, & GUI_FontHZ12); TEXT_SetText (hItem, ""); break;} case wm_policy_parent: {Id = WM_GetId (pMsg-> hWinSrc); NCode = pMsg-> Data. v; switch (Id) {case ID_BUTTON_ OK: {switch (NCode) {case wm_icationication_clicked: {// obtain the number of current lists hItem = WM_GetDialogItem (pMsg-> hWin, ID_LISTBOX_FUNC ); int a = LISTBOX_GetSel (hItem); sprintf (str, "% d", a); hItem = WM_GetDialogItem (pMsg-> hWin, id_text_arg); TEXT_SetText (hItem, str ); hItem = WM_GetDialogItem (pMsg-> hWin, success); LISTBOX_GetItemText (hItem, a, str, 20); hItem = Success (pMsg-> hWin, ID_TEXT_MATCH); TEXT_SetText (hItem, str); break;} case when: {break;} case ID_BUTTON_DOWN: {switch (NCode) {case wm_icationication_clicked: {// send the key signal GUI_SendKeyMsg (GUI_KEY_DOWN, 1); break;} case when: {break;} case ID_BUTTON_UP: {switch (NCode) {case wm_icationication_clicked: {// send the key signal GUI_SendKeyMsg (GUI_KEY_UP, 1); break;} case WM_NOTIFICATION_RELEASED: {break;} case ID_BUTTON_CANCEL: {switch (NCode) {case WM_NOTIFICATION_CLICKED: {break;} case WM_NOTIFICATION_RELEASED: {break ;}} break;} case ID_BUTTON_RIGHT: {switch (NCode) {case WM_NOTIFICATION_CLICKED: {break;} case wm_icationication_released: {break ;}} break;} case ID_BUTTON_LEFT: {switch (NCode) {case WM_NOTIFICATION_CLICKED: {break;} case when: {break;} case ID_LISTBOX_FUNC: {switch (NCode) {case WM_NOTIFICATION_CLICKED: {break ;} case wm_icationication_released: {break ;}} break;} default: {WM_DefaultProc (pMsg); break ;}}}


Why do I choose not to use ucgui?

1) the interface of the objects to be processed should be complex, and there are a lot of data processing. ucgui cannot do this well (for example, the memory requirements for dozens of interfaces containing images) it is not conducive to development. In addition, there are still fewer built-in ucgui libraries.
2) I think the single-chip microcomputer interface will gradually exit the market, because the cost of arm + linux is getting lower and lower, such as mobile phones and pad, which are powerful and easy to use, and can completely kill the stm32 Single-Chip Microcomputer Interface in seconds.
3) The ucgui screen is too small, because its mainstream application platforms are 3-4 inch screens, and complicated products are not enough. Otherwise, screen refreshing is too slow.

Look for someone to design the ucgui

Contact info
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.