diff --git a/README.md b/README.md index cab83a4b..4e5e7c35 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ See the examples for basic usage options - change default PID_MAX_APDU_LENGTH_ROUTER from 220 to 254 - fix broken ConfigReq Responses - fix programming application when FlashTablesInvalid for 0x091A +- add GroupObject::valueCompareTime() to send a GroupObject only when value changed or after some time without sending ### v2.3.1 - 2026-03-04 diff --git a/src/knx/group_object.cpp b/src/knx/group_object.cpp index 7f5247df..fc2ae427 100644 --- a/src/knx/group_object.cpp +++ b/src/knx/group_object.cpp @@ -349,4 +349,21 @@ bool GroupObject::valueCompare(const KNXValue& value, const Dpt& type) return true; } return false; +} + +bool GroupObject::valueCompareTime(const KNXValue& value, const Dpt& type, uint32_t& lastTime, const uint32_t time) +{ + if (valueNoSendCompare(value, type)) + { + objectWritten(); + lastTime = millis(); + return true; + } + else if(millis() - lastTime >= time) + { + objectWritten(); + lastTime = millis(); + 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 e64c86a9..3ffeb857 100644 --- a/src/knx/group_object.h +++ b/src/knx/group_object.h @@ -203,6 +203,21 @@ class GroupObject */ bool valueCompare(const KNXValue& value, const Dpt& type); + + /** + * Check if the value (after conversion to dpt) will differ from current value of the group object and send only when the value differs or the time since last sending exceeds a threshold. + * 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. + * @param lastTime the variable where the last sending time of this KO can be stored, will be passed as reference + * @param time the threshold in milliseconds used to calculate if group object is sent regardless if the value differs + * + * The parameters must fit the group object. Otherwise it will stay unchanged. + * + * @returns true if the value of the group object has been sent, false if not or conversion failed. + */ + bool valueCompareTime(const KNXValue& value, const Dpt& type, uint32_t& lastTime, const uint32_t time); + /** * set the current value of the group object and show success. * @param value the value the group object is set to