mirror of
https://github.com/eclipse/upm.git
synced 2025-07-06 11:51:10 +03:00
Added iMagnetometer interface
Signed-off-by: Serban Waltter <serban.waltter@rinftech.com> Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:

committed by
Mihai Tudor Panu

parent
aa966946d5
commit
f28a6d2561
@ -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)
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user