@@ -34,47 +34,85 @@ You should have received a copy of the GNU General Public License
34
34
along with this program. If not, see <http://www.gnu.org/licenses/>.
35
35
******************************************************************************/
36
36
#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>
39
41
#else
40
- #include < pgmspace.h>
42
+ #include < pgmspace.h>
41
43
#endif
42
44
#include < SFE_MicroOLED.h>
43
45
44
46
#ifndef _BV
45
47
#define _BV (x ) (1 << x)
46
48
#endif
47
49
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
-
52
50
// This fixed ugly GCC warning "only initialized variables can be placed into program memory area"
53
51
#if defined(__AVR__)
54
52
#undef PROGMEM
55
53
#define PROGMEM __attribute__ ((section(" .progmem.data" )))
56
54
#endif
57
55
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
70
80
#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
+
71
88
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.
73
91
const 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
77
113
fontlargeletter31x48
114
+ #else
115
+ NULL
78
116
#endif
79
117
};
80
118
@@ -997,7 +1035,13 @@ uint8_t MicroOLED::getFontTotalChar(void)
997
1035
*/
998
1036
uint8_t MicroOLED::getTotalFonts (void )
999
1037
{
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);
1001
1045
}
1002
1046
1003
1047
/* * \brief Get font type.
@@ -1015,8 +1059,8 @@ uint8_t MicroOLED::getFontType(void)
1015
1059
*/
1016
1060
uint8_t MicroOLED::setFontType (uint8_t type)
1017
1061
{
1018
- if ((type >= TOTALFONTS ) || (type < 0 ))
1019
- return false ;
1062
+ if ((type >= MAXFONTS ) || (fontsPointer[ type] == NULL ))
1063
+ return false ;
1020
1064
1021
1065
fontType = type;
1022
1066
fontWidth = pgm_read_byte (fontsPointer[fontType] + 0 );
0 commit comments