hmc5883l: C port; FTI; C++ wraps C

Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
Jon Trulson
2017-01-25 17:37:29 -07:00
parent 806b00c2b7
commit 0a91eb0b46
11 changed files with 711 additions and 199 deletions

View File

@@ -1,4 +1,8 @@
/*
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2017 Intel Corporation.
*
* Ported based on original C++ code by:
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
* Contributions: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
* Copyright (c) 2014 Intel Corporation.
@@ -24,88 +28,87 @@
*/
#pragma once
#include <mraa/i2c.hpp>
#define MAX_BUFFER_LENGTH 6
#include "hmc5883l.h"
namespace upm {
/**
* @brief HMC5883L Magnometer library
* @defgroup hmc5883l libupm-hmc5883l
* @ingroup seeed i2c compass robok
*/
/**
* @library hmc5883l
* @sensor hmc5883l
* @comname HMC5883L 3-Axis Digital Compass
* @altname Grove 3-Axis Digital Compass
* @type compass
* @man seeed
* @con i2c
* @kit robok
*
* @brief API for the HMC5883L 3-Axis Digital Compass
*
* Honeywell [HMC5883L]
* (http://www.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf)
* is a 3-axis digital compass. Communication with HMC5883L is simple and
* all done through an I2C interface. Different breakout boards are available.
* Typically, a 3V supply is all that is needed to power the sensor.
*
* @image html hmc5883l.jpeg
* @snippet hmc5883l.cxx Interesting
*/
class Hmc5883l {
public:
/**
* Creates an Hmc5883l object
* @brief HMC5883L Magnometer library
* @defgroup hmc5883l libupm-hmc5883l
* @ingroup seeed i2c compass robok
*/
/**
* @library hmc5883l
* @sensor hmc5883l
* @comname HMC5883L 3-Axis Digital Compass
* @altname Grove 3-Axis Digital Compass
* @type compass
* @man seeed
* @con i2c
* @kit robok
*
* @param bus Number of the used I2C bus
*/
Hmc5883l(int bus);
/*
* Returns the direction
*/
float direction();
/*
* Returns the heading
*/
float heading();
/**
* Returns a pointer to an int[3] that contains the coordinates as ints
* @brief API for the HMC5883L 3-Axis Digital Compass
*
* @return *int to an int[3]
*/
int16_t* coordinates();
/**
* Updates the values by reading from I2C
* Honeywell [HMC5883L]
* (http://www.adafruit.com/datasheets/HMC5883L_3-Axis_Digital_Compass_IC.pdf)
* is a 3-axis digital compass. Communication with HMC5883L is
* simple and all done through an I2C interface. Different
* breakout boards are available. Typically, a 3V supply is all
* that is needed to power the sensor.
*
* @return 0 if successful
* @image html hmc5883l.jpeg
* @snippet hmc5883l.cxx Interesting
*/
mraa::Result update();
class Hmc5883l {
public:
/**
* Creates an Hmc5883l object. The I2C address cannot be
* changed, and is always 0x1e (7-bit).
*
* @param bus I2C bus number
*/
Hmc5883l(int bus);
/**
* Sets the magnetic declination for better calibration
*/
void set_declination(float dec);
/*
* Returns the direction
*/
float direction();
/**
* Gets the current magnetic declination value
*
* @return Magnetic declination as a floating-point value
*/
float get_declination();
private:
int16_t m_coor[3];
float m_declination;
uint8_t m_rx_tx_buf[MAX_BUFFER_LENGTH];
mraa::I2c m_i2c;
};
/*
* Returns the heading
*/
float heading();
/**
* Returns a pointer to an int[3] that contains the coordinates as ints
*
* @return *int to an int[3]
*/
const int16_t* coordinates();
/**
* Updates the values by reading from I2C
*
* @return 0 if successful
*/
upm_result_t update();
/**
* Sets the magnetic declination for better calibration
*/
void set_declination(float dec);
/**
* Gets the current magnetic declination value
*
* @return Magnetic declination as a floating-point value
*/
float get_declination();
protected:
hmc5883l_context m_hmc5883l;
private:
};
}