How should I inherit from Stream
, for creating a new class MySerial
able to be initialized from a Stream0
instance?.
The error so far is: "cannot declare variable 'mySerial' to be of abstract type 'MySerial'"
.
If I make a class MySerial
not inheriting, but adding a property Stream
, everything works fine, except the new call mechanism for the resend()
function, created to accept Stream
instances.
EDIT: This is the edited code. Current error is: "expected unqualified-id before '=' token"
.
MySerial.h
class MySerial:public Stream{
private:
int param;
public:
MySerial(){}; // OK
MySerial(Stream &Serial0){MySerial=&Serial0} // Here is the question
// Stream Implementation
int available(){return available();}
int read(){return read();}
int peek(){return peek();}
size_t write(uint8_t c){return write(c);}
using Print::write;
};
MySerial.ino
#include <MySerial.h>
#include <SoftwareSerial.h>
SoftwareSerial swSerial(6,7);
MySerial mySerial(swSerial);
void setup(){}
void loop(){
if (mySerial.available()){
c=mySerial.read();
resend(mySerial,c);
}
}
// This function should accept any Stream: SoftwareSerial, MySerial, Serial...
void resend(Stream &Stream0, char c){
Stream0.write(c);
}