Arduino-TR-064-SOAP-Library icon indicating copy to clipboard operation
Arduino-TR-064-SOAP-Library copied to clipboard

Allow user to pass stream object rather than hard-coded "Serial"

Open Aypac opened this issue 7 years ago • 2 comments

From https://www.arduino.cc/en/Reference/APIStyleGuide:

When using serial communication, allow the user to specify any Stream object, rather than hard-coding "Serial". This will make your library compatible all serial ports on Mega and the Due, and can also use alternate interfaces like SoftwareSerial. The Stream object can be passed to your library's constructor or to a begin() function (as a reference, not a pointer). See Firmata 2.3 or XBee 0.4 for examples of each approach.

When writing a library that provides byte-stream communication, inherit Arduino's Stream class, so your library can be used with all other libraries that accept Stream objects. If possible, buffer incoming data, so that read() immediately accesses data the buffer but does not wait for more data to arrive. If possible, your write() method should store data to a transmit buffer, but write() must wait if the buffer does not have enough space to immediately store all outgoing data. The yield() function should be called while waiting.

Here are a few libraries that are exemplary from Adafruit. She breaks the functions of the devices down into their high-level activities really well. https://github.com/adafruit/Adafruit-BMP085-Library https://github.com/adafruit/DHT-sensor-library 


Aypac avatar Nov 26 '18 21:11 Aypac

Partially solved with #13

Aypac avatar Dec 09 '18 23:12 Aypac

We should also introduce a debug flag.

Aypac avatar Dec 18 '18 08:12 Aypac