Skip to content

Commit da22a4a

Browse files
committed
Having dtostrf on AVR available should enable support for %f.
This fixes #7.
1 parent bfce1fe commit da22a4a

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

Diff for: src/dtostrf.c

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
dtostrf - Emulation for dtostrf function from avr-libc
3+
Copyright (c) 2016 Arduino LLC. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
// This is a default implementation for dtostrf function.
21+
// This file should be used if the standard lib doesn't provide an
22+
// implementation of dtostrf.
23+
24+
// Create a file called "dtostrf.c" with the following include:
25+
// #include "api/deprecated-avr-comp/avr/dtostrf.c.impl"
26+
27+
#if defined(ARDUINO_ARCH_AVR)
28+
29+
#include <stdio.h>
30+
31+
char *dtostrf (double val, signed char width, unsigned char prec, char *sout) {
32+
asm(".global _printf_float");
33+
34+
char fmt[20];
35+
sprintf(fmt, "%%%d.%df", width, prec);
36+
sprintf(sout, fmt, val);
37+
return sout;
38+
}
39+
40+
#endif /* ARDUINO_ARCH_AVR */

0 commit comments

Comments
 (0)