Skip to content

Commit 7d4cfd0

Browse files
committed
Added compatibility with other Arduino IMU libraries
1 parent fa4fc94 commit 7d4cfd0

File tree

3 files changed

+42
-8
lines changed

3 files changed

+42
-8
lines changed

src/ArduinoIMU.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
This file is part of the ArduinoIMU library.
3+
Copyright (c) 2022 Arduino SA. All rights reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
#ifndef _ARUDINO_IMU_H_
21+
#define _ARUDINO_IMU_H_
22+
23+
#include "Arduino.h"
24+
25+
#if defined __has_include
26+
#define HAS_INCLUDE_IMU __has_include("Arduino_LSM6DSOX.h") || __has_include("Arduino_LSM6DS3.h") || __has_include("Arduino_LSM9DS1.h")
27+
#endif
28+
#endif
29+

src/LSM6DS3.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,10 @@ int LSM6DS3Class::writeRegister(uint8_t address, uint8_t value)
207207
}
208208
return 1;
209209
}
210-
211-
#ifdef ARDUINO_AVR_UNO_WIFI_REV2
212-
LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT);
213-
#else
214-
LSM6DS3Class IMU(Wire, LSM6DS3_ADDRESS);
215-
#endif
210+
#ifdef IMU_INCLUDED
211+
#ifdef ARDUINO_AVR_UNO_WIFI_REV2
212+
LSM6DS3Class IMU(SPI, SPIIMU_SS, SPIIMU_INT);
213+
#else
214+
LSM6DS3Class IMU(Wire, LSM6DS3_ADDRESS);
215+
#endif
216+
#endif

src/LSM6DS3.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#include <Arduino.h>
2121
#include <Wire.h>
2222
#include <SPI.h>
23+
#include "ArduinoIMU.h"
24+
25+
#define IMU_INCLUDED !HAS_INCLUDE_IMU
2326

2427
#define LSM6DS3_ADDRESS 0x6A
2528

@@ -84,5 +87,6 @@ class LSM6DS3Class {
8487

8588
SPISettings _spiSettings;
8689
};
87-
88-
extern LSM6DS3Class IMU;
90+
#ifdef IMU_INCLUDED
91+
extern LSM6DS3Class IMU;
92+
#endif

0 commit comments

Comments
 (0)