diff --git a/examples/java/BMI160_Example.java b/examples/java/BMI160_Example.java index b7f1b34b..eda0b529 100644 --- a/examples/java/BMI160_Example.java +++ b/examples/java/BMI160_Example.java @@ -62,15 +62,15 @@ public class BMI160_Example + " GZ: " + dataG.get(2)); - float dataM[] = sensor.getMagnetometer(); + AbstractList dataM = sensor.getMagnetometer(); System.out.println("Magnetometer: " + "MX: " - + dataM[0] + + dataM.get(0) + " MY: " - + dataM[1] + + dataM.get(1) + " MZ: " - + dataM[2]); + + dataM.get(2)); System.out.println(); Thread.sleep(500); diff --git a/examples/java/BMM150_Example.java b/examples/java/BMM150_Example.java index 194c14be..270009d1 100644 --- a/examples/java/BMM150_Example.java +++ b/examples/java/BMM150_Example.java @@ -24,10 +24,12 @@ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +import upm_interfaces.*; import upm_bmm150.BMM150; import java.util.AbstractList; import java.lang.Float; + public class BMM150_Example { public static void main(String[] args) throws InterruptedException diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 9f276e46..a47c9110 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -82,7 +82,7 @@ add_example(BME280_Example "bmp280;interfaces") add_example(BMG160_Example "bmg160;interfaces") add_example(BMI055_Example "bmx055;interfaces") add_example(BMI160_Example "bmi160;interfaces") -add_example(BMM150_Example bmm150) +add_example(BMM150_Example "bmm150;interfaces") add_example(BMP280_Example "bmp280;interfaces") add_example(BMPX8X_Example "bmpx8x;interfaces") add_example(BMX055_Example "bmx055;interfaces") diff --git a/include/interfaces/CMakeLists.txt b/include/interfaces/CMakeLists.txt index 47954b9e..9140a353 100644 --- a/include/interfaces/CMakeLists.txt +++ b/include/interfaces/CMakeLists.txt @@ -18,8 +18,10 @@ set (module_hpp iClock.hpp iHallEffect.hpp iHeartRate.hpp iHumidity.hpp + iGyroscope.hpp iLight.hpp iLineFinder.hpp + iMagnetometer.hpp iMoisture.hpp iMotion.hpp iPressure.hpp diff --git a/include/interfaces/iMagnetometer.hpp b/include/interfaces/iMagnetometer.hpp new file mode 100644 index 00000000..02f5f462 --- /dev/null +++ b/include/interfaces/iMagnetometer.hpp @@ -0,0 +1,48 @@ +/* + * Author: Serban Waltter + * Copyright (c) 2018 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#pragma once + +#include + +namespace upm +{ + /** + * @brief Interface for acceleration sensors + */ + class iMagnetometer + { + public: + virtual ~iMagnetometer() {} + + /** + * Return gyroscope data in degrees per second in the form of + * a floating point vector in micro Tesla. + * + * @return A floating point vector containing x, y, and z in + * that order in micro Tesla. + */ + virtual std::vector getMagnetometer() = 0; + }; +} // upm diff --git a/include/interfaces/interfaces.cxx b/include/interfaces/interfaces.cxx index 96ecf300..53472964 100644 --- a/include/interfaces/interfaces.cxx +++ b/include/interfaces/interfaces.cxx @@ -15,6 +15,7 @@ #include "iHumidity.hpp" #include "iLight.hpp" #include "iLineFinder.hpp" +#include "iMagnetometer.hpp" #include "iMoisture.hpp" #include "iMotion.hpp" #include "iOrp.hpp" diff --git a/include/interfaces/interfaces.i b/include/interfaces/interfaces.i index cf2390e5..87ac7123 100644 --- a/include/interfaces/interfaces.i +++ b/include/interfaces/interfaces.i @@ -56,6 +56,7 @@ import java.lang.Float; %interface_impl (upm::iHumidity); %interface_impl (upm::iLight); %interface_impl (upm::iLineFinder); + %interface_impl (upm::iMagnetometer); %interface_impl (upm::iMoisture); %interface_impl (upm::iMotion); %interface_impl (upm::iOrp); @@ -85,6 +86,7 @@ import java.lang.Float; #include "iHumidity.hpp" #include "iLight.hpp" #include "iLineFinder.hpp" + #include "iMagnetometer.hpp" #include "iMoisture.hpp" #include "iMotion.hpp" #include "iOrp.hpp" @@ -113,6 +115,7 @@ import java.lang.Float; %include "iHumidity.hpp" %include "iLight.hpp" %include "iLineFinder.hpp" +%include "iMagnetometer.hpp" %include "iMoisture.hpp" %include "iMotion.hpp" %include "iOrp.hpp" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b81efeb8..ac16575d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -267,13 +267,20 @@ function (_get_current_dot_i_file filePrefix varDotIFile) list (FIND module_iface "iAcceleration.hpp" _index) if (${_index} GREATER -1) set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") + else() list (FIND module_iface "iGyroscope.hpp" _index) - elseif(${_index} GREATER -1) - set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") + if(${_index} GREATER -1) + set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") + else() + list (FIND module_iface "iMagnetometer.hpp" _index) + if(${_index} GREATER -1) + set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") + endif() + endif() endif() else() cmake_policy(SET CMP0057 NEW) - if (("iAcceleration.hpp" IN_LIST module_iface) OR ("iGyroscope.hpp" IN_LIST module_iface)) + if (("iAcceleration.hpp" IN_LIST module_iface) OR ("iGyroscope.hpp" IN_LIST module_iface) OR ("iMagnetometer.hpp" IN_LIST module_iface)) set(JAVA_TYPEMAPS "%typemap(javaimports) SWIGTYPE %{\nimport upm_interfaces.*;\n\nimport java.util.AbstractList;\nimport java.lang.Float;\n%}\n") endif() endif() diff --git a/src/bmi160/CMakeLists.txt b/src/bmi160/CMakeLists.txt index 2d702958..e6b6eefd 100644 --- a/src/bmi160/CMakeLists.txt +++ b/src/bmi160/CMakeLists.txt @@ -4,7 +4,7 @@ upm_mixed_module_init (NAME bmi160 C_SRC bmi160.c bosch_bmi160.c CPP_HDR bmi160.hpp CPP_SRC bmi160.cxx - IFACE_HDR iAcceleration.hpp iGyroscope.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp iMagnetometer.hpp # FTI_SRC bmi160_fti.c CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/bmi160/bmi160.cxx b/src/bmi160/bmi160.cxx index af224729..c6043020 100644 --- a/src/bmi160/bmi160.cxx +++ b/src/bmi160/bmi160.cxx @@ -101,13 +101,13 @@ std::vector BMI160::getGyroscope() return std::vector(values, values + 3); } -float *BMI160::getMagnetometer() +std::vector BMI160::getMagnetometer() { static float values[3]; // x, y, and then z getMagnetometer(&values[0], &values[1], &values[2]); - return values; + return std::vector(values, values + 3); } void BMI160::enableMagnetometer(bool enable) diff --git a/src/bmi160/bmi160.hpp b/src/bmi160/bmi160.hpp index 044d935b..b4a1d3f3 100644 --- a/src/bmi160/bmi160.hpp +++ b/src/bmi160/bmi160.hpp @@ -27,6 +27,7 @@ #include #include +#include #define BMI160_I2C_BUS 0 #define BMI160_DEFAULT_I2C_ADDR 0x69 @@ -75,7 +76,7 @@ namespace upm { * * @snippet bmi160.cxx Interesting */ - class BMI160: virtual public iAcceleration, virtual public iGyroscope { + class BMI160: virtual public iAcceleration, virtual public iGyroscope, public virtual iMagnetometer { public: /** @@ -189,7 +190,7 @@ namespace upm { * @return Pointer to 3 floating point values: X, Y, and Z in * micro Teslas. */ - float *getMagnetometer(); + std::vector getMagnetometer(); /** * Get the Magnetometer values. The values returned are in micro diff --git a/src/bmm150/CMakeLists.txt b/src/bmm150/CMakeLists.txt index e2ca296b..3d20a605 100644 --- a/src/bmm150/CMakeLists.txt +++ b/src/bmm150/CMakeLists.txt @@ -4,6 +4,7 @@ upm_mixed_module_init (NAME bmm150 C_SRC bmm150.c CPP_HDR bmm150.hpp CPP_SRC bmm150.cxx + IFACE_HDR iMagnetometer.hpp FTI_SRC bmm150_fti.c CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/bmm150/bmm150.cxx b/src/bmm150/bmm150.cxx index 3cfbd599..8dad845b 100644 --- a/src/bmm150/bmm150.cxx +++ b/src/bmm150/bmm150.cxx @@ -96,9 +96,10 @@ void BMM150::getMagnetometer(float *x, float *y, float *z) std::vector BMM150::getMagnetometer() { + update(); float v[3]; - getMagnetometer(&v[0], &v[1], &v[2]); + bmm150_get_magnetometer(m_bmm150, &v[0], &v[1], &v[2]); return std::vector(v, v+3); } diff --git a/src/bmm150/bmm150.hpp b/src/bmm150/bmm150.hpp index 4d721955..90f2d3c3 100644 --- a/src/bmm150/bmm150.hpp +++ b/src/bmm150/bmm150.hpp @@ -31,6 +31,8 @@ #include #include "bmm150.h" +#include + namespace upm { /** @@ -73,7 +75,7 @@ namespace upm { * @snippet bmm150.cxx Interesting */ - class BMM150 { + class BMM150: virtual public iMagnetometer { public: /** * BMM150 constructor. diff --git a/src/bmm150/bmm150.i b/src/bmm150/bmm150.i index ef364d90..e2c25443 100644 --- a/src/bmm150/bmm150.i +++ b/src/bmm150/bmm150.i @@ -1,25 +1,25 @@ +#ifdef SWIGPYTHON +%module (package="upm") bmi160 +#endif + +%import "interfaces/interfaces.i" + %include "../common_top.i" /* BEGIN Java syntax ------------------------------------------------------- */ #ifdef SWIGJAVA -%include "../upm_javastdvector.i" - -%ignore getMagnetometer(float *, float *, float *); - %typemap(javaimports) SWIGTYPE %{ +import upm_interfaces.*; + import java.util.AbstractList; import java.lang.Float; %} +%ignore getMagnetometer(float *, float *, float *); + %typemap(javaout) SWIGTYPE { return new $&javaclassname($jnicall, true); } -%typemap(javaout) std::vector { - return (AbstractList)(new $&javaclassname($jnicall, true)); -} -%typemap(jstype) std::vector "AbstractList" - -%template(floatVector) std::vector; %ignore installISR (BMM150_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *); diff --git a/src/bmx055/CMakeLists.txt b/src/bmx055/CMakeLists.txt index b9b2ffb1..5a1d3f11 100644 --- a/src/bmx055/CMakeLists.txt +++ b/src/bmx055/CMakeLists.txt @@ -2,5 +2,5 @@ upm_mixed_module_init (NAME bmx055 DESCRIPTION "Bosch IMU Sensor Library" CPP_HDR bmx055.hpp bmc150.hpp bmi055.hpp CPP_SRC bmx055.cxx bmc150.cxx bmi055.cxx - IFACE_HDR iAcceleration.hpp iGyroscope.hpp + IFACE_HDR iAcceleration.hpp iGyroscope.hpp iMagnetometer.hpp REQUIRES mraa bmg160 bma250e bmm150) diff --git a/src/bmx055/bmc150.cxx b/src/bmx055/bmc150.cxx index ca5d36eb..52c1c083 100644 --- a/src/bmx055/bmc150.cxx +++ b/src/bmx055/bmc150.cxx @@ -117,6 +117,7 @@ void BMC150::getMagnetometer(float *x, float *y, float *z) std::vector BMC150::getMagnetometer() { + update(); if (m_mag) return m_mag->getMagnetometer(); else diff --git a/src/bmx055/bmc150.hpp b/src/bmx055/bmc150.hpp index 8a084883..d17cf79c 100644 --- a/src/bmx055/bmc150.hpp +++ b/src/bmx055/bmc150.hpp @@ -30,6 +30,7 @@ #include "bmm150.hpp" #include +#include #define BMC150_DEFAULT_BUS 0 #define BMC150_DEFAULT_ACC_ADDR 0x10 @@ -72,7 +73,7 @@ namespace upm { * @snippet bmx055-bmc150.cxx Interesting */ - class BMC150: virtual public iAcceleration { + class BMC150: virtual public iAcceleration, virtual public iMagnetometer { public: /** * BMC150 constructor. diff --git a/src/bmx055/bmx055.cxx b/src/bmx055/bmx055.cxx index 79bca090..05ba50fe 100644 --- a/src/bmx055/bmx055.cxx +++ b/src/bmx055/bmx055.cxx @@ -169,6 +169,7 @@ void BMX055::getMagnetometer(float *x, float *y, float *z) std::vector BMX055::getMagnetometer() { + update(); if (m_mag) return m_mag->getMagnetometer(); else diff --git a/src/bmx055/bmx055.hpp b/src/bmx055/bmx055.hpp index 5947cb4f..c70b4077 100644 --- a/src/bmx055/bmx055.hpp +++ b/src/bmx055/bmx055.hpp @@ -79,7 +79,7 @@ namespace upm { * @snippet bmx055.cxx Interesting */ - class BMX055: virtual public iAcceleration, virtual public iGyroscope { + class BMX055: virtual public iAcceleration, virtual public iGyroscope, public virtual iMagnetometer { public: /** * BMX055 constructor. diff --git a/src/bno055/bno055.hpp b/src/bno055/bno055.hpp index 275cff46..2c75c5e8 100644 --- a/src/bno055/bno055.hpp +++ b/src/bno055/bno055.hpp @@ -30,6 +30,7 @@ #include #include +#include namespace upm { diff --git a/src/lsm303agr/CMakeLists.txt b/src/lsm303agr/CMakeLists.txt index fe3a5496..2e9eff64 100644 --- a/src/lsm303agr/CMakeLists.txt +++ b/src/lsm303agr/CMakeLists.txt @@ -5,6 +5,6 @@ upm_mixed_module_init (NAME lsm303agr CPP_HDR lsm303agr.hpp CPP_SRC lsm303agr.cxx FTI_SRC lsm303agr_fti.c - IFACE_HDR iAcceleration.hpp + IFACE_HDR iAcceleration.hpp iMagnetometer.hpp CPP_WRAPS_C REQUIRES mraa utilities-c) diff --git a/src/lsm303agr/lsm303agr.cxx b/src/lsm303agr/lsm303agr.cxx index b9e3bb6e..1c3d78cd 100644 --- a/src/lsm303agr/lsm303agr.cxx +++ b/src/lsm303agr/lsm303agr.cxx @@ -90,9 +90,10 @@ void LSM303AGR::getMagnetometer(float *x, float *y, float *z) std::vector LSM303AGR::getMagnetometer() { + update(); float v[3]; - getMagnetometer(&v[0], &v[1], &v[2]); + lsm303agr_get_magnetometer(m_lsm303agr, &v[0], &v[1], &v[2]); return std::vector(v, v+3); } diff --git a/src/lsm303agr/lsm303agr.hpp b/src/lsm303agr/lsm303agr.hpp index 11dd9637..864fdee7 100644 --- a/src/lsm303agr/lsm303agr.hpp +++ b/src/lsm303agr/lsm303agr.hpp @@ -32,6 +32,7 @@ #include "lsm303agr.h" #include +#include namespace upm { @@ -67,7 +68,7 @@ namespace upm { * @snippet lsm303agr.cxx Interesting */ - class LSM303AGR: virtual public iAcceleration { + class LSM303AGR: virtual public iAcceleration, virtual public iMagnetometer { public: /** * LSM303AGR constructor diff --git a/src/lsm9ds0/CMakeLists.txt b/src/lsm9ds0/CMakeLists.txt index feab915c..b259de11 100644 --- a/src/lsm9ds0/CMakeLists.txt +++ b/src/lsm9ds0/CMakeLists.txt @@ -2,5 +2,5 @@ set (libname "lsm9ds0") set (libdescription "Triaxial Gyroscope/accelerometer/magnetometer Sensor") set (module_src ${libname}.cxx) set (module_hpp ${libname}.hpp) -set (module_iface iAcceleration.hpp iGyroscope.hpp) +set (module_iface iAcceleration.hpp iGyroscope.hpp iMagnetometer.hpp) upm_module_init(mraa) diff --git a/src/lsm9ds0/lsm9ds0.cxx b/src/lsm9ds0/lsm9ds0.cxx index a110bf62..4b129f63 100644 --- a/src/lsm9ds0/lsm9ds0.cxx +++ b/src/lsm9ds0/lsm9ds0.cxx @@ -645,8 +645,11 @@ std::vector LSM9DS0::getGyroscope() std::vector LSM9DS0::getMagnetometer() { + update(); std::vector v(3); - getMagnetometer(&v[0], &v[1], &v[2]); + v[0] = (m_magX * m_magScale) / 1000.0; + v[1] = (m_magY * m_magScale) / 1000.0; + v[2] = (m_magZ * m_magScale) / 1000.0; return v; } diff --git a/src/lsm9ds0/lsm9ds0.hpp b/src/lsm9ds0/lsm9ds0.hpp index dc18e5ce..c5b0bc04 100644 --- a/src/lsm9ds0/lsm9ds0.hpp +++ b/src/lsm9ds0/lsm9ds0.hpp @@ -32,6 +32,7 @@ #include #include +#include #define LSM9DS0_I2C_BUS 1 #define LSM9DS0_DEFAULT_XM_ADDR 0x1d @@ -80,7 +81,7 @@ namespace upm { * @snippet lsm9ds0.cxx Interesting */ - class LSM9DS0: virtual public iAcceleration, virtual public iGyroscope { + class LSM9DS0: virtual public iAcceleration, virtual public iGyroscope, virtual public iMagnetometer { public: // NOTE: reserved registers must not be written into or permanent diff --git a/src/mag3110/CMakeLists.txt b/src/mag3110/CMakeLists.txt index 32be4420..71284844 100644 --- a/src/mag3110/CMakeLists.txt +++ b/src/mag3110/CMakeLists.txt @@ -2,4 +2,5 @@ set (libname "mag3110") set (libdescription "Three-Axis Digital Magnetometer") set (module_src ${libname}.cpp) set (module_hpp ${libname}.hpp) +set (module_iface iMagnetometer.hpp) upm_module_init(mraa) diff --git a/src/mag3110/mag3110.cpp b/src/mag3110/mag3110.cpp index 18db6d43..60a1d19a 100644 --- a/src/mag3110/mag3110.cpp +++ b/src/mag3110/mag3110.cpp @@ -198,6 +198,28 @@ MAG3110::sampleData(void) return 0; } +std::vector MAG3110::getMagnetometer() +{ + uint8_t buf[7]; + int re = 0; + + re = m_i2ControlCtx.readBytesReg(MAG3110_DR_STATUS, buf, 7); + if (re != 7) { + /* did not read enough bytes */ + return {-1, -1, -1}; + } + + s_data->status = buf[0]; + s_data->x = ((int16_t)buf[1] << 8) | buf[2]; + s_data->y = ((int16_t)buf[3] << 8) | buf[4]; + s_data->z = ((int16_t)buf[5] << 8) | buf[6]; + + s_data->dtemp = m_i2ControlCtx.readReg(MAG3110_DIE_TEMP); + + return {(float)s_data->x, (float)s_data->y, (float)s_data->z}; + +} + int16_t MAG3110::getX(int bSampleData) { diff --git a/src/mag3110/mag3110.hpp b/src/mag3110/mag3110.hpp index fd9c3068..e98b7913 100644 --- a/src/mag3110/mag3110.hpp +++ b/src/mag3110/mag3110.hpp @@ -26,6 +26,8 @@ #pragma once +#include + #include #include #include @@ -162,7 +164,7 @@ typedef struct { * * @snippet mag3110.cxx Interesting */ -class MAG3110 { +class MAG3110: virtual public iMagnetometer { public: /** * @@ -183,6 +185,16 @@ class MAG3110 { */ int checkID(void); + /** + * Return magnetometer data in micro-Teslas (uT) in the form + * of a floating point vector. update() must have been called + * prior to calling this method. + * + * @return A floating point vector containing x, y, and z in + * that order. + */ + std::vector getMagnetometer(); + /** * Set user offset correction * Offset correction register will be erased after accelerometer reset diff --git a/src/mpu9150/CMakeLists.txt b/src/mpu9150/CMakeLists.txt index d4948835..a4410493 100644 --- a/src/mpu9150/CMakeLists.txt +++ b/src/mpu9150/CMakeLists.txt @@ -2,5 +2,5 @@ set (libname "mpu9150") set (libdescription "IMU Sensor Library Based On the Mpu9150") set (module_src ${libname}.cxx ak8975.cxx mpu60x0.cxx mpu9250.cxx) set (module_hpp ${libname}.hpp ak8975.hpp mpu60x0.hpp mpu9250.hpp) -set (module_iface iAcceleration.hpp iGyroscope.hpp) +set (module_iface iAcceleration.hpp iGyroscope.hpp iMagnetometer.hpp iTemperature.hpp) upm_module_init(mraa) diff --git a/src/mpu9150/ak8975.cxx b/src/mpu9150/ak8975.cxx index 83c80aac..52a73b79 100644 --- a/src/mpu9150/ak8975.cxx +++ b/src/mpu9150/ak8975.cxx @@ -237,3 +237,11 @@ void AK8975::getMagnetometer(float *x, float *y, float *z) *z = adjustValue(m_zData, m_zCoeff); } +std::vector AK8975::getMagnetometer() +{ + std::vector v(3); + v[0] = adjustValue(m_xData, m_xCoeff); + v[0] = adjustValue(m_yData, m_yCoeff); + v[0] = adjustValue(m_zData, m_zCoeff); + return v; +} \ No newline at end of file diff --git a/src/mpu9150/ak8975.hpp b/src/mpu9150/ak8975.hpp index fe0089fd..f5c6fa40 100644 --- a/src/mpu9150/ak8975.hpp +++ b/src/mpu9150/ak8975.hpp @@ -27,6 +27,8 @@ #include #include +#include + #define AK8975_I2C_BUS 0 #define AK8975_DEFAULT_I2C_ADDR 0x0c @@ -50,7 +52,7 @@ namespace upm { * * @snippet mpu9150-ak8975.cxx Interesting */ - class AK8975 { + class AK8975: virtual public iMagnetometer { public: /** @@ -202,6 +204,16 @@ namespace upm { */ void getMagnetometer(float *x, float *y, float *z); + /** + * Return magnetometer data in micro-Teslas (uT) in the form + * of a floating point vector. update() must have been called + * prior to calling this method. + * + * @return A floating point vector containing x, y, and z in + * that order. + */ + std::vector getMagnetometer(); + protected: /** diff --git a/src/mpu9150/mpu60x0.hpp b/src/mpu9150/mpu60x0.hpp index 31647b7d..35f9eae1 100644 --- a/src/mpu9150/mpu60x0.hpp +++ b/src/mpu9150/mpu60x0.hpp @@ -32,6 +32,7 @@ #include #include +#include #define MPU60X0_I2C_BUS 0 #define MPU60X0_DEFAULT_I2C_ADDR 0x68 diff --git a/src/mpu9150/mpu9150.cxx b/src/mpu9150/mpu9150.cxx index 6295328d..81ac38b7 100644 --- a/src/mpu9150/mpu9150.cxx +++ b/src/mpu9150/mpu9150.cxx @@ -112,6 +112,6 @@ void MPU9150::getMagnetometer(float *x, float *y, float *z) std::vector MPU9150::getMagnetometer() { std::vector v(3); - getMagnetometer(&v[0], &v[1], &v[2]); + m_mag->getMagnetometer(&v[0], &v[1], &v[2]); return v; } diff --git a/src/mpu9150/mpu9150.hpp b/src/mpu9150/mpu9150.hpp index 105e9c62..9ba45a68 100644 --- a/src/mpu9150/mpu9150.hpp +++ b/src/mpu9150/mpu9150.hpp @@ -58,7 +58,7 @@ namespace upm { * @snippet mpu9150.cxx Interesting */ - class MPU9150: public MPU60X0 + class MPU9150: public MPU60X0, virtual public iMagnetometer { public: /**