@@ -35,9 +35,9 @@ static void led_events_handler(void* handler_args, esp_event_base_t base, int32_
3535
3636static void led_render_task ();
3737
38- void led_temporary_state_entry ();
39- void led_temporary_state_run ();
40- void led_temporary_state_exit ();
38+ static void led_temporary_state_entry ();
39+ static void led_temporary_state_run ();
40+ static void led_temporary_state_exit ();
4141
4242static void normal_state_entry ();
4343static void normal_state_run ();
@@ -57,6 +57,8 @@ static void dimming_state_exit();
5757#define LED_MAX_DUTY ((1 << LEDC_TIMER_12_BIT) - 1)
5858#define LED_DUTY_RES LEDC_TIMER_10_BIT
5959
60+ #define TEMPORARY_FADE_PERIOD_MS 5000
61+
6062static inline led_duty_t channel_brightness_to_duty (led_brightness_t power );
6163static inline void color_to_duties (const led_color_t color , led_duty_t * duties );
6264static int led_set_channel_duty (uint8_t ch , led_duty_t duty );
@@ -836,3 +838,64 @@ static void preview_state_exit()
836838 led_update_color (_led .color_to_resume );
837839 ESP_LOGI (TAG , "Preview state ended." );
838840}
841+
842+ int led_set_temporary_duration (uint32_t duration )
843+ {
844+ _led .settings .temporary_duration = duration ;
845+ BO_TRY (led_save_user_settings ());
846+ return 0 ;
847+ }
848+
849+ int32_t led_get_temporary_remaining ()
850+ {
851+ if (led_get_state () == LED_STATE_TEMPORARY ) {
852+ int64_t now = (esp_timer_get_time () + 500LL ) / 1000LL ;
853+ return (int32_t )((_led .temporary_off_time - now + 500LL ) / 1000LL );
854+ }
855+ else {
856+ return -1 ;
857+ }
858+ }
859+
860+ void led_temporary_state_entry ()
861+ {
862+ if (!bo_power_is_on ()) {
863+ return ;
864+ }
865+
866+ if (_led .settings .mode != LED_MODE_SUN && _led .settings .mode != LED_MODE_SCHEDULED ) {
867+ return ;
868+ }
869+
870+ int64_t now = (esp_timer_get_time () + 500LL ) / 1000LL ;
871+
872+ _led .temporary_off_time = now + (_led .settings .temporary_duration * 60 * 1000 ) + TEMPORARY_FADE_PERIOD_MS ;
873+
874+ BO_MUST (led_fade_to_color (_led .settings .manual_color , TEMPORARY_FADE_PERIOD_MS ));
875+ }
876+
877+ void led_temporary_state_exit ()
878+ {
879+ assert (led_get_state () == LED_STATE_TEMPORARY );
880+
881+ _led .temporary_off_time = 0 ;
882+ }
883+
884+ void led_temporary_state_run ()
885+ {
886+ assert (led_get_state () == LED_STATE_TEMPORARY );
887+
888+ int64_t now = (esp_timer_get_time () + 500LL ) / 1000LL ;
889+
890+ if (now >= _led .temporary_off_time ) {
891+ smf_set_state (SMF_CTX (& _led ), & LED_STATE_TABLE [LED_STATE_NORMAL ]);
892+ }
893+ else {
894+ if (!led_is_fading ()) {
895+ led_update_color (_led .settings .manual_color );
896+ }
897+ else {
898+ led_fade_drive ();
899+ }
900+ }
901+ }
0 commit comments