ESPHome
2026.1.0-dev
Loading...
Searching...
No Matches
esphome
components
uart
uart_component.cpp
Go to the documentation of this file.
1
#include "
uart_component.h
"
2
3
namespace
esphome::uart
{
4
5
static
const
char
*
const
TAG
=
"uart"
;
6
7
bool
UARTComponent::check_read_timeout_
(
size_t
len
) {
8
if
(this->
available
() >=
int
(len))
9
return
true
;
10
11
uint32_t start_time =
millis
();
12
while
(this->
available
() <
int
(len)) {
13
if
(
millis
() - start_time > 100) {
14
ESP_LOGE(TAG,
"Reading from UART timed out at byte %u!"
, this->
available
());
15
return
false
;
16
}
17
yield
();
18
}
19
return
true
;
20
}
21
22
void
UARTComponent::set_rx_full_threshold_ms
(uint8_t time) {
23
uint8_t bytelength = this->
data_bits_
+ this->
stop_bits_
+ 1;
24
if
(this->
parity_
!=
UARTParityOptions::UART_CONFIG_PARITY_NONE
)
25
bytelength += 1;
26
int32_t
val
= clamp<int32_t>((this->
baud_rate_
/ (bytelength * 1000 / time)) - 1, 1, 120);
27
this->
set_rx_full_threshold
(val);
28
}
29
30
}
// namespace esphome::uart
esphome::uart::UARTComponent::parity_
UARTParityOptions parity_
Definition
uart_component.h:195
esphome::uart::UARTComponent::baud_rate_
uint32_t baud_rate_
Definition
uart_component.h:192
esphome::uart::UARTComponent::check_read_timeout_
bool check_read_timeout_(size_t len=1)
Definition
uart_component.cpp:7
esphome::uart::UARTComponent::data_bits_
uint8_t data_bits_
Definition
uart_component.h:194
esphome::uart::UARTComponent::set_rx_full_threshold_ms
void set_rx_full_threshold_ms(uint8_t time)
Definition
uart_component.cpp:22
esphome::uart::UARTComponent::set_rx_full_threshold
virtual void set_rx_full_threshold(size_t rx_full_threshold)
Definition
uart_component.h:99
esphome::uart::UARTComponent::available
virtual int available()=0
esphome::uart::UARTComponent::stop_bits_
uint8_t stop_bits_
Definition
uart_component.h:193
val
mopeka_std_values val[4]
Definition
mopeka_std_check.h:8
esphome::spi::TAG
const char *const TAG
Definition
spi.cpp:7
esphome::uart
Definition
automation.h:8
esphome::uart::UART_CONFIG_PARITY_NONE
@ UART_CONFIG_PARITY_NONE
Definition
uart_component.h:17
esphome::len
std::string size_t len
Definition
helpers.h:533
esphome::yield
void IRAM_ATTR HOT yield()
Definition
core.cpp:24
esphome::millis
uint32_t IRAM_ATTR HOT millis()
Definition
core.cpp:25
uart_component.h
Generated by
1.12.0