forked from meshtastic/firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create RedirectablePrint and NoopPrint for serial debug redirection
- Loading branch information
1 parent
dda946d
commit eb40013
Showing
2 changed files
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "RedirectablePrint.h" | ||
#include <assert.h> | ||
|
||
/** | ||
* A printer that doesn't go anywhere | ||
*/ | ||
NoopPrint noopPrint; | ||
|
||
void RedirectablePrint::setDestination(Print *_dest) | ||
{ | ||
assert(_dest); | ||
dest = _dest; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
|
||
#include <Print.h> | ||
|
||
/** | ||
* A Printable that can be switched to squirt its bytes to a different sink. | ||
* This class is mostly useful to allow debug printing to be redirected away from Serial | ||
* to some other transport if we switch Serial usage (on the fly) to some other purpose. | ||
*/ | ||
class RedirectablePrint : public Print | ||
{ | ||
Print *dest; | ||
|
||
public: | ||
RedirectablePrint(Print *_dest) : dest(_dest) {} | ||
|
||
/** | ||
* Set a new destination | ||
*/ | ||
void setDestination(Print *dest); | ||
|
||
virtual size_t write(uint8_t c) { return dest->write(c); } | ||
}; | ||
|
||
class NoopPrint : public Print | ||
{ | ||
public: | ||
virtual size_t write(uint8_t c) { return 1; } | ||
}; | ||
|
||
/** | ||
* A printer that doesn't go anywhere | ||
*/ | ||
extern NoopPrint noopPrint; |