samples: mesh: nrf52: removed unnecessary global vaiable

Removed unnecessary global variable & replaced them with different
variable defined in struct light_ctl_state.

Signed-off-by: Vikrant More <vikrant8051@gmail.com>
This commit is contained in:
Vikrant More 2019-11-12 23:13:43 +05:30 committed by Johan Hedberg
commit 235f5654d1
4 changed files with 70 additions and 85 deletions

View file

@ -133,7 +133,7 @@ void update_light_state(void)
{
update_led_gpio();
if (*ptr_counter == 0 || reset == false) {
if (ctl->transition->counter == 0 || reset == false) {
reset = true;
k_work_submit(&no_transition_work);
}

View file

@ -185,8 +185,8 @@ static void gen_onoff_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -254,8 +254,8 @@ static void gen_onoff_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -387,8 +387,8 @@ static void gen_level_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -453,8 +453,8 @@ static void gen_level_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -529,8 +529,8 @@ static void gen_delta_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -611,8 +611,8 @@ static void gen_delta_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -685,8 +685,8 @@ static void gen_move_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -760,8 +760,8 @@ static void gen_move_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1147,8 +1147,8 @@ static void light_lightness_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1220,8 +1220,8 @@ static void light_lightness_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1347,8 +1347,8 @@ static void light_lightness_linear_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1413,8 +1413,8 @@ static void light_lightness_linear_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1776,8 +1776,8 @@ static void light_ctl_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -1862,8 +1862,8 @@ static void light_ctl_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2251,8 +2251,8 @@ static void light_ctl_temp_set_unack(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2333,8 +2333,8 @@ static void light_ctl_temp_set(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2462,8 +2462,8 @@ static void gen_level_set_unack_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2528,8 +2528,8 @@ static void gen_level_set_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2604,8 +2604,8 @@ static void gen_delta_set_unack_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2686,8 +2686,8 @@ static void gen_delta_set_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2760,8 +2760,8 @@ static void gen_move_set_unack_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;
@ -2836,8 +2836,8 @@ static void gen_move_set_temp(struct bt_mesh_model *model,
return;
}
*ptr_counter = 0U;
k_timer_stop(ptr_timer);
state->transition->counter = 0U;
k_timer_stop(&state->transition->timer);
state->last_tid = tid;
state->last_src_addr = ctx->addr;

View file

@ -14,8 +14,6 @@
#include "transition.h"
u8_t default_tt;
u32_t *ptr_counter;
struct k_timer *ptr_timer = &dummy_timer;
struct transition transition;
@ -97,7 +95,6 @@ static bool set_transition_counter(struct transition *transition)
transition->counter = DEVICE_SPECIFIC_RESOLUTION;
}
ptr_counter = &transition->counter;
return true;
}
@ -176,7 +173,7 @@ static void onoff_work_handler(struct k_work *work)
ctl->light->current = ctl->light->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -214,7 +211,7 @@ static void level_lightness_work_handler(struct k_work *work)
ctl->light->current = ctl->light->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -252,7 +249,7 @@ static void level_temp_work_handler(struct k_work *work)
ctl->temp->current = ctl->temp->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -275,7 +272,7 @@ static void light_lightness_actual_work_handler(struct k_work *work)
ctl->light->current = ctl->light->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -298,7 +295,7 @@ static void light_lightness_linear_work_handler(struct k_work *work)
ctl->light->current = ctl->light->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -328,7 +325,7 @@ static void light_ctl_work_handler(struct k_work *work)
ctl->duv->current = ctl->duv->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -355,7 +352,7 @@ static void light_ctl_temp_work_handler(struct k_work *work)
ctl->duv->current = ctl->duv->target;
update_light_state();
k_timer_stop(ptr_timer);
k_timer_stop(&ctl->transition->timer);
}
}
@ -413,11 +410,9 @@ void onoff_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer, onoff_tt_handler, NULL);
k_timer_init(ptr_timer, onoff_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -429,11 +424,10 @@ void level_lightness_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer,
level_lightness_tt_handler, NULL);
k_timer_init(ptr_timer, level_lightness_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -445,11 +439,9 @@ void level_temp_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer, level_temp_tt_handler, NULL);
k_timer_init(ptr_timer, level_temp_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -461,11 +453,10 @@ void light_lightness_actual_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer,
light_lightness_actual_tt_handler, NULL);
k_timer_init(ptr_timer, light_lightness_actual_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -477,11 +468,10 @@ void light_lightness_linear_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer,
light_lightness_linear_tt_handler, NULL);
k_timer_init(ptr_timer, light_lightness_linear_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -493,11 +483,9 @@ void light_ctl_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer, light_ctl_tt_handler, NULL);
k_timer_init(ptr_timer, light_ctl_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}
@ -509,11 +497,10 @@ void light_ctl_temp_handler(struct light_ctl_state *state)
return;
}
ptr_timer = &state->transition->timer;
k_timer_init(&state->transition->timer,
light_ctl_temp_tt_handler, NULL);
k_timer_init(ptr_timer, light_ctl_temp_tt_handler, NULL);
k_timer_start(ptr_timer,
k_timer_start(&state->transition->timer,
K_MSEC(state->transition->delay * 5U),
K_MSEC(state->transition->quo_tt));
}

View file

@ -33,8 +33,6 @@ struct transition {
};
extern u8_t default_tt;
extern u32_t *ptr_counter;
extern struct k_timer *ptr_timer;
extern struct transition transition;