summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2009-04-25 21:11:16 +0000
committerThomas Martitz <kugel@rockbox.org>2009-04-25 21:11:16 +0000
commit5b316afcfdb874bb4aebfd85449247e33fcd9614 (patch)
tree65d05d349fbd13362eae6dd7d8fae9ac5df02488
parentc0662583217a65edbfdf9b768a71785ac364bd48 (diff)
downloadrockbox-5b316afcfdb874bb4aebfd85449247e33fcd9614.tar.gz
rockbox-5b316afcfdb874bb4aebfd85449247e33fcd9614.zip
Restructure backlight timeout management a bit by factoring out the get_current_timeout code. No functional change.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20789 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/backlight.c86
-rw-r--r--firmware/export/backlight.h1
2 files changed, 44 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;
131int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING; 131int backlight_brightness = DEFAULT_BRIGHTNESS_SETTING;
132#endif 132#endif
133static int backlight_timer SHAREDBSS_ATTR; 133static int backlight_timer SHAREDBSS_ATTR;
134static int backlight_timeout SHAREDBSS_ATTR;
135static int backlight_timeout_normal = 5*HZ; 134static int backlight_timeout_normal = 5*HZ;
136#if CONFIG_CHARGING 135#if CONFIG_CHARGING
137static int backlight_timeout_plugged = 5*HZ; 136static 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
188static int remote_backlight_timer; 187static int remote_backlight_timer;
189static int remote_backlight_timeout;
190static int remote_backlight_timeout_normal = 5*HZ; 188static int remote_backlight_timeout_normal = 5*HZ;
191#if CONFIG_CHARGING 189#if CONFIG_CHARGING
192static int remote_backlight_timeout_plugged = 5*HZ; 190static 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 */
491static void backlight_update_state(void) 489static 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 */
539static void remote_backlight_update_state(void) 521static 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. */
799bool is_backlight_on(bool ignore_always_off) 769bool 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 */
807int backlight_get_current_timeout(void) 778int 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
812void backlight_set_timeout(int value) 800void 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 */
913int remote_backlight_get_current_timeout(void) 901int 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 */
920bool is_remote_backlight_on(bool ignore_always_off) 919bool 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 */
diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h
index 1df262fbf2..a281b9ede0 100644
--- a/firmware/export/backlight.h
+++ b/firmware/export/backlight.h
@@ -73,6 +73,7 @@ void remote_backlight_off(void);
73void remote_backlight_set_timeout(int value); 73void remote_backlight_set_timeout(int value);
74void remote_backlight_set_timeout_plugged(int value); 74void remote_backlight_set_timeout_plugged(int value);
75bool is_remote_backlight_on(bool ignore_always_off); 75bool is_remote_backlight_on(bool ignore_always_off);
76int remote_backlight_get_current_timeout(void);
76 77
77#ifdef HAS_REMOTE_BUTTON_HOLD 78#ifdef HAS_REMOTE_BUTTON_HOLD
78void remote_backlight_hold_changed(bool rc_hold_button); 79void remote_backlight_hold_changed(bool rc_hold_button);