Prusa MINI Firmware overview
RingBuffer< T, S > Class Template Reference

#include <WebSocketSerial.h>

Public Member Functions

 RingBuffer (ring_buffer_pos_t size)
 
 ~RingBuffer ()
 
int available ()
 
int peek ()
 
int read ()
 
ring_buffer_pos_t read (uint8_t *buffer)
 
void flush ()
 
ring_buffer_pos_t write (const uint8_t c)
 
ring_buffer_pos_t write (const uint8_t *buffer, ring_buffer_pos_t size)
 
 RingBuffer ()
 
uint32_t available () volatile
 
uint32_t free () volatile
 
bool empty () volatile
 
bool full () volatile
 
void clear () volatile
 
bool peek (T *value) volatile
 
int read () volatile
 
bool write (T value) volatile
 

Detailed Description

template<typename T, uint32_t S>
class RingBuffer< T, S >

Marlin 3D Printer Firmware Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]

Based on Sprinter and grbl. Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/. Generic RingBuffer T type of the buffer array S size of the buffer (must be power of 2)

Constructor & Destructor Documentation

◆ RingBuffer() [1/2]

template<typename T, uint32_t S>
RingBuffer< T, S >::RingBuffer ( ring_buffer_pos_t  size)

◆ ~RingBuffer()

template<typename T, uint32_t S>
RingBuffer< T, S >::~RingBuffer ( )

◆ RingBuffer() [2/2]

template<typename T, uint32_t S>
RingBuffer< T, S >::RingBuffer ( )
40 { index_read = index_write = 0; }

Member Function Documentation

◆ available() [1/2]

template<typename T, uint32_t S>
int RingBuffer< T, S >::available ( )
Here is the caller graph for this function:

◆ peek() [1/2]

template<typename T, uint32_t S>
int RingBuffer< T, S >::peek ( )
Here is the caller graph for this function:

◆ read() [1/3]

template<typename T, uint32_t S>
int RingBuffer< T, S >::read ( )
Here is the caller graph for this function:

◆ read() [2/3]

template<typename T, uint32_t S>
ring_buffer_pos_t RingBuffer< T, S >::read ( uint8_t buffer)

◆ flush()

template<typename T, uint32_t S>
void RingBuffer< T, S >::flush ( )

◆ write() [1/3]

template<typename T, uint32_t S>
ring_buffer_pos_t RingBuffer< T, S >::write ( const uint8_t  c)
Here is the caller graph for this function:

◆ write() [2/3]

template<typename T, uint32_t S>
ring_buffer_pos_t RingBuffer< T, S >::write ( const uint8_t buffer,
ring_buffer_pos_t  size 
)

◆ available() [2/2]

template<typename T, uint32_t S>
uint32_t RingBuffer< T, S >::available ( void  ) volatile
41 { return index_write - index_read; }

◆ free()

template<typename T, uint32_t S>
uint32_t RingBuffer< T, S >::free ( ) volatile
42 { return buffer_size - available(); }
Here is the caller graph for this function:

◆ empty()

template<typename T, uint32_t S>
bool RingBuffer< T, S >::empty ( ) volatile
43 { return index_read == index_write; }
Here is the caller graph for this function:

◆ full()

template<typename T, uint32_t S>
bool RingBuffer< T, S >::full ( ) volatile
44 { return available() == buffer_size; }
Here is the caller graph for this function:

◆ clear()

template<typename T, uint32_t S>
void RingBuffer< T, S >::clear ( ) volatile
45 { index_read = index_write = 0; }
Here is the caller graph for this function:

◆ peek() [2/2]

template<typename T, uint32_t S>
bool RingBuffer< T, S >::peek ( T *  value) volatile
47  {
48  if (value == 0 || available() == 0)
49  return false;
50  *value = buffer[mask(index_read)];
51  return true;
52  }

◆ read() [3/3]

template<typename T, uint32_t S>
int RingBuffer< T, S >::read ( void  ) volatile
54  {
55  if (empty()) return -1;
56  return buffer[mask(index_read++)];
57  }

◆ write() [3/3]

template<typename T, uint32_t S>
bool RingBuffer< T, S >::write ( value) volatile
59  {
60  if (full()) return false;
61  buffer[mask(index_write++)] = value;
62  return true;
63  }
RingBuffer::available
int available()
RingBuffer::empty
bool empty() volatile
Definition: serial.h:43
RingBuffer::full
bool full() volatile
Definition: serial.h:44