ESPHome 2025.5.0
Loading...
Searching...
No Matches
automation.h
Go to the documentation of this file.
1#pragma once
2
3#include "uart.h"
5
6#include <vector>
7
8namespace esphome {
9namespace uart {
10
11template<typename... Ts> class UARTWriteAction : public Action<Ts...>, public Parented<UARTComponent> {
12 public:
13 void set_data_template(std::function<std::vector<uint8_t>(Ts...)> func) {
14 this->data_func_ = func;
15 this->static_ = false;
16 }
17 void set_data_static(const std::vector<uint8_t> &data) {
18 this->data_static_ = data;
19 this->static_ = true;
20 }
21
22 void play(Ts... x) override {
23 if (this->static_) {
24 this->parent_->write_array(this->data_static_);
25 } else {
26 auto val = this->data_func_(x...);
27 this->parent_->write_array(val);
28 }
29 }
30
31 protected:
32 bool static_{false};
33 std::function<std::vector<uint8_t>(Ts...)> data_func_{};
34 std::vector<uint8_t> data_static_{};
35};
36
37} // namespace uart
38} // namespace esphome
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
void set_data_static(const std::vector< uint8_t > &data)
Definition automation.h:17
void play(Ts... x) override
Definition automation.h:22
std::function< std::vector< uint8_t >(Ts...)> data_func_
Definition automation.h:33
void set_data_template(std::function< std::vector< uint8_t >(Ts...)> func)
Definition automation.h:13
std::vector< uint8_t > data_static_
Definition automation.h:34
mopeka_std_values val[4]
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5