Hi
I am currently writing a library that contains functions to operate the Openlog data logger. What i would like to do (if its possible) is to declare a public hardwareSerial object and initialize it according to the user’s requirements when the class constructor is called, instead of setting to a specific serial port. To be more specific see the code bellow.
//----------------------------------------------------------------------------------------------
//Datalog.cpp file (just a part of it)
//----------------------------------------------------------------------------------------------
Datalog::Datalog(HardwareSerial port, int sped)//Datalog constructor
{
serialPort=port; //Initialize the global serial port according to user's req
serialPort.begin(sped); //set the port speed
}
//----------------------------------------------------------------------------------------------
//Datalog.h file
//----------------------------------------------------------------------------------------------
#ifndef Datalog_h
#define Datalog_h
#include "WProgram.h"
#include "HardwareSerial.h"
class Datalog:public HardwareSerial
{
public:
typedef HardwareSerial serialPort; //here is the issue
Datalog(HardwareSerial port, int sped);//constructor
void writedata(String msg);
void appendFile(String file);
void resetDatalogger();
void enterCommandMode();
void resetFileCounter();
void newFile(String file);
void readFile(String filename);
};
#endif
//----------------------------------------------------------------------------------------------
//Arduino file (part)
//----------------------------------------------------------------------------------------------
#include <Datalog.h>
Datalog datalog=Datalog(Serial1,115200); //can be Serial, Serial2, Serial3 depending on user
So the problem here is that the compiler is complaining about with the following message "Datalog.cpp:33: error: no matching function for call to ‘HardwareSerial::HardwareSerial()’ ", the 33 line is actually the declaration of the constructor (that i already posted) in the cpp file. I know that the problem is located on the way that i am declaring the HardwareSerial object. So the question is if this is possible and if it is, how is the correct way to do it.
Thanks