ESPHome 2025.5.0
Loading...
Searching...
No Matches
ring_buffer.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP32
4
5#include <freertos/FreeRTOS.h>
6#include <freertos/ringbuf.h>
7
8#include <cinttypes>
9#include <memory>
10
11namespace esphome {
12
14 public:
16
28 size_t read(void *data, size_t len, TickType_t ticks_to_wait = 0);
29
40 size_t write(const void *data, size_t len);
41
53 size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait = 0);
54
63 size_t available() const;
64
73 size_t free() const;
74
80 BaseType_t reset();
81
82 static std::unique_ptr<RingBuffer> create(size_t len);
83
84 protected:
88 bool discard_bytes_(size_t discard_bytes);
89
90 RingbufHandle_t handle_{nullptr};
91 StaticRingbuffer_t structure_;
92 uint8_t *storage_{nullptr};
93 size_t size_{0};
94};
95
96} // namespace esphome
97
98#endif
size_t free() const
Returns the number of free bytes in the ring buffer.
static std::unique_ptr< RingBuffer > create(size_t len)
size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait=0)
Writes to the ring buffer without overwriting oldest data.
BaseType_t reset()
Resets the ring buffer, discarding all stored data.
RingbufHandle_t handle_
Definition ring_buffer.h:90
bool discard_bytes_(size_t discard_bytes)
Discards data from the ring buffer.
size_t write(const void *data, size_t len)
Writes to the ring buffer, overwriting oldest data if necessary.
size_t available() const
Returns the number of available bytes in the ring buffer.
StaticRingbuffer_t structure_
Definition ring_buffer.h:91
size_t read(void *data, size_t len, TickType_t ticks_to_wait=0)
Reads from the ring buffer, waiting up to a specified number of ticks if necessary.
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301