I have been playing around with my versions of the C/C++ libraries that I am developing that run on the Bap28 and I thought I would make some of my functions more Arduino like.
So I thought I would try creating a couple of serial output classes that are wrappers of my current stuff (Hardware serial, Timer based bit bang).
But when I define the classes, that look something like:
Code:
class Print
{
public:
virtual void write(byte) = 0;
virtual void write(const char *str);
virtual void write(const byte *buffer, byte size);
void print(const char[]);
// Are more members but reduced for test case...
};
class HardwareSerial : public Print
{
private:
byte _bWhich; //
public:
HardwareSerial(byte bWhich=0); // Which port 0=HSERIAL 2=HSERIAL2
// removed stuff for simplicity
virtual void write(byte);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
class SoftwareSerial : public Print
{
private:
byte _bPinOut; // May define with one or two pins...
byte _bPinIn; //
word _wMode; // what mode are we outputting...
public:
SoftwareSerial(byte bPinIn, byte bPinOut); // Which IO Pins
//...
virtual void write(byte);
using Print::write; // pull in write(str) and write(buf, size) from Print
};
I can get it to compile and the like, but my version of the C Phoenix code no longer fits on a Bap28. I found with these virtual functions, the compiler and linker brought in the kitchen sink. A lot of exception processing for Try/Catch... In a previous life I semi remember that there are a few functions you can define your own light weight functions to avoid this.
In this case I could probably get around this by not having virtual functions. Although it might be nice to be able to pass a pointer to a print object to parts of the program and have it abstract away if it is a hardware or serial port...
Kurt
Suggestions?
Kurt