UartBuffered.hpp

Submitted by Webbot on January 2, 2009 - 1:06am.

This class provides a Uart with buffered input and output and so allows your code to go at full speed whilst receiving and sending data in the background.

 

To create a buffered UART for output only that can buffer 64 characters then use:-

uint8_t g_uart_buffer[64];                                 // create space for 64 bytes

BUFFER g_uart_out(g_uart_buffer);                     // wrap it in a buffer

UART_BUFFERED g_uart(19200, &g_uart_out);     // connect the buffer to a 19,200 baud uart

 

You can then write output by using:

g_uart.display('1');

 

Equally you can define  an input buffer as well:-

uint8_t g_uart_buf_out[64];                                 // create space for 64 byte output

BUFFER g_uart_out(g_uart_buf_out);                     // wrap it in a buffer

uint8_t g_uart_buf_in[32];                                   // create space for 32 byte input

BUFFER g_uart_in(g_uart_buf_in);                         // wrap it in a buffer

UART_BUFFERED g_uart(19200, &g_uart_out,&g_uart_in);  // connect the buffers to a 19,200 baud uart

And then access the input buffer via the Buffer.hpp commands such as:-

if(  ! g_uart_in.isEmpty() ){

   uint8_t input = g_uart_in.get;  // get next char from uart

   ... do something ....

}