Anyone know how to make printf/fprintf write an entire line at a time?
I want to use printf/fprintf to write debug messages out of a Bluetooth connection. Up to now, I've been using a UART, and was able to take over the write() function and redirect output as described in the Libraries Reference Manual. But the printf function has a little quirk that makes using it with BT difficult.
As others in the forum have observed, if the format string does not have any conversion markers(%), the string is passed in its entirety to the write() function in a single call. But if any conversion is necessary, printf dribbles the string out one character at a time, making a separate write() call for each character. This works fine for a UART but for Bluetooth, everything is in packets. So it is necessary to know when the last character in a string is received so a packet can be created and sent.
This is somewhat like the way a block device would operate so I looked in the FILE definition but couldn't figure out what the parameters in the FILE do.
So has anyone solved this problem? Right now, I think I'm just going to cobble my own version of fprintf together using the sprintf() function.