chipKIT® Development Platform

Inspired by Arduino™

Problem with including cpp files

Created Mon, 23 Mar 2015 00:05:51 +0000 by Seniorlemuren


Seniorlemuren

Mon, 23 Mar 2015 00:05:51 +0000

Hi. I have a Uno32 with a graphic display and a touch screen. I have done a menyprogram from where I want to show a new page on the display. Every thing i working fine when I have all routines in the menu-sketch.

but now I want to have the new pages in separate cpp-files but I cant have it to work.

the menu sketch is this:

#include <UTouch.h> //the touch screen library
#include <UTFT.h> // the graphic library
#include "visaroder.h" //my headerfile


// Declare which fonts we will be using
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern unsigned short roderpil[0x2328];

// Set the pins to the correct ones for your development shield
UTFT myGLCD(ITDB32S,38,39,40,41);
UTouch myTouch(20,21,22,23,24);

int x, y;

// Setup the LCD
void setup()
{
  myTouch.InitTouch();
  myTouch.setPrecision(PREC_MEDIUM);
  myGLCD.InitLCD();
  myGLCD.clrScr();
  myGLCD.setFont(SmallFont);  
  
  
  drawButtons();  
}

void drawButtons()
{
  myGLCD.fillScr(VGA_BLACK);
  // Draw the upper row of buttons
  y = 0;
  for (x=0; x<2; x++)
  {
    myGLCD.setColor(VGA_RED);
    myGLCD.fillRoundRect (15+(x*150), 17+y, 153+(x*150), 73+y);
    myGLCD.setColor(VGA_BLUE);
    myGLCD.fillRoundRect (18+(x*150), 20+y, 150+(x*150), 70+y);
    
    myGLCD.setBackColor(VGA_BLUE);
    myGLCD.setColor(VGA_YELLOW);    
  } 
  myGLCD.print("WATER TEMP",45,39+y);
  myGLCD.print("OIL TEMP",202,39+y);
  // Draw the second row of buttons
  y = 75 ;
  for (x=0; x<2; x++)
  {
    myGLCD.setColor(VGA_RED);
    myGLCD.fillRoundRect (15+(x*150), 17+y, 153+(x*150), 73+y);
    myGLCD.setColor(VGA_BLUE);
    myGLCD.fillRoundRect (18+(x*150), 20+y, 150+(x*150), 70+y);
    
    myGLCD.setBackColor(VGA_BLUE);
    myGLCD.setColor(VGA_YELLOW);    
  } 
  myGLCD.print("DIESELFUEL",44,39+y);
  myGLCD.print("FRESH WATER",192,39+y);
  // Draw the last row of buttons
  y = 150 ;
  for (x=0; x<2; x++)
  {
    myGLCD.setColor(VGA_RED);
    myGLCD.fillRoundRect (15+(x*150), 17+y, 153+(x*150), 73+y);
    myGLCD.setColor(VGA_BLUE);
    myGLCD.fillRoundRect (18+(x*150), 20+y, 150+(x*150), 70+y);
    
    myGLCD.setBackColor(VGA_BLUE);
    myGLCD.setColor(VGA_YELLOW);    
  } 
  myGLCD.print("RUDDER IND:",44,39+y);
  myGLCD.print("NEXT PAGE",200,39+y);
  
}

void loop()
{
  int y = 0;
  if (myTouch.dataAvailable())
    {
      myTouch.read();
      x=myTouch.getX();
      y=myTouch.getY();
    }
    if ((y>=20) && (y<=70)){  // Visa roderpilen (funkar inte)
       ritapil();
    }
    if ((y>=80) && (y<=160)){  // visa bara röd skärm (funkar)
        myGLCD.fillScr(VGA_RED);
    }
    if ((y>=160) && (y<=210)){  // tillbaka till menyknapparna (funka 
        drawButtons();
    } 
  
}

Then I have the headerfile like this:

#ifndef visaroder_h
#define visaroder_h

    void ritapil();
      
    
#endif

And the CPP-file who is only shoul draw an arrow on the screen.

#include "visaroder.h"

void ritapil(){    
   
    myGLCD.drawBitmap (130, 80, 60, 150, roderpil,90,30,125);   
}

The error message is this:

visaroder.cpp: In function 'void ritapil()': visaroder.cpp:7:5: error: 'myGLCD' was not declared in this scope

but myGLDC is from the graphic library who is already defined in the menu program. (Mainprogram)

Hope someone could help me.


majenko

Mon, 23 Mar 2015 09:02:27 +0000

Yes, it's defined in the main program - but your .cpp file isn't part of your main program and can't work out what it's meant to be unless you tell it.

Add to your .h file:

#include <UTFT.h>

extern UTFT myGLCD;

That way the .cpp file knows to include the UTFT library's definitions when compiling, and gets to know that "myGLCD" is a symbol that is defined elsewhere (in the main program) and to hunt for it during the linking stage.


Seniorlemuren

Mon, 23 Mar 2015 10:47:19 +0000

Thank you! Its working now. :)