/* VectorNav HSI Calibration Library v1.0.0.2
 *
 * Copyright (c) 2018 VectorNav Technologies, LLC
 *
 * This source code is proprietary to and copyrighted by VectorNav Technologies, LLC and is
 * available solely under license from VectorNav. All rights reserved. If you do not have a
 * license to use this source code from VectorNav, any use hereof is strictly prohibited by
 * U.S. law and other applicable law. This source code is restricted for use solely with the
 * products of VectorNav and as otherwise set forth in any agreement with VectorNav. Any
 * disclosure of this source code to the public or to any third party is also prohibited.
 */
/** \file
*
* \section Description
* This header file contains declarations for using VectorNav HSI 2D tool.
*/
#ifndef VNHSI2D_H_INCLUDED
#define VNHSI2D_H_INCLUDED

#include "vnhsi.h"

#ifdef __cplusplus
extern "C" {
#endif

/** \brief Initialize the 2D HSI with the configuration parameters.
*
* \param[in] c  The configuration structure.
* \param[in] dipole  The magnetic field dipole.
* \return None. */
void vnhsi_2d_init(VnHsiDipole dipole, VnHsiConfig* c);

/** \brief Determine if a YMR measurement should be kept for 2D HSI computation.
  *
  * Takes in YMR measurement from a unit being rotated in a circle,
  * Uses YPR to calculate a gravity vector which it uses to threshold out measurements
  * taken when not float and level (compared to first measurement). Uses gyro
  * data to determine if a set amount of rotation has occurred since
  * last measurement kept and sets a flag to keep the measurement when that is
  * true.
  *
  * \param[in] c  The configuration structure.
  * \param[in] ypr The YPR measurement (in degrees).
  * \param[in] gyro The gyro measurement.
  * \return true to keep measurement, otherwise false. */
bool vnhsi_2d_keep(VnHsiDipole dipole, VnHsiConfig* c, union vn_vec3f ypr, union vn_vec3f gyro);


/** \brief Solve for the hard iron vector and the soft iron matrix for 2D measurement.
  *
  * Once certain number of measurements associated with the keep measurement criteria are selected
  * the 2D HSI calibration algorithm takes place in this function.
 
  * \param[in] dipole The magnetic dipole structure. 
  * \param[in] c The configuration structure. 
  * \param[in] meas  The kept YMR measurement.
  * \param[in] hsisolnIN  HSI solution to apply to measurements prior to solving.  Used for calculating accurate FOM. Set to NULL for uncorrected solution.
  * \param[in] numMeas The number of kept measurements.
  * \param[in] gyro The gyro measurement.
  * \param[out] hsisoln The HSI solution structure.
  * \param[out] FOM  The figures of merit.
  * \return Error code. */
    
enum VnError vnhsi_2d_solve(VnHsiDipole dipole, VnHsiConfig* c, VnHsiYmr* meas, VnHsiSol* hsisolnIN, size_t numMeas, VnHsiSol* hsisoln, VnHsiFom* FOM);


#ifdef __cplusplus
}
#endif

#endif