From 649d4025aa6076589e63a89836444f2216cd5d9b Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 14 Nov 2019 17:41:24 +0100 Subject: [PATCH] mesh: add timer to transition --- src/mesh/mesh_access.h | 1 + src/mesh/mesh_generic_on_off_server.c | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/mesh/mesh_access.h b/src/mesh/mesh_access.h index dfb6bd63c..90716a7c6 100644 --- a/src/mesh/mesh_access.h +++ b/src/mesh/mesh_access.h @@ -128,6 +128,7 @@ typedef enum { typedef struct mesh_transition { btstack_linked_item_t item; + btstack_timer_source_t timer; mesh_transition_state_t state; diff --git a/src/mesh/mesh_generic_on_off_server.c b/src/mesh/mesh_generic_on_off_server.c index 1f0c56442..6f3593f8c 100644 --- a/src/mesh/mesh_generic_on_off_server.c +++ b/src/mesh/mesh_generic_on_off_server.c @@ -159,24 +159,27 @@ static void mesh_server_transition_setup_transition_or_instantaneous_update(mesh mesh_generic_on_off_state_t * generic_on_off_server_state = (mesh_generic_on_off_state_t *)mesh_model->model_data; mesh_transition_t * transition = &generic_on_off_server_state->transition_data.base_transition; - if (transition_time_gdtt != 0 || delay_time_gdtt != 0) { - mesh_access_transitions_setup(transition, (mesh_model_t *) mesh_model, - transition_time_gdtt, delay_time_gdtt, &mesh_server_transition_step_bool); - mesh_access_transitions_add(transition); - } else { + // instanteneous update + if ((transition_time_gdtt == 0) && (delay_time_gdtt == 0)){ generic_on_off_server_state->transition_data.current_value = generic_on_off_server_state->transition_data.target_value; transition->phase_start_ms = 0; transition->remaining_delay_time_ms = 0; transition->remaining_transition_time_ms = 0; transition->state = MESH_TRANSITION_STATE_IDLE; - mesh_access_emit_state_update_bool(mesh_model->model_packet_handler, - mesh_access_get_element_index(mesh_model), - mesh_model->model_identifier, - MODEL_STATE_ID_GENERIC_ON_OFF, - reason, + mesh_access_emit_state_update_bool(mesh_model->model_packet_handler, + mesh_access_get_element_index(mesh_model), + mesh_model->model_identifier, + MODEL_STATE_ID_GENERIC_ON_OFF, + reason, generic_on_off_server_state->transition_data.current_value); + return; } + + // transaction + mesh_access_transitions_setup(transition, (mesh_model_t *) mesh_model, + transition_time_gdtt, delay_time_gdtt, &mesh_server_transition_step_bool); + mesh_access_transitions_add(transition); }