Go Down

Topic: Problems creating a library (Read 1 time) previous topic - next topic

PaulS

I'm confused. I thought we were trying to make the class aware of myGLCD. That is not an instance of UTFT or UTouch, is it?


cowasaki


I'm confused. I thought we were trying to make the class aware of myGLCD. That is not an instance of UTFT or UTouch, is it?




Sorry I mixed it up, I changed the name aGLCD to aUTFT....  It is changed back now so it is aGLCD

So the error is:


TFTlib.cpp: In constructor 'TFTlib::TFTlib()':
TFTlib.cpp:11: error: uninitialized reference member 'TFTlib::aGLCD'
TFTlib.cpp:11: error: uninitialized reference member 'TFTlib::aUTouch'

The extra line is because I need to do the same with the UTouch library i.e.:


Code: [Select]
void TFTlib::setGLCDInstance(UTFT &theUTFT){
   aGLCD = theUTFT;
}

void TFTlib::setTouchInstance(UTouch &theTouch){
   aUTouch = theTouch;
}

PaulS

OK. You might be able to set the reference to NULL, until the proper method is called.

Or, change the references to pointers. That requires a different way of dereferencing (aGLCD-> instead of aGLCD.).

cowasaki


OK. You might be able to set the reference to NULL, until the proper method is called.

Or, change the references to pointers. That requires a different way of dereferencing (aGLCD-> instead of aGLCD.).


Paul,

OK thanks, that makes sense but I don't actually know how to do either.....

PaulS

Header:
Code: [Select]
GLCD *pGLCD;

void setGLCDInstance(GLCD *pSomeInstance);


Source:
Code: [Select]
void setGLCDInstance(GLCD *pSomeInstance)
{
   pGLCD = pSomeInstance;
}


Sketch:
Code: [Select]
myTFTLib.setGLCDInstance(&myGLCD);

Source methods:
Code: [Select]
pGCLD->MakeItDoSomething();

cowasaki

Thanks Paul,


1)  I've added:


  myTFTlin.setGLCDInstance(&myGLCD);
  myTFTlin.setTouchInstance(&myTouch);

to the sketch's setup() function.



2)  I've changed the .h files as follows:

Code: [Select]

#ifndef TFTlib_h
#define TFTlib_h

#include "Arduino.h"
#include "SPI.h"
#include <UTFT.h>
#include <UTouch.h>

#define maxbuttons 25
#define stateDrawn 1
#define statePressed 2

class TFTlib{
  public:
    TFTlib();
    void setGLCDInstance(UTFT *pSomeInstance);
    void setTouchInstance(UTouch *pSomeInstance);
    void addButton(int buttonnumber,word x,word y,word xs,word ys,long colour,long borcolour,long textcolour,long presscolour,long presstextcolour,byte borwidth,String top,int xo,int yo);
    void drawButton(int buttonnumber);
    void drawButton_pressed(int buttonnumber);
    bool checkButton(word buttonnumber);
    int GUIbutton_x[maxbuttons];
    int GUIbutton_y[maxbuttons];
    int GUIbutton_xs[maxbuttons];
    int GUIbutton_ys[maxbuttons];
    int GUIbutton_xo[maxbuttons];
    int GUIbutton_yo[maxbuttons];
    long GUIbutton_colour[maxbuttons];
    long GUIbutton_borcolour[maxbuttons];
    long GUIbutton_textcolour[maxbuttons];
    long GUIbutton_pressedcolour[maxbuttons];
    long GUIbutton_pressedtextcolour[maxbuttons];
    int GUIbutton_borwidth[maxbuttons];
    String GUIbutton_top[maxbuttons];
    byte GUIbutton_currentstate[maxbuttons];
    UTFT    *pGLCD;
    UTouch  *pUTouch;

};

#endif




3)  I've changed the functions in the .cpp file:

Code: [Select]
void TFTlib::setGLCDInstance(UTFT *pSomeInstance){
   pGLCD = pSomeInstance;
}

void TFTlib::setTouchInstance(UTouch *pSomeInstance){
   pUTouch = pSomeInstance;
}




Re: Source methods: "pGCLD->MakeItDoSomething();"

Sorry I don't understand this.


&


What do I do with the functions i.e.:

   aGLCD.setColor((GUIbutton_pressedcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedcolour[buttonnumber]&0xFF));
    aGLCD.fillRoundRect (GUIbutton_x[buttonnumber],GUIbutton_y[buttonnumber], GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber]);

or


  int current_x = aUTouch.getX();

PaulS

Quote
Re: Source methods: "pGCLD->MakeItDoSomething();"

Sorry I don't understand this.


&


What do I do with the functions i.e.:

   aGLCD.setColor((GUIbutton_pressedcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedcolour[buttonnumber]&0xFF));

setColor is a way to make the aGLCD instance do something. aGLCD. becomes pGLCD->:

Code: [Select]
  pGLCD->setColor((GUIbutton_pressedcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedcolour[buttonnumber]&0xFF));

cowasaki

Thanks,  changed the entries but I'm now getting this error:

UI_lib_TEST.ino: In function 'void setup()':

GUI_lib_TEST:20: error: 'class TFTlib' has no member named 'setGLCDInstance'
GUI_lib_TEST:21: error: 'class TFTlib' has no member named 'setTouchInstance'



in relation to the lines:

myTFTlib.setGLCDInstance(&myGLCD);
 myTFTlib.setTouchInstance(&myTouch);



if I remark out the two lines I get numerous errors:

/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp: In member function 'void TFTlib::drawButton(int)':
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp:30: error: 'myGLCD' was not declared in this scope
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp:30: error: 'BigFont' was not declared in this scope
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp: In member function 'void TFTlib::drawButton_pressed(int)':
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp:45: error: 'myGLCD' was not declared in this scope
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp:45: error: 'BigFont' was not declared in this scope
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp: In member function 'bool TFTlib::checkButton(word)':
/Users/darren/Documents/Arduino/libraries/TFTlib/TFTlib.cpp:59: error: 'myTouch' was not declared in this scope



This is the .cpp file:

Code: [Select]

#include "SPI.h"
#include <UTFT.h>
#include <UTouch.h>
#include "TFTlib.h"
extern uint8_t BigFont[];


TFTlib::TFTlib(){
 for (byte i = 0; i < maxbuttons; i++) {GUIbutton_currentstate[i]=false;}
}

void TFTlib::setGLCDInstance(UTFT *pSomeInstance){
  pGLCD = pSomeInstance;
}

void TFTlib::setTouchInstance(UTouch *pSomeInstance){
  pUTouch = pSomeInstance;
}

void TFTlib::addButton(int buttonnumber,word x,word y,word xs,word ys,long colour,long borcolour,long textcolour,long presscolour,long presstextcolour,byte borwidth,String top,int xo,int yo){
 GUIbutton_x[buttonnumber]=x;
 GUIbutton_y[buttonnumber]=y;
 GUIbutton_xs[buttonnumber]=xs;
 GUIbutton_ys[buttonnumber]=ys;
 GUIbutton_xo[buttonnumber]=xo;
 GUIbutton_yo[buttonnumber]=yo;
 GUIbutton_colour[buttonnumber]=colour;
 GUIbutton_borcolour[buttonnumber]=colour;
 GUIbutton_textcolour[buttonnumber]=textcolour;
 GUIbutton_pressedcolour[buttonnumber]=presscolour;
 GUIbutton_pressedtextcolour[buttonnumber]=presstextcolour;
 GUIbutton_borwidth[buttonnumber]=borwidth;
 GUIbutton_top[buttonnumber]=top;
}

void TFTlib::drawButton(int buttonnumber){
 if (GUIbutton_currentstate[buttonnumber]!=stateDrawn){
   GUIbutton_currentstate[buttonnumber]=stateDrawn;
   pGLCD->setColor((GUIbutton_colour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_colour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_colour[buttonnumber]&0xFF));
   pGLCD->fillRoundRect (GUIbutton_x[buttonnumber],GUIbutton_y[buttonnumber], GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber]);
   pGLCD->setColor((GUIbutton_borcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_borcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_borcolour[buttonnumber]&0xFF));
   pGLCD->drawRoundRect (GUIbutton_x[buttonnumber],GUIbutton_y[buttonnumber],GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber]);
   pGLCD->setColor((GUIbutton_textcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_textcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_textcolour[buttonnumber]&0xFF));
   pGLCD->setBackColor((GUIbutton_colour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_colour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_colour[buttonnumber]&0xFF));
   pGLCD->print(GUIbutton_top[buttonnumber],GUIbutton_x[buttonnumber]+GUIbutton_xo[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_yo[buttonnumber]);
   pGLCD->setBackColor (0, 0, 0);
 }
}

void TFTlib::drawButton_pressed(int buttonnumber){
 if (GUIbutton_currentstate[buttonnumber]!=statePressed){
   GUIbutton_currentstate[buttonnumber]=statePressed;
   pGLCD->setColor((GUIbutton_pressedcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedcolour[buttonnumber]&0xFF));
   pGLCD->fillRoundRect (GUIbutton_x[buttonnumber],GUIbutton_y[buttonnumber], GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber]);
   pGLCD->setColor((GUIbutton_borcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_borcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_borcolour[buttonnumber]&0xFF));
   pGLCD->drawRoundRect (GUIbutton_x[buttonnumber],GUIbutton_y[buttonnumber],GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber]);
   pGLCD->setColor((GUIbutton_pressedtextcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedtextcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedtextcolour[buttonnumber]&0xFF));
   pGLCD->setBackColor((GUIbutton_pressedcolour[buttonnumber]&0xFF0000)/0x10000,(GUIbutton_pressedcolour[buttonnumber]&0xFFFF)/0x100,(GUIbutton_pressedcolour[buttonnumber]&0xFF));
   pGLCD->print(GUIbutton_top[buttonnumber],GUIbutton_x[buttonnumber]+GUIbutton_xo[buttonnumber],GUIbutton_y[buttonnumber]+GUIbutton_yo[buttonnumber]);
   pGLCD->setBackColor (0, 0, 0);
 }
}

bool TFTlib::checkButton(word buttonnumber){
 int current_x = pUTouch->getX();
 int current_y = pUTouch->getY();
 if ( (current_x>GUIbutton_x[buttonnumber]) && (current_y>GUIbutton_y[buttonnumber]) && (current_x<(GUIbutton_x[buttonnumber]+GUIbutton_xs[buttonnumber]))
      && (current_y<(GUIbutton_y[buttonnumber]+GUIbutton_ys[buttonnumber])) ){ return true; } else { return false;}
}



This is the .h file:

Code: [Select]
#ifndef TFTlib_h
#define TFTlib_h

#include "Arduino.h"
#include "SPI.h"
#include <UTFT.h>
#include <UTouch.h>

#define maxbuttons 25
#define stateDrawn 1
#define statePressed 2



class TFTlib{
 public:
   TFTlib();
   void setGLCDInstance(UTFT *pSomeInstance);
   void setTouchInstance(UTouch *pSomeInstance);
   void addButton(int buttonnumber,word x,word y,word xs,word ys,long colour,long borcolour,long textcolour,long presscolour,long presstextcolour,byte borwidth,String top,int xo,int yo);
   void drawButton(int buttonnumber);
   void drawButton_pressed(int buttonnumber);
   bool checkButton(word buttonnumber);
   int GUIbutton_x[maxbuttons];
   int GUIbutton_y[maxbuttons];
   int GUIbutton_xs[maxbuttons];
   int GUIbutton_ys[maxbuttons];
   int GUIbutton_xo[maxbuttons];
   int GUIbutton_yo[maxbuttons];
   long GUIbutton_colour[maxbuttons];
   long GUIbutton_borcolour[maxbuttons];
   long GUIbutton_textcolour[maxbuttons];
   long GUIbutton_pressedcolour[maxbuttons];
   long GUIbutton_pressedtextcolour[maxbuttons];
   int GUIbutton_borwidth[maxbuttons];
   String GUIbutton_top[maxbuttons];
   byte GUIbutton_currentstate[maxbuttons];
   UTFT    *pGLCD;
   UTouch  *pUTouch;

};

#endif




and the sketch:

Code: [Select]

#include "SPI.h"
#include <UTFT.h>
#include <UTouch.h>
#include <TFTlib.h>

#define FLASH_CS_PIN 52
#define SPI_RATE 2

UTFT myGLCD(CTE70);
UTouch myTouch(6,5,32,3,2);
TFTlib myTFTlib;

// Declare which fonts we will be using
extern uint8_t BigFont[];

void setup(){
  delay(500);
  Serial.begin(115200);
  //myTFTlib.setGLCDInstance(&myGLCD);
  //myTFTlib.setTouchInstance(&myTouch);
 
  myTFTlib.addButton(1,200,200,75,50,0x0000FF,0xFF0000,0xFFFFFF,0xFF0000,0xFFFFFF,2,"test",5,15);
  myTFTlib.drawButton(1);
  myTFTlib.addButton(2,400,200,100,50,0x0000FF,0xFF0000,0xFFFFFF,0xFF0000,0xFFFFFF,2,"hello",10,15);
  myTFTlib.drawButton(2);
}


void loop(){

  long x, y;
  String p;
  delay(10);
  myTouch.read();
  x = myTouch.getX();
  y = myTouch.getY();
  String test_string = String(x)+" , "+String(y) + "                            ";
  myGLCD.setColor(255, 255, 0);
  myGLCD.Put_Text(test_string,0,115,50);
  if (myTFTlib.checkButton(1)){ myTFTlib.drawButton_pressed(1); } else { myTFTlib.drawButton(1);}
  if (myTFTlib.checkButton(2)){ myTFTlib.drawButton_pressed(2); } else { myTFTlib.drawButton(2);}
 
}

promacjoe

Question: according to the CTE shield schematic, TP_DIN is on pen 4, and is shared with the SD_CS function. But everyone uses pen 32, Which is labeled DB8. As shown in your sketch 
Code: [Select]
UTouch myTouch(6,5,32,3,2);. Shouldn't it read
Code: [Select]
UTouch myTouch(6,5,4,3,2); instead, or is there a problem with my schematic.

The data in function to the touchscreen controller may not be used much but it has a purpose. If you set it up using the wrong pin it may functionally be correct until you need to write a command to the touch controller. Then a problem will show up. If you're going to adapt the drivers you should use the correct pin numbers.

promacjoe.

cowasaki


Question: according to the CTE shield schematic, TP_DIN is on pen 4, and is shared with the SD_CS function. But everyone uses pen 32, Which is labeled DB8. As shown in your sketch 
Code: [Select]
UTouch myTouch(6,5,32,3,2);. Shouldn't it read
Code: [Select]
UTouch myTouch(6,5,4,3,2); instead, or is there a problem with my schematic.

The data in function to the touchscreen controller may not be used much but it has a purpose. If you set it up using the wrong pin it may functionally be correct until you need to write a command to the touch controller. Then a problem will show up. If you're going to adapt the drivers you should use the correct pin numbers.

promacjoe.


The example sketch used the same pin connections. I am using a due if this makes any difference,  the touch functionality is working correctly with my connections. I actually checked them all with the meter previously ready to use Eagle to complete the entire board. ... I'm just using the shield whilst writing the initial software.

Go Up