@@ -151,15 +151,7 @@ static void onoff_work_handler(struct k_work *work)
151151{
152152 if (ctl -> transition -> just_started ) {
153153 ctl -> transition -> just_started = false;
154-
155- if (ctl -> transition -> counter == 0U ) {
156- update_light_state ();
157-
158- k_timer_stop (ptr_timer );
159- } else {
160- ctl -> transition -> start_timestamp = k_uptime_get ();
161- }
162-
154+ ctl -> transition -> start_timestamp = k_uptime_get ();
163155 return ;
164156 }
165157
@@ -198,36 +190,23 @@ static void level_move_lightness_work_handler(void)
198190
199191static void level_lightness_work_handler (struct k_work * work )
200192{
193+ if (ctl -> transition -> just_started ) {
194+ ctl -> transition -> just_started = false;
195+ ctl -> transition -> start_timestamp = k_uptime_get ();
196+ return ;
197+ }
198+
201199 switch (ctl -> transition -> type ) {
202200 case LEVEL_TT :
203201 case LEVEL_TT_DELTA :
204202 break ;
205203 case LEVEL_TT_MOVE :
206- if (ctl -> transition -> just_started ) {
207- ctl -> transition -> just_started = false;
208- return ;
209- }
210-
211204 level_move_lightness_work_handler ();
212205 return ;
213206 default :
214207 return ;
215208 }
216209
217- if (ctl -> transition -> just_started ) {
218- ctl -> transition -> just_started = false;
219-
220- if (ctl -> transition -> counter == 0U ) {
221- update_light_state ();
222-
223- k_timer_stop (ptr_timer );
224- } else {
225- ctl -> transition -> start_timestamp = k_uptime_get ();
226- }
227-
228- return ;
229- }
230-
231210 if (ctl -> transition -> counter != 0U ) {
232211 ctl -> transition -> counter -- ;
233212
@@ -263,35 +242,23 @@ static void level_move_temp_work_handler(void)
263242
264243static void level_temp_work_handler (struct k_work * work )
265244{
245+ if (ctl -> transition -> just_started ) {
246+ ctl -> transition -> just_started = false;
247+ ctl -> transition -> start_timestamp = k_uptime_get ();
248+ return ;
249+ }
250+
266251 switch (ctl -> transition -> type ) {
267252 case LEVEL_TEMP_TT :
268253 case LEVEL_TEMP_TT_DELTA :
269254 break ;
270255 case LEVEL_TEMP_TT_MOVE :
271- if (ctl -> transition -> just_started ) {
272- ctl -> transition -> just_started = false;
273- return ;
274- }
275-
276256 level_move_temp_work_handler ();
277257 return ;
278258 default :
279259 return ;
280260 }
281261
282- if (ctl -> transition -> just_started ) {
283- ctl -> transition -> just_started = false;
284-
285- if (ctl -> transition -> counter == 0U ) {
286- update_light_state ();
287- k_timer_stop (ptr_timer );
288- } else {
289- ctl -> transition -> start_timestamp = k_uptime_get ();
290- }
291-
292- return ;
293- }
294-
295262 if (ctl -> transition -> counter != 0U ) {
296263 ctl -> transition -> counter -- ;
297264
@@ -311,15 +278,7 @@ static void light_lightness_actual_work_handler(struct k_work *work)
311278{
312279 if (ctl -> transition -> just_started ) {
313280 ctl -> transition -> just_started = false;
314-
315- if (ctl -> transition -> counter == 0U ) {
316- update_light_state ();
317-
318- k_timer_stop (ptr_timer );
319- } else {
320- ctl -> transition -> start_timestamp = k_uptime_get ();
321- }
322-
281+ ctl -> transition -> start_timestamp = k_uptime_get ();
323282 return ;
324283 }
325284
@@ -342,15 +301,7 @@ static void light_lightness_linear_work_handler(struct k_work *work)
342301{
343302 if (ctl -> transition -> just_started ) {
344303 ctl -> transition -> just_started = false;
345-
346- if (ctl -> transition -> counter == 0U ) {
347- update_light_state ();
348-
349- k_timer_stop (ptr_timer );
350- } else {
351- ctl -> transition -> start_timestamp = k_uptime_get ();
352- }
353-
304+ ctl -> transition -> start_timestamp = k_uptime_get ();
354305 return ;
355306 }
356307
@@ -373,15 +324,7 @@ static void light_ctl_work_handler(struct k_work *work)
373324{
374325 if (ctl -> transition -> just_started ) {
375326 ctl -> transition -> just_started = false;
376-
377- if (ctl -> transition -> counter == 0U ) {
378- update_light_state ();
379-
380- k_timer_stop (ptr_timer );
381- } else {
382- ctl -> transition -> start_timestamp = k_uptime_get ();
383- }
384-
327+ ctl -> transition -> start_timestamp = k_uptime_get ();
385328 return ;
386329 }
387330
@@ -411,15 +354,7 @@ static void light_ctl_temp_work_handler(struct k_work *work)
411354{
412355 if (ctl -> transition -> just_started ) {
413356 ctl -> transition -> just_started = false;
414-
415- if (ctl -> transition -> counter == 0U ) {
416- update_light_state ();
417-
418- k_timer_stop (ptr_timer );
419- } else {
420- ctl -> transition -> start_timestamp = k_uptime_get ();
421- }
422-
357+ ctl -> transition -> start_timestamp = k_uptime_get ();
423358 return ;
424359 }
425360
@@ -491,6 +426,11 @@ K_TIMER_DEFINE(dummy_timer, NULL, NULL);
491426/* Messages handlers (Start) */
492427void onoff_handler (struct light_ctl_state * state )
493428{
429+ if (state -> transition -> counter == 0U ) {
430+ update_light_state ();
431+ return ;
432+ }
433+
494434 ptr_timer = & state -> transition -> timer ;
495435
496436 k_timer_init (ptr_timer , onoff_tt_handler , NULL );
@@ -502,6 +442,11 @@ void onoff_handler(struct light_ctl_state *state)
502442
503443void level_lightness_handler (struct light_ctl_state * state )
504444{
445+ if (state -> transition -> counter == 0U ) {
446+ update_light_state ();
447+ return ;
448+ }
449+
505450 ptr_timer = & state -> transition -> timer ;
506451
507452 k_timer_init (ptr_timer , level_lightness_tt_handler , NULL );
@@ -513,6 +458,11 @@ void level_lightness_handler(struct light_ctl_state *state)
513458
514459void level_temp_handler (struct light_ctl_state * state )
515460{
461+ if (state -> transition -> counter == 0U ) {
462+ update_light_state ();
463+ return ;
464+ }
465+
516466 ptr_timer = & state -> transition -> timer ;
517467
518468 k_timer_init (ptr_timer , level_temp_tt_handler , NULL );
@@ -524,6 +474,11 @@ void level_temp_handler(struct light_ctl_state *state)
524474
525475void light_lightness_actual_handler (struct light_ctl_state * state )
526476{
477+ if (state -> transition -> counter == 0U ) {
478+ update_light_state ();
479+ return ;
480+ }
481+
527482 ptr_timer = & state -> transition -> timer ;
528483
529484 k_timer_init (ptr_timer , light_lightness_actual_tt_handler , NULL );
@@ -535,6 +490,11 @@ void light_lightness_actual_handler(struct light_ctl_state *state)
535490
536491void light_lightness_linear_handler (struct light_ctl_state * state )
537492{
493+ if (state -> transition -> counter == 0U ) {
494+ update_light_state ();
495+ return ;
496+ }
497+
538498 ptr_timer = & state -> transition -> timer ;
539499
540500 k_timer_init (ptr_timer , light_lightness_linear_tt_handler , NULL );
@@ -546,6 +506,11 @@ void light_lightness_linear_handler(struct light_ctl_state *state)
546506
547507void light_ctl_handler (struct light_ctl_state * state )
548508{
509+ if (state -> transition -> counter == 0U ) {
510+ update_light_state ();
511+ return ;
512+ }
513+
549514 ptr_timer = & state -> transition -> timer ;
550515
551516 k_timer_init (ptr_timer , light_ctl_tt_handler , NULL );
@@ -557,6 +522,11 @@ void light_ctl_handler(struct light_ctl_state *state)
557522
558523void light_ctl_temp_handler (struct light_ctl_state * state )
559524{
525+ if (state -> transition -> counter == 0U ) {
526+ update_light_state ();
527+ return ;
528+ }
529+
560530 ptr_timer = & state -> transition -> timer ;
561531
562532 k_timer_init (ptr_timer , light_ctl_temp_tt_handler , NULL );
0 commit comments