@@ -57,9 +57,9 @@ static inline void color_to_duties(const led_color_t color, led_duty_t* duties);
5757static int led_set_channel_duty (uint8_t ch , led_duty_t duty );
5858static int led_set_duties (const led_duty_t * duties );
5959static int led_fade_to_color (const led_color_t color , uint32_t milssecs );
60- static bool led_fade_inprogress ();
60+ static bool led_is_fading ();
6161static int led_fade_stop ();
62- static int led_fade_powering_on ();
62+ static int led_fade_to_normal ();
6363static void led_fade_drive ();
6464
6565static int led_mode_manual_entry ();
@@ -198,7 +198,7 @@ int led_init()
198198 }
199199
200200 if (bo_power_is_on ()) {
201- BO_TRY (led_fade_powering_on ());
201+ BO_TRY (led_fade_to_normal ());
202202 }
203203
204204 xTaskCreate (& led_proc , "led_task" , 2 * 1024 , NULL , tskIDLE_PRIORITY + 2 , NULL );
@@ -354,7 +354,7 @@ int led_fade_to_color(const led_color_t color, uint32_t duration_ms)
354354 return 0 ;
355355}
356356
357- int led_fade_powering_on ()
357+ int led_fade_to_normal ()
358358{
359359 led_color_t end_color ;
360360
@@ -396,7 +396,7 @@ int led_fade_stop()
396396
397397void led_fade_drive ()
398398{
399- if (!led_fade_inprogress ()) {
399+ if (!led_is_fading ()) {
400400 return ;
401401 }
402402
@@ -418,7 +418,7 @@ void led_fade_drive()
418418 BO_MUST (led_update_color (color ));
419419}
420420
421- inline static bool led_fade_inprogress () { return _led .fade_start_time_ms > 0LL ; }
421+ inline static bool led_is_fading () { return _led .fade_start_time_ms > 0LL ; }
422422
423423int led_set_channel_brightness (uint8_t ch , led_brightness_t brightness )
424424{
@@ -497,23 +497,26 @@ static void system_events_handler(void* handler_args, esp_event_base_t base, int
497497 switch (event_id ) {
498498 case BO_EVENT_SHUTDOWN_FAULT :
499499 case BO_EVENT_FATAL_ERROR : {
500- if (led_fade_inprogress ()) {
500+ if (led_is_fading ()) {
501501 BO_MUST (led_fade_stop ());
502502 }
503- BO_MUST (led_switch_state (LED_STATE_POWERING_OFF ));
504503 led_blank ();
504+ BO_MUST (led_switch_state (LED_STATE_NORMAL ));
505505 } break ;
506506
507507 case BO_EVENT_SHUTDOWN_SCHEDULED : {
508- BO_MUST (led_switch_state (LED_STATE_POWERING_OFF ));
508+ BO_MUST (led_switch_state (LED_STATE_NORMAL ));
509509 } break ;
510510
511511 case BO_EVENT_POWER_ON : {
512- BO_MUST (led_switch_state (LED_STATE_POWERING_ON ));
512+ BO_MUST (led_switch_state (LED_STATE_NORMAL ));
513513 } break ;
514514
515515 case BO_EVENT_GEO_LOCATION_CHANGED : {
516- led_sun_update_scheduler ();
516+ int rc = led_sun_update_scheduler ();
517+ if (rc ) {
518+ ESP_LOGE (TAG , "Failed to update solar scheduler" );
519+ }
517520 } break ;
518521
519522 default :
@@ -641,7 +644,7 @@ static int normal_state_entry()
641644
642645static void normal_state_drive ()
643646{
644- if (led_fade_inprogress ()) {
647+ if (led_is_fading ()) {
645648 led_fade_drive ();
646649 return ;
647650 }
@@ -743,7 +746,7 @@ int temporary_state_entry(uint8_t prev_state)
743746 return - EINVAL ;
744747 }
745748
746- if (prev_state != LED_STATE_NORMAL && prev_state != LED_STATE_POWERING_ON ) {
749+ if (prev_state != LED_STATE_NORMAL ) {
747750 return - EINVAL ;
748751 }
749752
@@ -767,7 +770,7 @@ static int temporary_state_exit()
767770 }
768771
769772 _led .temporary_off_time = 0 ;
770- BO_TRY (led_switch_state (LED_STATE_POWERING_ON ));
773+ BO_TRY (led_switch_state (LED_STATE_NORMAL ));
771774 return 0 ;
772775}
773776
@@ -783,7 +786,7 @@ static void temporary_state_drive()
783786 BO_MUST (temporary_state_exit ());
784787 }
785788 else {
786- if (!led_fade_inprogress ()) {
789+ if (!led_is_fading ()) {
787790 led_update_color (_led .settings .manual_color );
788791 }
789792 else {
@@ -794,6 +797,11 @@ static void temporary_state_drive()
794797
795798static void led_drive ()
796799{
800+ if (led_is_fading ()) {
801+ led_fade_drive ();
802+ return ;
803+ }
804+
797805 switch (_led .state ) {
798806
799807 case LED_STATE_NORMAL : {
@@ -811,24 +819,26 @@ static void led_drive()
811819 preview_state_drive ();
812820 } break ;
813821
814- case LED_STATE_POWERING_OFF : {
815- if (led_fade_inprogress ()) {
816- led_fade_drive ();
817- }
818- else {
819- led_blank ();
820- _led .state = LED_STATE_NORMAL ;
821- }
822- } break ;
822+ /*
823+ case LED_STATE_POWERING_OFF: {
824+ if (led_is_fading()) {
825+ led_fade_drive();
826+ }
827+ else {
828+ led_blank();
829+ _led.state = LED_STATE_NORMAL;
830+ }
831+ } break;
823832
824- case LED_STATE_POWERING_ON : {
825- if (led_fade_inprogress ()) {
826- led_fade_drive ();
827- }
828- else {
829- led_switch_state (LED_STATE_NORMAL );
830- }
831- } break ;
833+ case LED_STATE_POWERING_ON: {
834+ if (led_is_fading()) {
835+ led_fade_drive();
836+ }
837+ else {
838+ led_switch_state(LED_STATE_NORMAL);
839+ }
840+ } break;
841+ */
832842
833843 default :
834844 assert (false);
@@ -859,7 +869,7 @@ int led_switch_state(uint8_t state)
859869 return - EINVAL ;
860870 }
861871
862- if (led_fade_inprogress ()) {
872+ if (led_is_fading ()) {
863873 BO_TRY (led_fade_stop ());
864874 }
865875
@@ -875,10 +885,6 @@ int led_switch_state(uint8_t state)
875885 preview_state_exit ();
876886 } break ;
877887
878- case LED_STATE_POWERING_ON :
879- case LED_STATE_POWERING_OFF : {
880- } break ;
881-
882888 default :
883889 return -1 ;
884890 }
@@ -894,8 +900,7 @@ int led_switch_state(uint8_t state)
894900 return - EINVAL ;
895901 }
896902 // TODO Start the timer
897- if (_led .state == LED_STATE_NORMAL || _led .state == LED_STATE_PREVIEW || _led .state == LED_STATE_POWERING_ON
898- || _led .state == LED_STATE_TEMPORARY ) {
903+ if (_led .state == LED_STATE_NORMAL || _led .state == LED_STATE_PREVIEW || _led .state == LED_STATE_TEMPORARY ) {
899904 _led .state = state ;
900905 }
901906 else {
@@ -917,16 +922,6 @@ int led_switch_state(uint8_t state)
917922 BO_TRY (preview_state_entry ());
918923 } break ;
919924
920- case LED_STATE_POWERING_ON : {
921- _led .state = state ;
922- BO_TRY (led_fade_powering_on ());
923- } break ;
924-
925- case LED_STATE_POWERING_OFF : {
926- _led .state = state ;
927- BO_TRY (led_fade_to_color (LED_COLOR_BLANK , FADE_OFF_PERIOD_MS ));
928- } break ;
929-
930925 default :
931926 return -1 ;
932927 }
0 commit comments