This is an helper class that provides a simple ring buffers that works as a FIFO.
More...
template<typename T, size_t SIZE>
class esphome::weikai::WKRingBuffer< T, SIZE >
This is an helper class that provides a simple ring buffers that works as a FIFO.
This ring buffer is used to buffer the bytes received in the FIFO of the Weika device. The best way to read characters from the device FIFO, is to first check how many bytes were received and then read them all at once. Unfortunately in all the code I have reviewed the characters are read one by one in a while loop by checking if bytes are available then reading the byte until no more byte available. This is pretty inefficient for two reasons:
- Fist you need to perform a test for each byte to read
- and second you call the read byte method for each character.
Assuming you need to read 100 bytes that results into 200 calls. This is to compare to 2 calls (one to find the number of bytes available plus one to read all the bytes) in the best case! If the registers you read are located on the micro-controller this is acceptable because the registers can be accessed fast. But when the registers are located on a remote device accessing them requires several cycles on a slow bus. As it it not possible to fix this problem by asking users to rewrite their code, I have implemented this ring buffer that store the bytes received locally.
Definition at line 61 of file weikai.h.