From 7d4cfd0c77358219df0ecab46724d7585a1cd7ac Mon Sep 17 00:00:00 2001 From: Riccardo Date: Thu, 6 Oct 2022 16:06:25 +0200 Subject: [PATCH 1/3] Added compatibility with other Arduino IMU libraries --- src/ArduinoIMU.h | 29 +++++++++++++++++++++++++++++ src/LSM6DS3.cpp | 13 +++++++------ src/LSM6DS3.h | 8 ++++++-- 3 files changed, 42 insertions(+), 8 deletions(-) create mode 100644 src/ArduinoIMU.h diff --git a/src/ArduinoIMU.h b/src/ArduinoIMU.h new file mode 100644 index 0000000..c6a41e3 --- /dev/null +++ b/src/ArduinoIMU.h @@ -0,0 +1,29 @@ +/* + This file is part of the ArduinoIMU library. + Copyright (c) 2022 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _ARUDINO_IMU_H_ +#define _ARUDINO_IMU_H_ + +#include "Arduino.h" + +#if defined __has_include + #define HAS_INCLUDE_IMU __has_include("Arduino_LSM6DSOX.h") || __has_include("Arduino_LSM6DS3.h") || __has_include("Arduino_LSM9DS1.h") +#endif +#endif + diff --git a/src/LSM6DS3.cpp b/src/LSM6DS3.cpp index 5f6fbdc..5864ec0 100644 --- a/src/LSM6DS3.cpp +++ b/src/LSM6DS3.cpp @@ -207,9 +207,10 @@ int LSM6DS3Class::writeRegister(uint8_t address, uint8_t value) } return 1; } - -#ifdef ARDUINO_AVR_UNO_WIFI_REV2 -LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT); -#else -LSM6DS3Class IMU(Wire, LSM6DS3_ADDRESS); -#endif +#ifdef IMU_INCLUDED + #ifdef ARDUINO_AVR_UNO_WIFI_REV2 + LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT); + #else + LSM6DS3Class IMU(Wire, LSM6DS3_ADDRESS); + #endif +#endif \ No newline at end of file diff --git a/src/LSM6DS3.h b/src/LSM6DS3.h index bff6533..3b128a8 100644 --- a/src/LSM6DS3.h +++ b/src/LSM6DS3.h @@ -20,6 +20,9 @@ #include #include #include +#include "ArduinoIMU.h" + +#define IMU_INCLUDED !HAS_INCLUDE_IMU #define LSM6DS3_ADDRESS 0x6A @@ -84,5 +87,6 @@ class LSM6DS3Class { SPISettings _spiSettings; }; - -extern LSM6DS3Class IMU; +#ifdef IMU_INCLUDED + extern LSM6DS3Class IMU; +#endif \ No newline at end of file From d385ea00f4fff2a8f94cb9b637125e8ff068efd9 Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 7 Oct 2022 11:34:11 +0200 Subject: [PATCH 2/3] Fix has_include usage --- src/ArduinoIMU.h | 29 ----------------------------- src/Arduino_LSM6DS3.h | 4 ++-- src/LSM6DS3.cpp | 3 ++- src/LSM6DS3.h | 9 ++++++--- 4 files changed, 10 insertions(+), 35 deletions(-) delete mode 100644 src/ArduinoIMU.h diff --git a/src/ArduinoIMU.h b/src/ArduinoIMU.h deleted file mode 100644 index c6a41e3..0000000 --- a/src/ArduinoIMU.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - This file is part of the ArduinoIMU library. - Copyright (c) 2022 Arduino SA. All rights reserved. - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef _ARUDINO_IMU_H_ -#define _ARUDINO_IMU_H_ - -#include "Arduino.h" - -#if defined __has_include - #define HAS_INCLUDE_IMU __has_include("Arduino_LSM6DSOX.h") || __has_include("Arduino_LSM6DS3.h") || __has_include("Arduino_LSM9DS1.h") -#endif -#endif - diff --git a/src/Arduino_LSM6DS3.h b/src/Arduino_LSM6DS3.h index ede1dfb..4b80f2b 100644 --- a/src/Arduino_LSM6DS3.h +++ b/src/Arduino_LSM6DS3.h @@ -17,8 +17,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef _ARUDINO_LSM6DS3_H_ -#define _ARUDINO_LSM6DS3_H_ +#ifndef _ARDUINO_LSM6DS3_H_ +#define _ARDUINO_LSM6DS3_H_ #include "LSM6DS3.h" diff --git a/src/LSM6DS3.cpp b/src/LSM6DS3.cpp index 5864ec0..f249a8c 100644 --- a/src/LSM6DS3.cpp +++ b/src/LSM6DS3.cpp @@ -207,7 +207,8 @@ int LSM6DS3Class::writeRegister(uint8_t address, uint8_t value) } return 1; } -#ifdef IMU_INCLUDED + +#ifndef LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT #ifdef ARDUINO_AVR_UNO_WIFI_REV2 LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT); #else diff --git a/src/LSM6DS3.h b/src/LSM6DS3.h index 3b128a8..b4bff63 100644 --- a/src/LSM6DS3.h +++ b/src/LSM6DS3.h @@ -20,9 +20,12 @@ #include #include #include -#include "ArduinoIMU.h" -#define IMU_INCLUDED !HAS_INCLUDE_IMU +#if defined __has_include + #if __has_include("Arduino_LSM6DSOX.h") || __has_include("Arduino_LSM9DS1.h") || __has_include("BoschSensorClass.h") + #define LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT + #endif +#endif #define LSM6DS3_ADDRESS 0x6A @@ -87,6 +90,6 @@ class LSM6DS3Class { SPISettings _spiSettings; }; -#ifdef IMU_INCLUDED +#ifndef LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT extern LSM6DS3Class IMU; #endif \ No newline at end of file From 5664175f117fa44384dcd898e600c11d9052843f Mon Sep 17 00:00:00 2001 From: Martino Facchin Date: Fri, 7 Oct 2022 13:06:39 +0200 Subject: [PATCH 3/3] Fix coexistence with other IMU libs --- src/LSM6DS3.cpp | 10 ++++------ src/LSM6DS3.h | 13 ++++--------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/LSM6DS3.cpp b/src/LSM6DS3.cpp index f249a8c..1386620 100644 --- a/src/LSM6DS3.cpp +++ b/src/LSM6DS3.cpp @@ -208,10 +208,8 @@ int LSM6DS3Class::writeRegister(uint8_t address, uint8_t value) return 1; } -#ifndef LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT - #ifdef ARDUINO_AVR_UNO_WIFI_REV2 - LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT); - #else - LSM6DS3Class IMU(Wire, LSM6DS3_ADDRESS); - #endif +#ifdef ARDUINO_AVR_UNO_WIFI_REV2 + LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT); +#else + LSM6DS3Class IMU_LSM6DS3(Wire, LSM6DS3_ADDRESS); #endif \ No newline at end of file diff --git a/src/LSM6DS3.h b/src/LSM6DS3.h index b4bff63..c81f19f 100644 --- a/src/LSM6DS3.h +++ b/src/LSM6DS3.h @@ -21,12 +21,6 @@ #include #include -#if defined __has_include - #if __has_include("Arduino_LSM6DSOX.h") || __has_include("Arduino_LSM9DS1.h") || __has_include("BoschSensorClass.h") - #define LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT - #endif -#endif - #define LSM6DS3_ADDRESS 0x6A #define LSM6DS3_WHO_AM_I_REG 0X0F @@ -90,6 +84,7 @@ class LSM6DS3Class { SPISettings _spiSettings; }; -#ifndef LSM6DS3_SHOULDNT_DECLARE_IMU_OBJECT - extern LSM6DS3Class IMU; -#endif \ No newline at end of file + +extern LSM6DS3Class IMU_LSM6DS3; +#undef IMU +#define IMU IMU_LSM6DS3 \ No newline at end of file