Renamed the C++ implementation files to match the component folder naming: - lsm6ds.h -> lsm6ds_base.h - lsm6ds.cpp -> lsm6ds_base.cpp Updated all includes: - lsm6ds_base/lsm6ds_base.cpp: Updated self-include - lsm6ds_i2c/lsm6ds_i2c.h: Updated to include lsm6ds_base.h - lsm6ds_spi/lsm6ds_spi.h: Updated to include lsm6ds_base.h Fixed test file: - tests/lsm6ds_test.yaml: Updated sensor platforms to use lsm6ds_i2c and lsm6ds_spi This ensures all files follow consistent naming conventions with the _base suffix.
81 lines
2.5 KiB
C++
81 lines
2.5 KiB
C++
#pragma once
|
|
|
|
#include "esphome/core/component.h"
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
namespace esphome {
|
|
namespace lsm6ds_base {
|
|
|
|
enum LSM6DSAccelRange {
|
|
LSM6DS_ACCEL_RANGE_2G = 0x00,
|
|
LSM6DS_ACCEL_RANGE_16G = 0x01,
|
|
LSM6DS_ACCEL_RANGE_4G = 0x02,
|
|
LSM6DS_ACCEL_RANGE_8G = 0x03,
|
|
};
|
|
|
|
enum LSM6DSGyroRange {
|
|
LSM6DS_GYRO_RANGE_250DPS = 0x00,
|
|
LSM6DS_GYRO_RANGE_500DPS = 0x01,
|
|
LSM6DS_GYRO_RANGE_1000DPS = 0x02,
|
|
LSM6DS_GYRO_RANGE_2000DPS = 0x03,
|
|
LSM6DS_GYRO_RANGE_125DPS = 0x04,
|
|
};
|
|
|
|
enum LSM6DSODR {
|
|
LSM6DS_ODR_OFF = 0x00,
|
|
LSM6DS_ODR_12_5HZ = 0x01,
|
|
LSM6DS_ODR_26HZ = 0x02,
|
|
LSM6DS_ODR_52HZ = 0x03,
|
|
LSM6DS_ODR_104HZ = 0x04,
|
|
LSM6DS_ODR_208HZ = 0x05,
|
|
LSM6DS_ODR_416HZ = 0x06,
|
|
LSM6DS_ODR_833HZ = 0x07,
|
|
LSM6DS_ODR_1_66KHZ = 0x08,
|
|
LSM6DS_ODR_3_33KHZ = 0x09,
|
|
LSM6DS_ODR_6_66KHZ = 0x0A,
|
|
};
|
|
|
|
class LSM6DSComponent : public PollingComponent {
|
|
public:
|
|
void setup() override;
|
|
void dump_config() override;
|
|
void update() override;
|
|
float get_setup_priority() const override { return setup_priority::DATA; }
|
|
|
|
void set_accel_x_sensor(sensor::Sensor *accel_x) { accel_x_sensor_ = accel_x; }
|
|
void set_accel_y_sensor(sensor::Sensor *accel_y) { accel_y_sensor_ = accel_y; }
|
|
void set_accel_z_sensor(sensor::Sensor *accel_z) { accel_z_sensor_ = accel_z; }
|
|
void set_gyro_x_sensor(sensor::Sensor *gyro_x) { gyro_x_sensor_ = gyro_x; }
|
|
void set_gyro_y_sensor(sensor::Sensor *gyro_y) { gyro_y_sensor_ = gyro_y; }
|
|
void set_gyro_z_sensor(sensor::Sensor *gyro_z) { gyro_z_sensor_ = gyro_z; }
|
|
void set_temperature_sensor(sensor::Sensor *temp) { temperature_sensor_ = temp; }
|
|
|
|
void set_accel_range(LSM6DSAccelRange range) { accel_range_ = range; }
|
|
void set_gyro_range(LSM6DSGyroRange range) { gyro_range_ = range; }
|
|
void set_accel_odr(LSM6DSODR odr) { accel_odr_ = odr; }
|
|
void set_gyro_odr(LSM6DSODR odr) { gyro_odr_ = odr; }
|
|
|
|
protected:
|
|
virtual bool read_register(uint8_t reg, uint8_t *data, size_t len) = 0;
|
|
virtual bool write_register(uint8_t reg, uint8_t data) = 0;
|
|
|
|
sensor::Sensor *accel_x_sensor_{nullptr};
|
|
sensor::Sensor *accel_y_sensor_{nullptr};
|
|
sensor::Sensor *accel_z_sensor_{nullptr};
|
|
sensor::Sensor *gyro_x_sensor_{nullptr};
|
|
sensor::Sensor *gyro_y_sensor_{nullptr};
|
|
sensor::Sensor *gyro_z_sensor_{nullptr};
|
|
sensor::Sensor *temperature_sensor_{nullptr};
|
|
|
|
LSM6DSAccelRange accel_range_;
|
|
LSM6DSGyroRange gyro_range_;
|
|
LSM6DSODR accel_odr_;
|
|
LSM6DSODR gyro_odr_;
|
|
|
|
float accel_sensitivity_;
|
|
float gyro_sensitivity_;
|
|
};
|
|
|
|
} // namespace lsm6ds_base
|
|
} // namespace esphome
|