Hello everyone.
Maybe you can help, I really do not see why this is happening.
I am working with fonts on small Arduino (AT32U4).
Storing the fonts into flash and using them is imperative, but I have issues using the data structures provided with fonts.
The fonts are build-up the following way, in the .h file:
typedef struct {
const uint8_t *dataX;
uint16_t width;
uint16_t height;
uint8_t dataSize;
} tImage;
typedef struct {
long int code;
const tImage *image;
} tChar;
typedef struct {
int length;
const tChar *chars;
} tFont;
extern const tFont Font;
The .c file contains the fonts:
//font bitmap
static const uint8_t image_data_Font_0x2d[264] PROGMEM = {
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
0xff, 0xff, 0xff, 0xe0,
.
.
.
.
};
//font data + font metrics as size, width etc.
static const tImage Font_0x2e[] PROGMEM = { image_data_Font_0x2e,
22, 66, 8};
//array of font data + font metrics
const tChar Font_array[] = {
#if (0x0 == 0x0)
// character: '+'
{0x2b, &Font_0x2b},
#else
// character: '+' == ''
{0x2b, &Font_0x},
#endif
//finally the font is constructed
PROGMEM const tFont Font = { 13, Font_array };
The issue occurs when I try to access members in Font.
void write_index(uint16_t code, uint16_t index){
byte temp = (byte)code;
Serial.print("\r\nANSI: ");
Serial.write(temp);
Serial.print(", CODE: 0x");
Serial.print(code, HEX);
Serial.print("\r\nLENGTH: ");
Serial.print(Font.length);
Serial.print("\r\nDecoded CODE: 0x");
Serial.print(Font.chars[index].code, HEX);
Serial.print("\r\nWidth: ");
Serial.print(Font.chars[index].image->width);
Serial.print("\r\nheight: ");
Serial.print(Font.chars[index].image->height);
Serial.print("\r\nDATA: 0x");
Serial.print(Font.chars[index].image->dataX[0], HEX);
Serial.print(Font.chars[index].image->dataX[1], HEX);
Serial.print(Font.chars[index].image->dataX[2], HEX);
}
ANSI: -, CODE: 0x2D (control)
LENGTH: 13 (correct)
Decoded CODE: 0x2D (correct)
Width: 4883 (WRONG!)
height: 4883 (WRONG!)
DATA: 0x131313 (WRONG!)
It looks like, that when I access parameters from "image" structure, the data is wrong. Why is that?