diff options
Diffstat (limited to 'firmware/backlight.c')
-rw-r--r-- | firmware/backlight.c | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c index cff76a249c..bf2baeb1c3 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c | |||
@@ -131,7 +131,6 @@ static unsigned int backlight_thread_id = 0; | |||
131 | int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; | 131 | int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; |
132 | #endif | 132 | #endif |
133 | static int backlight_timer SHAREDBSS_ATTR; | 133 | static int backlight_timer SHAREDBSS_ATTR; |
134 | static int backlight_timeout SHAREDBSS_ATTR; | ||
135 | static int backlight_timeout_normal = 5*HZ; | 134 | static int backlight_timeout_normal = 5*HZ; |
136 | #if CONFIG_CHARGING | 135 | #if CONFIG_CHARGING |
137 | static int backlight_timeout_plugged = 5*HZ; | 136 | static int backlight_timeout_plugged = 5*HZ; |
@@ -186,7 +185,6 @@ int buttonlight_get_current_timeout(void) | |||
186 | 185 | ||
187 | #ifdef HAVE_REMOTE_LCD | 186 | #ifdef HAVE_REMOTE_LCD |
188 | static int remote_backlight_timer; | 187 | static int remote_backlight_timer; |
189 | static int remote_backlight_timeout; | ||
190 | static int remote_backlight_timeout_normal = 5*HZ; | 188 | static int remote_backlight_timeout_normal = 5*HZ; |
191 | #if CONFIG_CHARGING | 189 | #if CONFIG_CHARGING |
192 | static int remote_backlight_timeout_plugged = 5*HZ; | 190 | static int remote_backlight_timeout_plugged = 5*HZ; |
@@ -490,27 +488,11 @@ static void backlight_setup_fade_down(void) | |||
490 | /* Update state of backlight according to timeout setting */ | 488 | /* Update state of backlight according to timeout setting */ |
491 | static void backlight_update_state(void) | 489 | static void backlight_update_state(void) |
492 | { | 490 | { |
493 | #ifdef HAS_BUTTON_HOLD | 491 | |
494 | if ((backlight_on_button_hold != 0) | 492 | int timeout = backlight_get_current_timeout(); |
495 | #ifdef HAVE_REMOTE_LCD_AS_MAIN | ||
496 | && remote_button_hold() | ||
497 | #else | ||
498 | && button_hold() | ||
499 | #endif | ||
500 | ) | ||
501 | backlight_timeout = (backlight_on_button_hold == 2) ? 0 : -1; | ||
502 | /* always on or always off */ | ||
503 | else | ||
504 | #endif | ||
505 | #if CONFIG_CHARGING | ||
506 | if (power_input_present()) | ||
507 | backlight_timeout = backlight_timeout_plugged; | ||
508 | else | ||
509 | #endif | ||
510 | backlight_timeout = backlight_timeout_normal; | ||
511 | 493 | ||
512 | /* Backlight == OFF in the setting? */ | 494 | /* Backlight == OFF in the setting? */ |
513 | if (UNLIKELY(backlight_timeout < 0)) | 495 | if (UNLIKELY(timeout < 0)) |
514 | { | 496 | { |
515 | backlight_timer = 0; /* Disable the timeout */ | 497 | backlight_timer = 0; /* Disable the timeout */ |
516 | #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \ | 498 | #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \ |
@@ -524,7 +506,7 @@ static void backlight_update_state(void) | |||
524 | } | 506 | } |
525 | else | 507 | else |
526 | { | 508 | { |
527 | backlight_timer = backlight_timeout; | 509 | backlight_timer = timeout; |
528 | #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \ | 510 | #if (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_SETTING) \ |
529 | || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG) | 511 | || (CONFIG_BACKLIGHT_FADING == BACKLIGHT_FADING_SW_HW_REG) |
530 | backlight_setup_fade_up(); | 512 | backlight_setup_fade_up(); |
@@ -538,28 +520,16 @@ static void backlight_update_state(void) | |||
538 | /* Update state of remote backlight according to timeout setting */ | 520 | /* Update state of remote backlight according to timeout setting */ |
539 | static void remote_backlight_update_state(void) | 521 | static void remote_backlight_update_state(void) |
540 | { | 522 | { |
541 | #ifdef HAS_REMOTE_BUTTON_HOLD | 523 | int timeout = remote_backlight_get_current_timeout(); |
542 | if (remote_button_hold() && (remote_backlight_on_button_hold != 0)) | ||
543 | remote_backlight_timeout = (remote_backlight_on_button_hold == 2) | ||
544 | ? 0 : -1; /* always on or always off */ | ||
545 | else | ||
546 | #endif | ||
547 | #if CONFIG_CHARGING | ||
548 | if (power_input_present()) | ||
549 | remote_backlight_timeout = remote_backlight_timeout_plugged; | ||
550 | else | ||
551 | #endif | ||
552 | remote_backlight_timeout = remote_backlight_timeout_normal; | ||
553 | |||
554 | /* Backlight == OFF in the setting? */ | 524 | /* Backlight == OFF in the setting? */ |
555 | if (remote_backlight_timeout < 0) | 525 | if (timeout < 0) |
556 | { | 526 | { |
557 | remote_backlight_timer = 0; /* Disable the timeout */ | 527 | remote_backlight_timer = 0; /* Disable the timeout */ |
558 | _remote_backlight_off(); | 528 | _remote_backlight_off(); |
559 | } | 529 | } |
560 | else | 530 | else |
561 | { | 531 | { |
562 | remote_backlight_timer = remote_backlight_timeout; | 532 | remote_backlight_timer = timeout; |
563 | _remote_backlight_on(); | 533 | _remote_backlight_on(); |
564 | } | 534 | } |
565 | } | 535 | } |
@@ -798,15 +768,33 @@ void backlight_off(void) | |||
798 | * and optionally when it's set to always off. */ | 768 | * and optionally when it's set to always off. */ |
799 | bool is_backlight_on(bool ignore_always_off) | 769 | bool is_backlight_on(bool ignore_always_off) |
800 | { | 770 | { |
771 | int timeout = backlight_get_current_timeout(); | ||
801 | return (backlight_timer > 0) /* countdown */ | 772 | return (backlight_timer > 0) /* countdown */ |
802 | || (backlight_timeout == 0) /* always on */ | 773 | || (timeout == 0) /* always on */ |
803 | || ((backlight_timeout < 0) && !ignore_always_off); | 774 | || ((timeout < 0) && !ignore_always_off); |
804 | } | 775 | } |
805 | 776 | ||
806 | /* return value in ticks; 0 means always on, <0 means always off */ | 777 | /* return value in ticks; 0 means always on, <0 means always off */ |
807 | int backlight_get_current_timeout(void) | 778 | int backlight_get_current_timeout(void) |
808 | { | 779 | { |
809 | return backlight_timeout; | 780 | #ifdef HAS_BUTTON_HOLD |
781 | if ((backlight_on_button_hold != 0) | ||
782 | #ifdef HAVE_REMOTE_LCD_AS_MAIN | ||
783 | && remote_button_hold() | ||
784 | #else | ||
785 | && button_hold() | ||
786 | #endif | ||
787 | ) | ||
788 | return (backlight_on_button_hold == 2) ? 0 : -1; | ||
789 | /* always on or always off */ | ||
790 | else | ||
791 | #endif | ||
792 | #if CONFIG_CHARGING | ||
793 | if (power_input_present()) | ||
794 | return backlight_timeout_plugged; | ||
795 | else | ||
796 | #endif | ||
797 | return backlight_timeout_normal; | ||
810 | } | 798 | } |
811 | 799 | ||
812 | void backlight_set_timeout(int value) | 800 | void backlight_set_timeout(int value) |
@@ -912,16 +900,28 @@ void remote_backlight_set_on_button_hold(int index) | |||
912 | /* return value in ticks; 0 means always on, <0 means always off */ | 900 | /* return value in ticks; 0 means always on, <0 means always off */ |
913 | int remote_backlight_get_current_timeout(void) | 901 | int remote_backlight_get_current_timeout(void) |
914 | { | 902 | { |
915 | return remote_backlight_timeout; | 903 | #ifdef HAS_REMOTE_BUTTON_HOLD |
904 | if (remote_button_hold() && (remote_backlight_on_button_hold != 0)) | ||
905 | return (remote_backlight_on_button_hold == 2) | ||
906 | ? 0 : -1; /* always on or always off */ | ||
907 | else | ||
908 | #endif | ||
909 | #if CONFIG_CHARGING | ||
910 | if (power_input_present()) | ||
911 | return remote_backlight_timeout_plugged; | ||
912 | else | ||
913 | #endif | ||
914 | return remote_backlight_timeout_normal; | ||
916 | } | 915 | } |
917 | 916 | ||
918 | /* returns true when the backlight is on, and | 917 | /* returns true when the backlight is on, and |
919 | * optionally when it's set to always off */ | 918 | * optionally when it's set to always off */ |
920 | bool is_remote_backlight_on(bool ignore_always_off) | 919 | bool is_remote_backlight_on(bool ignore_always_off) |
921 | { | 920 | { |
921 | int timeout = remote_backlight_get_current_timeout(); | ||
922 | return (remote_backlight_timer > 0) /* countdown */ | 922 | return (remote_backlight_timer > 0) /* countdown */ |
923 | || (remote_backlight_timeout == 0) /* always on */ | 923 | || (timeout == 0) /* always on */ |
924 | || ((remote_backlight_timeout < 0) && !ignore_always_off); | 924 | || ((timeout < 0) && !ignore_always_off); |
925 | } | 925 | } |
926 | 926 | ||
927 | #endif /* HAVE_REMOTE_LCD */ | 927 | #endif /* HAVE_REMOTE_LCD */ |