From 0a9a233b01bb8ae7906c749addc44d76ab57fb02 Mon Sep 17 00:00:00 2001 From: Patrik Jonsson Date: Tue, 16 Mar 2021 19:16:03 -1000 Subject: [PATCH 1/9] Each of the fonts can now be included/excluded individually. --- src/SFE_MicroOLED.cpp | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index 6583771..a1addac 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -63,18 +63,35 @@ along with this program. If not, see . #include "util/fontlargeletter31x48.h" // Change the total fonts included -#ifdef INCLUDE_LARGE_LETTER_FONT #define TOTALFONTS 5 -#else -#define TOTALFONTS 4 -#endif -// Add the font name as declared in the header file. Remove as many as possible to conserve FLASH memory. +// Add the font name as declared in the header file. Remove as many +// as possible to conserve FLASH memory. const unsigned char *MicroOLED::fontsPointer[] = { - font5x7, font8x16, sevensegment, fontlargenumber +#if INCLUDE_FONT0 + font5x7, +#else + 0x0, +#endif +#if INCLUDE_FONT1 + font8x16, +#else + 0x0, +#endif +#if INCLUDE_FONT2 + sevensegment, +#else + 0x0, +#endif +#if INCLUDE_FONT3 + fontlargenumber, +#else + 0x0, +#endif #ifdef INCLUDE_LARGE_LETTER_FONT - , fontlargeletter31x48 +#else + 0x0 #endif }; @@ -1015,8 +1032,8 @@ uint8_t MicroOLED::getFontType(void) */ uint8_t MicroOLED::setFontType(uint8_t type) { - if ((type >= TOTALFONTS) || (type < 0)) - return false; + if ((type >= TOTALFONTS) || !fontsPointer[type]) + return false; fontType = type; fontWidth = pgm_read_byte(fontsPointer[fontType] + 0); From 2d3fb6c0fe408e8d0d6502b176a08386758f1e97 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 11:49:11 +0100 Subject: [PATCH 2/9] Allow the code to compile and run on MBED (APOLLO3 v2) --- src/SFE_MicroOLED.cpp | 8 +++++--- src/SFE_MicroOLED.h | 8 +++++--- src/util/7segment.h | 9 ++++++--- src/util/font5x7.h | 11 +++++++---- src/util/font8x16.h | 9 ++++++--- src/util/fontlargeletter31x48.h | 9 +++++++-- src/util/fontlargenumber.h | 9 ++++++--- 7 files changed, 42 insertions(+), 21 deletions(-) diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index 6583771..434cd30 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -34,10 +34,12 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . ******************************************************************************/ #include -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) -#include +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + #include #else -#include + #include #endif #include diff --git a/src/SFE_MicroOLED.h b/src/SFE_MicroOLED.h index 5e79e84..56728e8 100644 --- a/src/SFE_MicroOLED.h +++ b/src/SFE_MicroOLED.h @@ -44,10 +44,12 @@ along with this program. If not, see . #include // Needed for TwoWire - even if we are using SPI or Parallel #include // Needed for SPIClass - even if we are using I2C or Parallel -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) -#include +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + #include #else -#include + #include #endif #define I2C_ADDRESS_SA0_0 0b0111100 diff --git a/src/util/7segment.h b/src/util/7segment.h index 61fe37b..afa56f0 100644 --- a/src/util/7segment.h +++ b/src/util/7segment.h @@ -25,13 +25,16 @@ July 27, 2015 #ifndef FONT7SEGMENT_H #define FONT7SEGMENT_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + static const unsigned char sevensegment [] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char sevensegment [] PROGMEM = { #else #include + static const unsigned char sevensegment [] PROGMEM = { #endif - -static const unsigned char sevensegment [] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 10,16,46,13,1,30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/font5x7.h b/src/util/font5x7.h index 5392c17..cffcc59 100644 --- a/src/util/font5x7.h +++ b/src/util/font5x7.h @@ -25,14 +25,17 @@ July 27, 2015 #ifndef FONT5X7_H #define FONT5X7_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +// Standard ASCII 5x7 font +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + static const unsigned char font5x7[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char font5x7[] PROGMEM = { #else #include + static const unsigned char font5x7[] PROGMEM = { #endif - -// Standard ASCII 5x7 font -static const unsigned char font5x7[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 5,8,0,255,12,75, 0x00, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/font8x16.h b/src/util/font8x16.h index e518666..e531076 100644 --- a/src/util/font8x16.h +++ b/src/util/font8x16.h @@ -24,13 +24,16 @@ July 27, 2015 #ifndef FONT8X16_H #define FONT8X16_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + static const unsigned char font8x16[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char font8x16[] PROGMEM = { #else #include + static const unsigned char font8x16[] PROGMEM = { #endif - -static const unsigned char font8x16[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 8,16,32,96,2,56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x00, 0x00, 0x00, 0x00, diff --git a/src/util/fontlargeletter31x48.h b/src/util/fontlargeletter31x48.h index 6b954a1..5850c15 100644 --- a/src/util/fontlargeletter31x48.h +++ b/src/util/fontlargeletter31x48.h @@ -19,12 +19,17 @@ August 13, 2015 #ifndef FONTLARGELETTER31X48_H #define FONTLARGELETTER31X48_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) + +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + static const unsigned char fontlargeletter31x48 [] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char fontlargeletter31x48 [] PROGMEM = { #else #include + static const unsigned char fontlargeletter31x48 [] PROGMEM = { #endif -static const unsigned char fontlargeletter31x48 [] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 31,48,65,58,0,62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xF8, 0xF8, 0xF8, 0xF8, diff --git a/src/util/fontlargenumber.h b/src/util/fontlargenumber.h index dc87bb8..99aed72 100644 --- a/src/util/fontlargenumber.h +++ b/src/util/fontlargenumber.h @@ -25,13 +25,16 @@ July 27, 2015 #ifndef FONTLARGENUMBER_H #define FONTLARGENUMBER_H -#if defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) +#if defined(ARDUINO_ARCH_MBED) + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + static const unsigned char fontlargenumber[] = { +#elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include + static const unsigned char fontlargenumber[] PROGMEM = { #else #include + static const unsigned char fontlargenumber[] PROGMEM = { #endif - -static const unsigned char fontlargenumber[] PROGMEM = { // first row defines - FONTWIDTH, FONTHEIGHT, ASCII START CHAR, TOTAL CHARACTERS, FONT MAP WIDTH HIGH, FONT MAP WIDTH LOW (2,56 meaning 256) 12,48,48,11,1,32, 0x00, 0xC0, 0xF8, 0x7C, 0x3E, 0x3E, 0xFC, 0xF8, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xE0, From fd4764ce201af5ff929ee9c296b1018fdafa00b5 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 11:58:57 +0100 Subject: [PATCH 3/9] Add note about PROGMEM --- src/SFE_MicroOLED.cpp | 2 +- src/SFE_MicroOLED.h | 2 +- src/util/7segment.h | 2 +- src/util/font5x7.h | 2 +- src/util/font8x16.h | 2 +- src/util/fontlargeletter31x48.h | 2 +- src/util/fontlargenumber.h | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index 434cd30..4ecdd66 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -35,7 +35,7 @@ along with this program. If not, see . ******************************************************************************/ #include #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include #else diff --git a/src/SFE_MicroOLED.h b/src/SFE_MicroOLED.h index 56728e8..534ec81 100644 --- a/src/SFE_MicroOLED.h +++ b/src/SFE_MicroOLED.h @@ -45,7 +45,7 @@ along with this program. If not, see . #include // Needed for SPIClass - even if we are using I2C or Parallel #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include #else diff --git a/src/util/7segment.h b/src/util/7segment.h index afa56f0..1559559 100644 --- a/src/util/7segment.h +++ b/src/util/7segment.h @@ -26,7 +26,7 @@ July 27, 2015 #define FONT7SEGMENT_H #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM static const unsigned char sevensegment [] = { #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include diff --git a/src/util/font5x7.h b/src/util/font5x7.h index cffcc59..5851a19 100644 --- a/src/util/font5x7.h +++ b/src/util/font5x7.h @@ -27,7 +27,7 @@ July 27, 2015 // Standard ASCII 5x7 font #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM static const unsigned char font5x7[] = { #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include diff --git a/src/util/font8x16.h b/src/util/font8x16.h index e531076..6025af3 100644 --- a/src/util/font8x16.h +++ b/src/util/font8x16.h @@ -25,7 +25,7 @@ July 27, 2015 #define FONT8X16_H #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM static const unsigned char font8x16[] = { #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include diff --git a/src/util/fontlargeletter31x48.h b/src/util/fontlargeletter31x48.h index 5850c15..e9f9440 100644 --- a/src/util/fontlargeletter31x48.h +++ b/src/util/fontlargeletter31x48.h @@ -21,7 +21,7 @@ August 13, 2015 #define FONTLARGELETTER31X48_H #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM static const unsigned char fontlargeletter31x48 [] = { #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include diff --git a/src/util/fontlargenumber.h b/src/util/fontlargenumber.h index 99aed72..bc640f7 100644 --- a/src/util/fontlargenumber.h +++ b/src/util/fontlargenumber.h @@ -26,7 +26,7 @@ July 27, 2015 #define FONTLARGENUMBER_H #if defined(ARDUINO_ARCH_MBED) - // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h + // ARDUINO_ARCH_MBED (APOLLO3 v2) does not support or require pgmspace.h / PROGMEM static const unsigned char fontlargenumber[] = { #elif defined(__AVR__) || defined(__arm__) || defined(__ARDUINO_ARC__) #include From b98ccb9801a1a0c218e4e65fce25b072540f2f2d Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 12:48:55 +0100 Subject: [PATCH 4/9] Modify #32 : commenting the #include disables the font --- src/SFE_MicroOLED.cpp | 51 +++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index efa59d7..e15dba5 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -47,53 +47,50 @@ along with this program. If not, see . #define _BV(x) (1 << x) #endif -// The 31x48 font is handy, but uses a big chunk of flash memory - about 7k. -// If you want to use font 4 in your sketch, uncomment out the line below: -//#define INCLUDE_LARGE_LETTER_FONT - // This fixed ugly GCC warning "only initialized variables can be placed into program memory area" #if defined(__AVR__) #undef PROGMEM #define PROGMEM __attribute__((section(".progmem.data"))) #endif -// Add header of the fonts here. Remove as many as possible to conserve FLASH memory. -#include "util/font5x7.h" -#include "util/font8x16.h" -#include "util/fontlargenumber.h" -#include "util/7segment.h" +// Add header of the fonts here. Comment as many as possible to conserve FLASH memory. +#include "util/font5x7.h" // Comment this line if you do not need the 5x7 font +#include "util/font8x16.h" // Comment this line if you do not need the 8x16 font +#include "util/fontlargenumber.h" // Comment this line if you do not need the large number font +#include "util/7segment.h" // Comment this line if you do not need the 7segment font +// The 31x48 font is handy, but uses a big chunk of flash memory - about 7k. +// If you want to save memory, comment out the line below: #include "util/fontlargeletter31x48.h" -// Change the total fonts included -#define TOTALFONTS 5 +#define MAXFONTS 5 // Do not change this line // Add the font name as declared in the header file. Remove as many // as possible to conserve FLASH memory. const unsigned char *MicroOLED::fontsPointer[] = { -#if INCLUDE_FONT0 +#ifdef FONT5X7_H font5x7, #else - 0x0, + 0x0, #endif -#if INCLUDE_FONT1 +#ifdef FONT8X16_H font8x16, #else - 0x0, + 0x0, #endif -#if INCLUDE_FONT2 +#ifdef FONT7SEGMENT_H sevensegment, #else - 0x0, + 0x0, #endif -#if INCLUDE_FONT3 - fontlargenumber, +#ifdef FONTLARGENUMBER_H + fontlargenumber, #else - 0x0, + 0x0, #endif -#ifdef INCLUDE_LARGE_LETTER_FONT +#ifdef FONTLARGELETTER31X48_H fontlargeletter31x48 #else - 0x0 + 0x0 #endif }; @@ -1016,7 +1013,13 @@ uint8_t MicroOLED::getFontTotalChar(void) */ uint8_t MicroOLED::getTotalFonts(void) { - return TOTALFONTS; + uint8_t totalFonts = 0; + for (uint8_t thisFont = 0; thisFont < MAXFONTS; thisFont++) + { + if (fontsPointer[thisFont] > 0) + totalFonts++; + } + return (totalFonts); } /** \brief Get font type. @@ -1034,7 +1037,7 @@ uint8_t MicroOLED::getFontType(void) */ uint8_t MicroOLED::setFontType(uint8_t type) { - if ((type >= TOTALFONTS) || !fontsPointer[type]) + if ((type >= MAXFONTS) || !fontsPointer[type]) return false; fontType = type; From 86240c414f7a3a76c2feff686340c0a8d61a3901 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 20:03:06 +0100 Subject: [PATCH 5/9] Disable font 4 by default. Add Example11 --- .../Example11_BigFont/Example11_BigFont.ino | 85 +++++++++++++++++++ src/SFE_MicroOLED.cpp | 4 +- 2 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 examples/Example11_BigFont/Example11_BigFont.ino diff --git a/examples/Example11_BigFont/Example11_BigFont.ino b/examples/Example11_BigFont/Example11_BigFont.ino new file mode 100644 index 0000000..4ffe2c8 --- /dev/null +++ b/examples/Example11_BigFont/Example11_BigFont.ino @@ -0,0 +1,85 @@ +/* + SFE_MicroOLED Library Demo + Paul Clark @ SparkFun Electronics + Original Creation Date: April 3rd, 2021 + + This sketch demonstrates how to use the Large Letter 31x48 font. + This font is disabled by default. To enable it, you need to edit + SFE_MicroOLED.cpp and uncomment the line which says: + #include "util/fontlargeletter31x48.h" + + Hardware Connections: + This example assumes you are using Qwiic. See the SPI examples for + a detailed breakdown of connection info. + + Want to support open source hardware? Buy a board from SparkFun! + https://www.sparkfun.com/products/13003 + https://www.sparkfun.com/products/14532 + + This code is beerware; if you see me (or any other SparkFun employee) at the + local, and you've found our code helpful, please buy us a round! + + Distributed as-is; no warranty is given. +*/ + +#include +#include //Click here to get the library: http://librarymanager/All#SparkFun_Micro_OLED + +#define PIN_RESET 9 + +// From version v1.3, we can instantiate oled like this (but only for I2C) +MicroOLED oled(PIN_RESET); + +void setup() +{ + Serial.begin(115200); // Begin the Serial port + Serial.println(F("SparkFun MicroOLED Example")); + + delay(100); + Wire.begin(); + + // This is the new way of initializing the OLED. + // We can pass a different I2C address and TwoWire port + // If 0x3D does not work, try 0x3C + oled.begin(0x3C, Wire); // Initialize the OLED + + // Print the total number of fonts loaded into memory + Serial.print(F("There are ")); + Serial.print(oled.getTotalFonts()); + Serial.println(F(" fonts available")); + + oled.clear(ALL); // Clear the display's internal memory + oled.display(); // Display what's in the buffer (splashscreen) + + delay(1000); // Delay 1000 ms + + oled.clear(PAGE); // Clear the buffer. + + if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48) + { + Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!")); + Serial.println(F("Have you uncommented #include \"util/fontlargeletter31x48.h\" in SFE_MicroOLED.cpp?")); + Serial.println(F("Freezing...")); + while (1) + ; // Do nothing more + } +} + +void loop() +{ + // Demonstrate font 4 + // There are 58 possible characters in the font 4 type: A - z + // Lets run through all of them and print them out! + for (int i = 'A'; i <= 'z'; i += 2) + { + oled.clear(PAGE); // Clear the screen + + oled.setCursor(0, 0); // Set cursor to top-left + + oled.write(i); // Write a byte out as a character + oled.write(i+1); // Write the next byte out as a character + oled.display(); // Draw on the screen + + delay(500); // Delay 500 ms + } +} diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index e15dba5..23e737e 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -59,8 +59,8 @@ along with this program. If not, see . #include "util/fontlargenumber.h" // Comment this line if you do not need the large number font #include "util/7segment.h" // Comment this line if you do not need the 7segment font // The 31x48 font is handy, but uses a big chunk of flash memory - about 7k. -// If you want to save memory, comment out the line below: -#include "util/fontlargeletter31x48.h" +// If you want to use this font, uncomment the line below: +//#include "util/fontlargeletter31x48.h" #define MAXFONTS 5 // Do not change this line From d4470ff49bf0aac9fda3a24061446f5b1b58be7d Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 20:06:38 +0100 Subject: [PATCH 6/9] Default to 0x3D --- examples/Example11_BigFont/Example11_BigFont.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/Example11_BigFont/Example11_BigFont.ino b/examples/Example11_BigFont/Example11_BigFont.ino index 4ffe2c8..f63fcc6 100644 --- a/examples/Example11_BigFont/Example11_BigFont.ino +++ b/examples/Example11_BigFont/Example11_BigFont.ino @@ -41,7 +41,7 @@ void setup() // This is the new way of initializing the OLED. // We can pass a different I2C address and TwoWire port // If 0x3D does not work, try 0x3C - oled.begin(0x3C, Wire); // Initialize the OLED + oled.begin(0x3D, Wire); // Initialize the OLED // Print the total number of fonts loaded into memory Serial.print(F("There are ")); From c57b4a074080b03a81ebfc9273a494c06c0c8157 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Sat, 3 Apr 2021 20:20:04 +0100 Subject: [PATCH 7/9] v1.3.2 --- library.json | 2 +- library.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library.json b/library.json index 9795482..86e43dc 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "SparkFun Micro OLED Breakout", - "version": "1.3.1", + "version": "1.3.2", "keywords": "display oled", "description": "Library for the SparkFun Micro OLED Breakout", "repository": diff --git a/library.properties b/library.properties index 197e759..35682dd 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SparkFun Micro OLED Breakout -version=1.3.1 +version=1.3.2 author=SparkFun Electronics maintainer=SparkFun Electronics sentence=Library for the SparkFun Micro OLED Breakout. From e2fe602dcc8a6a9cfe68997cf984e4c753fc9533 Mon Sep 17 00:00:00 2001 From: Patrik Jonsson Date: Sun, 4 Apr 2021 10:11:04 -1000 Subject: [PATCH 8/9] Exclude either by defining or by changing the default. --- src/SFE_MicroOLED.cpp | 45 ++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index 23e737e..ab8da9f 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -53,41 +53,60 @@ along with this program. If not, see . #define PROGMEM __attribute__((section(".progmem.data"))) #endif -// Add header of the fonts here. Comment as many as possible to conserve FLASH memory. -#include "util/font5x7.h" // Comment this line if you do not need the 5x7 font -#include "util/font8x16.h" // Comment this line if you do not need the 8x16 font -#include "util/fontlargenumber.h" // Comment this line if you do not need the large number font -#include "util/7segment.h" // Comment this line if you do not need the 7segment font -// The 31x48 font is handy, but uses a big chunk of flash memory - about 7k. -// If you want to use this font, uncomment the line below: -//#include "util/fontlargeletter31x48.h" +// Add header of the fonts here. Fonts that aren't included below are +// eliminated by the compiler. +#include "util/font5x7.h" +#include "util/font8x16.h" +#include "util/fontlargenumber.h" +#include "util/7segment.h" +#include "util/fontlargeletter31x48.h" #define MAXFONTS 5 // Do not change this line +// To save flash memory, change these to zeros for the fonts you do +// not want. In particular, the 31x48 font is handy, but uses a big +// chunk of flash memory - about 7k. It is excluded by default. +#ifndef INCLUDE_FONT_5x7 +#define INCLUDE_FONT_5x7 1 +#endif +#ifndef INCLUDE_FONT_8x16 +#define INCLUDE_FONT_8x16 1 +#endif +#ifndef INCLUDE_FONT_7SEG +#define INCLUDE_FONT_7SEG 1 +#endif +#ifndef INCLUDE_FONT_LARGENUMBER +#define INCLUDE_FONT_LARGENUMBER 1 +#endif +#ifndef INCLUDE_FONT_LARGELETTER +#define INCLUDE_FONT_LARGELETTER 0 +#endif + + // Add the font name as declared in the header file. Remove as many // as possible to conserve FLASH memory. const unsigned char *MicroOLED::fontsPointer[] = { -#ifdef FONT5X7_H +#if INCLUDE_FONT_5x7 font5x7, #else 0x0, #endif -#ifdef FONT8X16_H +#if INCLUDE_FONT_8x16 font8x16, #else 0x0, #endif -#ifdef FONT7SEGMENT_H +#if INCLUDE_FONT_7SEG sevensegment, #else 0x0, #endif -#ifdef FONTLARGENUMBER_H +#if INCLUDE_FONT_LARGENUMBER fontlargenumber, #else 0x0, #endif -#ifdef FONTLARGELETTER31X48_H +#if INCLUDE_FONT_LARGELETTER fontlargeletter31x48 #else 0x0 From 5beb1c10c597f57e245a7a8061f2b53021d84300 Mon Sep 17 00:00:00 2001 From: PaulZC Date: Mon, 5 Apr 2021 07:48:55 +0100 Subject: [PATCH 9/9] Added extra comments. Changed excluded font pointers to NULL --- .../Example11_BigFont/Example11_BigFont.ino | 8 ++- src/SFE_MicroOLED.cpp | 55 ++++++++++--------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/examples/Example11_BigFont/Example11_BigFont.ino b/examples/Example11_BigFont/Example11_BigFont.ino index f63fcc6..3300479 100644 --- a/examples/Example11_BigFont/Example11_BigFont.ino +++ b/examples/Example11_BigFont/Example11_BigFont.ino @@ -5,8 +5,10 @@ This sketch demonstrates how to use the Large Letter 31x48 font. This font is disabled by default. To enable it, you need to edit - SFE_MicroOLED.cpp and uncomment the line which says: - #include "util/fontlargeletter31x48.h" + SFE_MicroOLED.cpp and change line 85 (or thereabouts) from: + #define INCLUDE_FONT_LARGELETTER 0 + to: + #define INCLUDE_FONT_LARGELETTER 1 Hardware Connections: This example assumes you are using Qwiic. See the SPI examples for @@ -58,7 +60,7 @@ void setup() if (oled.setFontType(4) == 0) // Set font to type 4 (fontlargeletter31x48) { Serial.println(F("Could not enable font 4 (fontlargeletter31x48)!")); - Serial.println(F("Have you uncommented #include \"util/fontlargeletter31x48.h\" in SFE_MicroOLED.cpp?")); + Serial.println(F("Have you changed the #define INCLUDE_FONT_LARGELETTER to 1 in SFE_MicroOLED.cpp?")); Serial.println(F("Freezing...")); while (1) ; // Do nothing more diff --git a/src/SFE_MicroOLED.cpp b/src/SFE_MicroOLED.cpp index ab8da9f..c688070 100644 --- a/src/SFE_MicroOLED.cpp +++ b/src/SFE_MicroOLED.cpp @@ -53,63 +53,66 @@ along with this program. If not, see . #define PROGMEM __attribute__((section(".progmem.data"))) #endif -// Add header of the fonts here. Fonts that aren't included below are -// eliminated by the compiler. -#include "util/font5x7.h" -#include "util/font8x16.h" -#include "util/fontlargenumber.h" -#include "util/7segment.h" -#include "util/fontlargeletter31x48.h" - -#define MAXFONTS 5 // Do not change this line - -// To save flash memory, change these to zeros for the fonts you do -// not want. In particular, the 31x48 font is handy, but uses a big +// Add header of the fonts here. +// Fonts that aren't included the section below are excluded by the compiler. +#include "util/font5x7.h" // Font 0 +#include "util/font8x16.h" // Font 1 +#include "util/7segment.h" // Font 2 +#include "util/fontlargenumber.h" // Font 3 +#include "util/fontlargeletter31x48.h" // Font 4 (excluded by default - see below) + +#define MAXFONTS 5 // Do not change this line - except when _adding_ new fonts + +// To save flash memory, change these to zeros for the fonts you want to exclude. +// In particular, the 31x48 font is handy, but uses a big // chunk of flash memory - about 7k. It is excluded by default. +// +// If you are compiling the code using your own makefile, you can use compiler flags to include +// or exclude individual fonts. E.g.: -DINCLUDE_FONT_LARGELETTER=1 or -DINCLUDE_FONT_LARGENUMBER=0 #ifndef INCLUDE_FONT_5x7 -#define INCLUDE_FONT_5x7 1 +#define INCLUDE_FONT_5x7 1 // Change this to 0 to exclude the 5x7 font #endif #ifndef INCLUDE_FONT_8x16 -#define INCLUDE_FONT_8x16 1 +#define INCLUDE_FONT_8x16 1 // Change this to 0 to exclude the 8x16 font #endif #ifndef INCLUDE_FONT_7SEG -#define INCLUDE_FONT_7SEG 1 +#define INCLUDE_FONT_7SEG 1 // Change this to 0 to exclude the seven segment font #endif #ifndef INCLUDE_FONT_LARGENUMBER -#define INCLUDE_FONT_LARGENUMBER 1 +#define INCLUDE_FONT_LARGENUMBER 1 // Change this to 0 to exclude the large number font #endif #ifndef INCLUDE_FONT_LARGELETTER -#define INCLUDE_FONT_LARGELETTER 0 +#define INCLUDE_FONT_LARGELETTER 0 // Change this to 1 to include the large letter font #endif -// Add the font name as declared in the header file. Remove as many -// as possible to conserve FLASH memory. +// Add the font name as declared in the header file. +// Exclude as many as possible to conserve FLASH memory. const unsigned char *MicroOLED::fontsPointer[] = { #if INCLUDE_FONT_5x7 font5x7, #else - 0x0, + NULL, #endif #if INCLUDE_FONT_8x16 font8x16, #else - 0x0, + NULL, #endif #if INCLUDE_FONT_7SEG sevensegment, #else - 0x0, + NULL, #endif #if INCLUDE_FONT_LARGENUMBER fontlargenumber, #else - 0x0, + NULL, #endif #if INCLUDE_FONT_LARGELETTER fontlargeletter31x48 #else - 0x0 + NULL #endif }; @@ -1035,7 +1038,7 @@ uint8_t MicroOLED::getTotalFonts(void) uint8_t totalFonts = 0; for (uint8_t thisFont = 0; thisFont < MAXFONTS; thisFont++) { - if (fontsPointer[thisFont] > 0) + if (fontsPointer[thisFont] != NULL) totalFonts++; } return (totalFonts); @@ -1056,7 +1059,7 @@ uint8_t MicroOLED::getFontType(void) */ uint8_t MicroOLED::setFontType(uint8_t type) { - if ((type >= MAXFONTS) || !fontsPointer[type]) + if ((type >= MAXFONTS) || (fontsPointer[type] == NULL)) return false; fontType = type;