Files
jdillenburg-esphome/components/adxl345/adxl345.h
John Dillenburg 7dc846a6eb matthiazzz - The current adxl345 component in ESPHome relies on multiple external Adafruit libraries (Adafruit Unified Sensor, Adafruit BusIO, Adafruit ADXL345). This causes unnecessary dependencies, compilation overhead, and sometimes incompatibilities when used with tca9548a multiplexers.
I modified the component to remove all Adafruit library dependencies and instead use a lightweight, self-contained ESPHome driver for ADXL345. After these changes, multiple ADXL345 sensors can be used in combination with a TCA9548A I²C multiplexer without conflicts.
2025-09-06 15:38:59 -05:00

36 lines
1.1 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace adxl345 {
class ADXL345Component : public PollingComponent, public i2c::I2CDevice {
public:
ADXL345Component() : PollingComponent(1000) {}
void setup() override;
void update() override;
void dump_config() override;
void set_off_vertical_sensor(sensor::Sensor *off_vertical) { off_vertical_ = off_vertical; }
void set_jitter_sensor(sensor::Sensor *jitter) { jitter_ = jitter; }
void set_accel_x_sensor(sensor::Sensor *accel_x) { accel_x_ = accel_x; }
void set_accel_y_sensor(sensor::Sensor *accel_y) { accel_y_ = accel_y; }
void set_accel_z_sensor(sensor::Sensor *accel_z) { accel_z_ = accel_z; }
void set_range(uint8_t range) { range_ = range; }
protected:
sensor::Sensor *off_vertical_{nullptr};
sensor::Sensor *jitter_{nullptr};
sensor::Sensor *accel_x_{nullptr};
sensor::Sensor *accel_y_{nullptr};
sensor::Sensor *accel_z_{nullptr};
uint8_t range_{0}; // Default 2G
};
} // namespace adxl345
} // namespace esphome