mirror of
https://github.com/jdillenburg/esphome.git
synced 2026-01-10 07:10:39 -07:00
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.
This commit is contained in:
@@ -3,16 +3,13 @@
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_Sensor.h>
|
||||
#include <Adafruit_ADXL345_U.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace adxl345 {
|
||||
|
||||
class ADXL345Component : public PollingComponent, public i2c::I2CDevice {
|
||||
public:
|
||||
ADXL345Component() : PollingComponent(100) {}
|
||||
ADXL345Component() : PollingComponent(1000) {}
|
||||
|
||||
void setup() override;
|
||||
void update() override;
|
||||
@@ -23,18 +20,16 @@ class ADXL345Component : public PollingComponent, public i2c::I2CDevice {
|
||||
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:
|
||||
Adafruit_ADXL345_Unified accel_{12345};
|
||||
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 to 2G range (0)
|
||||
uint8_t range_{0}; // Default 2G
|
||||
};
|
||||
|
||||
} // namespace adxl345
|
||||
} // namespace esphome
|
||||
} // namespace adxl345
|
||||
} // namespace esphome
|
||||
|
||||
Reference in New Issue
Block a user