Taha Paksu
Taha Paksu

Reputation: 15616

embedded software structure for sublevel screens and menus

I'm new into embedded c programming and I need some advice.

I'm trying to create a menu structure with underneath screens on an embedded system, the OS code and the drawing/menu libraries are ready, but I can't figure out how I'd design this system.

it'll have :

I wrote some code that's working and still feels like I'm writing procedural spagetti code. And I'm new to embedded c systems so I don't know if I can use classes or objects inside the code. I'd be grateful if someone shows me the right way to do this. I'm experienced about programming anything else BTW so feel free with the tech talk. ;)

BTW the menu code is structured like this:

menu myMenu;
entry* myMenuEntries;
int selection = 0;
myMenuEntries[0] = [entry definer code];
...
myMenu.entries = (entry *) myMenuEntries;
selection = DisplayMenu(myMenu);
switch(selection){
   case 0: exit(); break;
}

How can I create an object in embedded c like it's used in myMenu.entries?

Upvotes: 3

Views: 2232

Answers (1)

c.fogelklou
c.fogelklou

Reputation: 1801

I would definitely use object oriented C here, like you suspect is possible. There are lots of references to how to do oop in C on stack overflow. You make classes out of structs and use function pointers as the member functions which can then be overridden if you want polymorphism.

Each screen could have on onEnter(), for example, to initialize stuff when the screen is loaded, and you could have a drawable class that can encompass strings, primitives, images, etc that know how to draw themselves at any x,y coordinate. You could also have a standard screen object which is made up of a list of the objects on the screen, their coordinates, and contents. These could be initialized at compile time, too, in a big table.

(I've done all this on a DSP using C and ASM)

There are also ready made libraries that can do this. I know that micrium has one. I'm on my phone or I'd Google it and put the link here.

Upvotes: 3

Related Questions