From af0cbb0805de33e743f06ff5edbe24a28e306030 Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 16:01:13 +0100 Subject: [PATCH 1/6] Reverse IMU I2C address from supplement to full --- src/defines.h | 4 ++++ src/sensors/SensorManager.cpp | 1 - src/sensors/SensorManager.h | 15 +++++++-------- src/sensors/bmi160sensor.h | 4 ++-- src/sensors/bno055sensor.h | 4 ++-- src/sensors/bno080sensor.h | 16 ++++++++-------- src/sensors/icm20948sensor.h | 4 ++-- src/sensors/mpu6050sensor.h | 4 ++-- src/sensors/mpu9250sensor.h | 4 ++-- src/sensors/sensoraddresses.h | 7 ------- src/sensors/softfusion/softfusionsensor.h | 6 +++--- 11 files changed, 32 insertions(+), 37 deletions(-) delete mode 100644 src/sensors/sensoraddresses.h diff --git a/src/defines.h b/src/defines.h index 3f3ce5f8..19c69cea 100644 --- a/src/defines.h +++ b/src/defines.h @@ -35,6 +35,10 @@ #define PRIMARY_IMU_OPTIONAL false #define SECONDARY_IMU_OPTIONAL true +// Set I2C address here or directly in IMU_DESC_ENTRY for each IMU used +#define PRIMARY_IMU_ADDRESS_ONE 0x4a +#define SECONDARY_IMU_ADDRESS_TWO 0x4b + #define MAX_IMU_COUNT 2 // Axis mapping example diff --git a/src/sensors/SensorManager.cpp b/src/sensors/SensorManager.cpp index 09262d03..fbdeb8eb 100644 --- a/src/sensors/SensorManager.cpp +++ b/src/sensors/SensorManager.cpp @@ -29,7 +29,6 @@ #include "icm20948sensor.h" #include "mpu6050sensor.h" #include "mpu9250sensor.h" -#include "sensoraddresses.h" #include "softfusion/drivers/bmi270.h" #include "softfusion/drivers/icm42688.h" #include "softfusion/drivers/lsm6ds3trc.h" diff --git a/src/sensors/SensorManager.h b/src/sensors/SensorManager.h index 9a898067..12babdf2 100644 --- a/src/sensors/SensorManager.h +++ b/src/sensors/SensorManager.h @@ -61,20 +61,19 @@ class SensorManager { template std::unique_ptr buildSensor( uint8_t sensorID, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, bool optional = false, int extraParam = 0 ) { - const uint8_t address = ImuType::Address + addrSuppl; m_Logger.trace( "Building IMU with: id=%d,\n\ address=0x%02X, rotation=%f,\n\ sclPin=%d, sdaPin=%d, extraParam=%d, optional=%d", sensorID, - address, + i2cAddress, rotation, sclPin, sdaPin, @@ -89,21 +88,21 @@ class SensorManager { I2CSCAN::clearBus(sdaPin, sclPin); swapI2C(sclPin, sdaPin); - if (I2CSCAN::hasDevOnBus(address)) { - m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, address); + if (I2CSCAN::hasDevOnBus(i2cAddress)) { + m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, i2cAddress); } else { if (!optional) { m_Logger.error( "Mandatory sensor %d not found at address 0x%02X", sensorID + 1, - address + i2cAddress ); sensor = std::make_unique(sensorID, ImuType::TypeID); } else { m_Logger.debug( "Optional sensor %d not found at address 0x%02X", sensorID + 1, - address + i2cAddress ); sensor = std::make_unique(sensorID); } @@ -113,7 +112,7 @@ class SensorManager { uint8_t intPin = extraParam; sensor = std::make_unique( sensorID, - addrSuppl, + i2cAddress, rotation, sclPin, sdaPin, diff --git a/src/sensors/bmi160sensor.h b/src/sensors/bmi160sensor.h index 1b1cf11e..686f203c 100644 --- a/src/sensors/bmi160sensor.h +++ b/src/sensors/bmi160sensor.h @@ -138,7 +138,7 @@ class BMI160Sensor : public Sensor { BMI160Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -148,7 +148,7 @@ class BMI160Sensor : public Sensor { "BMI160Sensor", ImuID::BMI160, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin diff --git a/src/sensors/bno055sensor.h b/src/sensors/bno055sensor.h index 1e348bfd..526b67c2 100644 --- a/src/sensors/bno055sensor.h +++ b/src/sensors/bno055sensor.h @@ -35,7 +35,7 @@ class BNO055Sensor : public Sensor { BNO055Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -45,7 +45,7 @@ class BNO055Sensor : public Sensor { "BNO055Sensor", ImuID::BNO055, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin diff --git a/src/sensors/bno080sensor.h b/src/sensors/bno080sensor.h index 57f797b7..68ee4eb7 100644 --- a/src/sensors/bno080sensor.h +++ b/src/sensors/bno080sensor.h @@ -37,7 +37,7 @@ class BNO080Sensor : public Sensor { BNO080Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -47,7 +47,7 @@ class BNO080Sensor : public Sensor { "BNO080Sensor", ImuID::BNO080, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin @@ -69,13 +69,13 @@ class BNO080Sensor : public Sensor { const char* sensorName, ImuID imuId, uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, uint8_t intPin ) - : Sensor(sensorName, imuId, id, Address + addrSuppl, rotation, sclPin, sdaPin) + : Sensor(sensorName, imuId, id, i2cAddress, rotation, sclPin, sdaPin) , m_IntPin(intPin){}; private: @@ -102,7 +102,7 @@ class BNO085Sensor : public BNO080Sensor { static constexpr auto TypeID = ImuID::BNO085; BNO085Sensor( uint8_t id, - uint8_t address, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -112,7 +112,7 @@ class BNO085Sensor : public BNO080Sensor { "BNO085Sensor", ImuID::BNO085, id, - address, + i2cAddress, rotation, sclPin, sdaPin, @@ -125,7 +125,7 @@ class BNO086Sensor : public BNO080Sensor { static constexpr auto TypeID = ImuID::BNO086; BNO086Sensor( uint8_t id, - uint8_t address, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -135,7 +135,7 @@ class BNO086Sensor : public BNO080Sensor { "BNO086Sensor", ImuID::BNO086, id, - address, + i2cAddress, rotation, sclPin, sdaPin, diff --git a/src/sensors/icm20948sensor.h b/src/sensors/icm20948sensor.h index 5e938b34..0d70d2ed 100644 --- a/src/sensors/icm20948sensor.h +++ b/src/sensors/icm20948sensor.h @@ -35,7 +35,7 @@ class ICM20948Sensor : public Sensor { ICM20948Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -45,7 +45,7 @@ class ICM20948Sensor : public Sensor { "ICM20948Sensor", ImuID::ICM20948, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin diff --git a/src/sensors/mpu6050sensor.h b/src/sensors/mpu6050sensor.h index ad46a399..4f5f66cc 100644 --- a/src/sensors/mpu6050sensor.h +++ b/src/sensors/mpu6050sensor.h @@ -36,7 +36,7 @@ class MPU6050Sensor : public Sensor { MPU6050Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -46,7 +46,7 @@ class MPU6050Sensor : public Sensor { "MPU6050Sensor", ImuID::MPU6050, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin diff --git a/src/sensors/mpu9250sensor.h b/src/sensors/mpu9250sensor.h index d6d0b727..e6f18802 100644 --- a/src/sensors/mpu9250sensor.h +++ b/src/sensors/mpu9250sensor.h @@ -49,7 +49,7 @@ class MPU9250Sensor : public Sensor { MPU9250Sensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -59,7 +59,7 @@ class MPU9250Sensor : public Sensor { "MPU9250Sensor", ImuID::MPU9250, id, - Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin diff --git a/src/sensors/sensoraddresses.h b/src/sensors/sensoraddresses.h deleted file mode 100644 index e2c37f1e..00000000 --- a/src/sensors/sensoraddresses.h +++ /dev/null @@ -1,7 +0,0 @@ -// those variables are used as "supplement" to base IMU address coming directly from IMU -// driver they are remaining to keep backward compatibility with old style of defines.h - -#define PRIMARY_IMU_ADDRESS_ONE 0 -#define PRIMARY_IMU_ADDRESS_TWO 1 -#define SECONDARY_IMU_ADDRESS_ONE 0 -#define SECONDARY_IMU_ADDRESS_TWO 1 diff --git a/src/sensors/softfusion/softfusionsensor.h b/src/sensors/softfusion/softfusionsensor.h index 133bea48..82f212fc 100644 --- a/src/sensors/softfusion/softfusionsensor.h +++ b/src/sensors/softfusion/softfusionsensor.h @@ -181,7 +181,7 @@ class SoftFusionSensor : public Sensor { SoftFusionSensor( uint8_t id, - uint8_t addrSuppl, + uint8_t i2cAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, @@ -191,13 +191,13 @@ class SoftFusionSensor : public Sensor { imu::Name, imu::Type, id, - imu::Address + addrSuppl, + i2cAddress, rotation, sclPin, sdaPin ) , m_fusion(imu::GyrTs, imu::AccTs, imu::MagTs) - , m_sensor(I2CImpl(imu::Address + addrSuppl), m_Logger) {} + , m_sensor(I2CImpl(i2cAddress), m_Logger) {} ~SoftFusionSensor() {} void motionLoop() override final { From 98b7e5dda575b19bcecb96010edaea6a163e5239 Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 16:04:23 +0100 Subject: [PATCH 2/6] Formatting fix --- src/consts.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/consts.h b/src/consts.h index 4d529d03..94b3edc6 100644 --- a/src/consts.h +++ b/src/consts.h @@ -83,9 +83,9 @@ enum class ImuID { #define BOARD_MOCOPI 15 // Used by mocopi/moslime #define BOARD_WEMOSWROOM02 16 #define BOARD_XIAO_ESP32C3 17 -#define BOARD_HARITORA 18 // Used by Haritora/SlimeTora +#define BOARD_HARITORA 18 // Used by Haritora/SlimeTora #define BOARD_ES32C6DEVKITC1 19 -#define BOARD_DEV_RESERVED 250 // Reserved, should not be used in any release firmware +#define BOARD_DEV_RESERVED 250 // Reserved, should not be used in any release firmware #define BAT_EXTERNAL 1 #define BAT_INTERNAL 2 From e5ddc3077663084f5707c801df8ec1e11013a9bd Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 16:07:06 +0100 Subject: [PATCH 3/6] More formatting --- src/sensors/SensorManager.h | 3 ++- src/sensors/softfusion/softfusionsensor.h | 10 +--------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/sensors/SensorManager.h b/src/sensors/SensorManager.h index 12babdf2..31bd123b 100644 --- a/src/sensors/SensorManager.h +++ b/src/sensors/SensorManager.h @@ -89,7 +89,8 @@ class SensorManager { swapI2C(sclPin, sdaPin); if (I2CSCAN::hasDevOnBus(i2cAddress)) { - m_Logger.trace("Sensor %d found at address 0x%02X", sensorID + 1, i2cAddress); + m_Logger + .trace("Sensor %d found at address 0x%02X", sensorID + 1, i2cAddress); } else { if (!optional) { m_Logger.error( diff --git a/src/sensors/softfusion/softfusionsensor.h b/src/sensors/softfusion/softfusionsensor.h index 82f212fc..f04c3f1f 100644 --- a/src/sensors/softfusion/softfusionsensor.h +++ b/src/sensors/softfusion/softfusionsensor.h @@ -187,15 +187,7 @@ class SoftFusionSensor : public Sensor { uint8_t sdaPin, uint8_t ) - : Sensor( - imu::Name, - imu::Type, - id, - i2cAddress, - rotation, - sclPin, - sdaPin - ) + : Sensor(imu::Name, imu::Type, id, i2cAddress, rotation, sclPin, sdaPin) , m_fusion(imu::GyrTs, imu::AccTs, imu::MagTs) , m_sensor(I2CImpl(i2cAddress), m_Logger) {} ~SoftFusionSensor() {} From b4dbfca0d21d662f32043af83869e0d4bf1a6fcd Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 17:23:23 +0100 Subject: [PATCH 4/6] Make suggested change to improve compatibility with lazy people --- src/defines.h | 5 +++-- src/sensors/SensorManager.h | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/defines.h b/src/defines.h index 19c69cea..992c2539 100644 --- a/src/defines.h +++ b/src/defines.h @@ -36,8 +36,9 @@ #define SECONDARY_IMU_OPTIONAL true // Set I2C address here or directly in IMU_DESC_ENTRY for each IMU used -#define PRIMARY_IMU_ADDRESS_ONE 0x4a -#define SECONDARY_IMU_ADDRESS_TWO 0x4b +// If not set, default address is used based on the IMU and Sensor ID +// #define PRIMARY_IMU_ADDRESS_ONE 0x4a +// #define SECONDARY_IMU_ADDRESS_TWO 0x4b #define MAX_IMU_COUNT 2 diff --git a/src/sensors/SensorManager.h b/src/sensors/SensorManager.h index 31bd123b..8698d38a 100644 --- a/src/sensors/SensorManager.h +++ b/src/sensors/SensorManager.h @@ -20,10 +20,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ - #ifndef SLIMEVR_SENSORMANAGER #define SLIMEVR_SENSORMANAGER +#ifndef PRIMARY_IMU_ADDRESS_ONE +#define PRIMARY_IMU_ADDRESS_ONE std::nullopt +#endif + +#ifndef SECONDARY_IMU_ADDRESS_TWO +#define SECONDARY_IMU_ADDRESS_TWO std::nullopt +#endif + #include #include @@ -61,13 +68,14 @@ class SensorManager { template std::unique_ptr buildSensor( uint8_t sensorID, - uint8_t i2cAddress, + std::optional imuAddress, float rotation, uint8_t sclPin, uint8_t sdaPin, bool optional = false, int extraParam = 0 ) { + uint8_t i2cAddress = imuAddress.value_or(ImuType::Address + sensorID); m_Logger.trace( "Building IMU with: id=%d,\n\ address=0x%02X, rotation=%f,\n\ From 52f78f1a1d99c2f4d8239534e04f58e330c71cb1 Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 17:23:28 +0100 Subject: [PATCH 5/6] Create CODEOWNERS --- .github/CODEOWNERS | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/CODEOWNERS diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 00000000..cc5ed45b --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,13 @@ +# Global code owner +* @Eirenliel + +# Make Loucas code owner of the defines to keep fw tool compatibility +/src/defines.h @loucass003 +/src/consts.h @loucass003 +/src/debug.h @loucass003 + +# Sfusion framework +/src/sensors/softfusion/ @gorbit99 @l0ud +/srs/sensors/SensorFusion* @gorbit99 @l0ud +/srs/sensors/motionprocessing/ @gorbit99 @l0ud +/lib/vqf/ \ No newline at end of file From 54eefacd00d51bbafc7e9135d74438a42284a52b Mon Sep 17 00:00:00 2001 From: Eiren Rain Date: Fri, 20 Dec 2024 17:55:13 +0100 Subject: [PATCH 6/6] Fix include and C++ standards --- src/sensors/SensorManager.h | 1 + src/serial/serialcommands.cpp | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sensors/SensorManager.h b/src/sensors/SensorManager.h index 8698d38a..c2ebdb5c 100644 --- a/src/sensors/SensorManager.h +++ b/src/sensors/SensorManager.h @@ -34,6 +34,7 @@ #include #include +#include #include "EmptySensor.h" #include "ErroneousSensor.h" diff --git a/src/serial/serialcommands.cpp b/src/serial/serialcommands.cpp index 4466e5c2..a8da5366 100644 --- a/src/serial/serialcommands.cpp +++ b/src/serial/serialcommands.cpp @@ -173,7 +173,7 @@ void printState() { } #if ESP32 -char* getEncryptionTypeName(wifi_auth_mode_t type) { +String getEncryptionTypeName(wifi_auth_mode_t type) { switch (type) { case WIFI_AUTH_OPEN: return "OPEN"; @@ -197,7 +197,7 @@ char* getEncryptionTypeName(wifi_auth_mode_t type) { return "WPA3_ENT_192"; } #else -char* getEncryptionTypeName(uint8_t type) { +String getEncryptionTypeName(uint8_t type) { switch (type) { case ENC_TYPE_NONE: return "OPEN";