NEW Adafruit_mfGFX multifont library


#81

cool Thanks, working good!


#82

Basic newbie question.
When a Photon program gets compiled, does it just include the fonts that are actually used by the program, or does it compile the full ‘fonts’ library?


#83

In the fonts.h file you’ll comment/uncomment the fonts you wish to keep out/use.


#84

Thanks!
It looks like both the ‘fonts.h’ and ‘fonts.cpp’ files need to be modified and kept in sync in order to successfully compile and minimize the footprint. I almost feels easier and cleaner to add to empty template files as needed!

It works, just comment out the lines indicated in the fonts.h file as directed in the file itself. (Embarrassed)

Thanks again for the answer.


#85

Hi all

At risk of getting slightly off topic here, does anyone have much of an idea of how much work it would require to add support for a 128x64 SSD1325 display to this library?
I’ve had a go at trying to understand the u8glib (which supports the SSD1325) and a feeble attempt at trying to port the arduino version to Particle…
Would I be better to understand the differences between the datasheet of the SSD1306 and SSD1325 and try to replace the SSD1306 commands etc. with the SSD1325 ones?
Thanks for all the great work already, any help would be much appreciated!


#86

@peekay123, is there a way to determine the character width via function? I need to center letters inside a cirecle and each character is a different width.

thanks


#87

@wesner0019, there isn’t but it could be added. :smile:


#88

@peekay123, what would that take to add something like that?


#89

@wesner0019, I think the best approach would be to pass a char array pointer to a function which then returns the total width of the string in the array. Let me think on it. :smile:


#90

@peekay123, do you know of a way to show simple animations with this library?


#91

@wesner0019, I’ve add a simple function to mfGFX that will return the width of the character you pass to it, including the kern value which is 1 by default. I am having issues posting it on the IDE but the update will be there soon.

For animations, the library itself supports drawBitmap() but no screen buffering (too much RAM). So to animate, you could draw successive bitmaps of the same size, each overwriting the other.
:smile:


#92

@wesner0019, the new mfGFX library is available on the web IDE :smile:


#93

@peekay123, awesome! do you have a git address? I’ve made some changes to the mfGFX to meet other needs so I’d like to see just what changed and add this into my library


#94

@peekay123, I’ve added the two below functions to this library. The x allows to use println and not having to worry about proper y spacing or visa versa.

void Adafruit_GFX::setCursorX(int16_t x) {
  cursor_x = x;
}

void Adafruit_GFX::setCursorY(int16_t y) {
  cursor_y = y;
} 

#95

@peekay123 Font width calculation? FANTASTIC!
Can you give us an example of how to calculate the width of a string of characters?
(edit) I tried doing this myself, but no matter what character size I send, it comes back as width = 3. I did get some fantastic fonts going otherwise… great work on the library; Particle would be lost without the "Elites’ keeping things going!


#96

@Awake, the width is dependent on a) The currently active font and b) The character value you specify. To calculate a string of chars, simply loop through each char in the string and total their widths.


#97

Thanks.
I’ll try again. Good learning exercise…


#98

I seem to have a basic misunderstanding of how the charWidth function is supposed to work.
The code below will not compile, because the first charWidth call is incorrect.
If I fix it so it compiles, everything comes out the same width (3), even though I can visually see that it’s different.

#define dc   D0 // May be listed as 'A0' instead of 'dc' on the display. Data / Command. (must use thus pin)
#define rst  NO_RST_PIN // Connect to RST on Photon regardless
// Display LED to +3.3V
// Display SCK to A3 (must use this print)
// Display MOSI may be shown as SDA, connect to A5 (must use this pin)
// Display GND to GND
// Display VCC to +3.3V

#include "Adafruit_mfGFX.h"    // Core graphics library
#include "Adafruit_ST7735.h"   // Hardware-specific library
#include <math.h>
#include "application.h"
#include "HttpClient.h"

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst); // hardware spi

void setup() {
  delay (10000);
  Serial.begin (9600);
  tft.setFont(COMICS_8);
  Serial.println (tft.charWidth("."));
  Serial.println (tft.charWidth(atoi("8")));
  delay (2000);
}

void loop(){
}

#99

@Awake, I’m not sure how you even compiled the code as it threw some errors when I tried to compile it, exactly where I expected. In these two lines:

  Serial.println (tft.charWidth("."));
  Serial.println (tft.charWidth(atoi("8")))

You specify a string by using double quotes instead of a char by using single quotes. This is where the compiler threw the error. A string always includes an ending NULL character. Also atoi("8") will return the integer value of the string “8”. I have no idea why you are doing that!!!

Here is how the code should be:

  unsigned char c = '.';
  Serial.println (tft.charWidth(c));
  Serial.println (tft.charWidth('8'));

#100

Thanks again!
I used atoi out of desperation in an attempt to get it to compile, since I was getting (as you so wonderfully elucidate above), I was getting type conversion errors. And when using atoi it compiles!

So the problem was using a double quote instead of a single quote even though I am dealing with characters all along. Almost sounds like a programmers plot to keep the riff-raff out by making things 'except’ional.! :smile:

If nothing else, I bring a beginners perspective to the forum!