ESPHome 2026.6.0-dev
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
5
6static const char *const TAG = "as3935_i2c";
7
8void I2CAS3935Component::write_register(uint8_t reg, uint8_t mask, uint8_t bits, uint8_t start_pos) {
9 uint8_t write_reg;
10 if (!this->read_byte(reg, &write_reg)) {
11 this->mark_failed();
12 ESP_LOGW(TAG, "read_byte failed - increase log level for more details!");
13 return;
14 }
15
16 write_reg &= (~mask);
17 write_reg |= (bits << start_pos);
18
19 if (!this->write_byte(reg, write_reg)) {
20 ESP_LOGW(TAG, "write_byte failed - increase log level for more details!");
21 return;
22 }
23}
24
26 uint8_t value;
27 if (write(&reg, 1) != i2c::ERROR_OK) {
28 ESP_LOGW(TAG, "Writing register failed!");
29 return 0;
30 }
31 if (read(&value, 1) != i2c::ERROR_OK) {
32 ESP_LOGW(TAG, "Reading register failed!");
33 return 0;
34 }
35 return value;
36}
38 AS3935Component::dump_config();
39 LOG_I2C_DEVICE(this);
40}
41
42} // namespace esphome::as3935_i2c
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:8
ErrorCode write(const uint8_t *data, size_t len) const
writes an array of bytes to a device using an I2CBus
Definition i2c.h:183
ErrorCode read(uint8_t *data, size_t len) const
reads an array of bytes from the device using an I2CBus
Definition i2c.h:163
bool write_byte(uint8_t a_register, uint8_t data) const
Definition i2c.h:265
bool read_byte(uint8_t a_register, uint8_t *data)
Definition i2c.h:240
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
Definition i2c.h:152
@ ERROR_OK
No error found during execution of method.
Definition i2c_bus.h:14