ESPHome  2024.10.2
automation.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "esphome/core/helpers.h"
5 
6 #include "at581x.h"
7 
8 namespace esphome {
9 namespace at581x {
10 
11 template<typename... Ts> class AT581XResetAction : public Action<Ts...>, public Parented<AT581XComponent> {
12  public:
13  void play(Ts... x) { this->parent_->reset_hardware_frontend(); }
14 };
15 
16 template<typename... Ts> class AT581XSettingsAction : public Action<Ts...>, public Parented<AT581XComponent> {
17  public:
18  TEMPLATABLE_VALUE(int8_t, hw_frontend_reset)
19  TEMPLATABLE_VALUE(int, frequency)
20  TEMPLATABLE_VALUE(int, sensing_distance)
21  TEMPLATABLE_VALUE(int, poweron_selfcheck_time)
22  TEMPLATABLE_VALUE(int, power_consumption)
23  TEMPLATABLE_VALUE(int, protect_time)
24  TEMPLATABLE_VALUE(int, trigger_base)
25  TEMPLATABLE_VALUE(int, trigger_keep)
26  TEMPLATABLE_VALUE(int, stage_gain)
27 
28  void play(Ts... x) {
29  if (this->frequency_.has_value()) {
30  int v = this->frequency_.value(x...);
31  this->parent_->set_frequency(v);
32  }
33  if (this->sensing_distance_.has_value()) {
34  int v = this->sensing_distance_.value(x...);
35  this->parent_->set_sensing_distance(v);
36  }
37  if (this->poweron_selfcheck_time_.has_value()) {
38  int v = this->poweron_selfcheck_time_.value(x...);
39  this->parent_->set_poweron_selfcheck_time(v);
40  }
41  if (this->power_consumption_.has_value()) {
42  int v = this->power_consumption_.value(x...);
43  this->parent_->set_power_consumption(v);
44  }
45  if (this->protect_time_.has_value()) {
46  int v = this->protect_time_.value(x...);
47  this->parent_->set_protect_time(v);
48  }
49  if (this->trigger_base_.has_value()) {
50  int v = this->trigger_base_.value(x...);
51  this->parent_->set_trigger_base(v);
52  }
53  if (this->trigger_keep_.has_value()) {
54  int v = this->trigger_keep_.value(x...);
55  this->parent_->set_trigger_keep(v);
56  }
57  if (this->stage_gain_.has_value()) {
58  int v = this->stage_gain_.value(x...);
59  this->parent_->set_stage_gain(v);
60  }
61 
62  // This actually perform all the modification on the system
63  this->parent_->i2c_write_config();
64 
65  if (this->hw_frontend_reset_.has_value() && this->hw_frontend_reset_.value(x...) == true) {
66  this->parent_->reset_hardware_frontend();
67  }
68  }
69 };
70 } // namespace at581x
71 } // namespace esphome
uint16_t x
Definition: tt21100.cpp:17
uint16_le_t frequency
Definition: bl0942.h:72
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Helper class to easily give an object a parent of type T.
Definition: helpers.h:521