-
Notifications
You must be signed in to change notification settings - Fork 1k
Add printf to print class #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Any updates on this? I forgot to mention that this does not add any extra flash usage when not used in the user program. |
@MCUdude |
does it support F() macro? |
The current PR does not. However, I can add it. I will probably use the code from the Teensy core files, since this supports the F() macro as well. If you and @fpistm want, I can test this code and update the PR with these changes afterward. |
nice to have possibility to redefine buf size |
Actually, the printf code from Teensy didn't work very well when printing simultaneously on all serial ports. Adafruit's code work well, so I'll stick with this. It doesn't seems like the F() macro doesn't do much really. It calls the PSTR() macro, which is just a dummy. But sure, There's no problem supporting F macros inside printf, but it won't affect the memory usage. |
It's now possible to change the printf buffer size at compile time
This addition requires to be documented in the Wiki:
Code example: #include <Streaming.h>
const char * lorem = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
void setup() {
Serial.begin(9600);
}
void loop() {
static uint32_t i = 0;
// 1
Serial.print("Iter ");
Serial.print(i++);
Serial.print(" --> ");
Serial.println(lorem);
// 2
Serial.printf("Iter %i --> %s\n", i++, lorem);
// 3
Serial << "Iter " << i++ << " --> " << lorem << endl;
} Size:
As you can see Streaming usage is the best way. |
Co-Authored-By: Frederic Pillon <frederic.pillon@st.com>
Co-Authored-By: Frederic Pillon <frederic.pillon@st.com>
Co-Authored-By: Frederic Pillon <frederic.pillon@st.com>
I tried the online Resolve and commit functionality for the first time. Hopefully it is OK now |
Cool! Will this be available in release 1.8.0? |
Well thinking about that, I really not like the buffer. |
I merge this and will provide a hardening to remove |
Sure! I do agree that having a hardcoded buffer isn't optimal, but at least it is a start. I'm not sure how relevant it is, but here's how it is implemented on 8-bit AVRs, without any hardcoded buffer. |
Where can I find vdprintf?
It tried to include <stdio.h> but still no luck. |
Could you be more precise? What is your setup? Board selected? Core version? Arduino IDE version? Sketch?... Because I never seen this issue. vdprintf is provided by newlib. |
This PR uses Adafruits printf implementation.
For those who didn't know, printf is super useful when you want to format your output. When printf is a part of the Print class, all libraries that inherits the print class (such as Serial, LiquidCrystal, SoftwareSerial + other LCD libraries).
This PR makes this possible:
Serial.printf("Milliseconds since start: %d\n", millis());