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