Go Down

Topic: tft.println missing in my library  (Read 491 times) previous topic - next topic

smitmasibus

Mar 16, 2018, 08:23 am Last Edit: Mar 16, 2018, 08:35 am by smitmasibus
 Dear All,

I am using the GFX library(https://github.com/adafruit/Adafruit-GFX-Library) for the TFT display of adafruit based TF display shield..

I am going through the library but i cant fine the println function in the Adafruit_GFX.cpp and its .h file can anyone find the function of println under that library..


david_prentice

Google can't find any GLX library.    Nor a TF display.

Any library that inherits Adafruit_GFX class will also inherit the Print class.
Hence you can use all the print() and println() methods.

If you have a problem with a library,   go to the IDE Library Manager to identify the library version.
Quote a link to the specific library if not supported by the Library Manager.

David.

smitmasibus

sorry david..

its typographic error its GFX not GLX

found under https://github.com/adafruit/Adafruit-GFX-Library

pert

The relevant part of the Adafruit library is the write function implementation:
https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L809-L858

Then you can find println in the Arduino core library for your board. For Arduino AVR Boards that is here:
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Print.cpp

david_prentice

Seriously.    Check the versions with the Library Manager.

It is always preferable to install libraries with the Manager.    This will ensure that you have "official" versions.     Using some random hacked library that you found on the Internet is unwise (tm).

The Adafruit_GFX library is probably ok.    But there are hundreds of hacked "Adafruit_TFTLCD" libraries that make no attempt to use a different class name.

Please quote the libraries and versions as reported by the Library Manager.

David.

smitmasibus

I have question rearding where in Adafruit_GFX.cpp or Adafruit_ILI9341.cpp the println function function found!!!


Suppose i write the code to print my name in the TFT LCD now one should code like below code

Code: [Select]

#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
// For the Adafruit shield, these are the default.
#define TFT_DC 9
#define TFT_CS 10

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
  // put your setup code here, to run once:

  tft.begin();

  tft.println("Hello World!");

}

void loop() {
  // put your main code here, to run repeatedly:

}


Now this will perfectly print Hello World! to the LCD but i have doubt that how one should find the code beneath the println of the TFT i didnt find bcoz i want to explore the println code for playing around with it but i didnt find any println under #include "Adafruit_GFX.h" or #include "Adafruit_ILI9341.h" and its cpp files!!

Can any one explain me why is it so?

pert

The relevant part of the Adafruit library is the write function implementation:
https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.cpp#L809-L858

Then you can find println in the Arduino core library for your board. For Arduino AVR Boards that is here:
https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/Print.cpp


pert

This is a complex topic. If you're interested in learning then you're going to need to spend some time to understand the code of the Print class. If you're not willing to make that effort then don't worry about it. The library will work fine whether you understand all the underlying details or not. The choice is yours.

The idea behind the Print class is to put the conversions of all these different common types in one place where they can be shared between all the code that needs them instead of being duplicated a zillion times. All the code that inherits from the Print class needs to do is define a write function and the Print class handles all the conversions that feed characters into that write function. So you have the various variants of println defined in Print.cpp and then the generic display specific write function defined in the Adafruit_GFX.cpp. In fact other display libraries may overwrite that write function definition with their own version if desired but that is not the case with Adafruit_ILI9341.

smitmasibus

This is a complex topic. If you're interested in learning then you're going to need to spend some time to understand the code of the Print class. If you're not willing to make that effort then don't worry about it. The library will work fine whether you understand all the underlying details or not. The choice is yours.

The idea behind the Print class is to put the conversions of all these different common types in one place where they can be shared between all the code that needs them instead of being duplicated a zillion times. All the code that inherits from the Print class needs to do is define a write function and the Print class handles all the conversions that feed characters into that write function. So you have the various variants of println defined in Print.cpp and then the generic display specific write function defined in the Adafruit_GFX.cpp. In fact other display libraries may overwrite that write function definition with their own version if desired but that is not the case with Adafruit_ILI9341.
So you mean to say that the write function in any .cpp file will inherate the Print class automatically and used by the same?

I want to learn this bcoz i want this library to be used in different controller not in the arduino as the ardunino is good for proto of the Display but i want to use for the other controller and use this open library for that so i have to learn how they do this  println !! so that i can implement the same using other controller!

david_prentice

The official Adafruit_ILI9341 library works fine with println()
Please quote what versions and where you obtained your libraries.

"doubt" suggests that you come from India.
Make sure that you install official libraries from Adafruit i.e. U.S.A.

We are happy to show you how C++ class inheritance works.   But only when you have installed genuine Adafruit libraries.

David.

pert

It doesn't happen automatically. You need to specify the inheritance:
https://github.com/adafruit/Adafruit-GFX-Library/blob/master/Adafruit_GFX.h#L12
Code: [Select]
class Adafruit_GFX : public Print {
More information:
http://www.cplusplus.com/doc/tutorial/inheritance/

david_prentice

Yes,   of course you have to specify the class inheritance.  e.g. GFX inherits Print
And Adafruit_ILI9341 inherits Adafruit_GFX

So any Adafruit_ILI9341 object can perform all of the Print, GFX, ILI9341 methods.

David.

Go Up