SdFat: RingBuf< F, Size > Class Template Reference

SdFat

Public Member Functions | List of all members
RingBuf< F, Size > Class Template Reference

Ring buffer for data loggers. More...

`#include <RingBuf.h>`

Inheritance diagram for RingBuf< F, Size >:
[legend]
Collaboration diagram for RingBuf< F, Size >:
[legend]

## Public Member Functions
void | begin (F *file)
size_t | bytesFree () const
size_t | bytesFreeIsr () const
size_t | bytesUsed () const
size_t | bytesUsedIsr () const
size_t | memcpyIn (const void *buf, size_t count)
size_t | memcpyOut (void *buf, size_t count)
size_t | printField (double value, char term, uint8_t prec=2)
size_t | printField (float value, char term, uint8_t prec=2)
template<typename Type >
size_t | printField (Type value, char term)
size_t | readIn (size_t count)
| RingBuf ()
bool | sync ()
size_t | write (const uint8_t *buf, size_t count) override
size_t | write (const void *buf, size_t count)
size_t | write (uint8_t data) override
size_t | writeOut (size_t count)

## Detailed Description

### template<class F, size_t Size>
class RingBuf< F, Size >

Ring buffer for data loggers.

This ring buffer may be used in ISRs. bytesFreeIsr(), bytesUsedIsr(), memcopyIn(), and memcopyOut() are ISR callable. For ISR use call memcopyIn() in the ISR and use writeOut() in non-interrupt code to write data to a file. readIn() and memcopyOut can be use in a similar way to provide file data to an ISR.

Print into a RingBuf in an ISR should also work but has not been verified.

## Constructor & Destructor Documentation

## ◆ RingBuf()

template<class F , size_t Size>

RingBuf< F, Size >::RingBuf | ( |  | ) |
| inline

RingBuf Constructor.

## Member Function Documentation

## ◆ begin()

template<class F , size_t Size>

void RingBuf< F, Size >::begin | ( | F * | file | ) |
| inline

Initialize RingBuf.

Parameters

  [in] | file | Underlying file.

## ◆ bytesFree()

template<class F , size_t Size>

size_t RingBuf< F, Size >::bytesFree | ( |  | ) | const
| inline

Returns
  the RingBuf free space in bytes. Not ISR callable.

## ◆ bytesFreeIsr()

template<class F , size_t Size>

size_t RingBuf< F, Size >::bytesFreeIsr | ( |  | ) | const
| inline

Returns
  the RingBuf free space in bytes. ISR callable.

## ◆ bytesUsed()

template<class F , size_t Size>

size_t RingBuf< F, Size >::bytesUsed | ( |  | ) | const
| inline

Returns
  the RingBuf used space in bytes. Not ISR callable.

## ◆ bytesUsedIsr()

template<class F , size_t Size>

size_t RingBuf< F, Size >::bytesUsedIsr | ( |  | ) | const
| inline

Returns
  the RingBuf used space in bytes. ISR callable.

## ◆ memcpyIn()

template<class F , size_t Size>

size_t RingBuf< F, Size >::memcpyIn | ( | const void * | buf,
|  | size_t | count
| ) |  |
| inline

Copy data to the RingBuf from buf. The number of bytes copied may be less than count if count is greater than bytesFree.

This function may be used in an ISR with writeOut() in non-interrupt code.

Parameters

  [in] | buf | Location of data to be copied.
  [in] | count | number of bytes to be copied.

Returns
  Number of bytes actually copied.

## ◆ memcpyOut()

template<class F , size_t Size>

size_t RingBuf< F, Size >::memcpyOut | ( | void * | buf,
|  | size_t | count
| ) |  |
| inline

Copy date from the RingBuf to buf. The number of bytes copied may be less than count if bytesUsed is less than count.

This function may be used in an ISR with readIn() in non-interrupt code.

Parameters

  [out] | buf | Location to receive the data.
  [in] | count | number of bytes to be copied.

Returns
  Number of bytes actually copied.

## ◆ printField() [1/3]

template<class F , size_t Size>

size_t RingBuf< F, Size >::printField | ( | double | value,
|  | char | term,
|  | uint8_t | prec = `2`
| ) |  |
| inline

Print a number followed by a field terminator.

Parameters

  [in] | value | The number to be printed.
  [in] | term | The field terminator. Use '\n' for CR LF.
  [in] | prec | Number of digits after decimal point.

Returns
  The number of bytes written.

## ◆ printField() [2/3]

template<class F , size_t Size>

size_t RingBuf< F, Size >::printField | ( | float | value,
|  | char | term,
|  | uint8_t | prec = `2`
| ) |  |
| inline

Print a number followed by a field terminator.

Parameters

  [in] | value | The number to be printed.
  [in] | term | The field terminator. Use '\n' for CR LF.
  [in] | prec | Number of digits after decimal point.

Returns
  The number of bytes written or -1 if an error occurs.

## ◆ printField() [3/3]

template<class F , size_t Size>
template<typename Type >

size_t RingBuf< F, Size >::printField | ( | Type | value,
|  | char | term
| ) |  |
| inline

Print a number followed by a field terminator.

Parameters

  [in] | value | The number to be printed.
  [in] | term | The field terminator. Use '\n' for CR LF.

Returns
  The number of bytes written or -1 if an error occurs.

## ◆ readIn()

template<class F , size_t Size>

size_t RingBuf< F, Size >::readIn | ( | size_t | count | ) |
| inline

Read data into the RingBuf from the underlying file. the number of bytes read may be less than count if bytesFree is less than count.

This function may be used in non-interrupt code with memcopyOut() in an ISR.

Parameters

  [in] | count | number of bytes to be read.

Returns
  Number of bytes actually read.

## ◆ sync()

template<class F , size_t Size>

bool RingBuf< F, Size >::sync | ( |  | ) |
| inline

Write all data in the RingBuf to the underlying file.

Parameters

  [in] | data | Byte to be written.

Returns
  Number of bytes actually written.

## ◆ write() [1/3]

template<class F , size_t Size>

size_t RingBuf< F, Size >::write | ( | const uint8_t * | buf,
|  | size_t | count
| ) |  |
| inlineoverride

Override virtual function in Print for efficiency.

Parameters

  [in] | buf | Location of data to be written.
  [in] | count | number of bytes to be written.

Returns
  Number of bytes actually written.

## ◆ write() [2/3]

template<class F , size_t Size>

size_t RingBuf< F, Size >::write | ( | const void * | buf,
|  | size_t | count
| ) |  |
| inline

Copy data to the RingBuf from buf.

The number of bytes copied may be less than count if count is greater than bytesFree. Use getWriteError() to check for print errors and clearWriteError() to clear error.

Parameters

  [in] | buf | Location of data to be written.
  [in] | count | number of bytes to be written.

Returns
  Number of bytes actually written.

## ◆ write() [3/3]

template<class F , size_t Size>

size_t RingBuf< F, Size >::write | ( | uint8_t | data | ) |
| inlineoverride

Required function for Print.

Parameters

  [in] | data | Byte to be written.

Returns
  Number of bytes actually written.

## ◆ writeOut()

template<class F , size_t Size>

size_t RingBuf< F, Size >::writeOut | ( | size_t | count | ) |
| inline

Write data to file from RingBuf buffer.

Parameters

  [in] | count | number of bytes to be written.

The number of bytes written may be less than count if bytesUsed is less than count or if an error occurs.

This function may be used in non-interrupt code with memcopyIn() in an ISR.

Returns
  Number of bytes actually written.

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

- ArduinoSdFat/libraries/SdFat/src/RingBuf.h