summaryrefslogtreecommitdiff
path: root/firmware/backlight.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/backlight.c')
-rw-r--r--firmware/backlight.c73
1 files changed, 44 insertions, 29 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index d695d1ee19..d7e2fb1a81 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -109,6 +109,45 @@ static int backlight_on_button_hold = 0;
109static int button_backlight_timer; 109static int button_backlight_timer;
110static int button_backlight_timeout = 5*HZ; 110static int button_backlight_timeout = 5*HZ;
111 111
112/* internal interface */
113static void _button_backlight_on(void)
114{
115#ifndef SIMULATOR
116#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
117 __button_backlight_dim(false);
118#else
119 __button_backlight_on();
120#endif
121#endif
122}
123
124void _button_backlight_off(void)
125{
126#ifndef SIMULATOR
127#ifdef HAVE_BUTTONLIGHT_BRIGHTNESS
128 if(button_backlight_timeout>0)
129 __button_backlight_dim(true);
130 else
131#endif
132 __button_backlight_off();
133#endif
134}
135
136/* Update state of buttonlight according to timeout setting */
137static void buttonlight_update_state(void)
138{
139 button_backlight_timer = button_backlight_timeout;
140
141 /* Buttonlight == OFF in the setting? */
142 if (button_backlight_timer < 0)
143 {
144 button_backlight_timer = 0; /* Disable the timeout */
145 _button_backlight_off();
146 }
147 else
148 _button_backlight_on();
149}
150
112/* external interface */ 151/* external interface */
113void button_backlight_on(void) 152void button_backlight_on(void)
114{ 153{
@@ -127,33 +166,7 @@ void button_backlight_set_timeout(int index)
127 /* if given a weird value, use default */ 166 /* if given a weird value, use default */
128 index = 6; 167 index = 6;
129 button_backlight_timeout = HZ * backlight_timeout_value[index]; 168 button_backlight_timeout = HZ * backlight_timeout_value[index];
130 if (index == 0) /* off */ 169 buttonlight_update_state();
131 button_backlight_off();
132 else if (index == 1) /* on */
133 button_backlight_on();
134
135 button_backlight_timer = button_backlight_timeout;
136}
137
138/* internal interface */
139static void _button_backlight_on(void)
140{
141 if (button_backlight_timeout < 0)
142 return;
143 button_backlight_timer = button_backlight_timeout;
144#ifndef SIMULATOR
145 __button_backlight_on();
146#endif
147}
148
149static void _button_backlight_off(void)
150{
151 if (button_backlight_timeout == 0)
152 return;
153 button_backlight_timer = 0;
154#ifndef SIMULATOR
155 __button_backlight_off();
156#endif
157} 170}
158 171
159#endif 172#endif
@@ -511,9 +524,10 @@ void backlight_thread(void)
511#endif 524#endif
512#ifdef HAVE_BUTTON_LIGHT 525#ifdef HAVE_BUTTON_LIGHT
513 case BUTTON_LIGHT_ON: 526 case BUTTON_LIGHT_ON:
514 _button_backlight_on(); 527 buttonlight_update_state();
515 break; 528 break;
516 case BUTTON_LIGHT_OFF: 529 case BUTTON_LIGHT_OFF:
530 button_backlight_timer = 0;
517 _button_backlight_off(); 531 _button_backlight_off();
518 break; 532 break;
519#endif 533#endif
@@ -796,7 +810,6 @@ void remote_backlight_hold_changed(bool rc_hold_button)
796 remote_backlight_off(); /* setting == Off */ 810 remote_backlight_off(); /* setting == Off */
797 else /* setting == On, Normal, no hold button, or anything else */ 811 else /* setting == On, Normal, no hold button, or anything else */
798 remote_backlight_on(); 812 remote_backlight_on();
799
800} 813}
801 814
802void remote_backlight_set_on_button_hold(int index) 815void remote_backlight_set_on_button_hold(int index)
@@ -863,6 +876,8 @@ void buttonlight_set_brightness(int val)
863 val = MAX_BRIGHTNESS_SETTING; 876 val = MAX_BRIGHTNESS_SETTING;
864 877
865 __buttonlight_set_brightness(val); 878 __buttonlight_set_brightness(val);
879 if(button_backlight_timeout<0)
880 _button_backlight_off();
866} 881}
867#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */ 882#endif /* HAVE_BUTTONLIGHT_BRIGHTNESS */
868 883