File tree 1 file changed +31
-0
lines changed 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 19
19
#include < stdlib.h>
20
20
#include < stdio.h>
21
21
#include < string.h>
22
+ #include < cstdarg>
22
23
#include < math.h>
23
24
#include < limits.h>
24
25
#include " Arduino.h"
@@ -39,6 +40,36 @@ size_t Print::write(const uint8_t *buffer, size_t size)
39
40
return n;
40
41
}
41
42
43
+ size_t Print::printf (const char *format, ...)
44
+ {
45
+ char loc_buf[64 ];
46
+ char * temp = loc_buf;
47
+ va_list arg;
48
+ va_list copy;
49
+ va_start (arg, format);
50
+ va_copy (copy, arg);
51
+ int len = vsnprintf (temp, sizeof (loc_buf), format, copy);
52
+ va_end (copy);
53
+ if (len < 0 ) {
54
+ va_end (arg);
55
+ return 0 ;
56
+ };
57
+ if (len >= sizeof (loc_buf)){
58
+ temp = (char *) malloc (len+1 );
59
+ if (temp == NULL ) {
60
+ va_end (arg);
61
+ return 0 ;
62
+ }
63
+ len = vsnprintf (temp, len+1 , format, arg);
64
+ }
65
+ va_end (arg);
66
+ len = write ((uint8_t *)temp, len);
67
+ if (temp != loc_buf){
68
+ free (temp);
69
+ }
70
+ return len;
71
+ }
72
+
42
73
size_t Print::print (const __FlashStringHelper *ifsh)
43
74
{
44
75
return print (reinterpret_cast <const char *>(ifsh));
You can’t perform that action at this time.
0 commit comments