Envorimental Monitoring
Loading...
Searching...
No Matches
ring_buffer.c File Reference

Circular (ring) buffer implementation for float sensor samples. More...

#include "ring_buffer.h"

Functions

void buffer_init (buf_handle_t *p_handle, float *p_buffer, uint16_t size)
 Initialises a ring buffer handle.
bool buffer_isFull (buf_handle_t *p_handle)
 Checks whether the buffer is full.
void buffer_clear (buf_handle_t *p_handle)
 Resets the buffer to an empty state without clearing storage memory.
bool buffer_isEmpty (buf_handle_t *p_handle)
 Checks whether the buffer is empty.
int buffer_get_value (buf_handle_t *p_handle, float *p_sensor_data)
 Reads and removes the oldest sample from the buffer (FIFO order).
int buffer_write_value (buf_handle_t *p_handle, float p_sensor_data)
 Writes a new sample into the buffer.

Detailed Description

Circular (ring) buffer implementation for float sensor samples.

Author
Şule Nur Demirdaş
Date
April 2026

Function Documentation

◆ buffer_clear()

void buffer_clear ( buf_handle_t * p_handle)

Resets the buffer to an empty state without clearing storage memory.

Parameters
[in,out]p_handlePointer to the buffer handle.

◆ buffer_get_value()

int buffer_get_value ( buf_handle_t * p_handle,
float * p_sensor_data )

Reads and removes the oldest sample from the buffer (FIFO order).

Parameters
[in,out]p_handlePointer to the buffer handle.
[out]p_sensor_dataPointer to the float that receives the value.
Returns
0 on success, -1 if the buffer is empty.

◆ buffer_init()

void buffer_init ( buf_handle_t * p_handle,
float * p_buffer,
uint16_t size )

Initialises a ring buffer handle.

Must be called once before any other buffer operation. The caller provides the backing storage array and its capacity.

Parameters
[out]p_handlePointer to the buffer handle to initialise.
[in]p_bufferPointer to the float array used as storage.
[in]sizeNumber of elements in p_buffer.

◆ buffer_isEmpty()

bool buffer_isEmpty ( buf_handle_t * p_handle)

Checks whether the buffer is empty.

Parameters
[in]p_handlePointer to the buffer handle.
Returns
true if count == 0, false otherwise.

◆ buffer_isFull()

bool buffer_isFull ( buf_handle_t * p_handle)

Checks whether the buffer is full.

Parameters
[in]p_handlePointer to the buffer handle.
Returns
true if count == size, false otherwise.

◆ buffer_write_value()

int buffer_write_value ( buf_handle_t * p_handle,
float p_sensor_data )

Writes a new sample into the buffer.

If the buffer is full the oldest sample is overwritten (count is kept at size). This ensures the buffer always holds the most recent samples.

Parameters
[in,out]p_handlePointer to the buffer handle.
[in]p_sensor_dataFloat value to store.
Returns
Always 0.