Serial Stream Refactor and Split-Channel Example#220
Conversation
|
Quick early comment (before reviewing thoroughly) is that the name of the sketch is long. Also I'd like to include "empty" in the name to show what functionality it provides. Suggest "VLCB_SerialGC_empty_withSerialUI.ino" Does this make sense? |
|
Yes, it makes sense. The longest example filename is |
Yes. it does. Just thinking that the "empty" bit should be earlier in the file name. But that would affect existing VLCB_SerialGC sketches. Need to think about a naming convention and if needed change all sketches. |
| @@ -0,0 +1,144 @@ | |||
| // Copyright (C) Sven Rosvall (sven@rosvall.ie) | |||
There was a problem hiding this comment.
Please claim copyright for yourself.
There was a problem hiding this comment.
Ahah. I didn't think about this ;-)
| serialUserPort << F("> compiled on ") << __DATE__ << F(" at ") << __TIME__ << F(", compiler ver = ") << __cplusplus << endl; | ||
|
|
||
| // copyright | ||
| serialUserPort << F("> © Sven Rosvall (MERG 3777) 2026") << endl; |
There was a problem hiding this comment.
Claim copyright for yourself. ;)
There was a problem hiding this comment.
Well, 90% of the code is yours. But OK ;-)
| // | ||
| /// print code version config details and copyright notice | ||
| // | ||
| void printConfig() |
There was a problem hiding this comment.
Can you put this function at the bottom of this file. Then it is easier to compare the different "*_empty" sketches.
There was a problem hiding this comment.
I thought I had put it back in my last commit. Need to check.
| { | ||
| } | ||
|
|
||
| Serial_T & operator<<(Serial_T & s, int i) |
There was a problem hiding this comment.
I implemented these operators this way so that any debug info would be printed in the text outputs for the unit tests. This is handy when troubleshooting.
Can you keep these operators but change to use your Stream class?
|
|
||
| struct Serial_T | ||
| { | ||
| void begin(int baudrate); |
There was a problem hiding this comment.
This begin() function is used by the example sketches.
No, these headers are not used by the Arduino IDE or your new workflows when compiling the example sketches. However I also use the headers in the Arduino directory for my IDE (CLion) so that the example sketch codes come up nicely in the IDE without any red markers. So please keep the begin() function in the Stream.h .
| virtual void flush() {} | ||
| }; | ||
|
|
||
| // Operator overloads for Stream to work with Streaming library |
There was a problem hiding this comment.
These operators don't need definitions in the Arduino directory. This directory is only used to make my IDE work well with Arduino code.
For executing test code the definitions should reside in ArduinoMock.cpp in the test directory. See also comments there.
| { | ||
| public: | ||
| SerialGC(typeof(Serial)& _serial = Serial) : serial(_serial) {} | ||
| SerialGC(Stream& _serial = Serial) : serial(_serial) {} |
There was a problem hiding this comment.
Yes! That looks much nicer. Should have done that from the beginning. :)
| { | ||
| public: | ||
| /// @cond LIBRARY | ||
| SerialUserInterface(Stream& _serial = Serial) : serial(_serial) {} |
There was a problem hiding this comment.
The constructor should be declared above the @cond line.
The @cond tells Doxygen to ignore a block (until @endcond) of declarations. This is useful to reduce the amount of documentation a sketch developer needs to see. (The library developer needs to see everything.)
This constructor is something a sketch developer will use and thus it should be include in the sketch developer documentation.
|
Thanks for this pull request. It looks good. Will be a good feature. I know John Fletcher will be happy about this. The comments I have added are mostly about my style and how I work with this project. Sorry that this is not documented properly. So the comments are there to share this until I get that bit done. |
Thank you. I will fix the remaining "glitches" and commit on this PR. Happy to make John happy :-)
No problem. |
This PR refactors serial bindings to use Arduino
Streaminstead of hard-wiring to globalSerial, while preserving default behavior.It also adds a new example showing split serial channels:
SerialGCon hardwareSerial(GridConnect transport)SerialUserInterfaceonSoftwareSerialor Serial1 on Mega2560 (user console)Changes
SerialGCconstructor/member type toStream&SerialGC::begin()(Removed startup banner print from begin)SerialUserInterfaceto injectedStream&with defaultSerialexamples/VLCB_SerialGC_SerialUI_SoftwareSerial/VLCB_SerialGC_SerialUI_SoftwareSerial.inodocs/Examples.mdWhy
SerialGCandSerialUserInterfaceto work with eitherHardwareSerialorSoftwareSerial(or other Stream-compatible ports).Compatibility
Serial.Closes #216