From 7ba5a904e3e0db29208e4a8f4d8eaf48512c135e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Rodr=C3=ADguez=20Royo?= <jdrr1998@hotmail.com> Date: Tue, 11 Oct 2022 18:08:33 +0000 Subject: [PATCH] Feature: Change callback in a command --- components/esp_matter/esp_matter_core.cpp | 11 +++++++++++ components/esp_matter/esp_matter_core.h | 12 ++++++++++++ 2 files changed, 23 insertions(+) diff --git a/components/esp_matter/esp_matter_core.cpp b/components/esp_matter/esp_matter_core.cpp index e15ad8a05..4f3504e3b 100644 --- a/components/esp_matter/esp_matter_core.cpp +++ b/components/esp_matter/esp_matter_core.cpp @@ -1313,6 +1313,17 @@ uint32_t get_id(command_t *command) return current_command->command_id; } +esp_err_t set_callback(command_t *command, callback_t callback) +{ + if (!command) { + ESP_LOGE(TAG, "Command cannot be NULL"); + return ESP_ERR_INVALID_ARG; + } + _command_t *current_command = (_command_t *)command; + current_command->callback = callback; + return ESP_OK; +} + callback_t get_callback(command_t *command) { if (!command) { diff --git a/components/esp_matter/esp_matter_core.h b/components/esp_matter/esp_matter_core.h index 0ba49cde2..d17ec765c 100644 --- a/components/esp_matter/esp_matter_core.h +++ b/components/esp_matter/esp_matter_core.h @@ -679,6 +679,18 @@ command_t *get_next(command_t *command); */ uint32_t get_id(command_t *command); +/** Set command callback + * + * Set the command callback for the command. + * + * @param[in] command Command handle. + * @param[in] callback Command callback. + * + * @return ESP_OK on success. + * @return error in case of failure. + */ +esp_err_t set_callback(command_t *command, callback_t callback); + /** Get command callback * * Get the command callback for the command.