Re: Support for float (%f) in chprintf
Posted: Thu Jun 21, 2012 4:18 pm
I did a fixed format implementation of printing (calling chprintf) on my main.c file. I made it just to test variadic functions and va_list implementations. In my tests passing any number of floats seems to work. Of course I have to know before hand what I passed 'cause there's no parsing of format.
I don't know yet why it works in this context but maybe this can give some ideas to someone.
And the end I call chprintf with 3 floats and it gives an error.
Output:
Fabio Utzig
I don't know yet why it works in this context but maybe this can give some ideas to someone.
And the end I call chprintf with 3 floats and it gives an error.
Code: Select all
void print_values(char *fmt, ...)
{
va_list ap;
float f;
long l;
va_start(ap, fmt);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
l = va_arg(ap, long);
chprintf((BaseSequentialStream *) &SD2, "%d\r\n", l);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
l = va_arg(ap, long);
chprintf((BaseSequentialStream *) &SD2, "%d\r\n", l);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
l = va_arg(ap, long);
chprintf((BaseSequentialStream *) &SD2, "%d\r\n", l);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
f = (float) va_arg(ap, double);
chprintf((BaseSequentialStream *) &SD2, "%f\r\n", f);
f = (float) va_arg(ap, double);
va_end(ap);
}
int main(void)
{
...
sdStart(&SD2, &ser_config);
print_values("", 1.0, 1, 2.0, 2, 3.0, 3, 4.0, 5.0, 6.0);
chprintf((BaseSequentialStream *) &SD2, "%f %f %f\r\n", 1.0, 2.0, 3.0);
...
}
Output:
Code: Select all
1.00000
1
2.00000
2
3.00000
3
4.00000
5.00000
6.00000
1.00000 0.00000 0.00000
Fabio Utzig