modm API documentation
Input/Output Streams

Classes

class  modm::IODevice
 
class  modm::IODeviceObjectWrapper< Device, behavior >
 
class  modm::IODeviceWrapper< Device, behavior >
 
class  modm::IOStream
 

Enums

enum  modm::IOBuffer { DiscardIfFull, BlockIfFull }
 
IOStreammodm::flush (IOStream &ios)
 
IOStreammodm::endl (IOStream &ios)
 Write a newline. DOES NOT FLUSH THE STREAM!
 
IOStreammodm::bin (IOStream &ios)
 set the output mode to binary style
 
IOStreammodm::hex (IOStream &ios)
 set the output mode to hexadecimal style
 
IOStreammodm::ascii (IOStream &ios)
 set the output mode to ASCII style
 
IOStreammodm::black (IOStream &ios)
 Set the foreground colour on ANSI terminals.
 
IOStreammodm::red (IOStream &ios)
 
IOStreammodm::green (IOStream &ios)
 
IOStreammodm::yellow (IOStream &ios)
 
IOStreammodm::blue (IOStream &ios)
 
IOStreammodm::magenta (IOStream &ios)
 
IOStreammodm::cyan (IOStream &ios)
 
IOStreammodm::white (IOStream &ios)
 
template<class Rep , class Period >
modm::IOStreammodm::operator<< (modm::IOStream &s, const std::chrono::duration< Rep, Period > &d)
 
template<class Clock , class Duration >
modm::IOStreammodm::operator<< (modm::IOStream &s, const std::chrono::time_point< Clock, Duration > &tp)
 
modm::IOStreammodm::operator<< (modm::IOStream &s, const std::tm &tm)
 

Detailed Description

lbuild module: modm:io

The modm::IOStream class contains efficient formatting that supports both C++ std::basic_ostream-like formatting via operator << as well as implementing printf via the modm:printf module.

modm::IOStream stream(device);
stream << "format number 8: " << uint8_t(8) << " or as signed -100: " << int8_t(-100);
stream << modm::endl;
stream.printf("format number 8: %u or as signed -100: %d", 8, -100);
Warning
AVR supported features All expensive features including printf are disabled by default to reduce firmware size! Please check the options.
Note
modm::endl does NOT implicitly flush! Flushing is extremely expensive on embedded systems, therefore modm::endl does not implicitly flush the stream. Please call modm::flush explicitly.

Redirecting IOStreams

The modm::IODeviceWrapper transforms any peripheral device that provides static write() and read() functions into an IODevice:

// configure a UART
using Uart = Uart0;
// wrap it into an IODevice
// use this device to print a message
device.write("Hello");
// or create a IOStream and use the stream to print something
modm::IOStream stream(device);
stream << " World!";

IODevice Buffer Behavior

The modm::IODeviceWrapper can be configured to discard or block in case the device is full. Discarding data is always non-blocking, however, blocking on write involves waiting in a loop until the device has space. This can cause a deadlock when called inside an interrupt!

If compiled with the modm:processing:fiber module, the blocking behavior allows the fiber to yield while waiting for the device. To prevent interlaced output from different fibers, the write(char) function is protected by a mutex that releases when a newline character \n is written. The flush() function is also mutex protected to allow one fiber to reliably flush the stream without having other fibers push data into the device.

Module Options

modm:io:with_long_long: Support for 64-bit integer formatting

Generated with: no in [yes, no]

modm:io:with_float: Support for floating point formatting

On AVRs floating point values can be printed, however, the formatting cannot be specified and all values are printed as scientific-notation exponential floating point

Generated with: no in [yes, no]

modm:io:with_printf: Support for printf-style formatting

Generated with: no in [yes, no]

Enumeration Type Documentation

enum modm::IOBuffer
strong

The preferred behavior when the IODevice buffer is full

Function Documentation

IOStream& modm::flush ( IOStream ios)
inline

Flushes the output stream. This manipulator simply calls the stream's flush() member function.