AVRTools
A Library for the AVR ATmega328 and ATmega2560 Microcontrollers
Public Types | Public Member Functions | List of all members
Writer Class Referenceabstract

This is an abstract class defining a generic interface to write numbers and strings to a sequential stream of bytes (such as a serial output device). More...

#include <Writer.h>

Inheritance diagram for Writer:
Inheritance graph
[legend]

Public Types

enum  IntegerOutputBase { kBin = 2, kOct = 8, kDec = 10, kHex = 16 }
 An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters. More...
 

Public Member Functions

virtual size_t write (char c)=0
 Pure virtual function that writes a single character to the output stream. More...
 
virtual size_t write (const char *str)=0
 Pure virtual function that writes a null-terminated string to the output stream. More...
 
virtual size_t write (const char *buffer, size_t size)=0
 Pure virtual function that writes a given number of characters from a buffer to the output stream. More...
 
virtual size_t write (const uint8_t *buffer, size_t size)=0
 Pure virtual function that writes a given number of bytes from a buffer to the output stream. More...
 
virtual void flush ()=0
 Pure virtual function to flush the output stream. When this function returns, all previously written data will have been transmitted through the underlying output stream.
 
size_t print (const char *str, bool addLn=false)
 Print a null-terminated string to the output stream, with or without adding a new line character at the end. More...
 
size_t print (const uint8_t *buf, size_t size, bool addLn=false)
 Print a number of bytes to the output stream, with or without adding a new line character at the end. More...
 
size_t print (char c, bool addLn=false)
 Print a single character to the output stream, with or without adding a new line character at the end. More...
 
size_t print (int8_t n, int base=kDec, bool addLn=false)
 Print an 8-bit integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (uint8_t n, int base=kDec, bool addLn=false)
 Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (int n, int base=kDec, bool addLn=false)
 Print an integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (unsigned int n, int base=kDec, bool addLn=false)
 Print an unsigned integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (long n, int base=kDec, bool addLn=false)
 Print a long integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (unsigned long n, int base=kDec, bool addLn=false)
 Print an unsigned long integer to the output stream, with or without adding a new line character at the end. More...
 
size_t print (double d, int digits=2, bool addLn=false)
 Print a floating point number to the output stream, with or without adding a new line character at the end. More...
 
size_t println (const char *str)
 Print a null-terminated string to the output stream, adding a new line character at the end. More...
 
size_t println (const uint8_t *buf, size_t size)
 Print a number of bytes to the output stream, adding a new line character at the end. More...
 
size_t println (char c)
 Print a single character to the output stream, adding a new line character at the end. More...
 
size_t println (int8_t n, int base=kDec)
 Print an 8-bit integer to the output stream, adding a new line character at the end. More...
 
size_t println (uint8_t n, int base=kDec)
 Print an 8-bit unsigned integer to the output stream, adding a new line character at the end. More...
 
size_t println (int n, int base=kDec)
 Print an integer to the output stream, adding a new line character at the end. More...
 
size_t println (unsigned int n, int base=kDec)
 Print an unsigned integer to the output stream, adding a new line character at the end. More...
 
size_t println (long n, int base=kDec)
 Print a long integer to the output stream, adding a new line character at the end. More...
 
size_t println (unsigned long n, int base=kDec)
 Print an unsigned long integer to the output stream, adding a new line character at the end. More...
 
size_t println (double d, int digits=2)
 Print a floating point number to the output stream, adding a new line character at the end. More...
 
size_t println ()
 Print a new line to the output stream.
 

Detailed Description

This is an abstract class defining a generic interface to write numbers and strings to a sequential stream of bytes (such as a serial output device).

It implements functions to convert various integers and floating point numbers into a sequence of bytes (so it is not a pure interface class). These functions depend on a small set of lower-level functions that are purely abstract and must be implemented by classes deriving from Writer.

Serial0 is an example of a class that derives from Writer by implementating the purely abstract functions in Writer.

Member Enumeration Documentation

§ IntegerOutputBase

An enumeration that defines the number that will be used as the base for representing integer quantities as a string of characters.

Enumerator
kBin 

Produce a binary representation of integers (e.g., 11 is output as 0b1011)

kOct 

Produce an octal representation of integers (e.g, 11 is output as 013)

kDec 

Produce a decimal representation of integers (e.g., 11 is output as 11.

kHex 

Produce a hexadecimal representation of integers (e.g., 11 is output as 0x0b)

Member Function Documentation

§ print() [1/10]

size_t Writer::print ( const char *  str,
bool  addLn = false 
)

Print a null-terminated string to the output stream, with or without adding a new line character at the end.

  • str is the null-terminated string to output.
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [2/10]

size_t Writer::print ( const uint8_t *  buf,
size_t  size,
bool  addLn = false 
)

Print a number of bytes to the output stream, with or without adding a new line character at the end.

  • buf is the buffer containing bytes to output.
  • size is the number of bytes from the buffer to output.
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [3/10]

size_t Writer::print ( char  c,
bool  addLn = false 
)

Print a single character to the output stream, with or without adding a new line character at the end.

  • c is the character to output.
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [4/10]

size_t Writer::print ( int8_t  n,
int  base = kDec,
bool  addLn = false 
)

Print an 8-bit integer to the output stream, with or without adding a new line character at the end.

  • n is the integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [5/10]

size_t Writer::print ( uint8_t  n,
int  base = kDec,
bool  addLn = false 
)
inline

Print an 8-bit unsigned integer to the output stream, with or without adding a new line character at the end.

  • n is the integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [6/10]

size_t Writer::print ( int  n,
int  base = kDec,
bool  addLn = false 
)

Print an integer to the output stream, with or without adding a new line character at the end.

  • n is the integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [7/10]

size_t Writer::print ( unsigned int  n,
int  base = kDec,
bool  addLn = false 
)
inline

Print an unsigned integer to the output stream, with or without adding a new line character at the end.

  • n is the unsigned integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [8/10]

size_t Writer::print ( long  n,
int  base = kDec,
bool  addLn = false 
)

Print a long integer to the output stream, with or without adding a new line character at the end.

  • n is the long integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [9/10]

size_t Writer::print ( unsigned long  n,
int  base = kDec,
bool  addLn = false 
)

Print an unsigned long integer to the output stream, with or without adding a new line character at the end.

  • n is the unsigned long integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ print() [10/10]

size_t Writer::print ( double  d,
int  digits = 2,
bool  addLn = false 
)

Print a floating point number to the output stream, with or without adding a new line character at the end.

  • d is the floating point number to output.
  • digits is the number of decimal digits to output; the default is 2.
  • addLn if true, a new line character is added at the end of the output; the default is false.
Returns
the number of bytes sent to the output stream.

§ println() [1/10]

size_t Writer::println ( const char *  str)
inline

Print a null-terminated string to the output stream, adding a new line character at the end.

  • str is the null-terminated string to output.
Returns
the number of bytes sent to the output stream.

§ println() [2/10]

size_t Writer::println ( const uint8_t *  buf,
size_t  size 
)
inline

Print a number of bytes to the output stream, adding a new line character at the end.

  • buf is the buffer containing bytes to output.
  • size is the number of bytes from the buffer to output.
Returns
the number of bytes sent to the output stream.

§ println() [3/10]

size_t Writer::println ( char  c)
inline

Print a single character to the output stream, adding a new line character at the end.

  • c is the character to output.
Returns
the number of bytes sent to the output stream.

§ println() [4/10]

size_t Writer::println ( int8_t  n,
int  base = kDec 
)
inline

Print an 8-bit integer to the output stream, adding a new line character at the end.

  • n is the integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [5/10]

size_t Writer::println ( uint8_t  n,
int  base = kDec 
)
inline

Print an 8-bit unsigned integer to the output stream, adding a new line character at the end.

  • n is the unsigned integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [6/10]

size_t Writer::println ( int  n,
int  base = kDec 
)
inline

Print an integer to the output stream, adding a new line character at the end.

  • n is the integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [7/10]

size_t Writer::println ( unsigned int  n,
int  base = kDec 
)
inline

Print an unsigned integer to the output stream, adding a new line character at the end.

  • n is the unsigned integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [8/10]

size_t Writer::println ( long  n,
int  base = kDec 
)
inline

Print a long integer to the output stream, adding a new line character at the end.

  • n is the long integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [9/10]

size_t Writer::println ( unsigned long  n,
int  base = kDec 
)
inline

Print an unsigned long integer to the output stream, adding a new line character at the end.

  • n is the unsigned long integer to output.
  • base is the base used to represent the number; should be one of IntegerOutputBase; defaults to decimal representation (kDec).
Returns
the number of bytes sent to the output stream.

§ println() [10/10]

size_t Writer::println ( double  d,
int  digits = 2 
)
inline

Print a floating point number to the output stream, adding a new line character at the end.

  • d is the flaoting point number to output.
  • digits is the number of decimal digits to output; the default is 2.
Returns
the number of bytes sent to the output stream.

§ write() [1/4]

size_t Writer::write ( char  c)
pure virtual

Pure virtual function that writes a single character to the output stream.

  • c the character to be written.
Returns
the number of bytes written.

Implemented in Serial1, Serial2, Serial3, Serial0, and I2cLcd.

§ write() [2/4]

size_t Writer::write ( const char *  str)
pure virtual

Pure virtual function that writes a null-terminated string to the output stream.

  • str the string to be written.
Returns
the number of bytes written.

Implemented in Serial1, Serial2, Serial3, Serial0, and I2cLcd.

§ write() [3/4]

size_t Writer::write ( const char *  buffer,
size_t  size 
)
pure virtual

Pure virtual function that writes a given number of characters from a buffer to the output stream.

  • buffer the buffer of characters to write.
  • size the number of characters to write
Returns
the number of bytes written.

Implemented in Serial1, Serial2, Serial3, Serial0, and I2cLcd.

§ write() [4/4]

size_t Writer::write ( const uint8_t *  buffer,
size_t  size 
)
pure virtual

Pure virtual function that writes a given number of bytes from a buffer to the output stream.

  • buffer the buffer of bytes to write.
  • size the number of bytes to write
Returns
the number of bytes written.

Implemented in Serial1, Serial2, Serial3, Serial0, and I2cLcd.


The documentation for this class was generated from the following files: