ESPHome 2026.2.1
Loading...
Searching...
No Matches
lightwaverf.cpp
Go to the documentation of this file.
2#include "esphome/core/log.h"
3
4#ifdef USE_ESP8266
5
6#include "lightwaverf.h"
7
8namespace esphome {
9namespace lightwaverf {
10
11static const char *const TAG = "lightwaverf.sensor";
12
13static const uint8_t DEFAULT_REPEAT = 10;
14static const bool DEFAULT_INVERT = false;
15static const uint32_t DEFAULT_TICK = 330;
16
18 this->lwtx_.lwtx_setup(pin_tx_, DEFAULT_REPEAT, DEFAULT_INVERT, DEFAULT_TICK);
20}
21
22void LightWaveRF::update() { this->read_tx(); }
23
25 if (this->lwrx_.lwrx_message()) {
28 }
29}
30
31void LightWaveRF::send_rx(const std::vector<uint8_t> &msg, uint8_t repeats, bool inverted, int u_sec) {
32 this->lwtx_.lwtx_setup(pin_tx_, repeats, inverted, u_sec);
33
34 uint32_t timeout = 0;
35 if (this->lwtx_.lwtx_free()) {
36 this->lwtx_.lwtx_send(msg);
37 timeout = millis();
38 ESP_LOGD(TAG, "[%i] msg start", timeout);
39 }
40 while (!this->lwtx_.lwtx_free() && millis() < (timeout + 1000)) {
41 delay(10);
42 }
43 timeout = millis() - timeout;
44 ESP_LOGD(TAG, "[%u] msg sent: %i", millis(), timeout);
45}
46
47void LightWaveRF::print_msg_(uint8_t *msg, uint8_t len) {
48#if ESPHOME_LOG_LEVEL >= ESPHOME_LOG_LEVEL_DEBUG
49 char buffer[65]; // max 10 entries * 6 chars + null
50 ESP_LOGD(TAG, " Received code (len:%i): ", len);
51
52 size_t pos = 0;
53 for (int i = 0; i < len; i++) {
54 pos = buf_append_printf(buffer, sizeof(buffer), pos, "0x%02x, ", msg[i]);
55 }
56 ESP_LOGD(TAG, "[%s]", buffer);
57#endif
58}
59
61 ESP_LOGCONFIG(TAG, "Lightwave RF:");
62 LOG_PIN(" Pin TX: ", this->pin_tx_);
63 LOG_PIN(" Pin RX: ", this->pin_rx_);
64 LOG_UPDATE_INTERVAL(this);
65}
66} // namespace lightwaverf
67} // namespace esphome
68
69#endif
void print_msg_(uint8_t *msg, uint8_t len)
void send_rx(const std::vector< uint8_t > &msg, uint8_t repeats, bool inverted, int u_sec)
void lwrx_setup(InternalGPIOPin *pin)
Set things up to receive LightWaveRF 434Mhz messages pin must be 2 or 3 to trigger interrupts !...
Definition LwRx.cpp:313
bool lwrx_message()
Test if a message has arrived.
Definition LwRx.cpp:175
bool lwrx_getmessage(uint8_t *buf, uint8_t len)
Transfer a message to user buffer.
Definition LwRx.cpp:184
void lwtx_setup(InternalGPIOPin *pin, uint8_t repeats, bool inverted, int u_sec)
Set things up to transmit LightWaveRF 434Mhz messages.
Definition LwTx.cpp:149
void lwtx_send(const std::vector< uint8_t > &msg)
Send a LightwaveRF message (10 nibbles in bytes)
Definition LwTx.cpp:110
bool lwtx_free()
Check for send free.
Definition LwTx.cpp:105
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:692
size_t size_t pos
Definition helpers.h:729
void IRAM_ATTR HOT delay(uint32_t ms)
Definition core.cpp:26
uint32_t IRAM_ATTR HOT millis()
Definition core.cpp:25