Subversion Repositories libLSM9DS1

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /*
  2.   This file is part of the Arduino_LSM9DS1 library.
  3.   Copyright (c) 2019 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 "main.h"
  21. #include "math.h"
  22.  
  23. class LSM9DS1Class {
  24.   public:
  25.     LSM9DS1Class(I2C_HandleTypeDef* i2c);
  26.     virtual ~LSM9DS1Class();
  27.  
  28.     int begin();
  29.     void end();
  30.  
  31.     // Controls whether a FIFO is continuously filled, or a single reading is stored.
  32.     // Defaults to one-shot.
  33.     void setContinuousMode();
  34.     void setOneShotMode();
  35.  
  36.     // Accelerometer
  37.     virtual int readAcceleration(float& x, float& y, float& z); // Results are in g (earth gravity).
  38.     virtual int accelerationAvailable(); // Number of samples in the FIFO.
  39.     virtual float accelerationSampleRate(); // Sampling rate of the sensor.
  40.  
  41.     // Gyroscope
  42.     virtual int readGyroscope(float& x, float& y, float& z); // Results are in degrees/second.
  43.     virtual int gyroscopeAvailable(); // Number of samples in the FIFO.
  44.     virtual float gyroscopeSampleRate(); // Sampling rate of the sensor.
  45.  
  46.     // Magnetometer
  47.     virtual int readMagneticField(float& x, float& y, float& z); // Results are in uT (micro Tesla).
  48.     virtual int magneticFieldAvailable(); // Number of samples in the FIFO.
  49.     virtual float magneticFieldSampleRate(); // Sampling rate of the sensor.
  50.  
  51.   private:
  52.     bool continuousMode;
  53.     int readRegister(uint8_t slaveAddress, uint8_t address);
  54.     int readRegisters(uint8_t slaveAddress, uint8_t address, uint8_t* data, size_t length);
  55.     int writeRegister(uint8_t slaveAddress, uint8_t address, uint8_t value);
  56.  
  57.   private:
  58.     I2C_HandleTypeDef* _i2c;
  59. };
  60.  
  61. extern LSM9DS1Class IMU;
  62.