PROGMEM

Hello

I'm using a library to write text to a display, this library uses .h files for the fonts (eg. font8x16.h).

In the file it looks like this:

#define FONT_8X16_LEN  1544

const byte font_8x16[FONT_8X16_LEN] __attribute__((section(".progmem.data"))) =
{
   70, 86, 32,127,  8, 16,  2, 16,
    0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
    0,  0,  0,252,252,  0,  0,  0,  0,  0,  0, 51, 51,  0,  0,  0,

....lot of more lines.

Currently i use 3 fonts. Since my sketch is running out of program space, i wonder about 2 things:

1.) Does the Compiler write only the characters that are used in the code, or does it write all the data to flash? Like in the case of the 8x16 font i guess it would write 1544 bytes?

If it writes the complete 1544 bytes, see 2.)

2.) i have a attached a zip of the libary. to write a string to the display, you have to use

DOG.string(start column, start line, fontname, "thisIsAText")

Lets say i only need 10 characters of the font. Can i shrink the font by only defining the needed characters ? And how to modify the library?

I hope someone could help me with this, since my board is already soldered.. :cry: and i really run out of space. 1k or so would save me alot of hassle...

Regards
johnny

dog_7565R.zip (18.9 KB)

1.) Does the Compiler write only the characters that are used in the code, or does it write all the data to flash?

It reserves space in flash for the entire array. That the array may only be sparsely populated is irrelevant.

Can i shrink the font by only defining the needed characters ?

Yes. But, you have to deal with the fact that the user of your library may have different requirements concerning which characters are needed.

And how to modify the library?

With a text editor.

PaulS:
It reserves space in flash for the entire array. That the array may only be sparsely populated is irrelevant.

Yes. But, you have to deal with the fact that the user of your library may have different requirements concerning which characters are needed.

The "user" is in this case only me, i'm having the problem that my sketch uses to much space, and i need around 1-2k to use the SD libaray, so my only option is to shrink something...

My idea would be to copy the function to like [Dog.specialString] or so, so the orignal lib works still for future projects

PaulS:
With a text editor.

:slight_smile: yes, or eclipse.

But... i was more hoping for a tipp what i have to change in the code. Currently i don't even get how the library finds out where to look for a letter of my string?. I found no mapping table like 'A' = Address 7 or so.......

sgt_johnny:
Currently i don't even get how the library finds out where to look for a letter of my string?. I found no mapping table like 'A' = Address 7 or so.......

From the string() method in the dog_7565R.cpp file:

				//calculate positon of ascii character in font array
				//bytes for header + (ascii - startcode) * bytes per char)
				pos_array = 8 + (unsigned int)(*string++ - start_code) * bytes_p_char;
				pos_array += y*width; //get the dot pattern for the part of the char to print

You'd need to modify that method if you want to leave out some characters. Not exactly a trivial thing to do. The code assumes that every character has a representation in the array. You'd need another array that mapped the characters present to a position in the array, and you'd need to deal with characters that are not present in the array.

Today i found out i don't need to modfy!

There is class "DOG.image" which lets you display a image, so i can encode my strings as image