ESPHome  2024.12.2
ags10.h
Go to the documentation of this file.
1 #pragma once
2 
7 
8 namespace esphome {
9 namespace ags10 {
10 
12  public:
16  void set_tvoc(sensor::Sensor *tvoc) { this->tvoc_ = tvoc; }
17 
22 
26  void set_resistance(sensor::Sensor *resistance) { this->resistance_ = resistance; }
27 
28  void setup() override;
29 
30  void update() override;
31 
32  void dump_config() override;
33 
34  float get_setup_priority() const override { return setup_priority::DATA; }
35 
41  bool new_i2c_address(uint8_t newaddress);
42 
47 
52 
56  bool set_zero_point_with(uint16_t value);
57 
58  protected:
62  sensor::Sensor *tvoc_{nullptr};
63 
68 
73 
77  enum ErrorCode {
78  NONE = 0,
83  } error_code_{NONE};
84 
89 
94 
99 
103  template<size_t N> optional<std::array<uint8_t, N>> read_and_check_(uint8_t a_register);
104 
113  template<size_t N> uint8_t calc_crc8_(std::array<uint8_t, N> dat, uint8_t num);
114 };
115 
116 template<typename... Ts> class AGS10NewI2cAddressAction : public Action<Ts...>, public Parented<AGS10Component> {
117  public:
118  TEMPLATABLE_VALUE(uint8_t, new_address)
119 
120  void play(Ts... x) override { this->parent_->new_i2c_address(this->new_address_.value(x...)); }
121 };
122 
124  // Zero-point reset.
126  // Zero-point calibration with current resistance.
128  // Zero-point calibration with custom resistance.
130 };
131 
132 template<typename... Ts> class AGS10SetZeroPointAction : public Action<Ts...>, public Parented<AGS10Component> {
133  public:
134  TEMPLATABLE_VALUE(uint16_t, value)
135  TEMPLATABLE_VALUE(AGS10SetZeroPointActionMode, mode)
136 
137  void play(Ts... x) override {
138  switch (this->mode_.value(x...)) {
139  case FACTORY_DEFAULT:
140  this->parent_->set_zero_point_with_factory_defaults();
141  break;
142  case CURRENT_VALUE:
143  this->parent_->set_zero_point_with_current_resistance();
144  break;
145  case CUSTOM_VALUE:
146  this->parent_->set_zero_point_with(this->value_.value(x...));
147  break;
148  }
149  }
150 };
151 } // namespace ags10
152 } // namespace esphome
optional< uint32_t > read_resistance_()
Reads and returns the resistance of AGS10.
Definition: ags10.cpp:170
TEMPLATABLE_VALUE(uint8_t, new_address) void play(Ts... x) override
Definition: ags10.h:118
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
optional< uint32_t > read_tvoc_()
Reads and returns value of TVOC.
Definition: ags10.cpp:134
bool new_i2c_address(uint8_t newaddress)
Modifies target address of AGS10.
Definition: ags10.cpp:92
optional< uint8_t > read_version_()
Reads and returns a firmware version of AGS10.
Definition: ags10.cpp:161
bool set_zero_point_with_factory_defaults()
Sets zero-point with factory defaults.
Definition: ags10.cpp:109
uint16_t x
Definition: tt21100.cpp:17
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void dump_config() override
Definition: ags10.cpp:61
bool set_zero_point_with_current_resistance()
Sets zero-point with current sensor resistance.
Definition: ags10.cpp:111
void update() override
Definition: ags10.cpp:51
void setup() override
Definition: ags10.cpp:25
BedjetMode mode
BedJet operating mode.
Definition: bedjet_codec.h:183
uint8_t calc_crc8_(std::array< uint8_t, N > dat, uint8_t num)
Calculates CRC8 value.
Definition: ags10.cpp:199
void set_tvoc(sensor::Sensor *tvoc)
Sets TVOC sensor.
Definition: ags10.h:16
sensor::Sensor * version_
Firmvare version.
Definition: ags10.h:67
sensor::Sensor * tvoc_
TVOC.
Definition: ags10.h:62
ErrorCode
Last operation error code.
Definition: ags10.h:77
float get_setup_priority() const override
Definition: ags10.h:34
sensor::Sensor * resistance_
Resistance.
Definition: ags10.h:72
bool set_zero_point_with(uint16_t value)
Sets zero-point with the value.
Definition: ags10.cpp:113
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
void set_resistance(sensor::Sensor *resistance)
Sets resistance info sensor.
Definition: ags10.h:26
void set_version(sensor::Sensor *version)
Sets version info sensor.
Definition: ags10.h:21
AGS10SetZeroPointActionMode
Definition: ags10.h:123
Base-class for all sensors.
Definition: sensor.h:57
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
Helper class to easily give an object a parent of type T.
Definition: helpers.h:530
optional< std::array< uint8_t, N > > read_and_check_(uint8_t a_register)
Read, checks and returns data from the sensor.
Definition: ags10.cpp:179
enum esphome::ags10::AGS10Component::ErrorCode NONE