ESPHome 2025.10.0-dev
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 bool write_partial = true);
55
64 size_t available() const;
65
74 size_t free() const;
75
81 BaseType_t reset();
82
83 static std::unique_ptr<RingBuffer> create(size_t len);
84
85 protected:
89 bool discard_bytes_(size_t discard_bytes);
90
91 RingbufHandle_t handle_{nullptr};
92 StaticRingbuffer_t structure_;
93 uint8_t *storage_{nullptr};
94 size_t size_{0};
95};
96
97} // namespace esphome
98
99#endif
size_t free() const
Returns the number of free bytes in the ring buffer.
static std::unique_ptr< RingBuffer > create(size_t len)
BaseType_t reset()
Resets the ring buffer, discarding all stored data.
RingbufHandle_t handle_
Definition ring_buffer.h:91
size_t write_without_replacement(const void *data, size_t len, TickType_t ticks_to_wait=0, bool write_partial=true)
Writes to the ring buffer without overwriting oldest data.
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:92
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:291