120 lines
4.1 KiB
C
120 lines
4.1 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_zeroposnegstring.h"
|
|
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* defines
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#define AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_INSLOT_VALUE 0
|
|
|
|
#define AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT 0
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQHREACT_UNIT *AqHomeReact_UnitZeroPosNegString_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, "zeroPosNegString");
|
|
AQHREACT_Unit_SetDescription(unit, "Translate double value into strings for zero, positive, negative values");
|
|
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
|
|
|
|
outputSlot=AQHREACT_OutputSlot_new();
|
|
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
|
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT);
|
|
AQHREACT_OutputSlot_SetEmittedDataType(outputSlot, AQHREACT_DATAOBJECTTYPE_STRING);
|
|
AQHREACT_Unit_AddOutputSlot(unit, outputSlot);
|
|
|
|
inputSlot=AQHREACT_InputSlot_new();
|
|
AQHREACT_InputSlot_SetName(inputSlot, "input");
|
|
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_INSLOT_VALUE);
|
|
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
|
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
|
|
|
param=AQHREACT_Param_new();
|
|
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_NEG);
|
|
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_STRING);
|
|
AQHREACT_Unit_AddParam(unit, param);
|
|
|
|
param=AQHREACT_Param_new();
|
|
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_POS);
|
|
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_STRING);
|
|
AQHREACT_Unit_AddParam(unit, param);
|
|
|
|
param=AQHREACT_Param_new();
|
|
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_ZERO);
|
|
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_STRING);
|
|
AQHREACT_Unit_AddParam(unit, param);
|
|
|
|
return unit;
|
|
}
|
|
|
|
|
|
|
|
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
|
|
{
|
|
if (unit && dataObject) {
|
|
const char *result=NULL;
|
|
const AQHREACT_INPUT_SLOT *inputSlot;
|
|
|
|
inputSlot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, slotIdForUnit);
|
|
if (inputSlot) {
|
|
AQHREACT_DATAOBJECT *dataObject;
|
|
|
|
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
|
|
if (dataObject) {
|
|
double data;
|
|
|
|
data=AQHREACT_DataObject_GetDoubleData(dataObject);
|
|
if (data>0.0)
|
|
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_POS, NULL);
|
|
else if (data<0.0)
|
|
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_NEG, NULL);
|
|
else
|
|
result=AQHREACT_Unit_GetParamValueString(unit, AQHOMEREACT_UNIT_VALUESET_PARAM_VALUE_ZERO, NULL);
|
|
}
|
|
}
|
|
|
|
if (result && *result)
|
|
AQHREACT_Unit_OutputStringData(unit, AQHOMEREACT_UNIT_ZEROPOSNEGSTRING_OUTSLOT_RESULT, result);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|