Skip to content

Commit 5beb1c1

Browse files
committed
Added extra comments. Changed excluded font pointers to NULL
1 parent c4ff514 commit 5beb1c1

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

examples/Example11_BigFont/Example11_BigFont.ino

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
66
This sketch demonstrates how to use the Large Letter 31x48 font.
77
This font is disabled by default. To enable it, you need to edit
8-
SFE_MicroOLED.cpp and uncomment the line which says:
9-
#include "util/fontlargeletter31x48.h"
8+
SFE_MicroOLED.cpp and change line 85 (or thereabouts) from:
9+
#define INCLUDE_FONT_LARGELETTER 0
10+
to:
11+
#define INCLUDE_FONT_LARGELETTER 1
1012
1113
Hardware Connections:
1214
This example assumes you are using Qwiic. See the SPI examples for
@@ -58,7 +60,7 @@ void setup()
5860
if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48)
5961
{
6062
Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!"));
61-
Serial.println(F("Have you uncommented #include \"util/fontlargeletter31x48.h\" in SFE_MicroOLED.cpp?"));
63+
Serial.println(F("Have you changed the #define INCLUDE_FONT_LARGELETTER to 1 in SFE_MicroOLED.cpp?"));
6264
Serial.println(F("Freezing..."));
6365
while (1)
6466
; // Do nothing more

src/SFE_MicroOLED.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -53,63 +53,66 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
5353
#define PROGMEM __attribute__((section(".progmem.data")))
5454
#endif
5555

56-
// Add header of the fonts here. Fonts that aren't included below are
57-
// eliminated by the compiler.
58-
#include "util/font5x7.h"
59-
#include "util/font8x16.h"
60-
#include "util/fontlargenumber.h"
61-
#include "util/7segment.h"
62-
#include "util/fontlargeletter31x48.h"
63-
64-
#define MAXFONTS 5 // Do not change this line
65-
66-
// To save flash memory, change these to zeros for the fonts you do
67-
// not want. In particular, the 31x48 font is handy, but uses a big
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
6868
// 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
6972
#ifndef INCLUDE_FONT_5x7
70-
#define INCLUDE_FONT_5x7 1
73+
#define INCLUDE_FONT_5x7 1 // Change this to 0 to exclude the 5x7 font
7174
#endif
7275
#ifndef INCLUDE_FONT_8x16
73-
#define INCLUDE_FONT_8x16 1
76+
#define INCLUDE_FONT_8x16 1 // Change this to 0 to exclude the 8x16 font
7477
#endif
7578
#ifndef INCLUDE_FONT_7SEG
76-
#define INCLUDE_FONT_7SEG 1
79+
#define INCLUDE_FONT_7SEG 1 // Change this to 0 to exclude the seven segment font
7780
#endif
7881
#ifndef INCLUDE_FONT_LARGENUMBER
79-
#define INCLUDE_FONT_LARGENUMBER 1
82+
#define INCLUDE_FONT_LARGENUMBER 1 // Change this to 0 to exclude the large number font
8083
#endif
8184
#ifndef INCLUDE_FONT_LARGELETTER
82-
#define INCLUDE_FONT_LARGELETTER 0
85+
#define INCLUDE_FONT_LARGELETTER 0 // Change this to 1 to include the large letter font
8386
#endif
8487

8588

86-
// Add the font name as declared in the header file. Remove as many
87-
// 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.
8891
const unsigned char *MicroOLED::fontsPointer[] = {
8992
#if INCLUDE_FONT_5x7
9093
font5x7,
9194
#else
92-
0x0,
95+
NULL,
9396
#endif
9497
#if INCLUDE_FONT_8x16
9598
font8x16,
9699
#else
97-
0x0,
100+
NULL,
98101
#endif
99102
#if INCLUDE_FONT_7SEG
100103
sevensegment,
101104
#else
102-
0x0,
105+
NULL,
103106
#endif
104107
#if INCLUDE_FONT_LARGENUMBER
105108
fontlargenumber,
106109
#else
107-
0x0,
110+
NULL,
108111
#endif
109112
#if INCLUDE_FONT_LARGELETTER
110113
fontlargeletter31x48
111114
#else
112-
0x0
115+
NULL
113116
#endif
114117
};
115118

@@ -1035,7 +1038,7 @@ uint8_t MicroOLED::getTotalFonts(void)
10351038
uint8_t totalFonts = 0;
10361039
for (uint8_t thisFont = 0; thisFont < MAXFONTS; thisFont++)
10371040
{
1038-
if (fontsPointer[thisFont] > 0)
1041+
if (fontsPointer[thisFont] != NULL)
10391042
totalFonts++;
10401043
}
10411044
return (totalFonts);
@@ -1056,7 +1059,7 @@ uint8_t MicroOLED::getFontType(void)
10561059
*/
10571060
uint8_t MicroOLED::setFontType(uint8_t type)
10581061
{
1059-
if ((type >= MAXFONTS) || !fontsPointer[type])
1062+
if ((type >= MAXFONTS) || (fontsPointer[type] == NULL))
10601063
return false;
10611064

10621065
fontType = type;

0 commit comments

Comments
 (0)