|
| 1 | +/* |
| 2 | + This file is part of the Arduino_LSM6DSOX library. |
| 3 | + Copyright (c) 2021 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 | +#include "IMUClass.h" |
| 21 | + |
| 22 | +// sets function called on slave write |
| 23 | +IMUClass::IMUClass( getRev_t getRevision) |
| 24 | +{ |
| 25 | + //If board_revision = 0, IMU module is LSM6DSOX, otherwise is LSM6DS3 |
| 26 | + board_revision = getRevision; |
| 27 | +} |
| 28 | + |
| 29 | +IMUClass::~IMUClass() |
| 30 | +{ |
| 31 | +} |
| 32 | + |
| 33 | +int IMUClass::begin() |
| 34 | +{ |
| 35 | + _revision = board_revision(); |
| 36 | + if (_revision == BOARD_REVISION_2) { |
| 37 | + LSM6DSOX = new LSM6DSOXClass(Wire, LSM6DSOX_ADDRESS); |
| 38 | + if (LSM6DSOX == nullptr) return 0; |
| 39 | + return LSM6DSOX->begin(); |
| 40 | + } else { |
| 41 | + LSM6DS3 = new LSM6DS3Class(Wire, LSM6DS3_ADDRESS); |
| 42 | + if (LSM6DS3 == nullptr) return 0; |
| 43 | + return LSM6DS3->begin(); |
| 44 | + } |
| 45 | + |
| 46 | +} |
| 47 | + |
| 48 | +void IMUClass::end() |
| 49 | +{ |
| 50 | + if (_revision == BOARD_REVISION_2) { |
| 51 | + LSM6DSOX->end(); |
| 52 | + delete LSM6DSOX; |
| 53 | + LSM6DSOX = nullptr; |
| 54 | + } else { |
| 55 | + LSM6DS3->end(); |
| 56 | + delete LSM6DS3; |
| 57 | + LSM6DS3 = nullptr; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +int IMUClass::readAcceleration(float& x, float& y, float& z) |
| 62 | +{ |
| 63 | + if (_revision == BOARD_REVISION_2) { |
| 64 | + return LSM6DSOX->readAcceleration(x,y,z); |
| 65 | + } else { |
| 66 | + return LSM6DS3->readAcceleration(x,y,z); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +int IMUClass::accelerationAvailable() |
| 71 | +{ |
| 72 | + if (_revision == BOARD_REVISION_2) { |
| 73 | + return LSM6DSOX->accelerationAvailable(); |
| 74 | + } else { |
| 75 | + return LSM6DS3->accelerationAvailable(); |
| 76 | + } |
| 77 | + |
| 78 | +} |
| 79 | + |
| 80 | +float IMUClass::accelerationSampleRate() |
| 81 | +{ |
| 82 | + if (_revision == BOARD_REVISION_2) { |
| 83 | + return LSM6DSOX->accelerationSampleRate(); |
| 84 | + } else { |
| 85 | + return LSM6DS3->accelerationSampleRate(); |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +int IMUClass::readGyroscope(float& x, float& y, float& z) |
| 90 | +{ |
| 91 | + if (_revision == BOARD_REVISION_2) { |
| 92 | + return LSM6DSOX->readGyroscope(x,y,z); |
| 93 | + } else { |
| 94 | + return LSM6DS3->readGyroscope(x,y,z); |
| 95 | + } |
| 96 | +} |
| 97 | + |
| 98 | +int IMUClass::gyroscopeAvailable() |
| 99 | +{ |
| 100 | + if (_revision == BOARD_REVISION_2) { |
| 101 | + return LSM6DSOX->gyroscopeAvailable(); |
| 102 | + } else { |
| 103 | + return LSM6DS3->gyroscopeAvailable(); |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +float IMUClass::gyroscopeSampleRate() |
| 108 | +{ |
| 109 | + if (_revision == BOARD_REVISION_2) { |
| 110 | + return LSM6DSOX->gyroscopeSampleRate(); |
| 111 | + } else { |
| 112 | + return LSM6DS3->gyroscopeSampleRate(); |
| 113 | + } |
| 114 | +} |
0 commit comments