Alan Chang Posted August 15, 2017 Report Share Posted August 15, 2017 Hi everyone, I use uGFX with FreeRTOS on STM32F407. I tried to use the key of the board to control the Textedit visual. But when I press the key, the screen was became white. Here is the gui.c file. static void createPagePage0(void) { GWidgetInit wi; gwinWidgetClearInit(&wi); // create container widget: ghContainerPage0 wi.g.show = FALSE; wi.g.x = 0; wi.g.y = 0; wi.g.width = 240; wi.g.height = 320; wi.g.parent = 0; wi.text = "Container"; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; ghContainerPage0 = gwinContainerCreate(0, &wi, 0); // Create textedit widget: ghTextedit1 wi.g.show = FALSE; wi.g.x = 10; wi.g.y = 70; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage0; wi.text = "First Name"; wi.customDraw = gwinTexteditDefaultDraw; wi.customParam = 0; wi.customStyle = 0; ghTextedit1 = gwinTexteditCreate(0, &wi, 0); // Create textedit widget: ghTextedit2 wi.g.show = TRUE; wi.g.x = 10; wi.g.y = 10; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage0; wi.text = "User Name"; wi.customDraw = gwinTexteditDefaultDraw; wi.customParam = 0; wi.customStyle = 0; ghTextedit2 = gwinTexteditCreate(0, &wi, 0); // create button widget: ghButton1 wi.g.show = TRUE; wi.g.x = 50; wi.g.y = 280; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage0; wi.text = "Change Page"; wi.customDraw = gwinButtonDraw_Normal; wi.customParam = 0; wi.customStyle = 0; ghButton1 = gwinButtonCreate(0, &wi); } static void createPagePage1(void) { GWidgetInit wi; gwinWidgetClearInit(&wi); // create container widget: ghContainerPage1 wi.g.show = FALSE; wi.g.x = 0; wi.g.y = 0; wi.g.width = 240; wi.g.height = 320; wi.g.parent = 0; wi.text = "Container"; wi.customDraw = 0; wi.customParam = 0; wi.customStyle = 0; ghContainerPage1 = gwinContainerCreate(0, &wi, 0); // create container widget: ghContainer1 wi.g.show = TRUE; wi.g.x = 30; wi.g.y = 170; wi.g.width = 200; wi.g.height = 110; wi.g.parent = ghContainerPage1; wi.text = "Container1"; wi.customDraw = gwinContainerDraw_Std; wi.customParam = 0; wi.customStyle = 0; ghContainer1 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); // create radiobutton widget: ghRadiobutton3 wi.g.show = TRUE; wi.g.x = 80; wi.g.y = 70; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainer1; wi.text = "white"; wi.customDraw = gwinRadioDraw_Radio; wi.customParam = 0; wi.customStyle = 0; ghRadiobutton3 = gwinRadioCreate(0, &wi, 0); gwinSetColor(ghRadiobutton3, black_studio); gwinSetBgColor(ghRadiobutton3, white_studio); // create radiobutton widget: ghRadiobutton2 wi.g.show = TRUE; wi.g.x = 80; wi.g.y = 40; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainer1; wi.text = "Black"; wi.customDraw = gwinRadioDraw_Radio; wi.customParam = 0; wi.customStyle = 0; ghRadiobutton2 = gwinRadioCreate(0, &wi, 0); gwinSetColor(ghRadiobutton2, black_studio); gwinSetBgColor(ghRadiobutton2, white_studio); // create radiobutton widget: ghRadiobutton1 wi.g.show = TRUE; wi.g.x = 80; wi.g.y = 10; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainer1; wi.text = "Custom"; wi.customDraw = gwinRadioDraw_Radio; wi.customParam = 0; wi.customStyle = 0; ghRadiobutton1 = gwinRadioCreate(0, &wi, 0); gwinSetColor(ghRadiobutton1, black_studio); gwinSetBgColor(ghRadiobutton1, white_studio); gwinRadioPress(ghRadiobutton1); // create checkbox widget: ghCheckbox1 wi.g.show = TRUE; wi.g.x = 50; wi.g.y = 10; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage1; wi.text = "Checkbox1"; wi.customDraw = gwinCheckboxDraw_CheckOnLeft; wi.customParam = 0; wi.customStyle = 0; ghCheckbox1 = gwinCheckboxCreate(0, &wi); gwinCheckboxCheck(ghCheckbox1, FALSE); // create checkbox widget: ghCheckbox2 wi.g.show = TRUE; wi.g.x = 50; wi.g.y = 30; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage1; wi.text = "Checkbox2"; wi.customDraw = gwinCheckboxDraw_CheckOnLeft; wi.customParam = 0; wi.customStyle = 0; ghCheckbox2 = gwinCheckboxCreate(0, &wi); gwinCheckboxCheck(ghCheckbox2, FALSE); // create button widget: ghButton2 wi.g.show = TRUE; wi.g.x = 50; wi.g.y = 290; wi.g.width = 120; wi.g.height = 20; wi.g.parent = ghContainerPage1; wi.text = "Change Page"; wi.customDraw = gwinButtonDraw_Normal; wi.customParam = 0; wi.customStyle = 0; ghButton2 = gwinButtonCreate(0, &wi); // Create label widget: ghLabel1 wi.g.show = TRUE; wi.g.x = 30; wi.g.y = 140; wi.g.width = 173; wi.g.height = 24; wi.g.parent = ghContainerPage1; wi.text = "Select a Widget Style"; wi.customDraw = gwinLabelDrawJustifiedLeft; wi.customParam = 0; wi.customStyle = 0; ghLabel1 = gwinLabelCreate(0, &wi); gwinLabelSetBorder(ghLabel1, FALSE); } void guiShowPage(unsigned pageIndex) { // Hide all pages gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); // Show page selected page switch (pageIndex) { case 0: gwinShow(ghContainerPage0); break; case 1: gwinShow(ghContainerPage1); break; default: break; } } void guiCreate(void) { GWidgetInit wi; // Prepare fonts dejavu_sans_16 = gdispOpenFont("DejaVuSans16"); // Prepare images // GWIN settings gwinWidgetClearInit(&wi); gwinSetDefaultFont(dejavu_sans_16); gwinSetDefaultStyle(&white, FALSE); gwinSetDefaultColor(black_studio); gwinSetDefaultBgColor(white_studio); // Create all the display pages createPagePage0(); createPagePage1(); // Select the default display page guiShowPage(0); } void guiEventLoop(void) { GEvent* pe; while (1) { gwinAttachToggle(ghButton1, 0, 0); // Get an event pe = geventEventWait(&glistener, 0); if(pe->type==GEVENT_GWIN_BUTTON){ printf("Button clicked\r\n"); //test gwinShow(ghTextedit1); } } } I attached the executive result. Hope can give some advice. Thank you guys. Link to comment Share on other sites More sharing options...
inmarket Posted August 15, 2017 Report Share Posted August 15, 2017 Problem 1: When you called geventEventWait you passed a timeout patameter of 0. This means it can return immediately with a timeout if there is no event waiting. This makes geventEventWait return NULL. You have not tested for NULL and could hard fault on the next line on some processors. Problem 2: calling geventEventWait with a 0 parameter is not good on many operating systems as it does not allow other threads to run - particularly on co-operative operating systems such as RAW32. While FreeRTOS is not one it is still bad practice. Problem 3: You are calling gwinAttachToggle inside the loop. This call only needs to be called once and should not be inside the loop. The solution to the first two problems is to either specify a (non-zero) timeout and test for NULL, or use TIME_INFINITE for the timeout value. When using TIME_INFINITE geventEventWait will never return NULL. Solve those problems first and test again. Link to comment Share on other sites More sharing options...
Alan Chang Posted August 16, 2017 Author Report Share Posted August 16, 2017 Hi, Thanks for the information. I modified the code for geventEventWait problem. I put non-zero like this. void guiEventLoop(void) { GEvent* pe; while (1) { // Get an event pe = geventEventWait(&glistener, 500 ); if(pe->type==GEVENT_GWIN_BUTTON){ printf("Button clicked\r\n"); //test gwinShow(ghTextedit1); } } Also I moved the gwinAttachToggle to other place. void guiCreate(void) { GWidgetInit wi; // Prepare fonts dejavu_sans_16 = gdispOpenFont("DejaVuSans16"); // Prepare images // GWIN settings gwinWidgetClearInit(&wi); gwinSetDefaultFont(dejavu_sans_16); gwinSetDefaultStyle(&white, FALSE); gwinSetDefaultColor(black_studio); gwinSetDefaultBgColor(white_studio); // Create all the display pages createPagePage0(); createPagePage1(); // Select the default display page guiShowPage(0); gwinAttachToggle(ghButton1, 0, 0); } After test, I still got same result which white screen happened same as before. Do I miss something? By the way, I check the puTTY. I saw it can show the "Button clicked" after press the button, so I think the printf in guiEventLoop executed well. Hope can give some advice. Thank you guys. Link to comment Share on other sites More sharing options...
inmarket Posted August 16, 2017 Report Share Posted August 16, 2017 You still haven't added the test for pe being NULL ie <code>if (pe && pe->type == GEVENT_GWIN_BUTTON)</code> What you have currently may be hard faulting because of the lack of the test for NULL. Link to comment Share on other sites More sharing options...
Alan Chang Posted August 23, 2017 Author Report Share Posted August 23, 2017 Hi, Thanks for help. I also check the low level driver of LCD, and fixed some issue. Now it can run well. Thanks. Link to comment Share on other sites More sharing options...
Joel Bodenmann Posted August 23, 2017 Report Share Posted August 23, 2017 Glad to hear that you managed to get everything running. Good work! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now