Can you have a struct pointer ?
Posted: Mon Aug 09, 2010 10:35 am
Dont laugh to hard if this is a ridiculous question.
I have a group of fonts that are set up as structs as follows.
Now, as you see here is was for "Font12T" then i have "Font14T", "Font16T" and so on.
For me to get the data i do:
BYTE x_size = Font12T[0].sizeInfo.bSize;
BYTE x_size = Font12T[0].sizeInfo.xSize;
BYTE y_size = Font12T[0].sizeInfo.ySize;
const BYTE *pdata = Font12F[0].fontdata;
ok, here is my issue, i have a routine called
"void LCD_String(char *lcd_string, BYTE font_type, WORD x, WORD y)"
where i pass my string to be printed to the LCD, i want to tell it font type on the fly. But since my fonts are in these structures, i have a fixed statement like
x_size = Font12T[0].sizeInfo.bSize;
I was wondering if i could create another structure, and have it point to the start of the font struct i wanted. here is what i am looking to do if you will.
//This will be my temp struct., now this is probably not set up right, buy you get the idea.
struct Temp_XySize
{
BYTE bSize;
BYTE xSize;
BYTE ySize;
};
struct Temp_Font
{
XySize sizeInfo;
BYTE fontdata[24];
}
then in my main code i could do this.
#define FONT12T (0)
#define FONT14T (1)
LCD_String("Hello World", FONT12T, 0,0);
Then inside LCD_String i would do this.
void LCD_String(char *lcd_string, BYTE font_type, WORD x, WORD y)
{
switch(font_type)
{
case FONT12T:
// I know this is jacked up, but i need my temp structure to point to the real font one.
Temp_Font = Font12T[0];
break;
case FONT14T:
// I know this is jacked up, but i need my temp structure to point to the real font one.
Temp_Font = Font14T[0];
break;
}
}
then i can now just use this and it will be pointing to the font i have chosen.
BYTE x_size = Temp_Font[0].sizeInfo.bSize;
BYTE x_size = Temp_Font[0].sizeInfo.xSize;
BYTE y_size = Temp_Font[0].sizeInfo.ySize;
hopefully i was able to make sense of what i am trying to do.
I have a group of fonts that are set up as structs as follows.
struct XySize
{
BYTE bSize;
BYTE xSize;
BYTE ySize;
};
const struct Font12T
{
XySize sizeInfo;
BYTE fontdata[24];
}
Font12T[95] =
{
/* Element 0x0010 - Char 0x0030 */
{{2, 8, 12},{
0x00,0x00, /* ................ */
0x00,0x00, /* ................ */
0x00,0x00, /* ................ */
0x38,0x00, /* ..%%%........... */
0x44,0x00, /* .%...%.......... */
0x44,0x00, /* .%...%.......... */
0x44,0x00, /* .%...%.......... */
0x44,0x00, /* .%...%.......... */
0x44,0x00, /* .%...%.......... */
0x38,0x00, /* ..%%%........... */
0x00,0x00, /* ................ */
0x00,0x00 /* ................ */
}}
,
/* Element 0x0011 - Char 0x0031 */
{{2, 8, 12},{
0x00,0x00, /* ................ */
0x00,0x00, /* ................ */
0x00,0x00, /* ................ */
0x10,0x00, /* ...%............ */
0x30,0x00, /* ..%%............ */
0x10,0x00, /* ...%............ */
0x10,0x00, /* ...%............ */
0x10,0x00, /* ...%............ */
0x10,0x00, /* ...%............ */
0x38,0x00, /* ..%%%........... */
0x00,0x00, /* ................ */
0x00,0x00 /* ................ */
}}
,... and so on.
Now, as you see here is was for "Font12T" then i have "Font14T", "Font16T" and so on.
For me to get the data i do:
BYTE x_size = Font12T[0].sizeInfo.bSize;
BYTE x_size = Font12T[0].sizeInfo.xSize;
BYTE y_size = Font12T[0].sizeInfo.ySize;
const BYTE *pdata = Font12F[0].fontdata;
ok, here is my issue, i have a routine called
"void LCD_String(char *lcd_string, BYTE font_type, WORD x, WORD y)"
where i pass my string to be printed to the LCD, i want to tell it font type on the fly. But since my fonts are in these structures, i have a fixed statement like
x_size = Font12T[0].sizeInfo.bSize;
I was wondering if i could create another structure, and have it point to the start of the font struct i wanted. here is what i am looking to do if you will.
//This will be my temp struct., now this is probably not set up right, buy you get the idea.
struct Temp_XySize
{
BYTE bSize;
BYTE xSize;
BYTE ySize;
};
struct Temp_Font
{
XySize sizeInfo;
BYTE fontdata[24];
}
then in my main code i could do this.
#define FONT12T (0)
#define FONT14T (1)
LCD_String("Hello World", FONT12T, 0,0);
Then inside LCD_String i would do this.
void LCD_String(char *lcd_string, BYTE font_type, WORD x, WORD y)
{
switch(font_type)
{
case FONT12T:
// I know this is jacked up, but i need my temp structure to point to the real font one.
Temp_Font = Font12T[0];
break;
case FONT14T:
// I know this is jacked up, but i need my temp structure to point to the real font one.
Temp_Font = Font14T[0];
break;
}
}
then i can now just use this and it will be pointing to the font i have chosen.
BYTE x_size = Temp_Font[0].sizeInfo.bSize;
BYTE x_size = Temp_Font[0].sizeInfo.xSize;
BYTE y_size = Temp_Font[0].sizeInfo.ySize;
hopefully i was able to make sense of what i am trying to do.