serial_c_iface.cpp
Go to the documentation of this file.
1 /******************************************************************************/
36 /******************************************************************************/
37 
38 #include "serial_c_iface.h"
39 
40 int
42  const char *format,
43  ...
44 ) {
45  va_list args;
46 
47  va_start(args, format);
48 
49  /* +1 for the null terminator \0 at the end */
50  int bufsize = vsnprintf(NULL, 0, format, args) + 1;
51  char buf[bufsize];
52 
53  va_end(args);
54 
55  va_start(args, format);
56  vsnprintf(buf, bufsize, format, args);
57  va_end(args);
58 
59  return serial_print(buf);
60 }
61 
62 int
64  const char *buffer
65 ) {
66  int num;
67 
68  num = Serial.print(buffer);
69 #if DEBUG
70  Serial.flush();
71 #endif
72  return num;
73 }
74 
75 void
77  int baud_rate
78 ) {
79  Serial.begin(baud_rate);
80 }
81 
82 void
84 ) {
85  Serial.end();
86 }
Provides a printf implementaton for C code running from inside an Arduino Sketch. ...
int serial_printf_c(const char *format,...)
A version of printf that limits the number of characters printed per call.
int serial_print(const char *buffer)
A print function wrapping Arduino's serial stream.
void serial_init(int baud_rate)
Initializes serial port 0 for communications.
void serial_close()
Closes the communication port so that the pins can be used as general I/O.