@@ -34,47 +34,85 @@ You should have received a copy of the GNU General Public License
3434along with this program. If not, see <http://www.gnu.org/licenses/>.
3535******************************************************************************/
3636#include < Arduino.h>
37- #if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
38- #include < avr/pgmspace.h>
37+ #if defined(ARDUINO_ARCH_MBED)
38+ // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM
39+ #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__)
40+ #include < avr/pgmspace.h>
3941#else
40- #include < pgmspace.h>
42+ #include < pgmspace.h>
4143#endif
4244#include < SFE_MicroOLED.h>
4345
4446#ifndef _BV
4547#define _BV (x ) (1 << x)
4648#endif
4749
48- // The 31x48 font is handy, but uses a big chunk of flash memory - about 7k.
49- // If you want to use font 4 in your sketch, uncomment out the line below:
50- // #define INCLUDE_LARGE_LETTER_FONT
51-
5250// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
5351#if defined(__AVR__)
5452#undef PROGMEM
5553#define PROGMEM __attribute__ ((section(" .progmem.data" )))
5654#endif
5755
58- // Add header of the fonts here. Remove as many as possible to conserve FLASH memory.
59- #include " util/font5x7.h"
60- #include " util/font8x16.h"
61- #include " util/fontlargenumber.h"
62- #include " util/7segment.h"
63- #include " util/fontlargeletter31x48.h"
64-
65- // Change the total fonts included
66- #ifdef INCLUDE_LARGE_LETTER_FONT
67- #define TOTALFONTS 5
68- #else
69- #define TOTALFONTS 4
56+ // Add header of the fonts here.
57+ // Fonts that aren't included the section below are excluded by the compiler.
58+ #include " util/font5x7.h" // Font 0
59+ #include " util/font8x16.h" // Font 1
60+ #include " util/7segment.h" // Font 2
61+ #include " util/fontlargenumber.h" // Font 3
62+ #include " util/fontlargeletter31x48.h" // Font 4 (excluded by default - see below)
63+
64+ #define MAXFONTS 5 // Do not change this line - except when _adding_ new fonts
65+
66+ // To save flash memory, change these to zeros for the fonts you want to exclude.
67+ // In particular, the 31x48 font is handy, but uses a big
68+ // chunk of flash memory - about 7k. It is excluded by default.
69+ //
70+ // If you are compiling the code using your own makefile, you can use compiler flags to include
71+ // or exclude individual fonts. E.g.: -DINCLUDE_FONT_LARGELETTER=1 or -DINCLUDE_FONT_LARGENUMBER=0
72+ #ifndef INCLUDE_FONT_5x7
73+ #define INCLUDE_FONT_5x7 1 // Change this to 0 to exclude the 5x7 font
74+ #endif
75+ #ifndef INCLUDE_FONT_8x16
76+ #define INCLUDE_FONT_8x16 1 // Change this to 0 to exclude the 8x16 font
77+ #endif
78+ #ifndef INCLUDE_FONT_7SEG
79+ #define INCLUDE_FONT_7SEG 1 // Change this to 0 to exclude the seven segment font
7080#endif
81+ #ifndef INCLUDE_FONT_LARGENUMBER
82+ #define INCLUDE_FONT_LARGENUMBER 1 // Change this to 0 to exclude the large number font
83+ #endif
84+ #ifndef INCLUDE_FONT_LARGELETTER
85+ #define INCLUDE_FONT_LARGELETTER 0 // Change this to 1 to include the large letter font
86+ #endif
87+
7188
72- // Add the font name as declared in the header file. Remove as many as possible to conserve FLASH memory.
89+ // Add the font name as declared in the header file.
90+ // Exclude as many as possible to conserve FLASH memory.
7391const unsigned char *MicroOLED::fontsPointer[] = {
74- font5x7, font8x16, sevensegment, fontlargenumber
75- #ifdef INCLUDE_LARGE_LETTER_FONT
76- ,
92+ #if INCLUDE_FONT_5x7
93+ font5x7,
94+ #else
95+ NULL ,
96+ #endif
97+ #if INCLUDE_FONT_8x16
98+ font8x16,
99+ #else
100+ NULL ,
101+ #endif
102+ #if INCLUDE_FONT_7SEG
103+ sevensegment,
104+ #else
105+ NULL ,
106+ #endif
107+ #if INCLUDE_FONT_LARGENUMBER
108+ fontlargenumber,
109+ #else
110+ NULL ,
111+ #endif
112+ #if INCLUDE_FONT_LARGELETTER
77113 fontlargeletter31x48
114+ #else
115+ NULL
78116#endif
79117};
80118
@@ -997,7 +1035,13 @@ uint8_t MicroOLED::getFontTotalChar(void)
9971035*/
9981036uint8_t MicroOLED::getTotalFonts (void )
9991037{
1000- return TOTALFONTS;
1038+ uint8_t totalFonts = 0 ;
1039+ for (uint8_t thisFont = 0 ; thisFont < MAXFONTS; thisFont++)
1040+ {
1041+ if (fontsPointer[thisFont] != NULL )
1042+ totalFonts++;
1043+ }
1044+ return (totalFonts);
10011045}
10021046
10031047/* * \brief Get font type.
@@ -1015,8 +1059,8 @@ uint8_t MicroOLED::getFontType(void)
10151059*/
10161060uint8_t MicroOLED::setFontType (uint8_t type)
10171061{
1018- if ((type >= TOTALFONTS ) || (type < 0 ))
1019- return false ;
1062+ if ((type >= MAXFONTS ) || (fontsPointer[ type] == NULL ))
1063+ return false ;
10201064
10211065 fontType = type;
10221066 fontWidth = pgm_read_byte (fontsPointer[fontType] + 0 );
0 commit comments