From a330699a0e72e9ee92c586e10528799f38f25e13 Mon Sep 17 00:00:00 2001 From: Michael Geramb Date: Wed, 17 Apr 2024 19:21:27 +0200 Subject: [PATCH] Add function to group object to send a value only if it was changed. --- src/knx/group_object.cpp | 10 ++++++++++ src/knx/group_object.h | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 0abbfc0..5a9ad28 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -310,4 +310,14 @@ bool GroupObject::valueNoSendCompare(const KNXValue& value, const Dpt& type) return dataChanged; } +} + +bool GroupObject::valueCompare(const KNXValue& value, const Dpt& type) +{ + if (valueNoSendCompare(value, type)) + { + objectWritten(); + return true; + } + return false; } \ No newline at end of file diff --git a/src/knx/group_object.h b/src/knx/group_object.h index 38b8291..02bd0c3 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -173,6 +173,19 @@ class GroupObject * The parameters must fit the group object. Otherwise it will stay unchanged. */ void value(const KNXValue& value, const Dpt& type); + + /** + * Check if the value (after conversion to dpt) will differ from current value of the group object and changes the state of the group object to ::WriteRequest if different. + * Use this method only, when the value should not be sent if it was not changed, otherwise value(const KNXValue&, const Dpt&) will do the same (without overhead for comparing) + * @param value the value the group object is set to + * @param type the datapoint type used for the conversion. + * + * The parameters must fit the group object. Otherwise it will stay unchanged. + * + * @returns true if the value of the group object has changed + */ + bool valueCompare(const KNXValue& value, const Dpt& type); + /** * set the current value of the group object. * @param value the value the group object is set to