Pico-Arduino
PicoStreamPrintf.h
1 #pragma once
2 #include <stdarg.h>
3 #include <stdio.h>
4 #include "Stream.h"
5 
6 
7 #ifndef PRINTF_BUFFER_SIZE
8 #define PRINTF_BUFFER_SIZE 512
9 #endif
10 
11 namespace pico_arduino {
12 
16 class StreamPrintf {
17 
18  public:
19  StreamPrintf(Stream *stream){
20  stream_ptr = stream;
21  }
22 
23  virtual int printf(const char* fmt, ...) {
24  int len = 0;
25  if (stream_ptr!=nullptr){
26  char serial_printf_buffer[PRINTF_BUFFER_SIZE] = {0};
27  va_list args;
28  va_start(args,fmt);
29  len = vsnprintf(serial_printf_buffer,PRINTF_BUFFER_SIZE, fmt, args);
30  stream_ptr->print(serial_printf_buffer);
31  va_end(args);
32  }
33  return len;
34  }
35  protected:
36  Stream *stream_ptr;
37 };
38 
39 }
Definition: Stream.h:51
Support for Serial.printf. The maximum printable length is defined by PRINTF_BUFFER_SIZE which is set...
Definition: PicoStreamPrintf.h:16
Pico Arduino Framework.
Definition: Arduino.cpp:26