Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Setting Value of Group-Object with Sending Changed Converted Value Only #258

Closed
27 changes: 27 additions & 0 deletions src/knx/group_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,30 @@ void GroupObject::valueNoSend(const KNXValue& value, const Dpt& type)

KNX_Encode_Value(value, _data, _dataLength, type);
}

bool GroupObject::valueModifiedSend(const KNXValue& value, const Dpt& type, const bool forceSend /*= false*/)
{
if (_commFlag == Uninitialized)
cornelius-koepp marked this conversation as resolved.
Show resolved Hide resolved
{
// always send first value
this->value(value, type);
return true;
}
else
{
// convert new value to given dtp
uint8_t newData[_dataLength];
KNX_Encode_Value(value, newData, _dataLength, type);

// check for change in converted value / update value on change only
const bool dataChanged = memcmp(_data, newData, _dataLength);
if (dataChanged)
memcpy(_data, newData, _dataLength);

// trigger sending
if (dataChanged || forceSend)
cornelius-koepp marked this conversation as resolved.
Show resolved Hide resolved
objectWritten();

return dataChanged;
}
}
13 changes: 13 additions & 0 deletions src/knx/group_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@ class GroupObject
* The parameters must fit the group object. Otherwise it will stay unchanged.
*/
void valueNoSend(const KNXValue& value, const Dpt& type);

/**
* set the current value of the group object and only when resulting value differes, changes the state of the group object to ::WriteRequest.
* @param value the value the group object is set to
* @param type the datapoint type used for the conversion.
* @param forceSend (optional) trigger sending independend of value change. Use e.g. for repeated sending.
*
* The parameters must fit the group object. Otherwise it will stay unchanged.
*
* @returns true if the value of the group object has changed (and send was triggered)
*/
bool valueModifiedSend(const KNXValue& value, const Dpt& type, const bool forceSend = false);

/**
* set the current value of the group object.
* @param value the value the group object is set to
Expand Down