ESPHome 2025.5.0
Loading...
Searching...
No Matches
as3935_i2c.cpp
Go to the documentation of this file.
1#include "as3935_i2c.h"
2#include "esphome/core/log.h"
3
4namespace esphome {
5namespace as3935_i2c {
6
7static const char *const TAG = "as3935_i2c";
8
9void I2CAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
10 uint8_t write_reg;
11 if (!this->read_byte(reg, &write_reg)) {
12 this->mark_failed();
13 ESP_LOGW(TAG, "read_byte failed - increase log level for more details!");
14 return;
15 }
16
17 write_reg &= (~mask);
18 write_reg |= (bits << start_pos);
19
20 if (!this->write_byte(reg, write_reg)) {
21 ESP_LOGW(TAG, "write_byte failed - increase log level for more details!");
22 return;
23 }
24}
25
27 uint8_t value;
28 if (write(&reg, 1) != i2c::ERROR_OK) {
29 ESP_LOGW(TAG, "Writing register failed!");
30 return 0;
31 }
32 if (read(&value, 1) != i2c::ERROR_OK) {
33 ESP_LOGW(TAG, "Reading register failed!");
34 return 0;
35 }
36 return value;
37}
39 AS3935Component::dump_config();
40 LOG_I2C_DEVICE(this);
41}
42
43} // namespace as3935_i2c
44} // namespace esphome
virtual void mark_failed()
Mark this component as failed.
uint8_t read_register(uint8_t reg) override
void write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_position) override
Definition as3935_i2c.cpp:9
ErrorCode write(const uint8_t *data, size_t len, bool stop=true)
writes an array of bytes to a device using an I2CBus
Definition i2c.h:190
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
Definition i2c.h:266
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:153
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
Definition i2c.h:239
ErrorCode read(uint8_t *data, size_t len)
reads an array of bytes from the device using an I2CBus
Definition i2c.h:164
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:13
Providing packet encoding functions for exchanging data with a remote host.
Definition a01nyub.cpp:7