ESPHome 2025.5.0
Loading...
Searching...
No Matches
ags10.h
Go to the documentation of this file.
1#pragma once
2
7
8namespace esphome {
9namespace ags10 {
10
12 public:
16 void set_tvoc(sensor::Sensor *tvoc) { this->tvoc_ = tvoc; }
17
21 void set_version(sensor::Sensor *version) { this->version_ = version; }
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:
63
68
73
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
116template<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
132template<typename... Ts> class AGS10SetZeroPointAction : public Action<Ts...>, public Parented<AGS10Component> {
133 public:
134 TEMPLATABLE_VALUE(uint16_t, value)
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
BedjetMode mode
BedJet operating mode.
virtual void play(Ts... x)=0
Helper class to easily give an object a parent of type T.
Definition helpers.h:538
This class simplifies creating components that periodically check a state.
Definition component.h:301
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
ErrorCode
Last operation error code.
Definition ags10.h:77
bool set_zero_point_with_factory_defaults()
Sets zero-point with factory defaults.
Definition ags10.cpp:109
optional< uint8_t > read_version_()
Reads and returns a firmware version of AGS10.
Definition ags10.cpp:161
void set_resistance(sensor::Sensor *resistance)
Sets resistance info sensor.
Definition ags10.h:26
enum esphome::ags10::AGS10Component::ErrorCode NONE
sensor::Sensor * tvoc_
TVOC.
Definition ags10.h:62
bool set_zero_point_with_current_resistance()
Sets zero-point with current sensor resistance.
Definition ags10.cpp:111
sensor::Sensor * resistance_
Resistance.
Definition ags10.h:72
void set_tvoc(sensor::Sensor *tvoc)
Sets TVOC sensor.
Definition ags10.h:16
void set_version(sensor::Sensor *version)
Sets version info sensor.
Definition ags10.h:21
uint8_t calc_crc8_(std::array< uint8_t, N > dat, uint8_t num)
Calculates CRC8 value.
Definition ags10.cpp:199
optional< uint32_t > read_resistance_()
Reads and returns the resistance of AGS10.
Definition ags10.cpp:170
float get_setup_priority() const override
Definition ags10.h:34
optional< uint32_t > read_tvoc_()
Reads and returns value of TVOC.
Definition ags10.cpp:134
sensor::Sensor * version_
Firmvare version.
Definition ags10.h:67
bool set_zero_point_with(uint16_t value)
Sets zero-point with the value.
Definition ags10.cpp:113
bool new_i2c_address(uint8_t newaddress)
Modifies target address of AGS10.
Definition ags10.cpp:92
void dump_config() override
Definition ags10.cpp:61
TEMPLATABLE_VALUE(uint8_t, new_address) void play(Ts... x) override
Definition ags10.h:118
TEMPLATABLE_VALUE(uint16_t, value) TEMPLATABLE_VALUE(AGS10SetZeroPointActionMode
mode void play(Ts... x) override
Definition ags10.h:137
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
Base-class for all sensors.
Definition sensor.h:57
AGS10SetZeroPointActionMode
Definition ags10.h:123
@ FACTORY_DEFAULT
Definition ags10.h:125
const float DATA
For components that import data from directly connected sensors like DHT.
Definition component.cpp:19
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
uint16_t x
Definition tt21100.cpp:5