ESPHome 2025.5.2
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
lightwaverf.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef USE_ESP8266
4
6#include "esphome/core/hal.h"
8
9#include <vector>
10
11#include "LwRx.h"
12#include "LwTx.h"
13
14namespace esphome {
15namespace lightwaverf {
16
17#ifdef USE_ESP8266
18
20 public:
21 void set_pin(InternalGPIOPin *pin_tx, InternalGPIOPin *pin_rx) {
22 pin_tx_ = pin_tx;
23 pin_rx_ = pin_rx;
24 }
25 void update() override;
26 void setup() override;
27 void dump_config() override;
28 void read_tx();
29 void send_rx(const std::vector<uint8_t> &msg, uint8_t repeats, bool inverted, int u_sec);
30
31 protected:
32 void print_msg_(uint8_t *msg, uint8_t len);
33 uint8_t msg_[10];
34 uint8_t msglen_ = 10;
39};
40
41template<typename... Ts> class SendRawAction : public Action<Ts...> {
42 public:
43 SendRawAction(LightWaveRF *parent) : parent_(parent){};
44 TEMPLATABLE_VALUE(int, repeat);
45 TEMPLATABLE_VALUE(int, inverted);
46 TEMPLATABLE_VALUE(int, pulse_length);
47 TEMPLATABLE_VALUE(std::vector<uint8_t>, code);
48
49 void set_repeats(const int &data) { repeat_ = data; }
50 void set_inverted(const int &data) { inverted_ = data; }
51 void set_pulse_length(const int &data) { pulse_length_ = data; }
52 void set_data(const std::vector<uint8_t> &data) { code_ = data; }
53
54 void play(Ts... x) {
55 int repeats = this->repeat_.value(x...);
56 int inverted = this->inverted_.value(x...);
57 int pulse_length = this->pulse_length_.value(x...);
58 std::vector<uint8_t> msg = this->code_.value(x...);
59
60 this->parent_->send_rx(msg, repeats, inverted, pulse_length);
61 }
62
63 protected:
65};
66
67#endif
68} // namespace lightwaverf
69} // namespace esphome
70#endif
This class simplifies creating components that periodically check a state.
Definition component.h:301
void set_pin(InternalGPIOPin *pin_tx, InternalGPIOPin *pin_rx)
Definition lightwaverf.h:21
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)
TEMPLATABLE_VALUE(std::vector< uint8_t >, code)
void set_data(const std::vector< uint8_t > &data)
Definition lightwaverf.h:52
void set_repeats(const int &data)
Definition lightwaverf.h:49
void set_inverted(const int &data)
Definition lightwaverf.h:50
void set_pulse_length(const int &data)
Definition lightwaverf.h:51
SendRawAction(LightWaveRF *parent)
Definition lightwaverf.h:43
TEMPLATABLE_VALUE(int, pulse_length)
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:302
uint16_t x
Definition tt21100.cpp:5