My original libraries are far too long to be included here, so I've created a cut-down but compile-able version here. (overview - the final objective is to have a GPS library where the serial port that the GPS module is physically connected to can be passed as a parameter)
Firstly, my low level library...
'TestA.h'
#ifndef TestA_h
#define TestA_h
extern "C" {
#include <string.h>
}
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class TestA
{
public:
TestA(HardwareSerial *serialX); // Constructor
byte readPort();
private:
// Member variables
HardwareSerial *_portX;
// Private methods
};
#endif
and 'TestA.cpp'
extern "C" {
#include <string.h>
}
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "TestA.h"
TestA::TestA(HardwareSerial *serialX)
{
_portX = serialX;
_portX->begin(57600);
}
byte TestA::readPort()
{
while (_portX->available())
{
// Read from one port and write directly to stout
Serial.print((char)_portX->read());
}
}
And the sketch to demonstrate they work and allow 'Serial1' to be passed as a parameter...
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <TestA.h>
int testNum=1;
TestA tst1(&Serial1);
void setup()
{
Serial.begin(115200);
Serial.println("#################### START ###############################");
}
void loop()
{
tst1.readPort();
}
Now for the higher level library that references 'TestA'
'TestB.h'
#ifndef TestB_h
#define TestB_h
extern "C" {
#include <string.h>
}
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <TestA.h>
class TestB
{
public:
TestB(); // Constructor
byte readPort();
private:
// Member variables
TestB _myGps(&Serial1);
// Private methods
};
#endif
and 'TestB.cpp'....
extern "C" {
#include <string.h>
}
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "TestB.h"
#include <TestA.h>
TestB::TestB()
{
}
byte TestB::readPort()
{
_myGps.readPort();
}
And the sketch to demonstrate that this doesn't work!....
#include <stdlib.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <TestA.h>
#include <TestB.h>
int testNum=1;
TestA tst2();
void setup()
{
Serial.begin(115200);
Serial.println("#################### START ###############################");
}
void loop()
{
tst2.readPort();
}
So, in the first sketch I can call the library with "TestA tst1(&Serial1);" which all works fine, but when I attempt to do the same thing from with the library TestB I get
expected identifier before '&' token
Thanks