Skip to content

Commit

Permalink
Override printf for Uart
Browse files Browse the repository at this point in the history
  • Loading branch information
h2zero committed Jan 14, 2025
1 parent 90a193b commit 9495e5a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
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

0 comments on commit 9495e5a

Please sign in to comment.