You will see no objection from me at least, if you post pseudocode.
Printable View
Yup I see that. I was in a hurry to post a reply so I missed that. It took me 4 attempts to post my original reply because my login would time out before I finished putting together that long of a response. Then when I clicked submit I would get a not logged in error and everything I typed was gone. I am a slow learner so it took me 3 rewrites before remembered to make a copy before I submitted ;o)
I will let you know.
Thanks,
v_dave
I have no problem with pseudo-code as such. In this particular case, the typo bit isn't very important, but the static const, as you seem to know, is a critical part in making it shorter/smaller [since any initialized RAM variables ALSO need to go in ROM, so the code-space AND the RAM space is used, when only ROM is really needed].
I've never programmed a real tiny system, but I have worked for about 10 years with various types of embedded systems.
--
Mats
Hello All,
OK so I got a few menu's working but I have run into an issue. As I mentioned am using an 8-bit embbeded microcontroller whith limited resources. One of my limitations is 2048 BYTEs (note this is BYTE's) of RAM.
I have approx 16 menu's with an average of 5 selections on each menu. That would be approx 80 structures that need to be defined. I have reduced each structure to as small as possible but each one uses 28 BYTE's of RAM. this totals 2240 BYTE's. A little more than I have availible.
Well it was a good idea that would work great on a system with more resources. but now it is back to the drawing board.
Thanks again for the help.
So does your code not live in ROM? const static code should be fine in ROM, right?
--
Mats
Do you need all of the menus in memory at the same time? Can you piece out any items that don't require a RAM image?
Here is what I implemented:
So umm duh, add a const in front of each structure and now they are in ROM. Sometimes its the simple stuff thats gets in the way.Code:typedef struct MENU
{
char title[MAX_TITLE];
void (*command)();
unsigned char num_submenus;
unsigned char idx;
struct MENU *submenu[MAX_SUBMENUS];
}menu;
menu motor_main_menu =
{
"1.Motor",
NULL,
1,
0,
{&motor_main, }
};
menu Info_Main_Menu =
{
"6.Info",
NULL,
0
};
menu Calib_Main_Menu =
{
"5.Calib",
NULL,
0
};
menu Move_Main_Menu =
{
"4.Movement",
NULL,
0
};
menu Valve_Main_Menu =
{
"3.Valve",
NULL,
0
};
menu Comm_Main_Menu =
{
"2.Comm",
NULL,
0
};
menu Step_Main_Menu =
{
"Step Mode",
NULL,
4
};
menu main_menu =
{
"Main Menu",
NULL,
6,
0,
{&motor_main_menu, &Comm_Main_Menu, &Valve_Main_Menu, &Move_Main_Menu, &Calib_Main_Menu, &Info_Main_Menu}
};
And more....
There are a few tricks to play... But what have you done so far?
EDIT: Nevermind, I actually scrolled down and saw it. There's more you can do.
Instead of holding the title as a static array in the struct, you could point out to a char literal. This would avoid wasting space when the menu title is short.
Depending on the range of values for "data" and "num_submenus," these could both be packed somehow into a single short.
And instead of using pointers to the submenus, you could use a single char to store an offset into a global array of all submenus.
But if you're happy just sticking it in ROM and forgetting it, then that's fine.
I think sticking it in ROM will be fine. I have plenty ROM it is RAM that is limited.
I am getting the following Warning:
Warning : C1825: Indirection to different types ('MENU const *const ' instead of 'MENU *const ')
LCD_Cntrl.c line 151
When I do this
My code still runs but I am working on removing this warning.Code:static const menu GR_314_Menu =
{
"1.3.14",
set_gr_var,
0,
0
};
static const menu GR_Main_Menu =
{
"Gear Ratio",
NULL,
5,
0,
// This is the line that causes the warning
{&GR_314_Menu, &GR_475_Menu, &GR_985_Menu, &GR_1491_Menu, &GR_2225_Menu }
};
Tell the structure that its member points to ROM?
Code:const struct MENU *submenu[MAX_SUBMENUS];