diff options
Diffstat (limited to 'firmware/backlight.c')
-rw-r--r-- | firmware/backlight.c | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c index 74cdee1205..edd78ec7ef 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c | |||
@@ -184,14 +184,41 @@ static int remote_backlight_on_button_hold = 0; | |||
184 | #endif /* HAVE_REMOTE_LCD */ | 184 | #endif /* HAVE_REMOTE_LCD */ |
185 | 185 | ||
186 | #ifdef HAVE_LCD_SLEEP | 186 | #ifdef HAVE_LCD_SLEEP |
187 | #ifdef HAVE_LCD_SLEEP_SETTING | ||
187 | const signed char lcd_sleep_timeout_value[10] = | 188 | const signed char lcd_sleep_timeout_value[10] = |
188 | { | 189 | { |
189 | -1, 0, 5, 10, 15, 20, 30, 45, 60, 90 | 190 | -1, 0, 5, 10, 15, 20, 30, 45, 60, 90 |
190 | }; | 191 | }; |
191 | int _lcd_sleep_timer; | 192 | static int lcd_sleep_timeout = 10*HZ; |
192 | int _lcd_sleep_timeout = 10*HZ; | 193 | #else |
194 | /* Target defines needed value */ | ||
195 | static const int lcd_sleep_timeout = LCD_SLEEP_TIMEOUT; | ||
193 | #endif | 196 | #endif |
194 | 197 | ||
198 | static int lcd_sleep_timer = 0; | ||
199 | |||
200 | void backlight_lcd_sleep_countdown(bool start) | ||
201 | { | ||
202 | if (!start) | ||
203 | { | ||
204 | /* Cancel the LCD sleep countdown */ | ||
205 | lcd_sleep_timer = 0; | ||
206 | return; | ||
207 | } | ||
208 | |||
209 | /* Start LCD sleep countdown */ | ||
210 | if (lcd_sleep_timeout < 0) | ||
211 | { | ||
212 | lcd_sleep_timer = 0; /* Setting == Always */ | ||
213 | lcd_sleep(); | ||
214 | } | ||
215 | else | ||
216 | { | ||
217 | lcd_sleep_timer = lcd_sleep_timeout; | ||
218 | } | ||
219 | } | ||
220 | #endif /* HAVE_LCD_SLEEP */ | ||
221 | |||
195 | #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) | 222 | #if defined(HAVE_BACKLIGHT_PWM_FADING) && !defined(SIMULATOR) |
196 | /* backlight fading */ | 223 | /* backlight fading */ |
197 | #define BL_PWM_INTERVAL 5 /* Cycle interval in ms */ | 224 | #define BL_PWM_INTERVAL 5 /* Cycle interval in ms */ |
@@ -328,8 +355,9 @@ static void _backlight_on(void) | |||
328 | bl_dim_fraction = (BL_PWM_COUNT<<16); | 355 | bl_dim_fraction = (BL_PWM_COUNT<<16); |
329 | _backlight_on_normal(); | 356 | _backlight_on_normal(); |
330 | } | 357 | } |
358 | |||
331 | #ifdef HAVE_LCD_SLEEP | 359 | #ifdef HAVE_LCD_SLEEP |
332 | _lcd_sleep_timer = 0; /* LCD should be awake already */ | 360 | backlight_lcd_sleep(false); |
333 | #endif | 361 | #endif |
334 | } | 362 | } |
335 | 363 | ||
@@ -344,15 +372,9 @@ static void _backlight_off(void) | |||
344 | bl_dim_target = bl_dim_fraction = 0; | 372 | bl_dim_target = bl_dim_fraction = 0; |
345 | _backlight_off_normal(); | 373 | _backlight_off_normal(); |
346 | } | 374 | } |
375 | |||
347 | #ifdef HAVE_LCD_SLEEP | 376 | #ifdef HAVE_LCD_SLEEP |
348 | /* Start LCD sleep countdown */ | 377 | backlight_start_lcd_sleep_counter(false); |
349 | if (_lcd_sleep_timeout < 0) | ||
350 | { | ||
351 | _lcd_sleep_timer = 0; /* Setting == Always */ | ||
352 | lcd_sleep(); | ||
353 | } | ||
354 | else | ||
355 | _lcd_sleep_timer = _lcd_sleep_timeout; | ||
356 | #endif | 378 | #endif |
357 | } | 379 | } |
358 | 380 | ||
@@ -580,10 +602,10 @@ static void backlight_tick(void) | |||
580 | } | 602 | } |
581 | } | 603 | } |
582 | #ifdef HAVE_LCD_SLEEP | 604 | #ifdef HAVE_LCD_SLEEP |
583 | else if(_lcd_sleep_timer) | 605 | else if(lcd_sleep_timer) |
584 | { | 606 | { |
585 | _lcd_sleep_timer--; | 607 | lcd_sleep_timer--; |
586 | if(_lcd_sleep_timer == 0) | 608 | if(lcd_sleep_timer == 0) |
587 | { | 609 | { |
588 | /* Queue on bl thread or freeze! */ | 610 | /* Queue on bl thread or freeze! */ |
589 | queue_post(&backlight_queue, LCD_SLEEP, 0); | 611 | queue_post(&backlight_queue, LCD_SLEEP, 0); |
@@ -716,26 +738,26 @@ void backlight_set_on_button_hold(int index) | |||
716 | } | 738 | } |
717 | #endif /* HAS_BUTTON_HOLD */ | 739 | #endif /* HAS_BUTTON_HOLD */ |
718 | 740 | ||
719 | #ifdef HAVE_LCD_SLEEP | 741 | #ifdef HAVE_LCD_SLEEP_SETTING |
720 | void lcd_set_sleep_after_backlight_off(int index) | 742 | void lcd_set_sleep_after_backlight_off(int index) |
721 | { | 743 | { |
722 | if ((unsigned)index >= sizeof(lcd_sleep_timeout_value)) | 744 | if ((unsigned)index >= sizeof(lcd_sleep_timeout_value)) |
723 | /* if given a weird value, use default */ | 745 | /* if given a weird value, use default */ |
724 | index = 3; | 746 | index = 3; |
725 | 747 | ||
726 | _lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index]; | 748 | lcd_sleep_timeout = HZ * lcd_sleep_timeout_value[index]; |
727 | 749 | ||
728 | if (backlight_timer > 0 || backlight_get_current_timeout() == 0) | 750 | if (backlight_timer > 0 || backlight_get_current_timeout() == 0) |
729 | /* Timer will be set when bl turns off or bl set to on. */ | 751 | /* Timer will be set when bl turns off or bl set to on. */ |
730 | return; | 752 | return; |
731 | 753 | ||
732 | /* Backlight is Off */ | 754 | /* Backlight is Off */ |
733 | if (_lcd_sleep_timeout < 0) | 755 | if (lcd_sleep_timeout < 0) |
734 | _lcd_sleep_timer = 1; /* Always - sleep next tick */ | 756 | lcd_sleep_timer = 1; /* Always - sleep next tick */ |
735 | else | 757 | else |
736 | _lcd_sleep_timer = _lcd_sleep_timeout; /* Never, other */ | 758 | lcd_sleep_timer = lcd_sleep_timeout; /* Never, other */ |
737 | } | 759 | } |
738 | #endif /* HAVE_LCD_SLEEP */ | 760 | #endif /* HAVE_LCD_SLEEP_SETTING */ |
739 | 761 | ||
740 | #ifdef HAVE_REMOTE_LCD | 762 | #ifdef HAVE_REMOTE_LCD |
741 | void remote_backlight_on(void) | 763 | void remote_backlight_on(void) |