Files
aqhomecontrol/apps/aqhome-react/units/u_highpass.c
2024-03-24 18:51:56 +01:00

99 lines
3.4 KiB
C

/****************************************************************************
* This file is part of the project AqHome.
* AqHome (c) by 2024 Martin Preuss, all rights reserved.
*
* The license for this file can be found in the file COPYING which you
* should have received along with this file.
****************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "./u_highpass.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT 0
#define AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitHighPass_new(AQHOME_REACT *aqh)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
AQHREACT_PARAM *param;
unit=AQHREACT_Unit_new(aqh);
AQHREACT_Unit_SetName(unit, "highpass");
AQHREACT_Unit_SetDescription(unit, "Highpass filter for data");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT);
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
inputSlot=AQHREACT_InputSlot_new();
AQHREACT_InputSlot_SetName(inputSlot, "input");
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
param=AQHREACT_Param_new();
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT);
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddParam(unit, param);
param=AQHREACT_Param_new();
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_HIGHPASS_PARAM_NEWVALUE);
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddParam(unit, param);
return unit;
}
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_HIGHPASS_INSLOT_INPUT) {
double data;
double limit;
double newValue;
data=AQHREACT_DataObject_GetDoubleData(dataObject);
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT, data);
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HIGHPASS_PARAM_NEWVALUE, data);
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_HIGHPASS_OUTSLOT_OUTPUT, (data>=limit)?data:newValue);
}
}