Alan Chang Posted August 23, 2017 Report Posted August 23, 2017 Hello, If I want to control the 2 GHandles by one key, what can I do? It is like to switch 2 pages, and there are ghButton1 and ghButton2 in the different page. I use gwinAttachToggle to assign ghButton1 and can change to page 2. Quote gwinAttachToggle(ghButton1, 0, 0); How can I assign ghButton2 and return back page 1? Quote switch (pe->type) { case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->gwin == ghButton1) { guiShowPage(1); } else if (((GEventGWinButton*)pe)->gwin == ghButton2) { guiShowPage(0); } break; } Please give some advice. Thanks.
Joel Bodenmann Posted August 23, 2017 Report Posted August 23, 2017 Hello Alan, Unfortunately, I don't really understand your question. The code you're showing is correct. That is the proper way of doing it. You can't do anything other than that - it's the intended way of handling this.
Alan Chang Posted August 24, 2017 Author Report Posted August 24, 2017 Hi Joel, Thanks for your reply. Maybe I did not describe my question well. Sorry about that. Now I am using STM32F429i-discovery board. There is only one USER button on this board. According to this code, I have 2 pages. void guiShowPage(unsigned pageIndex) { gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); switch (pageIndex) { case 0: gwinShow(ghContainerPage0); break; case 1: gwinShow(ghContainerPage1); break; default: break; } I want to switch these 2 pages when get ghButton1 or ghButton2 event. ghButton1 is in ghContainerPage0. ghButton2 is in ghContainerPage1. So when get ghButton1, change to ghContainerPage1. when get ghButton2, change back to ghContainerPage0. switch (pe->type) { case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->gwin == ghButton1) { guiShowPage(1); } else if (((GEventGWinButton*)pe)->gwin == ghButton2) { guiShowPage(0); } break; } However, I only have one button on my STM32F429i-discovery board. Can I use same button and attach to ghButton1 and ghButton2? I have tried this way, but it was wrong action. gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 0, 0); Then I change other way like this. gwinAttachToggle(ghButton1, 0, 0); gwinAttachToggle(ghButton2, 1, 0); But also wrong. My question is below. 1. I want to know how to set ghButton1 and ghButton2 in same toggle instance. Is that possible? 2. What is the "role" meaning in gwinAttachToggle()? Please give me some advice or other solution. Hope you can understand my question. Thanks, Joel.
Alan Chang Posted August 28, 2017 Author Report Posted August 28, 2017 Hello, Does someone help me? I really do not have idea. Thanks.
Joel Bodenmann Posted August 28, 2017 Report Posted August 28, 2017 Hello Alan, The solution to this is simple: Extend your guiShowPage() function to attach the physical button to the corresponding software button of each page (untested code!): void guiShowPage(unsigned pageIndex) { // Detach all toggles gwinDetachToggle(ghButton1, 0); gwinDetachToggle(ghButton2, 0); // Hide all containers gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); switch (pageIndex) { case 0: gwinShow(ghContainerPage0); gwinAttachToggle(ghButton1, 0, 0); break; case 1: gwinShow(ghContainerPage1); gwinAttachToggle(ghButton2, 0, 0); break; default: break; } } Note that you'll have to use the latest master branch state from the µGFX repository as the gwinDetachToggle() function is not part of the v2.7 release yet. I hope that helps.
Alan Chang Posted August 29, 2017 Author Report Posted August 29, 2017 Hi Joel, Thanks for your reply. I tried this code. void guiShowPage(unsigned pageIndex) { // Detach all toggles gwinDetachToggle(ghButton1, 0); gwinDetachToggle(ghButton2, 0); // Hide all pages gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); // Show page selected page switch (pageIndex) { case 0: gwinShow(ghContainerPage0); gwinAttachToggle(ghButton1, 0, 0); break; case 1: gwinShow(ghContainerPage1); gwinAttachToggle(ghButton2, 0, 0); break; default: break; } } void guiEventLoop(void) { while (1) { // Get an event pe = geventEventWait(&glistener, TIME_INFINITE ); switch (pe->type) { case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->gwin == ghButton1) { guiShowPage(1); } else if (((GEventGWinButton*)pe)->gwin == ghButton2) { guiShowPage(0); } break; } } } It is not work. But If I do not use "gwinDetachToggle", it can work. void guiShowPage(unsigned pageIndex) { // Detach all toggles //gwinDetachToggle(ghButton1, 0); //gwinDetachToggle(ghButton2, 0); // Hide all pages gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); // Show page selected page switch (pageIndex) { case 0: gwinShow(ghContainerPage0); gwinAttachToggle(ghButton1, 0, 0); break; case 1: gwinShow(ghContainerPage1); gwinAttachToggle(ghButton2, 0, 0); break; default: break; } } What is "gwinDetachToggle"? Thanks.
Joel Bodenmann Posted August 29, 2017 Report Posted August 29, 2017 What does "doesn't work" mean? Can you please be more specific.
Alan Chang Posted August 30, 2017 Author Report Posted August 30, 2017 Hi Joel, I tried this code first. void guiShowPage(unsigned pageIndex) { // Detach all toggles gwinDetachToggle(ghButton1, 0); gwinDetachToggle(ghButton2, 0); // Hide all pages gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); // Show page selected page switch (pageIndex) { case 0: gwinShow(ghContainerPage0); gwinAttachToggle(ghButton1, 0, 0); break; case 1: gwinShow(ghContainerPage1); gwinAttachToggle(ghButton2, 0, 0); break; default: break; } } void guiEventLoop(void) { while (1) { // Get an event pe = geventEventWait(&glistener, TIME_INFINITE ); switch (pe->type) { case GEVENT_GWIN_BUTTON: if (((GEventGWinButton*)pe)->gwin == ghButton1) { guiShowPage(1); } else if (((GEventGWinButton*)pe)->gwin == ghButton2) { guiShowPage(0); } break; } } } When press physical button, the page did not change. Same as before. Then I tried to remove the gwinDetachToggle, and run again. void guiShowPage(unsigned pageIndex) { // Hide all pages gwinHide(ghContainerPage0); gwinHide(ghContainerPage1); // Show page selected page switch (pageIndex) { case 0: gwinShow(ghContainerPage0); gwinAttachToggle(ghButton1, 0, 0); break; case 1: gwinShow(ghContainerPage1); gwinAttachToggle(ghButton2, 0, 0); break; default: break; } } It can work now. I can change page when press the physical button. Hope you can understand. I searched the gwinDetachToggle, but I still do not figure out this function. Thanks.
Joel Bodenmann Posted August 30, 2017 Report Posted August 30, 2017 In my post I wrote that the gwinDetachToggle() function is not in the current release. Please use the latest master branch of the µGFX repository: On 8/28/2017 at 10:20, Joel Bodenmann said: Note that you'll have to use the latest master branch state from the µGFX repository as the gwinDetachToggle() function is not part of the v2.7 release yet.
Alan Chang Posted September 4, 2017 Author Report Posted September 4, 2017 Hi Joel, I have check the file "changelog.txt". I can see "*** Changes after 2.7 ***". Does that mean that I use the latest version? Thanks.
Joel Bodenmann Posted September 4, 2017 Report Posted September 4, 2017 Hi Alan, No, that just means that you use some state of the library after the official 2.7 release. Please just do as I told you and grab the latest master branch from the git repository here: https://git.ugfx.io/uGFX/uGFX If you never worked with git or you don't want to get into it, you can always just download a ZIP archive of the latest state: https://git.ugfx.io/uGFX/uGFX/archive/master.zip
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