-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Add method Print.printf(). Fixed & tested. #592
base: master
Are you sure you want to change the base?
Conversation
The printf() method always uses self instance of the class Print, without additional implementation of the output to UARTs, TFTs, and etc.
enable printf by default
Fix bug with use fopencookie() for implemet Print.printf(). I checked it, and Print.printf() now works.
cleanup source
Is there any way to add an additional format specifier for binary? I'd love to be able to use: Serial.printf("bits=0b%08b\n", 0x33); |
Not tested, but this should work if you are not using nano.specs: |
you can choose one solution from here: https://stackoverflow.com/questions/111928/is-there-a-printf-converter-to-print-in-binary-format |
Thanks @justinschoeman! We learn something new everyday. |
Why does one of the the change to print.cpp include this block of comment ? `/* //worked: fopencookie( 0, "rw+", { RD_fn, WR_fn, NULL, NULL }) //worked: fopencookie( 0, "rw+", { NULL, WR_fn, NULL, NULL }) As far as I can tell this code references the function fopencookie which does not exist |
As implemented in LIBC. :) |
Hmm.. This is supported in the native Linux gcc, Raspberry, gcc for Arduino DUE and ESP8286/32. |
|
I didn't test whether it compiled yet. I'll locally merge in a separate branch and see whether I get any errors when I compile. |
OK. But more testing would be needed before I can merge |
add #define _GNU_SOURCE So more correct for use fopencookie()
fopencookie () is an extension of LIBC. The correct use of this extension is as follows: And not as it is now written in the source, only It is possible that such a trifle is a source of problems. |
This PR does not seem to work for me. Please post a small example sketch which works |
I suspect that this is not compiled correctly or works. I will do a few test sketches, and describe their behavior on various new platforms assembled from scratch. |
OK. Thanks BTW. Did this PR work for you ? |
STM32F1/cores/maple/Print.cpp
Outdated
//failed: fopencookie( 0, "rw+", { NULL, WR_fn, NULL, NULL }) | ||
// | ||
//worked: fopencookie( 0, "rw+", { RD_fn, WR_fn, NULL, NULL }) | ||
//worked: fopencookie( 0, "rw+", { NULL, WR_fn, NULL, NULL }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 229 (worked) seems to be identical to line 226, which failed.
Btw, do we really need this comment block? I would remove it.
The solution matters, which is implemented below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So basically this PR doesn't work unless some lines are uncommitted ???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block comments should be removed. :)
The GLIBC documentation says that when fopencookie() is called, pointers to BOTH the write() and read() functions must be passed.
That is, if reading is not required, a valid pointer to a dummy function should be passed, and not NULL. Otherwise it does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand the reason, I just asked to remove unneeded comment block (which includes contradictory information).
delete contradictory information
Steve looks like the comments were cleaned up on February 28th, after your last comment. |
Maybe you could evaluate this: |
I think the solution from @fpistm should be applied, especially lines |
Added the printf() method to the Print class.
With this implementation, Print.print() works with any devices - Uart, TFT, SDCard and others.
The previous version has not been tested. I'm sorry.
This worked on other my platforms, but a bug was discovered on the Arduino STM32.
Fixed.