/******************************************************************************
//                                                                           //
//  Project: Software Interface for DMP-2 Devices                            //
//                                                                           //
//  CGC Instruments, (c) 2009-2015, Version 1.20. All rights reserved.       //
//                                                                           //
//  Definition for DMP-2.DLL routines                                        //
//                                                                           //
******************************************************************************/

#ifndef __DMP2_H__
#define __DMP2_H__

#include <windows.h>

#include "math.h"

#ifdef __cplusplus
extern "C" {
#endif

/************************************************************************************************************************
*
* The LPT_I2C_Open from LPT-I2C.dll must be called before the first usage of other routines.
*
* The return values of the routines are the defines LPT_I2C_ERR_XXX from LPT-I2C.h.
*
************************************************************************************************************************/

WORD _export pascal DMP_2_Version(); /* Get the DMP-2 software version */

/* Communication */
int _export pascal DMP_2_Check (BYTE & Present); /* Check for presence of the DMP-2 device, if the device responds, return non-zero in Present */


/* Filter control */
#define DMP_2_CH_X  0 /* Device channel X */
#define DMP_2_CH_Y  1 /* Device channel Y */

#define DMP_2_LPF_ALPHA_MAX  (1U<<15) /* Maximum allowable LPF Alpha parameter */
#define DMP_2_LPF_BETA_MIN         2  /* Minimum allowable LPF Beta parameter */
#define DMP_2_LPF_BETA_MAX        24  /* Maximum allowable LPF Beta parameter */
int   _export pascal DMP_2_SetLPF            (BYTE Channel,               BYTE   Beta);                   /* Set the LPF parameters */
int   _export pascal DMP_2_GetLPF            (BYTE Channel, WORD & Alpha, BYTE & Beta);                   /* Get the LPF parameters */
float _export pascal DMP_2_GetLPF_Frequency  (WORD Alpha, BYTE Beta);                                     /* Get the corner frequency for the given LPF parameters */
float _export pascal DMP_2_GetLPF_Damping    (WORD Alpha, BYTE Beta);                                     /* Get the damping factor for the given LPF parameters */
void  _export pascal DMP_2_GetLPF_Parameters (WORD Alpha, BYTE Beta, float & Frequency, float & Damping); /* Get the corner frequency and the damping factor for the given LPF parameters */
WORD  _export pascal DMP_2_GetLPF_Alpha      (BYTE Beta, float Damping = sqrt(3.) / 2.);                  /* Get the LPF parameter Alpha for a given parameter Beta and damping factor */

#define DMP_2_HPF_TAU_MIN   1 /* Minimum allowable HPF tau parameter */
#define DMP_2_HPF_TAU_MAX  20 /* Maximum allowable HPF tau parameter */
int   _export pascal DMP_2_SetHPF_Tau       (BYTE Channel, BYTE   Tau); /* Set the HPF tau parameter (corner frequency) of the specified channel */
int   _export pascal DMP_2_GetHPF_Tau       (BYTE Channel, BYTE & Tau); /* Get the HPF tau parameter (corner frequency) of the specified channel */
float _export pascal DMP_2_GetHPF_Frequency (BYTE Tau); /* Get the corner frequency for the given HPF Tau parameter */

#define DMP_2_AMPLIF_MAX  256 /* Maximum allowable amplification */
int _export pascal DMP_2_SetAmplification   (BYTE Channel, float   Amplification); /* Set the amplification of the specified channel */
int _export pascal DMP_2_GetAmplification   (BYTE Channel, float & Amplification); /* Get the amplification of the specified channel */

int _export pascal DMP_2_SetPolarity        (BYTE Channel, BYTE    Negative     ); /* Set the polarity of the specified channel, Negative is zero if the polarity is positive */
int _export pascal DMP_2_GetPolarity        (BYTE Channel, BYTE  & Negative     ); /* Get the polarity of the specified channel, Negative is zero if the polarity is positive */

#define DMP_2_OFFS_MAX  10 /* Maximum allowable offset */
int _export pascal DMP_2_SetOffset          (BYTE Channel, float   Offset       ); /* Set the offset of the specified channel in V */
int _export pascal DMP_2_GetOffset          (BYTE Channel, float & Offset       ); /* Get the offset of the specified channel in V */
int _export pascal DMP_2_SetOffsetRange                   (float   Range        ); /* Set the offset range in V */
int _export pascal DMP_2_GetOffsetRange                   (float & Range        ); /* Get the offset range in V */


/* Amplitude control */
#define DMP_2_FLT_ALPHA_MAX  (1U<<15) /* Maximum allowable LPF Alpha parameter */
#define DMP_2_FLT_BETA_MIN         2  /* Minimum allowable LPF Beta parameter */
#define DMP_2_FLT_BETA_MAX        24  /* Maximum allowable LPF Beta parameter */
int   _export pascal DMP_2_SetFLT            (BYTE Channel,               BYTE   Beta);                   /* Set the LPF parameters */
int   _export pascal DMP_2_GetFLT            (BYTE Channel, WORD & Alpha, BYTE & Beta);                   /* Get the LPF parameters */
float _export pascal DMP_2_GetFLT_Frequency  (WORD Alpha, BYTE Beta);                                     /* Get the corner frequency for the given LPF parameters */
float _export pascal DMP_2_GetFLT_Damping    (WORD Alpha, BYTE Beta);                                     /* Get the damping factor for the given LPF parameters */
void  _export pascal DMP_2_GetFLT_Parameters (WORD Alpha, BYTE Beta, float & Frequency, float & Damping); /* Get the corner frequency and the damping factor for the given LPF parameters */
WORD  _export pascal DMP_2_GetFLT_Alpha      (BYTE Beta, float Damping = sqrt(3.) / 2.);                  /* Get the LPF parameter Alpha for a given parameter Beta and damping factor */

#define DMP_2_AMPLIT_MAX  5.0 /* Maximum allowable amplitude */
int _export pascal DMP_2_SetAmplitude (BYTE Channel, float   Amplitude); /* Set the desired amplitude of the specified channel */
int _export pascal DMP_2_GetAmplitude (BYTE Channel, float & Amplitude); /* Get the desired amplitude of the specified channel */

int _export pascal DMP_2_GetMeasAmplit (BYTE Channel, float & Amplitude); /* Get the measured amplitude of the specified channel */

#define DMP_2_MODE_OFF   0 /* Operation mode: output off        */
#define DMP_2_MODE_DAMP  1 /* Operation mode: maximum damping   */
#define DMP_2_MODE_AMPL  2 /* Operation mode: amplitude control */
#define DMP_2_MODE_MAX   3 /* Number of operation modes         */
int _export pascal DMP_2_SetOperMode (BYTE Channel, BYTE   Mode); /* Set the operation mode of the specified channel */
int _export pascal DMP_2_GetOperMode (BYTE Channel, BYTE & Mode); /* Get the operation mode of the specified channel */


/* General information */
int _export pascal DMP_2_FW_Ver  (WORD & Version);        /* Get firmware version */
int _export pascal DMP_2_FW_Date (char * DateString);     /* Get firmware date, the buffer DateString should be 16 bytes long */
int _export pascal DMP_2_Prod_ID (char * Identification); /* Get product identification, the buffer DateString should be 81 bytes long */
int _export pascal DMP_2_Prod_No (DWORD & Number);        /* Get product number */


/* Housekeeping data */
int _export pascal DMP_2_Get5V   (float & Voltage    ); /* Get internal 5V supply voltage in Volt */
int _export pascal DMP_2_Get3V   (float & Voltage    ); /* Get internal 3V supply voltage in Volt */
int _export pascal DMP_2_GetTemp (float & Temperature); /* Get temperature in K */

int _export pascal DMP_2_GetClkCPU  (float & Clock); /* Get the CPU clock in Hz */
int _export pascal DMP_2_GetClkPer  (float & Clock); /* Get the peripheral clock in Hz */
int _export pascal DMP_2_GetClkADC  (float & Clock); /* Get the ADC clock in Hz */
int _export pascal DMP_2_GetClkDAC  (float & Clock); /* Get the DAC clock in Hz */
int _export pascal DMP_2_GetClkFilt (float & Clock); /* Get the filter clock in Hz */


/* Various */
int _export pascal DMP_2_GetUptime (double & Uptime); /* Get the uptime in seconds */

#ifdef __cplusplus
}
#endif

#endif//__DMP2_H__
