-
Notifications
You must be signed in to change notification settings - Fork 39
Feature request: printf padding/floating point #361
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
Comments
I usually include something like this in my projects, can this help? #ifndef HELPERS
#define HELPERS
#include "Arduino.h"
#include "stdarg.h"
//--------------------------------------------------------------------------------
constexpr size_t serial_printf_max_buffer = 256;
// variadic serial print using printf formatting
void serialPrintf(const char *fmt, ...);
#endif and the implementation: #include "helpers.h"
void serialPrintf(const char *fmt, ...) {
/* Buffer for storing the formatted data */
char buff[serial_printf_max_buffer];
/* pointer to the variable arguments list */
va_list pargs;
/* Initialise pargs to point to the first optional argument */
va_start(pargs, fmt);
/* create the formatted data and store in buff */
vsnprintf(buff, serial_printf_max_buffer, fmt, pargs);
va_end(pargs);
Serial.print(buff);
} |
(slightly adapted from a recipe found some time ago on a public github). |
Thanks @jerabaul29, In Mbed OS, it's very simple to enable std-printf or mbed-printf with support for floating-point. For example,
Cheers, |
We have more than issue tracking this. closing in favor of #278 |
Hi there,
In v2.x of the Apollo3 Core, Mbed OS is responsible for managing sprintf/printf (#239). However, it appears that padding is no longer enabled. A simple example code snippet to print the date and time:
Produces the following output:
But should have a number of zeros padding the values:
From what I can gather, this is due to the fact the Mbed core by default uses the minimal printf library to increase memory savings:
https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md#usage
It would be great to have padding reenabled, as well as the ability to print floating-point values. Given the specifications of the Artemis, I believe the additional Flash/RAM requirements should be trivial?
Cheers,
Adam
The text was updated successfully, but these errors were encountered: