feat: enhance Print class with float support and printf functionality#268
feat: enhance Print class with float support and printf functionality#268Aymane-ST wants to merge 1 commit intoarduino:masterfrom
Conversation
- Add float overloads to Print::print/println - Enhance Print with printf() and vprintf() helpers Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
per1234
left a comment
There was a problem hiding this comment.
Thanks so much for your pull requests @Aymane-ST! The addition of Print::printf et al. is a potential "poison pill" for this PR, since this is something that has historically been explicitly rejected by Arduino. For example:
https://groups.google.com/a/arduino.cc/g/developers/c/E0pUPWeDE2Y/m/GPWl9Nw1BwAJ
Massimo Banzi Feb 13, 2019, 1:26:42 AM
I would avoid adding
printftoSerial., the syntax is not very friendly.People who know how to use it can use
sprintfand pass the buffer to
Furthermore, we already have a pull request proposing the addition of Print::printf: #28
Please remove the Print::printf component from this pull request to make it focus exclusively on the addition of a float overload of Print::print.
You are very welcome to submit a review on #28 if you have any suggestions for changes to the implementation proposed there. If that review is not resolved to your satisfaction, you can submit a dedicated pull request for your Print::printf et al. proposal.
Summary
Enhance
Printwith:print(float, int digits)println(float, int digits)printf(...)vprintf(...)Why
This improves API completeness and usability:
floatgets explicit overloads, matching existingdoublesupportprintf/vprintfprovide familiar formatted output on top of thePrintinterfaceCompatibility
This change is additive and backward-compatible:
Printusers are unaffectedPrint-derived classes