Is there a way to add a font library to TFT library

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
murfmv
 
Posts: 26
Joined: Fri Aug 16, 2013 1:24 pm

Is there a way to add a font library to TFT library

Post by murfmv »

I'm trying to turn the TFT into a Keypad, but need bigger numbers. I've found various libraries with bigger numbers an them. Is there a way to add a font library the TFT library?

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to add a font library to TFT library

Post by adafruit_support_bill »

The font is defined in clcdfont.cpp in the GFX library. https://github.com/adafruit/Adafruit-GF ... glcdfont.c
There are some related constants to specify the size of each character. See the drawchar() function in GFX.cpp https://github.com/adafruit/Adafruit-GF ... it_GFX.cpp

User avatar
murfmv
 
Posts: 26
Joined: Fri Aug 16, 2013 1:24 pm

Re: Is there a way to add a font library to TFT library

Post by murfmv »

Hi Bill,
I need help defining the new font so I can call it in a tft.println code Hennings said I can put the Hallfetica_normal font right in the folder, but I see that it creating all kinds of errors that I need help with

Code: Select all

//  REMOTE CONTROLLER
// NOTE CAUTION THE AP CANNOT BE SENDING DATA TO RX (UNO) WHEN UPLOADING SOFTWARE THEY INTERFERE
// OK IF THE RECIEVE DATA IS ON A DIFFERENT RX 1,2, OR 3 (MEGA)
//  Serial Remote B1_0 Killer Serial Remote Works with AP B1 and later
// V B1_1 changed Serial1 baud rate to 28800
// V B1_3 incorporating TFT screen
// V C1 Use with C series of GPS and Autopilot. got the serial remote TFT working.  Changed how I get Easy Transfer data
      // use if(ET.receiveData()) before trying to read data.
// V C2  Added more data. new version so I didn't lose previous version
// V C3 C2 uploaded to dopbox, C3 general refinement
// C4  added multiple screen structure
// D Added int MSG to data uploaded.
// Hallfetica_normal(autopilot.c) (C)2010 by Henning Karlsen
// Font Size	: 16x16
// Memory usage	: 3044 bytes
// # characters	: 95


#include <EasyTransfer.h>
#include <Keypad.h>
#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

// For Hallfetica_normal font
#ifdef __AVR__
 #include <avr/pgmspace.h>
#else
 #define pgm_read_byte(addr) (*(const unsigned char *)(addr))
#endif


Hallfetica_normal::Hallfetica_normal(int16_t w, int16_t h):
   //uint8_t autopilot[3044] PROGMEM={};
  WIDTH(w), HEIGHT(h)
{
  _width    = WIDTH;
  _height   = HEIGHT;
  rotation  = 0;
  cursor_y  = cursor_x    = 0;
  textsize  = 1;
  textcolor = textbgcolor = 0xFFFF;
  wrap      = true;
}

// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);



boolean Print_ET2data = 1;// 1 = print, 0 no print

//  KEYPAD SETUP
const byte ROWS = 4; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'*','0','#'}
};
byte rowPins[ROWS] = {23,25,27,29,}; //connect to the row pinouts of the keypad  STANDARD
byte colPins[COLS] = {31,33,35}; //connect to the column pinouts of the keypad  STANDAR
//byte rowPins[ROWS] = {43,33,35,39}; //connect to the row pinouts of the keypad  JACK'S KEYPAD
//byte colPins[COLS] = {41,45,37}; //connect to the column pinouts of the keypad  JACK'S KEYPAD
//byte rowPins[ROWS] = {45,43,41,39}; //connect to the row pinouts of the keypad  membrane KEYPAD
//byte colPins[COLS] = {37,35,33}; //connect to the column pinouts of the keypad  membrane KEYPAD
char key = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

/****************  EASY TRANSFER 2  START****************************************/

// Set up for Easy Transfer to receive GPS data
 
 //create object
  EasyTransfer ET2; 
/**********************************************************************************/  
 
boolean NEMA_sentence = false;
boolean GPRMC_fix = false;
boolean GPAPB_fix = false;
String GPS_status= "NO GPS";
float course;
float course_to_steer; 
String CTS_MorT = "";
float SOG; 
float course_error;
//float tracking_error;
float AVG_tracking_error;
float MagVar; // Magnetic Variation East is plus and West is Minus
float heading_to_steer=0; //  see PID
float XTE;
float XTE_differential_error;
float XTE_integral_error;
float XTE_course_correction;
String XTE_LR="";
String XTE_unit="";
String Waypoint_next="";
float heading;
String Origin_Waypoint;
float Bearing_origin_to_destination=0;
String BOD_MorT = "";
float Bearing_to_destination;
float Range_Destination;
long UTC;
long Date;
float Next_Turn;
float bearingrate;
float rudder_position;
String Mode;
int screen = 1;
boolean key_pressed;
int MSG;  // Message number set in the AP and displaed on TFT. used integer to minimize  ez transfer data.
String Message;
boolean Print_ETtime = 0;  // prints Easy Transfer loop time 1 on 0 off
int line;  
/**********************************************************************************/ 
  struct RECEIVE_DATA_STRUCTURE{
    //put your variable definitions here for the data you want to receive
    //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  float course;
  float SOG;
  float SD_MagVar;
  float XTE;
  char Waypoint_next[11]; 
  float Bearing_origin_to_destination;
  float Bearing_to_destination;
  float Range_Destination;
 // long UTC;
  float Next_Turn;
  float heading;
  float heading_to_steer;
  float course_to_steer;
  float bearingrate;
  float rudder_position;
  char Mode[5];
  int MSG;
  
  };  //  end receive data structure
  
  //give a name to the group of data
  RECEIVE_DATA_STRUCTURE ET2data;
  

/****************  EASY TRANSFER 2  END******************************************/

void setup() 
{
  Serial.begin(57600);  // Serial connection to Serial Monitor
  Serial1.begin(57600); // Serial Key pad to external MEGA 
  keypad.addEventListener(keypadEvent); //add an event listener for this keypad  
   //keypad.setDebounceTime(200);
  ET2.begin(details(ET2data), &Serial1);  // RECEIVE ONLY
  tft.begin();
  //tft.setRotation(2);  // this command will rotate display 180 deg
  tft.fillScreen(ILI9341_BLACK);
  tft.setRotation(2); // I think it is 0,1,2,3
  Print_Screen_1();
  Print_Screen();
  key_pressed = true;
  Mode = "OFF";
  uint8_t autopilot[3044] PROGMEM={};

}

void loop()
{
   KEYPAD();
   if(ET2.receiveData()) 
   {
    Recieve_ET2Data();
   }
   
}

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to add a font library to TFT library

Post by adafruit_support_bill »

Hennings said I can put the Hallfetica_normal font right in the folder
I don't know Hennings or the tutorial you are referring to. If you are using our TFTLCD library, you will need the font in a binary format that is compatible with the underlying GFX library.

User avatar
murfmv
 
Posts: 26
Joined: Fri Aug 16, 2013 1:24 pm

Re: Is there a way to add a font library to TFT library

Post by murfmv »

Enclosed is the file from Henning Karlsen
I just tried adding to your library and got somewhat, but exceeded my brain
Attachments
hallfetica_normal.c
(15.89 KiB) Downloaded 122 times

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to add a font library to TFT library

Post by adafruit_support_bill »

I don't know what the format of your file is. The default font in the GFX library is 5x7, with each character stored as a 5-bytes, each representing one vertical column of character pixels. The Adafruit_GFX::write() and Adafruit_GFX::drawChar() are based the data being stored in this form.

If the HenningKarlsen file is organized the same way, you can probably use it. But you can't simply include it.
First you would need to replace the table in glcdfont.c with your table.
Then, since the characters are a different size, you will have to adjust the character size related constants in those two functions in Adafruit_GFX::write() and Adafruit_GFX::drawChar() to match.

User avatar
murfmv
 
Posts: 26
Joined: Fri Aug 16, 2013 1:24 pm

Re: Is there a way to add a font library to TFT library

Post by murfmv »

At some point I wanted to use both font tables. I will try just replacing the glcd font and see what happens, but then I need to insert a way to call either font or set up my font locally and have some voids to write characters from. I don't think I have the knowledge yet.

Thanks for all your help

User avatar
adafruit_support_bill
 
Posts: 88086
Joined: Sat Feb 07, 2009 10:11 am

Re: Is there a way to add a font library to TFT library

Post by adafruit_support_bill »

If you want to use both of them, you would need to give one a different name because you can't have 2 arrays named 'font'.

Switching between between them on-the-fly adds some more complexity to write() and drawchar(). Make sure you have a good understanding of how drawchar() works before you try to change it.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”