/**
 * @file	   puFilters.h
 *
 * @copyright  Nehemis SARL reserves all rights even in the event of industrial
 *             property rights. We reserve all rights of disposal such as
 *             copying and passing on to third parties.
 *
 * @brief	   
 *
 */
#ifndef PUFILTERS_H_
#define PUFILTERS_H_


/******************************************************************************
 * Include Header Files
 ******************************************************************************/
#include "nms_types.h"
#include "map_hal.h"

/******************************************************************************
 * Macro constant declarations
 ******************************************************************************/

/******************************************************************************
 * Type declarations
 ******************************************************************************/
/**
 * @brief Input structure for 2nd order filter used with the sensors.
 */
typedef struct
{
    float32 b1_f32;
    float32 b2_f32;
    float32 a2_f32;

    float32 xPrev_f32;
    float32 yPrev_f32;
} PuFilter_st;


typedef struct
{
    float32 pressureRoPs2_f32;
    float32 pmpPressureMeasFilt_f32;

} PuFiltersSensorData_st;


typedef struct
{
    float32 prevInput_f32;
    float32 prevOutput_f32;
    float32 sampleTime_f32;			// sampling time in seconds
} QDrainSpFilter_st;

/******************************************************************************
 * Extern Function Declarations
 ******************************************************************************/
/**
 * @brief  Initializes the filter module and associated sensor structures.
 * @note   This function sets up all second-order filters for flowmeters,
 *         pressure sensors, and other analog channels. It also initializes
 *         sensor calibration parameters such as Ku and voltage scaling.
 * @retval None
 */
void PuFiltersInit(void);

/**
 * @brief  Executes one filtering and conversion cycle for all analog inputs.
 * @note   This function:
 *         - Reads raw ADC values from the analog buffer
 *         - Applies filters to each channel
 *         - Converts filtered voltages to physical units (flow, pressure, etc.)
 *         - Sends the processed data via queue to consumer tasks (e.g., CAN, PID)
 * @retval None
 */
PuFiltersSensorData_st PuFiltersRun(void);

/**
 * @brief  Initializes the filter for the Qdrain setpoint.
 *
 * @param	filter_pst	Filter structure.
 * 			Ts_f32		Sample time.
 *
 * @retval None
 */
void PuQDrainSpFilterInit(QDrainSpFilter_st* filter_pst, float32 Ts_f32);

/**
 * @brief  Initializes the filter for the Qdrain setpoint.
 *
 * @param	filter_pst			Filter structure.
 * 			currentInput_f32	Input value, Qconso setpoint coming from CAN.
 *
 * @retval Filtered value to be used as setpoint.
 */
float32 PuQDrainSpFilterUpdate(QDrainSpFilter_st* filter_pst, float32 currentInput_f32);

#endif /* PUFILTERS_H_ */
