Is there a null Stream object for arduino to print to?

I'm thinking about using a Debug as a Stream pointer so all my debug related messages go through it, instead of Serial, so debug messages for myself and messages intended for users are separate. Then if I can just let Debug points to a null Stream, I can turn off all debug messages in one line.

Is this possible with arduino? I'm willing to do some work to implement this if necessary but then I have to read through the entire Stream library, possibly Print too.

Yes, its possible.

I have a null print object I can give you, otherwise I can easily convert it to a stream if you like. At work at the moment. In a few hours I'll post it when home.

If you wish to try yourself, use my CRC stream here: http://forum.arduino.cc/index.php?topic=202336.0 Then strip out the CRC stuff. But the basic building block needed for a stream extension is there.

Great! Thanks. I'll give it a try sometime. I thought a null stream would be useful for this purpose, without resorting to #ifdef.

Here is a null stream object.

struct NullStream : public Stream{
  NullStream( void ) { return; }
  int available( void ) { return 0; }
  void flush( void ) { return; }
  int peek( void ) { return -1; }
  int read( void ){ return -1 };
  size_t write( uint8_t u_Data ){ return u_Data, 0x01; }
};

You can overload ‘size_t write(const uint8_t *buffer, size_t size)’ for a speed increase too.

Thanks pYro! I'll give it a try.