ESPHome 2025.10.0-dev
|
The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class. More...
#include <weikai.h>
Public Member Functions | |
void | set_parent (WeikaiComponent *parent) |
We belongs to this WeikaiComponent. | |
void | set_channel (uint8_t channel) |
Sets the channel number. | |
void | set_channel_name (std::string &&name) |
The name as generated by the Python code generator. | |
const char * | get_channel_name () |
Get the channel name. | |
virtual void | setup_channel () |
Setup the channel. | |
virtual void | dump_channel () |
dump channel information | |
WeikaiRegister & | reg (uint8_t reg) |
Factory method to create a WeikaiRegister proxy object. | |
void | write_array (const uint8_t *buffer, size_t length) override |
Writes a specified number of bytes to a serial port. | |
bool | read_array (uint8_t *buffer, size_t length) override |
Reads a specified number of bytes from a serial port. | |
bool | peek_byte (uint8_t *buffer) override |
Reads the first byte in FIFO without removing it. | |
int | available () override |
Returns the number of bytes in the receive buffer. | |
void | flush () override |
Flush the output fifo. | |
![]() | |
void | write_array (const std::vector< uint8_t > &data) |
void | write_byte (uint8_t data) |
void | write_str (const char *str) |
bool | read_byte (uint8_t *data) |
void | set_tx_pin (InternalGPIOPin *tx_pin) |
void | set_rx_pin (InternalGPIOPin *rx_pin) |
void | set_flow_control_pin (InternalGPIOPin *flow_control_pin) |
void | set_rx_buffer_size (size_t rx_buffer_size) |
size_t | get_rx_buffer_size () |
virtual void | set_rx_full_threshold (size_t rx_full_threshold) |
void | set_rx_full_threshold_ms (uint8_t time) |
size_t | get_rx_full_threshold () |
virtual void | set_rx_timeout (size_t rx_timeout) |
size_t | get_rx_timeout () |
void | set_stop_bits (uint8_t stop_bits) |
uint8_t | get_stop_bits () const |
void | set_data_bits (uint8_t data_bits) |
uint8_t | get_data_bits () const |
void | set_parity (UARTParityOptions parity) |
UARTParityOptions | get_parity () const |
void | set_baud_rate (uint32_t baud_rate) |
uint32_t | get_baud_rate () const |
virtual void | load_settings (bool dump_config) |
Load the UART settings. | |
virtual void | load_settings () |
Load the UART settings. | |
void | add_debug_callback (std::function< void(UARTDirection, uint8_t)> &&callback) |
Protected Member Functions | |
void | check_logger_conflict () override |
this cannot happen with external uart therefore we do nothing | |
void | reset_fifo_ () |
reset the weikai internal FIFO | |
void | set_line_param_ () |
set the line parameters | |
void | set_baudrate_ () |
set the baud rate | |
size_t | rx_in_fifo_ () |
Returns the number of bytes in the receive fifo. | |
size_t | tx_in_fifo_ () |
Returns the number of bytes in the transmit fifo. | |
bool | tx_fifo_is_not_empty_ () |
test if transmit buffer is not empty in the status register (optimization) | |
size_t | xfer_fifo_to_buffer_ () |
transfer bytes from the weikai internal FIFO to the buffer (if any) | |
virtual bool | check_channel_down () |
check if channel is alive | |
void | uart_send_test_ (char *message) |
Test the write_array() method. | |
bool | uart_receive_test_ (char *message) |
Test the read_array() method. | |
![]() | |
bool | check_read_timeout_ (size_t len=1) |
Protected Attributes | |
WKRingBuffer< uint8_t, RING_BUFFER_SIZE > | receive_buffer_ |
the buffer where we store temporarily the bytes received | |
WeikaiComponent * | parent_ |
our WK2168component parent | |
uint8_t | channel_ |
our Channel number | |
uint8_t | data_ |
a one byte buffer for register read storage | |
std::string | name_ |
name of the entity | |
![]() | |
InternalGPIOPin * | tx_pin_ |
InternalGPIOPin * | rx_pin_ |
InternalGPIOPin * | flow_control_pin_ |
size_t | rx_buffer_size_ |
size_t | rx_full_threshold_ {1} |
size_t | rx_timeout_ {0} |
uint32_t | baud_rate_ |
uint8_t | stop_bits_ |
uint8_t | data_bits_ |
UARTParityOptions | parity_ |
CallbackManager< void(UARTDirection, uint8_t)> | debug_callback_ {} |
The WeikaiChannel class is used to implement all the virtual methods of the ESPHome uart::UARTComponent virtual class.
This class is common to the different members of the Weikai components family and therefore avoid code duplication.
|
overridevirtual |
Returns the number of bytes in the receive buffer.
Implements esphome::uart::UARTComponent.
Definition at line 401 of file weikai.cpp.
|
protectedvirtual |
|
inlineoverrideprotectedvirtual |
this cannot happen with external uart therefore we do nothing
Implements esphome::uart::UARTComponent.
|
virtual |
dump channel information
Definition at line 269 of file weikai.cpp.
|
overridevirtual |
Flush the output fifo.
If we refer to Serial.flush() in Arduino it says: ** Waits for the transmission of outgoing serial data to complete. (Prior to Arduino 1.0, this the method was removing any buffered incoming serial data.). ** Therefore we wait until all bytes are gone with a timeout of 100 ms
Implements esphome::uart::UARTComponent.
Definition at line 433 of file weikai.cpp.
|
inline |
|
overridevirtual |
Reads the first byte in FIFO without removing it.
buffer | pointer to the byte |
This method returns the next byte from receiving buffer without removing it from the internal fifo. It returns true if a character is available and has been read, false otherwise.
Implements esphome::uart::UARTComponent.
Definition at line 394 of file weikai.cpp.
|
overridevirtual |
Reads a specified number of bytes from a serial port.
buffer | buffer to store the bytes |
length | number of bytes to read |
Typical usage:
Implements esphome::uart::UARTComponent.
Definition at line 408 of file weikai.cpp.
|
inline |
Factory method to create a WeikaiRegister proxy object.
reg | address of the register |
|
protected |
reset the weikai internal FIFO
Definition at line 279 of file weikai.cpp.
|
protected |
Returns the number of bytes in the receive fifo.
Definition at line 347 of file weikai.cpp.
|
protected |
set the baud rate
Definition at line 306 of file weikai.cpp.
|
inline |
|
inline |
|
protected |
set the line parameters
Definition at line 286 of file weikai.cpp.
|
inline |
We belongs to this WeikaiComponent.
parent | pointer to the component we belongs to |
|
virtual |
Setup the channel.
Definition at line 257 of file weikai.cpp.
|
inlineprotected |
test if transmit buffer is not empty in the status register (optimization)
Definition at line 332 of file weikai.cpp.
|
protected |
Returns the number of bytes in the transmit fifo.
Definition at line 334 of file weikai.cpp.
|
overridevirtual |
Writes a specified number of bytes to a serial port.
buffer | pointer to the buffer |
length | number of bytes to write |
This method sends 'length' characters from the buffer to the serial line. Unfortunately (unlike the Arduino equivalent) this method does not return any flag and therefore it is not possible to know if any/all bytes have been transmitted correctly. Another problem is that it is not possible to know ahead of time how many bytes we can safely send as there is no tx_available() method provided! To avoid overrun when using the write method you can use the flush() method to wait until the transmit fifo is empty.
Typical usage could be:
Implements esphome::uart::UARTComponent.
Definition at line 425 of file weikai.cpp.
|
protected |
transfer bytes from the weikai internal FIFO to the buffer (if any)
Definition at line 444 of file weikai.cpp.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |