I'm writing a library and I'd like it work with either a SoftwareSerial object or HardwareSerial (the "Serial" object). By clearing the constructor in my library to take a Stream, I can get most of the way there.
However, I can't call stream.begin(4800) in my library because Stream doesn't have such a begin method, and the two serial classes don't have a common superclass or interface that defines a begin method.
Is there something I'm missing? If not, it would help in expanding use of SoftwareSerial if there were a common class that could be used.
wa5znu:
However, I can't call stream.begin(4800) in my library because Stream doesn't have such a begin method, and the two serial classes don't have a common superclass or interface that defines a begin method.
Alternative to avenue33's suggestion, what I did with my phi_interfaces library is to REQUIRE a Stream object that has already begun. There is no standard method to begin or end a serial port or I2C interface under Stream. The user will do the begin of whatever port and pass your library the address to the Stream object that has begun
Thank you, all. I am already using the caller-callers-begin() method, so I guess I'll stick with that. I hadn't considered the difficulties of extending to I2C.