Menu implementation in ChibiOS. Need advice.

ChibiOS public support forum for all topics not covered by a specific support forum.

Moderators: RoccoMarco, lbednarz, tfAteba

Post Reply
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Menu implementation in ChibiOS. Need advice.

Post by Chudik »

My HW design has 4 lines display (actually it is graphical display, I just use it for text information yet) and three buttons. Interrupt handler from the buttons sends event signal - currently to the particular debug thread, will be changed, of course.
In FW there should be 2-4 levels menu system.
Here is the picture, how it is going to be
M3 menu structure.png
M3 menu structure.png (19.33 KiB) Viewed 4139 times

Actually the last menu picture should not have lines around the arrows, but for now it is not too important.

So, I need an advice how to make this part more correct.
First scenario:
  • Using one big enough static thread for all menus;
  • Use one ShowMenu() function for all menus by calling this function with appropriate menulists (used that structure in previous projects);
  • Items structures of the menus don't have callbacks;
  • All buttons event signals come to this thread and it processes info from buttons based on information which menu is active: changing active item in menulist, calling next menu, calling another function...

Second scenario:
  • Each menu uses its own thread. Only main screen uses static thread, all the others - dynamic threads. All threads become small chunks of the memory, but there might be 3-4 menu levels deep and in this case I might actually need to use more memory, than for one big thread.
  • Each thread uses its own menulist and use ShowMenu() function with menulist defined for each particular thread;
  • Each items structures of the menus have callbacks for corresponding functions;
  • All buttons event signals come to the active menu thread and only the active thread processes info from buttons based on callback defined for the chosen button: changing active item in menulist, calling next menu/thread, calling another function...

The first scenario seems easy for me, but the second one looks like more structured. Which one is more appropriate?
For the second scenario need to find solutions for three things that I don't know yet:
  1. How to create and close dynamic thread. Actually did not check it, I guess it should not be a problem
  2. How to know which menu thread is active, how to define to which menu thread the buttons events have to go.
  3. How to define the callback arguments. Could not find that information yet.
User avatar
Giovanni
Site Admin
Posts: 14895
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 997 times

Re: Menu implementation in ChibiOS. Need advice.

Post by Giovanni »

Are you sure you need a multi-threaded approach for your GUI? probably you could use just one thread handling all the GUI events and spawn other threads only if you need activity in background, it depends much on which GUI framework you are using anyway.

Giovanni
User avatar
Tectu
Posts: 1225
Joined: Thu May 10, 2012 9:50 am

Re: Menu implementation in ChibiOS. Need advice.

Post by Tectu »

As Giovanni already mentioned multi-threaded GUIs are a really bad idea. No matter how complex the GUI, it should always be a single thread.
Even very big and well known libraries such as the Qt library are single-threaded. Note that (in case of you're using it) uGFX itself uses just one thread for the entire GWIN magic too.

If you're using uGFX this would be very easy as you can use the already implemented tabwidget for this. Each page is one tab. The tab itself is basically a parent container. Once the tab is activated (you don't actually have to display the tabs so no issues for your menus) all the elements in that tabs will be rendered and become active. When a new tab is activated those elements are deactivated again and the new page shows up. This approach is also implemented by the uGFX-Studio in form of display pages. Highlevel API is generated such as showMenuPage(unsigned page); to easily switch through the different menu pages.


~ Tectu
steved
Posts: 834
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 12 times
Been thanked: 138 times

Re: Menu implementation in ChibiOS. Need advice.

Post by steved »

I would agree with Giovanni; one thread for the graphics handling works well.

I'm using ugfx; this has a single thread managing the actual screen, then I have one thread dealing with the control, which is passed touch events to process. Within ugfx you can assign each button/touch area a unique 'tag value' so that you know exactly what is required when it is pressed. You can then devise a table structure to manage the flow, or simply hard-code it, as you find convenient; personally I like tables for this sort of thing.
User avatar
Chudik
Posts: 152
Joined: Fri Jan 16, 2015 7:51 am
Has thanked: 7 times
Been thanked: 1 time

Re: Menu implementation in ChibiOS. Need advice.

Post by Chudik »

Wow!!!!
I did not expect so many answers right away :)
Thank you guys, I will use the first scenario.

However, I'm glad I put all that thoughts in written form. Everything is more structured in my head also :)
Post Reply