Help with Subclass Adafruit_ILI9341 libary

I would like to make the functions in the adafruit library available to other libraries in a project. I would like for other libraries to be able to write to the LCD directly. In order to do this I am attempting to subclass the Adafruit libary.

I am following the example shown here
https://www.cs.bu.edu/teaching/cpp/inheritance/intro/

here is sample of what I am attempting

.h file

//#ifndef H_MINICON_
//#define H_MINICON_

#include <Arduino.h> //needed for Serial.println
#include <string.h> //needed for memcpy
#include <Adafruit_ILI9341.h> // Hardware-specific library
#include "Arduino.h"
#include "Print.h"

//#include "WProgram.h"

#include <Adafruit_GFX.h>
#include <avr/pgmspace.h>

//#define TFT_CS 53
//#define TFT_DC 77

class MiniConsole : public Adafruit_ILI9341 {

	public:

		MiniConsole(int8_t CS1);
		void miniScreenConsole(char *miniConData);

	private:

		int _pin;
};

here is the .cpp file

#include <MiniConsole.h>
#include <Arduino.h>
#include <avr/pgmspace.h>
#include <TouchScreen.h>
#include <string.h>

//#include <Adafruit_GFX.h>    // Core graphics library
//#include <Adafruit_ILI9341.h> // Hardware-specific library
//#include <Adafruit_STMPE610.h> // touch screen library

MiniConsole::MiniConsole(int8_t cs1) : Adafruit_ILI9341(53, 77){
	_pin = cs1;
};

void MiniConsole::miniScreenConsole(char *miniConData) {
	Serial.println("testetst");
	Adafruit_ILI9341::drawRect(80, 140, 175, 90, ILI9341_BLUE);
	Adafruit_ILI9341::fillRect(80, 140, 175, 90, ILI9341_WHITE);

	Adafruit_ILI9341::setCursor(0, 142);
	Adafruit_ILI9341::setTextColor(ILI9341_BLUE);
	Adafruit_ILI9341::setTextSize(1);
	Adafruit_ILI9341::print("TEST test");
}

Program complies however, once I call “miniScreenConsole” the program freezes after “Serial.println(“testetst”);” Not sure what is incorrect here.

Also if there is a more straight forward way to make the functions in the Adafruit library available/accessible to other libraries please let me know.

Thanks

Not sure what is incorrect here.

I find it difficult to believe that all the Adafruit_ILI9341 methods are static. If they truly are, then there is no point in having a class.

PaulS:
I find it difficult to believe that all the Adafruit_ILI9341 methods are static. If they truly are, then there is no point in having a class.

No I do not believe that they are static. How does that play into in issue? Are you suggesting that I make them all static so the functions can be called even if no objects of the class exist? I am new to classes and inheritance between them so I am not fully grasping your comment. but this is all I can gather from my reading online.

class Adafruit_ILI9341 : public Adafruit_GFX {

 public:

  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _MOSI, int8_t _SCLK,
   int8_t _RST, int8_t _MISO);
  Adafruit_ILI9341(int8_t _CS, int8_t _DC, int8_t _RST = -1);

  void     begin(void),
           setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1),
           pushColor(uint16_t color),
           fillScreen(uint16_t color),
           drawPixel(int16_t x, int16_t y, uint16_t color),
           drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
           drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
           fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
             uint16_t color),
           setRotation(uint8_t r),
           invertDisplay(boolean i);
  uint16_t color565(uint8_t r, uint8_t g, uint8_t b);


  /* These are not for current use, 8-bit protocol only! */
  uint8_t  readdata(void),
    readcommand8(uint8_t reg, uint8_t index = 0);
  /*
  uint16_t readcommand16(uint8_t);
  uint32_t readcommand32(uint8_t);
  void     dummyclock(void);
  */  

  void     spiwrite(uint8_t),
    writecommand(uint8_t c),
    writedata(uint8_t d),
    commandList(uint8_t *addr);
  uint8_t  spiread(void);

 private:
  uint8_t  tabcolor;



  boolean  hwSPI;
#if defined (__AVR__)
  uint8_t mySPCR;
  volatile uint8_t *mosiport, *clkport, *dcport, *rsport, *csport;
  int8_t  _cs, _dc, _rst, _mosi, _miso, _sclk;
  uint8_t  mosipinmask, clkpinmask, cspinmask, dcpinmask;
#elif defined (__arm__)
    volatile RwReg *mosiport, *clkport, *dcport, *rsport, *csport;
    uint32_t  _cs, _dc, _rst, _mosi, _miso, _sclk;
    uint32_t  mosipinmask, clkpinmask, cspinmask, dcpinmask;
#endif
};

#endif

No I do not believe that they are static. How does that play into in issue?

If the methods are not static, you can't use the scope resolution operator ( :: ) to call the methods. You UST create an instance of the class, and call the methods on the instance.

Are you suggesting that I make them all static so the functions can be called even if no objects of the class exist?

Absolutely not.

PaulS:
If the methods are not static, you can't use the scope resolution operator ( :: ) to call the methods. You UST create an instance of the class, and call the methods on the instance.

This was my original attempt.
I would like the methods/member functions in the Adafruit library to be available to other libraries in the project. (other .cpp files) So I included the needed "include" lines for the adafruit library, and created an instance of the class in the .cpp file with a unique object name specifically for that instance.

Adafruit_ILI9341 tft1 = Adafruit_ILI9341(53, 77);

I then attempted to access the members of this instance with the line

tft1.fillRect(80, 140, 175, 90, 0xFFFF);

where "fillRect" is a member of the class Adafruit_ILI9341 .

All this takes place in another libraries .cpp file. The code complies but freezes when the tft1.fillRect is called.

I have an other instance of the class with the variable name tft in the main .ino file that works fine.

Again I am very new to this area of C so there is a good chance I am way off.

any thoughts on how to get this working?

Inside the subclass you can just call the routines, the this pointer is implicit.
So it should work like this

void MiniConsole::miniScreenConsole(char *miniConData) {
	Serial.println("testetst");
	drawRect(80, 140, 175, 90, ILI9341_BLUE);
	fillRect(80, 140, 175, 90, ILI9341_WHITE);
	setCursor(0, 142);
	setTextColor(ILI9341_BLUE);
	setTextSize(1);
	print("TEST test");
}

Whandall:
Inside the subclass you can just call the routines, the this pointer is implicit.

Thanks for the reply, I tried this and it still freezes

As you are hiding the 'it' that freezes, you are on your own.

Whandall:
As you are hiding the ‘it’ that freezes, you are on your own.

Sorry, I did not set out to hide anything. Here is the code. Program freezes after the line, Serial.println(“testetst”); in the .cpp file.

#include <Wire.h> 
#include <avr/pgmspace.h>
#include <MemoryFree.h>
#include <TouchScreen.h>
#include <string.h>
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ILI9341.h> // Hardware-specific library
#include <Adafruit_STMPE610.h> // touch screen library
#include <SPI.h>
#include <SD.h>
#include <Flash.h> // used for easy progmem
#include <Wifi232.h>
#include <MiniConsole.h>

#define TS_MINX 230
#define TS_MINY 280
#define TS_MAXX 3800
#define TS_MAXY 3600
boolean touchScreenFlag = true;  // flag that control touch screen

								 // The STMPE610 uses hardware SPI on the shield, and #8
#define STMPE_CS 79
Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);


#define TFT_CS 53
#define TFT_DC 77

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(TFT_CS, TFT_DC);


MiniConsole mini = MiniConsole(1);

#define SD_CS A5 //PF5 J27
// this runs all the setup functions
void setup() {
	Serial.begin(115200);
	LCD_setup();
	mini.miniScreenConsole("testData_");
}

void loop() {};

void LCD_setup() {
	tft.begin();
	tft.fillScreen(ILI9341_BLUE);
	if (!ts.begin()) {
		Serial.println(F("Couldn't start touchscreen controller"));
		while (1);
	}
	Serial.print(F("Initializing SD card..."));
	if (!SD.begin(SD_CS)) {
		Serial.println(F("failed!"));
	}
	Serial.println(F("OK!"));
	tft.setRotation(1);
}

Why do you create so many (6 unoptimized IMHO) TFT-objects in such a strange way?
What is that unused pin in your subclass good for?
Why didn’t you include a constructor that passes the pins to the base-class instead of constants?
This

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
Adafruit_ILI9341 tft2 = Adafruit_ILI9341(TFT_CS, TFT_DC);
MiniConsole mini = MiniConsole(1);

should beMiniConsole mini(1);and all occurrences of tft and tft2 replaced by mini.
BTW I think using pin 1 can create trouble with the serial communication.

tft2 was left over from when i was attempting to get around the multiple class errors I was getting.
pin 1 is not used.
And regarding the constructor I was following the example in the Adafruit library.

I did make the suggested changes and the program still freezes at the same location.

I did make the suggested changes and the program still freezes at the same location.

By now, you should have figured out that you need to post your modified code, so that we can see that you made the changes correctly. ALL of your code.