ESPHome 2025.5.0
Loading...
Searching...
No Matches
am2315c.h
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2023-2024 Rob Tillaart
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22#pragma once
23
27
28namespace esphome {
29namespace am2315c {
30
31class AM2315C : public PollingComponent, public i2c::I2CDevice {
32 public:
33 void dump_config() override;
34 void update() override;
35 void setup() override;
36 float get_setup_priority() const override;
37
38 void set_temperature_sensor(sensor::Sensor *temperature_sensor) { this->temperature_sensor_ = temperature_sensor; }
39 void set_humidity_sensor(sensor::Sensor *humidity_sensor) { this->humidity_sensor_ = humidity_sensor; }
40
41 protected:
42 uint8_t crc8_(uint8_t *data, uint8_t len);
43 bool convert_(uint8_t *data, float &humidity, float &temperature);
44 bool reset_register_(uint8_t reg);
45
48};
49
50} // namespace am2315c
51} // namespace esphome
This class simplifies creating components that periodically check a state.
Definition component.h:301
void update() override
Definition am2315c.cpp:123
void dump_config() override
Definition am2315c.cpp:187
void setup() override
Definition am2315c.cpp:92
sensor::Sensor * humidity_sensor_
Definition am2315c.h:47
float get_setup_priority() const override
Definition am2315c.cpp:197
bool convert_(uint8_t *data, float &humidity, float &temperature)
Definition am2315c.cpp:83
void set_humidity_sensor(sensor::Sensor *humidity_sensor)
Definition am2315c.h:39
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition am2315c.h:38
bool reset_register_(uint8_t reg)
Definition am2315c.cpp:48
uint8_t crc8_(uint8_t *data, uint8_t len)
Definition am2315c.cpp:32
sensor::Sensor * temperature_sensor_
Definition am2315c.h:46
This Class provides the methods to read/write bytes from/to an i2c device.
Definition i2c.h:133
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:153
Base-class for all sensors.
Definition sensor.h:57
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7
std::string size_t len
Definition helpers.h:301
uint16_t temperature
Definition sun_gtil2.cpp:12