Add void pointer for initializing sensors
This commit is contained in:
@@ -38,7 +38,7 @@ struct BarometerMsg : public SensorMessageBase {
|
|||||||
|
|
||||||
class Barometer : public SensorBase<BarometerMsg> {
|
class Barometer : public SensorBase<BarometerMsg> {
|
||||||
public:
|
public:
|
||||||
bool initialize() override {
|
bool initialize(void* _) override {
|
||||||
_msg.success = _bmp.begin();
|
_msg.success = _bmp.begin();
|
||||||
return _msg.success;
|
return _msg.success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ struct IMUAnglesMsg : public SensorMessageBase {
|
|||||||
|
|
||||||
class IMU : public SensorBase<IMUAnglesMsg> {
|
class IMU : public SensorBase<IMUAnglesMsg> {
|
||||||
public:
|
public:
|
||||||
bool initialize() override {
|
bool initialize(void* _arg = nullptr) override {
|
||||||
#if FT_ENABLED(USE_MPU6050)
|
#if FT_ENABLED(USE_MPU6050)
|
||||||
_imu.initialize();
|
_imu.initialize();
|
||||||
_msg.success = _imu.testConnection();
|
_msg.success = _imu.testConnection();
|
||||||
@@ -88,23 +88,25 @@ class IMU : public SensorBase<IMUAnglesMsg> {
|
|||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_ICM20948)
|
#if FT_ENABLED(USE_ICM20948)
|
||||||
#if USE_ICM20948_SPIMODE > 0
|
#if USE_ICM20948_SPIMODE > 0
|
||||||
_imu.begin(CS_PIN, SPI_PORT);
|
_imu = (ICM_20948_SPI*)_arg;
|
||||||
|
_imu->begin(CS_PIN, SPI_PORT);
|
||||||
#else
|
#else
|
||||||
_imu.begin(Wire, 1, 0xFF);
|
_imu = (ICM_20948_I2C*)_arg;
|
||||||
|
_imu->begin(Wire, 1, 0xFF);
|
||||||
#endif
|
#endif
|
||||||
if (_imu.status != ICM_20948_Stat_Ok){ return false; }
|
if (_imu->status != ICM_20948_Stat_Ok){ return false; }
|
||||||
|
|
||||||
_imu.setSampleMode((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Continuous);
|
_imu->setSampleMode((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), ICM_20948_Sample_Mode_Continuous);
|
||||||
if (_imu.status != ICM_20948_Stat_Ok){ return false; }
|
if (_imu->status != ICM_20948_Stat_Ok){ return false; }
|
||||||
|
|
||||||
ICM_20948_fss_t myFSS;
|
ICM_20948_fss_t myFSS;
|
||||||
myFSS.a = gpm2;
|
myFSS.a = gpm2;
|
||||||
myFSS.g = dps250;
|
myFSS.g = dps250;
|
||||||
_imu.setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS);
|
_imu->setFullScale((ICM_20948_Internal_Acc | ICM_20948_Internal_Gyr), myFSS);
|
||||||
if (_imu.status != ICM_20948_Stat_Ok){ return false; }
|
if (_imu->status != ICM_20948_Stat_Ok){ return false; }
|
||||||
// TODO: Setup low pass filter config
|
// TODO: Setup low pass filter config
|
||||||
_imu.startupMagnetometer();
|
_imu->startupMagnetometer();
|
||||||
if (_imu.status != ICM_20948_Stat_Ok){ return false; }
|
if (_imu->status != ICM_20948_Stat_Ok){ return false; }
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -130,12 +132,12 @@ class IMU : public SensorBase<IMUAnglesMsg> {
|
|||||||
return false;
|
return false;
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_ICM20948)
|
#if FT_ENABLED(USE_ICM20948)
|
||||||
if (_imu.dataReady())
|
if (_imu->dataReady())
|
||||||
{
|
{
|
||||||
_imu.getAGMT();
|
_imu->getAGMT();
|
||||||
_msg.rpy[0] = _imu.gyrX();
|
_msg.rpy[0] = _imu->gyrX();
|
||||||
_msg.rpy[1] = _imu.gyrY();
|
_msg.rpy[1] = _imu->gyrY();
|
||||||
_msg.rpy[2] = _imu.gyrZ();
|
_msg.rpy[2] = _imu->gyrZ();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_BNO055)
|
#if FT_ENABLED(USE_BNO055)
|
||||||
@@ -181,10 +183,10 @@ class IMU : public SensorBase<IMUAnglesMsg> {
|
|||||||
#if FT_ENABLED(USE_ICM20948_SPIMODE) > 0
|
#if FT_ENABLED(USE_ICM20948_SPIMODE) > 0
|
||||||
#define SPI_PORT SPI // TODO in periphearals_seetings.h
|
#define SPI_PORT SPI // TODO in periphearals_seetings.h
|
||||||
#define CS_PIN 2
|
#define CS_PIN 2
|
||||||
ICM_20948_SPI _imu;
|
ICM_20948_SPI* _imu;
|
||||||
#else
|
#else
|
||||||
//#define WIRE_PORT Wire
|
//#define WIRE_PORT Wire
|
||||||
ICM_20948_I2C _imu;
|
ICM_20948_I2C* _imu;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
@@ -38,7 +38,7 @@ struct MagnetometerMsg : public SensorMessageBase {
|
|||||||
|
|
||||||
class Magnetometer : public SensorBase<MagnetometerMsg> {
|
class Magnetometer : public SensorBase<MagnetometerMsg> {
|
||||||
public:
|
public:
|
||||||
bool initialize() override {
|
bool initialize(void* _) override {
|
||||||
_msg.success = _mag.begin();
|
_msg.success = _mag.begin();
|
||||||
return _msg.success;
|
return _msg.success;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class SensorBase {
|
|||||||
public:
|
public:
|
||||||
SensorBase() {}
|
SensorBase() {}
|
||||||
|
|
||||||
virtual bool initialize() = 0;
|
virtual bool initialize(void* _arg) = 0;
|
||||||
|
|
||||||
virtual bool update() = 0;
|
virtual bool update() = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,15 @@ void Peripherals::begin() {
|
|||||||
|
|
||||||
updatePins();
|
updatePins();
|
||||||
|
|
||||||
#if FT_ENABLED(USE_MPU6050 || USE_BNO055 || USE_ICM20948)
|
#if FT_ENABLED(USE_MPU6050 || USE_BNO055)
|
||||||
if (!_imu.initialize()) ESP_LOGE("IMUService", "IMU initialize failed");
|
if (!_imu.initialize()) ESP_LOGE("IMUService", "IMU initialize failed");
|
||||||
|
#elif FT_ENABLED(USE_ICM20948)
|
||||||
|
#if USE_ICM20948_SPIMODE > 0
|
||||||
|
ICM_20948_SPI* icm20948 = new ICM_20948_SPI;
|
||||||
|
#else
|
||||||
|
ICM_20948_I2C* icm20948 = new ICM_20948_I2C;
|
||||||
|
#endif
|
||||||
|
if (!_imu.initialize(icm20948)) ESP_LOGE("IMUService", "IMU initialize failed (ICM20948)");
|
||||||
#endif
|
#endif
|
||||||
#if FT_ENABLED(USE_HMC5883) // TODO: Add USE_ICM20948
|
#if FT_ENABLED(USE_HMC5883) // TODO: Add USE_ICM20948
|
||||||
if (!_mag.initialize()) ESP_LOGE("IMUService", "MAG initialize failed");
|
if (!_mag.initialize()) ESP_LOGE("IMUService", "MAG initialize failed");
|
||||||
|
|||||||
Reference in New Issue
Block a user