ESPHome  2024.10.2
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 
14 namespace esphome {
15 namespace lightwaverf {
16 
17 #ifdef USE_ESP8266
18 
19 class LightWaveRF : public PollingComponent {
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 
41 template<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
uint16_t x
Definition: tt21100.cpp:17
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void set_data(const std::vector< uint8_t > &data)
Definition: lightwaverf.h:52
void send_rx(const std::vector< uint8_t > &msg, uint8_t repeats, bool inverted, int u_sec)
Definition: lightwaverf.cpp:32
void set_repeats(const int &data)
Definition: lightwaverf.h:49
void print_msg_(uint8_t *msg, uint8_t len)
Definition: lightwaverf.cpp:48
void set_inverted(const int &data)
Definition: lightwaverf.h:50
SendRawAction(LightWaveRF *parent)
Definition: lightwaverf.h:43
std::string size_t len
Definition: helpers.h:292
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_pulse_length(const int &data)
Definition: lightwaverf.h:51
void set_pin(InternalGPIOPin *pin_tx, InternalGPIOPin *pin_rx)
Definition: lightwaverf.h:21