Skip to content

Override printf for Uart #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion cores/nRF5/Print.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class Print
size_t println(double, int = 2);
size_t println(const Printable&);
size_t println(void);
int printf(const char* format, ...) __attribute__ ((format (printf, 2, 3)));

virtual int printf(const char* format, ...);

virtual void flush() { /* Empty implementation for backward compatibility */ }

Expand Down
9 changes: 9 additions & 0 deletions cores/nRF5/Uart.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ void Uart::end()
rxBuffer.clear();
}

int Uart::printf(const char* format, ...)
{
va_list va;
va_start(va, format);
int ret = vprintf(format, va);
va_end(va);
return ret;
}

void Uart::flush()
{
}
Expand Down
1 change: 1 addition & 0 deletions cores/nRF5/Uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Uart : public HardwareSerial
int read();
void flush();
size_t write(const uint8_t data);
int printf(const char* format, ...) override;
using Print::write; // pull in write(str) and write(buf, size) from Print

void IrqHandler();
Expand Down
Loading