Added iMagnetometer interface

Signed-off-by: Serban Waltter <serban.waltter@rinftech.com>
This commit is contained in:
Serban Waltter 2018-10-02 16:49:48 +03:00
parent 050634bbaf
commit 5ad91e219f
36 changed files with 173 additions and 39 deletions

View File

@ -62,15 +62,15 @@ public class BMI160_Example
+ " GZ: "
+ dataG.get(2));
float dataM[] = sensor.getMagnetometer();
AbstractList<Float> 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);

View File

@ -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

View File

@ -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")

View File

@ -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

View File

@ -0,0 +1,48 @@
/*
* Author: Serban Waltter <serban.waltter@rinftech.com>
* 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 <vector>
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<float> getMagnetometer() = 0;
};
} // upm

View File

@ -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"

View File

@ -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"

View File

@ -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)
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()

View File

@ -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)

View File

@ -101,13 +101,13 @@ std::vector<float> BMI160::getGyroscope()
return std::vector<float>(values, values + 3);
}
float *BMI160::getMagnetometer()
std::vector<float> BMI160::getMagnetometer()
{
static float values[3]; // x, y, and then z
getMagnetometer(&values[0], &values[1], &values[2]);
return values;
return std::vector<float>(values, values + 3);
}
void BMI160::enableMagnetometer(bool enable)

View File

@ -27,6 +27,7 @@
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iGyroscope.hpp>
#include <interfaces/iMagnetometer.hpp>
#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<float> getMagnetometer();
/**
* Get the Magnetometer values. The values returned are in micro

View File

@ -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)

View File

@ -96,9 +96,10 @@ void BMM150::getMagnetometer(float *x, float *y, float *z)
std::vector<float> 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<float>(v, v+3);
}

View File

@ -31,6 +31,8 @@
#include <mraa/gpio.hpp>
#include "bmm150.h"
#include <interfaces/iMagnetometer.hpp>
namespace upm {
/**
@ -73,7 +75,7 @@ namespace upm {
* @snippet bmm150.cxx Interesting
*/
class BMM150 {
class BMM150: virtual public iMagnetometer {
public:
/**
* BMM150 constructor.

View File

@ -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<float> {
return (AbstractList<Float>)(new $&javaclassname($jnicall, true));
}
%typemap(jstype) std::vector<float> "AbstractList<Float>"
%template(floatVector) std::vector<float>;
%ignore installISR (BMM150_INTERRUPT_PINS_T , int , mraa::Edge , void *, void *);

View File

@ -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)

View File

@ -117,6 +117,7 @@ void BMC150::getMagnetometer(float *x, float *y, float *z)
std::vector<float> BMC150::getMagnetometer()
{
update();
if (m_mag)
return m_mag->getMagnetometer();
else

View File

@ -30,6 +30,7 @@
#include "bmm150.hpp"
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iMagnetometer.hpp>
#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.

View File

@ -169,6 +169,7 @@ void BMX055::getMagnetometer(float *x, float *y, float *z)
std::vector<float> BMX055::getMagnetometer()
{
update();
if (m_mag)
return m_mag->getMagnetometer();
else

View File

@ -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.

View File

@ -30,6 +30,7 @@
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iGyroscope.hpp>
#include <interfaces/iMagnetometer.hpp>
namespace upm {

View File

@ -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)

View File

@ -90,9 +90,10 @@ void LSM303AGR::getMagnetometer(float *x, float *y, float *z)
std::vector<float> 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<float>(v, v+3);
}

View File

@ -32,6 +32,7 @@
#include "lsm303agr.h"
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iMagnetometer.hpp>
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

View File

@ -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)

View File

@ -645,8 +645,11 @@ std::vector<float> LSM9DS0::getGyroscope()
std::vector<float> LSM9DS0::getMagnetometer()
{
update();
std::vector<float> 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;
}

View File

@ -32,6 +32,7 @@
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iGyroscope.hpp>
#include <interfaces/iMagnetometer.hpp>
#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

View File

@ -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)

View File

@ -198,6 +198,28 @@ MAG3110::sampleData(void)
return 0;
}
std::vector<float> 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)
{

View File

@ -26,6 +26,8 @@
#pragma once
#include <interfaces/iMagnetometer.hpp>
#include <string>
#include <mraa/i2c.hpp>
#include <stdint.h>
@ -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<float> getMagnetometer();
/**
* Set user offset correction
* Offset correction register will be erased after accelerometer reset

View File

@ -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)

View File

@ -237,3 +237,11 @@ void AK8975::getMagnetometer(float *x, float *y, float *z)
*z = adjustValue(m_zData, m_zCoeff);
}
std::vector<float> AK8975::getMagnetometer()
{
std::vector<float> 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;
}

View File

@ -27,6 +27,8 @@
#include <mraa/common.hpp>
#include <mraa/i2c.hpp>
#include <interfaces/iMagnetometer.hpp>
#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<float> getMagnetometer();
protected:
/**

View File

@ -32,6 +32,7 @@
#include <interfaces/iAcceleration.hpp>
#include <interfaces/iGyroscope.hpp>
#include <interfaces/iTemperature.hpp>
#define MPU60X0_I2C_BUS 0
#define MPU60X0_DEFAULT_I2C_ADDR 0x68

View File

@ -112,6 +112,6 @@ void MPU9150::getMagnetometer(float *x, float *y, float *z)
std::vector<float> MPU9150::getMagnetometer()
{
std::vector<float> v(3);
getMagnetometer(&v[0], &v[1], &v[2]);
m_mag->getMagnetometer(&v[0], &v[1], &v[2]);
return v;
}

View File

@ -58,7 +58,7 @@ namespace upm {
* @snippet mpu9150.cxx Interesting
*/
class MPU9150: public MPU60X0
class MPU9150: public MPU60X0, virtual public iMagnetometer
{
public:
/**