Home | History | Annotate | Download | only in itg3200
      1 /*
      2  * Author: Mihai Tudor Panu <mihai.tudor.panu (at) intel.com>
      3  * Copyright (c) 2014 Intel Corporation.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be
     14  * included in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 #pragma once
     25 
     26 #include <mraa/i2c.hpp>
     27 
     28 #define READ_BUFFER_LENGTH 8
     29 
     30 namespace upm {
     31 
     32 /**
     33  * @brief ITG-3200 Gyroscope library
     34  * @defgroup itg3200 libupm-itg3200
     35  * @ingroup seeed i2c compass
     36  */
     37 
     38 /**
     39  * @library itg3200
     40  * @sensor itg3200
     41  * @comname ITG-3200 3-Axis Digital Gyroscope
     42  * @altname Grove 3-Axis Digital Gyroscope
     43  * @type compass
     44  * @man seeed
     45  * @con i2c
     46  *
     47  * @brief API for the ITG-3200 3-Axis Digital Gyroscope
     48  *
     49  * InvenSense* ITG-3200 is a 3-axis digital gyroscope.
     50  * (https://www.sparkfun.com/datasheets/Sensors/Gyro/PS-ITG-3200-00-01.4.pdf)
     51  * This sensor has been tested and can run at either 3.3V or 5V on Intel(R) Galileo.<br>
     52  * <strong>However</strong>, it is incompatible with and not detected on the I2C bus
     53  * by Intel(R) Edison using the Arduino* breakout board.
     54  *
     55  * @image html itg3200.jpeg
     56  * @snippet itg3200.cxx Interesting
     57  */
     58 class Itg3200 {
     59 public:
     60     /**
     61      * Creates an Itg3200 object
     62      *
     63      * @param bus Number of the used I2C bus
     64      */
     65     Itg3200(int bus);
     66 
     67     /**
     68      * Calibrates the sensor to 0 on all axes. The sensor needs to be resting for accurate calibration.
     69      * It takes about 3 seconds and is also called by the constructor on object creation.
     70      *
     71      */
     72     void calibrate();
     73 
     74     /**
     75      * Returns the temperature reading, in Celsius, from the integrated temperature sensor
     76      *
     77      * @return float Temperature in Celsius
     78      */
     79     float getTemperature();
     80 
     81     /**
     82      * Returns a pointer to a float[3] that contains computed rotational speeds (angular velocities)
     83      *
     84      * @return float* to a float[3]
     85      */
     86     float* getRotation();
     87 
     88     /**
     89      * Returns a pointer to an int[3] that contains raw register values for X, Y, and Z
     90      *
     91      * @return int* to an int[3]
     92      */
     93     int16_t* getRawValues();
     94 
     95     /**
     96      * Returns an int that contains the raw register value for the temperature
     97      *
     98      * @return int Raw temperature
     99      */
    100     int16_t getRawTemp();
    101 
    102     /**
    103      * Updates the rotational values and temperature by reading from the I2C bus
    104      *
    105      * @return 0 if successful
    106      */
    107     mraa::Result update();
    108 private:
    109     float m_angle[3];
    110     int16_t m_rotation[3];
    111     int16_t m_offsets[3];
    112     int16_t m_temperature;
    113     uint8_t m_buffer[READ_BUFFER_LENGTH];
    114     mraa::I2c m_i2c;
    115 };
    116 
    117 }
    118