138 lines
4.0 KiB
C
138 lines
4.0 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_or.h"
|
|
|
|
#include <gwenhywfar/debug.h>
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* defines
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
#define AQHOMEREACT_UNIT_OR_INSLOT_INPUT 0
|
|
#define AQHOMEREACT_UNIT_OR_INSLOT_AUTOINPUT 100
|
|
|
|
#define AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT 0
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* forward declarations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
static int _cbProcessFn(AQHREACT_UNIT *unit);
|
|
static int _sampleInputSlots(const AQHREACT_INPUT_SLOT_LIST *inputSlotList);
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------------------------
|
|
* implementations
|
|
* ------------------------------------------------------------------------------------------------
|
|
*/
|
|
|
|
AQHREACT_UNIT *AqHomeReact_UnitOr_new(AQHOME_REACT *aqh)
|
|
{
|
|
AQHREACT_UNIT *unit;
|
|
AQHREACT_OUTPUT_SLOT *outputSlot;
|
|
AQHREACT_INPUT_SLOT *inputSlot;
|
|
|
|
unit=AQHREACT_Unit_new(aqh);
|
|
AQHREACT_Unit_SetName(unit, "or");
|
|
AQHREACT_Unit_SetDescription(unit, "Logical OR inputs");
|
|
AQHREACT_Unit_SetProcessFn(unit, _cbProcessFn);
|
|
|
|
AQHREACT_Unit_SetNextInputSlotId(unit, AQHOMEREACT_UNIT_OR_INSLOT_AUTOINPUT); /* for auto-gen multi-slots */
|
|
|
|
outputSlot=AQHREACT_OutputSlot_new();
|
|
AQHREACT_OutputSlot_SetName(outputSlot, "output");
|
|
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT);
|
|
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_OR_INSLOT_INPUT);
|
|
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
|
|
AQHREACT_InputSlot_AddFlags(inputSlot, AQHREACT_UNIT_FLAGS_MULTI);
|
|
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
|
|
|
|
return unit;
|
|
}
|
|
|
|
|
|
|
|
int _cbProcessFn(AQHREACT_UNIT *unit)
|
|
{
|
|
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
|
|
AQHREACT_INPUT_SLOT_LIST *inputSlotList;
|
|
|
|
inputSlotList=AQHREACT_Unit_GetInputSlots(unit);
|
|
if (inputSlotList) {
|
|
int result;
|
|
|
|
result=_sampleInputSlots(inputSlotList);
|
|
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
|
|
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT, result?1.0:0.0);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
|
|
int _sampleInputSlots(const AQHREACT_INPUT_SLOT_LIST *inputSlotList)
|
|
{
|
|
const AQHREACT_INPUT_SLOT *inputSlot;
|
|
int result=0;
|
|
|
|
inputSlot=AQHREACT_InputSlot_List_First(inputSlotList);
|
|
while(inputSlot) {
|
|
const char *slotName;
|
|
const AQHREACT_DATAOBJECT *dataObject;
|
|
|
|
slotName=AQHREACT_InputSlot_GetName(inputSlot);
|
|
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(inputSlot);
|
|
if (dataObject) {
|
|
if (AQHREACT_DataObject_GetDataType(dataObject)==AQHREACT_DATAOBJECTTYPE_DOUBLE) {
|
|
double d;
|
|
|
|
d=AQHREACT_DataObject_GetDoubleData(dataObject);
|
|
if (d>0.0)
|
|
result|=1;
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Data at input slot \"%s\" isn't DOUBLE, ignoring", slotName?slotName:"<unnamed>");
|
|
}
|
|
}
|
|
else {
|
|
DBG_ERROR(NULL, "Data at input slot \"%s\" has not current data, ignoring", slotName?slotName:"<unnamed>");
|
|
}
|
|
|
|
inputSlot=AQHREACT_InputSlot_List_Next(inputSlot);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|