HerbertMunch
New Member
Code:
//Required by Menu system.
//Renders a menu item on chosen medium.
void DisplayMenuItem(MenuItem *item)
{
// SendCommand(0x01);
printf(item->text);
SendString(item->text);
}
void SendString(const rom char * string)
{
char* position = string;
char a;
while (*position != '\0')
{
a = *position;
SendCharacter(*position++);
}
}
Can anyone tell me how to make that method work with the following arrays?
I thought that I finally understood how to access strings, but I was wrong.
Code:
#pragma romdata
//Example heirarchy items.
// **********************************************************************************************
// The following arrays contain menu items for each level of menu heirarchy.
MenuItem menu1Items[] =
{
// TopLevel , Name , subMenu, handler
1 ,"Menu1-1" , 0 , handler,
1 ,"Menu1-2" , 0 , 0
};
//This represents the settings sub menu.
MenuItem menu2Items[] =
{
// TopLevel , Name , subMenu, handler
1 ,"Menu2-1" , 0 , 0,
1 ,"Menu2-2" , 0 , 0,
1 ,"Menu2-3" , 0 , 0
};
//base items. also: menu initialises by cha startup item to baseItems[0]
MenuItem menu0Items[] =
{
// TopLevel , Name , subMenu, handler
0 , "Menu1" , &menuLevels[1] , 0,
0 , "Menu2" , &menuLevels[2] , 0,
1 , "Menu3" , 0 , 0
};
//*********************************************************************************************
//End of item arrays
//The following array is required by menu system.
//It contains MenuLevel items, which describe a level that contains menu items.
//First item should be the base menu.
MenuLevel menuLevels[] = { // start index , array size , array
0 , sizeof(menu0Items) / sizeof (MenuItem), menu0Items,
0 , sizeof(menu1Items) / sizeof (MenuItem), menu1Items,
0 , sizeof(menu2Items) / sizeof (MenuItem), menu2Items,
};
When i step through the DisplayMenuItem method, the PrintF succeeds and displays "Menu1" in the uart window. My sendString method doesnt work! I dont know how to access the text, but the printf does!
Here are the struct defs
Code:
#pragma romdata
//represents an individual menu item which belongs to a menu level
typedef struct MenuItem
{
//bool. describes whether or not this node is a top level node.
//i.e when MenuClick() is called on this item, topLevelHandler will be called
//and the current item will be stored in history
unsigned char topLevel;
//Pointer to an array of characters representing the menu item
char *text;
//A pointer which points to the next level up in the menu heirarchy
//Actually a MenuLevel pointer.
near rom *subMenu;
/*
Pointer to handler method that deals with the application specifics.
Paremeter firstRun tells user code whether or not this is the first time
the method has run (i.e has the user just pressed the button to get here?)
*/
void (*topLevelHandler)(bool firstRun);
}MenuItem;
//represents a level of menu heirarchy.
typedef struct MenuLevel
{
//The index of the current selected menu on this level
char currentIndex;
//The length of the item array specified by *items
bool itemCount;
//Pointer to an array of menu items that represent this level
MenuItem *items;
}MenuLevel;
When i look in the watch window at the location of the string, it says 31DE. If i try and look at 31DE in the watch window, it just says out of bounds, FFF, etc.
I would be extremely grateful to anyone that can answer this
Any ideas?
Many thanks
Chris
Attachments
Last edited: