More work on aqhome-react.

- added some units
- added some types
This commit is contained in:
Martin Preuss
2024-03-10 20:15:21 +01:00
parent 656c9cf66f
commit d3a6256c8c
35 changed files with 1159 additions and 80 deletions

View File

@@ -38,15 +38,25 @@
<headers dist="true" >
u_or.h
u_passthrough.h
u_varchanges.h
u_valuefilter.h
u_timer.h
u_hold.h
u_lowpass.h
u_highpass.h
</headers>
<sources>
$(local/typefiles)
u_or.c
u_passthrough.c
u_varchanges.c
u_valuefilter.c
u_timer.c
u_hold.c
u_lowpass.c
u_highpass.c
</sources>
<useTargets>

View File

@@ -0,0 +1,4 @@
This folder contains units.
Please add code to function AqHomeReact_CreateUnitByName() in ../aqhome_react.c for new unit types.

View File

@@ -0,0 +1,98 @@
/****************************************************************************
* 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(void)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
AQHREACT_PARAM *param;
unit=AQHREACT_Unit_new();
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);
}
}

View File

@@ -0,0 +1,27 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQHOMEREACT_U_HIGHPASS_H
#define AQHOMEREACT_U_HIGHPASS_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#define AQHOMEREACT_UNIT_HIGHPASS_PARAM_LIMIT "threshold"
#define AQHOMEREACT_UNIT_HIGHPASS_PARAM_NEWVALUE "newValue"
AQHREACT_UNIT *AqHomeReact_UnitHighPass_new(void);
#endif

View File

@@ -0,0 +1,185 @@
/****************************************************************************
* 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_hold.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_HOLD_INSLOT_INPUT 0
#define AQHOMEREACT_UNIT_HOLD_INSLOT_TIMER 1
#define AQHOMEREACT_UNIT_HOLD_OUTSLOT_OUTPUT 0
/* ------------------------------------------------------------------------------------------------
* type declarations
* ------------------------------------------------------------------------------------------------
*/
typedef struct AQHREACT_UNIT_HOLD AQHREACT_UNIT_HOLD;
struct AQHREACT_UNIT_HOLD {
uint64_t tsHoldUntil;
int lastProcessedState;
int currentOutState;
};
GWEN_INHERIT(AQHREACT_UNIT, AQHREACT_UNIT_HOLD)
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void GWENHYWFAR_CB _freeData(void *bp, void *p);
static int _cbProcessFn(AQHREACT_UNIT *unit);
static int _checkState(AQHREACT_UNIT *unit);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitHold_new(void)
{
AQHREACT_UNIT_HOLD *xunit;
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
unit=AQHREACT_Unit_new();
GWEN_NEW_OBJECT(AQHREACT_UNIT_HOLD, xunit);
GWEN_INHERIT_SETDATA(AQHREACT_UNIT, AQHREACT_UNIT_HOLD, unit, xunit, _freeData);
AQHREACT_Unit_SetName(unit, "hold");
AQHREACT_Unit_SetDescription(unit, "Hold incoming signal for a given time");
AQHREACT_Unit_SetProcessFn(unit, _cbProcessFn);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_HOLD_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_HOLD_INSLOT_INPUT);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
inputSlot=AQHREACT_InputSlot_new();
AQHREACT_InputSlot_SetName(inputSlot, "timer");
AQHREACT_InputSlot_SetIdForUnit(inputSlot, AQHOMEREACT_UNIT_HOLD_INSLOT_TIMER);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
return unit;
}
void _freeData(void *bp, void *p)
{
AQHREACT_UNIT_HOLD *xunit;
xunit=(AQHREACT_UNIT_HOLD*) p;
GWEN_FREE_OBJECT(xunit);
}
int _cbProcessFn(AQHREACT_UNIT *unit)
{
if (unit && AQHREACT_Unit_InputHasChanged(unit)) {
int rv;
rv=_checkState(unit);
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
return rv;
}
return 0;
}
int _checkState(AQHREACT_UNIT *unit)
{
AQHREACT_UNIT_HOLD *xunit;
int result=0;
xunit=GWEN_INHERIT_GETDATA(AQHREACT_UNIT, AQHREACT_UNIT_HOLD, unit);
if (xunit) {
AQHREACT_INPUT_SLOT *dataSlot;
dataSlot=AQHREACT_Unit_GetInputSlotByIdForUnit(unit, AQHOMEREACT_UNIT_HOLD_INSLOT_INPUT);
if (dataSlot) {
AQHREACT_DATAOBJECT *dataObject;
dataObject=AQHREACT_InputSlot_GetCurrentDataObject(dataSlot);
if (dataObject) {
double data;
data=AQHREACT_DataObject_GetDoubleData(dataObject);
if (data>0.0) {
if (xunit->lastProcessedState==0) { /* was off, is on, turn output ON */
DBG_INFO(NULL, "Turning output ON");
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_HOLD_OUTSLOT_OUTPUT, 1.0);
xunit->currentOutState=1;
result=1;
}
xunit->lastProcessedState=1;
} /* if new value is ON */
else {
uint64_t now;
now=(uint64_t) time(NULL);
if (xunit->lastProcessedState) { /* was 1, is now 0, start hold timer */
int holdTime;
DBG_INFO(NULL, "Starting timeout counter");
holdTime=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_HOLD_PARAM_HOLDTIME, 30.0);
xunit->tsHoldUntil=now+holdTime;
result=1;
}
else { /* was 0, is 0, check timeout */
if (xunit->currentOutState>0) { /* output is still ON, check hold time */
if (now>xunit->tsHoldUntil) {
/* timeout, turn output OFF */
DBG_INFO(NULL, "Turning output OFF");
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_HOLD_OUTSLOT_OUTPUT, 0.0);
xunit->currentOutState=0;
xunit->tsHoldUntil=0;
result=1;
}
}
}
xunit->lastProcessedState=0;
}
}
}
}
return result;
}

View File

@@ -0,0 +1,25 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQHOMEREACT_U_HOLD_H
#define AQHOMEREACT_U_HOLD_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#define AQHOMEREACT_UNIT_HOLD_PARAM_HOLDTIME "holdTime"
AQHREACT_UNIT *AqHomeReact_UnitHold_new(void);
#endif

View File

@@ -0,0 +1,98 @@
/****************************************************************************
* 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_lowpass.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_LOWPASS_INSLOT_INPUT 0
#define AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitLowPass_new(void)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
AQHREACT_PARAM *param;
unit=AQHREACT_Unit_new();
AQHREACT_Unit_SetName(unit, "lowpass");
AQHREACT_Unit_SetDescription(unit, "Lowpass filter for data");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_LOWPASS_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_LOWPASS_INSLOT_INPUT);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
param=AQHREACT_Param_new();
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT);
AQHREACT_Param_SetDataType(param, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddParam(unit, param);
param=AQHREACT_Param_new();
AQHREACT_Param_SetName(param, AQHOMEREACT_UNIT_LOWPASS_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_LOWPASS_INSLOT_INPUT) {
double data;
double limit;
double newValue;
data=AQHREACT_DataObject_GetDoubleData(dataObject);
limit=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT, data);
newValue=AQHREACT_Unit_GetParamValueDouble(unit, AQHOMEREACT_UNIT_LOWPASS_PARAM_NEWVALUE, data);
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_LOWPASS_OUTSLOT_OUTPUT, (data<=limit)?data:newValue);
}
}

View File

@@ -0,0 +1,27 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQHOMEREACT_U_LOWPASS_H
#define AQHOMEREACT_U_LOWPASS_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#define AQHOMEREACT_UNIT_LOWPASS_PARAM_LIMIT "threshold"
#define AQHOMEREACT_UNIT_LOWPASS_PARAM_NEWVALUE "newValue"
AQHREACT_UNIT *AqHomeReact_UnitLowPass_new(void);
#endif

View File

@@ -86,6 +86,7 @@ int _cbProcessFn(AQHREACT_UNIT *unit)
result=_sampleInputSlots(inputSlotList);
AQHREACT_Unit_ClearChangeFlagsInUnitAndInputSlots(unit);
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_OR_OUTSLOT_RESULT, result?1.0:0.0);
return 1;
}
}

View File

@@ -0,0 +1,77 @@
/****************************************************************************
* 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_passthrough.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitPassthrough_new(void)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
unit=AQHREACT_Unit_new();
AQHREACT_Unit_SetName(unit, "passthrough");
AQHREACT_Unit_SetDescription(unit, "Generic passthrough unit");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_PASSTHROUGH_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_PASSTHROUGH_OUTSLOT_OUTPUT);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
return unit;
}
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
{
if (unit && dataObject && slotIdForUnit==AQHOMEREACT_UNIT_PASSTHROUGH_INSLOT_INPUT)
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, dataObject);
}

View File

@@ -0,0 +1,28 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQHOMEREACT_U_PASSTHROUGH_H
#define AQHOMEREACT_U_PASSTHROUGH_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#define AQHOMEREACT_UNIT_PASSTHROUGH_INSLOT_INPUT 0
#define AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT 0
AQHREACT_UNIT *AqHomeReact_UnitPassthrough_new(void);
#endif

View File

@@ -0,0 +1,42 @@
/****************************************************************************
* 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_timer.h"
#include "./u_passthrough.h"
#include <gwenhywfar/debug.h>
AQHREACT_UNIT *AqHomeReact_UnitTimer_new(void)
{
AQHREACT_UNIT *unit;
unit=AqHomeReact_UnitPassthrough_new();
AQHREACT_Unit_SetName(unit, "timer");
AQHREACT_Unit_SetDescription(unit, "Periodically generate a timer signal");
return unit;
}
void AqHomeReact_UnitTimer_GenerateTick(AQHREACT_UNIT *unit)
{
AQHREACT_Unit_OutputDoubleData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, 1.0);
}

View File

@@ -0,0 +1,24 @@
/****************************************************************************
* 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.
****************************************************************************/
#ifndef AQHOMEREACT_U_TIMER_H
#define AQHOMEREACT_U_TIMER_H
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
AQHREACT_UNIT *AqHomeReact_UnitTimer_new(void);
void AqHomeReact_UnitTimer_GenerateTick(AQHREACT_UNIT *unit);
#endif

View File

@@ -11,71 +11,42 @@
#endif
#include "./u_varchanges.h"
#include "./u_passthrough.h"
#include <gwenhywfar/debug.h>
/* ------------------------------------------------------------------------------------------------
* defines
* ------------------------------------------------------------------------------------------------
*/
#define AQHOMEREACT_UNIT_VARCHANGES_INSLOT_CHANGE 0
#define AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_RESULT 0
/* ------------------------------------------------------------------------------------------------
* forward declarations
* ------------------------------------------------------------------------------------------------
*/
static void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject);
/* ------------------------------------------------------------------------------------------------
* implementations
* ------------------------------------------------------------------------------------------------
*/
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh)
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(void)
{
AQHREACT_UNIT *unit;
AQHREACT_OUTPUT_SLOT *outputSlot;
AQHREACT_INPUT_SLOT *inputSlot;
unit=AQHREACT_Unit_new();
unit=AqHomeReact_UnitPassthrough_new();
AQHREACT_Unit_SetName(unit, "varchanges");
AQHREACT_Unit_SetDescription(unit, "Propagates changes of values on the data server");
AQHREACT_Unit_SetInputDataFn(unit, _cbInputData);
outputSlot=AQHREACT_OutputSlot_new();
AQHREACT_OutputSlot_SetName(outputSlot, "output");
AQHREACT_OutputSlot_SetIdForUnit(outputSlot, AQHOMEREACT_UNIT_VARCHANGES_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_VARCHANGES_INSLOT_CHANGE);
AQHREACT_InputSlot_SetAcceptedDataType(inputSlot, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_Unit_AddInputSlot(unit, inputSlot);
return unit;
}
void _cbInputData(AQHREACT_UNIT *unit, int slotIdForUnit, const AQHREACT_DATAOBJECT *dataObject)
void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALUE *value, uint64_t timestamp, double data)
{
if (unit && dataObject && slotIdForUnit==0)
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_VARCHANGES_OUTSLOT_RESULT, dataObject);
AQHREACT_DATAOBJECT *dataObject;
DBG_INFO(NULL, "Value \"%s\" changed", AQH_Value_GetNameForSystem(value));
dataObject=AQHREACT_DataObject_new();
AQHREACT_DataObject_SetDataType(dataObject, AQHREACT_DATAOBJECTTYPE_DOUBLE);
AQHREACT_DataObject_SetTimestamp(dataObject, timestamp);
AQHREACT_DataObject_SetDoubleData(dataObject, data);
AQHREACT_DataObject_SetSystemValueId(dataObject, AQH_Value_GetNameForSystem(value));
AQHREACT_DataObject_SetValueId(dataObject, AQH_Value_GetId(value));
AQHREACT_Unit_OutputData(unit, AQHOMEREACT_UNIT_PASSTHROUGH_OUTSLOT_OUTPUT, dataObject);
AQHREACT_DataObject_free(dataObject);
}

View File

@@ -13,9 +13,12 @@
#include "aqhome-react/aqhome_react.h"
#include "aqhome-react/types/unit.h"
#include "aqhome/data/value.h"
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(AQHOME_REACT *aqh);
AQHREACT_UNIT *AqHomeReact_UnitVarChanges_new(void);
void AqHomeReact_UnitVarChanges_ValueUpdated(AQHREACT_UNIT *unit, const AQH_VALUE *value, uint64_t timestamp, double data);
#endif