1/*
2 * Author: Jon Trulson <jtrulson@ics.com>
3 * Copyright (c) 2015 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
25#pragma once
26
27#include "mpu60x0.h"
28#include "ak8975.h"
29
30#define MPU9150_I2C_BUS 0
31#define MPU9150_DEFAULT_I2C_ADDR  MPU60X0_DEFAULT_I2C_ADDR
32
33
34namespace upm {
35
36  /**
37   * @brief MPU9150 accelerometer library
38   * @defgroup mpu9150 libupm-mpu9150
39   * @ingroup seeed i2c gpio accelerometer compass
40   */
41
42  /**
43   * @library mpu9150
44   * @sensor mpu9150
45   * @comname MPU9150 Inertial Measurement Unit
46   * @altname Grove IMU 9DOF
47   * @type accelerometer compass
48   * @man seeed
49   * @web http://www.seeedstudio.com/wiki/Grove_-_IMU_9DOF_v1.0
50   * @con i2c gpio
51   *
52   * @brief API for MPU9150 chip (Accelerometer, Gyro and Magnometer Sensor)
53   *
54   * This module defines the MPU9150 interface for libmpu9150
55   *
56   * @image html mpu9150.jpg
57   * @snippet mpu9150.cxx Interesting
58   */
59
60  class MPU9150: public MPU60X0
61  {
62  public:
63    /**
64     * MPU9150 constructor
65     *
66     * @param bus I2C bus to use
67     * @param address The address for this device
68     * @param magAddress The address of the connected magnetometer
69     */
70    MPU9150 (int bus=MPU9150_I2C_BUS, int address=MPU9150_DEFAULT_I2C_ADDR,
71             int magAddress=AK8975_DEFAULT_I2C_ADDR, bool enableAk8975=false);
72
73    /**
74     * MPU9150 destructor
75     */
76    ~MPU9150 ();
77
78    /**
79     * Set up initial values and start operation
80     *
81     * @return true if successful
82     */
83    bool init();
84
85    /**
86     * Take a measurement and store the current sensor values
87     * internally.  Note, these user facing registers are only updated
88     * from the internal device sensor values when the i2c serial
89     * traffic is 'idle'.  So, if you are reading the values too fast,
90     * the bus may never be idle, and you will just end up reading
91     * the same values over and over.
92     *
93     * Unfortunately, it is is not clear how long 'idle' actually
94     * means, so if you see this behavior, reduce the rate at which
95     * you are calling update().
96     */
97    void update();
98
99    /**
100     * Return the compensated values for the x, y, and z axes.  The
101     * unit of measurement is in micro-teslas (uT).
102     *
103     * @param x Pointer to returned X axis value
104     * @param y Pointer to returned Y axis value
105     * @param z Pointer to returned Z axis value
106     */
107    void getMagnetometer(float *x, float *y, float *z);
108
109#ifdef SWIGJAVA
110    /**
111     * Return the compensated values for the x, y, and z axes.  The
112     * unit of measurement is in micro-teslas (uT).
113     *
114     * @return Array containing X, Y, Z magnetometer values
115     */
116    float *getMagnetometer();
117#endif
118
119
120
121  protected:
122    // magnetometer instance
123    AK8975* m_mag;
124
125
126  private:
127    int m_i2cBus;
128    uint8_t m_magAddress;
129    bool m_enableAk8975;
130  };
131
132}
133