diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 69900c5e6a..a2592eb26b 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -10741,3 +10741,20 @@ *: "Context Menu" + + id: LANG_BUTTONLIGHT_TIMEOUT + desc: in settings_menu + user: + + *: "" + e200: "Wheel Light Timeout" + + + *: "" + e200: "Wheel Light Timeout" + + + *: "" + e200: "Wheel Light Timeout" + + diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index bc253ed398..528587dffb 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c @@ -319,6 +319,10 @@ MENUITEM_SETTING(car_adapter_mode, &global_settings.car_adapter_mode, NULL); #endif MENUITEM_SETTING(start_screen, &global_settings.start_in_screen, NULL); +#ifdef HAVE_BUTTON_LIGHT +MENUITEM_SETTING(button_light_timeout, &global_settings.button_light_timeout, NULL); +#endif + MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), 0, Icon_System_menu, &start_screen, @@ -344,6 +348,9 @@ MAKE_MENU(system_menu, ID2P(LANG_SYSTEM), #endif #if CONFIG_CHARGING &car_adapter_mode, +#endif +#ifdef HAVE_BUTTON_LIGHT + &button_light_timeout, #endif ); diff --git a/apps/settings.c b/apps/settings.c index f3ce2d41c1..537ca9f5b6 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -709,6 +709,9 @@ void settings_apply(void) backlight_set_fade_out(global_settings.backlight_fade_out); #endif #endif +#ifdef HAVE_BUTTON_LIGHT + button_backlight_set_timeout(global_settings.button_light_timeout); +#endif #ifdef HAVE_BACKLIGHT_BRIGHTNESS backlight_set_brightness(global_settings.brightness); #endif diff --git a/apps/settings.h b/apps/settings.h index 0a82051498..13291be3df 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -717,6 +717,9 @@ struct user_settings unsigned char remote_icon_file[MAX_FILENAME+1]; unsigned char remote_viewers_icon_file[MAX_FILENAME+1]; #endif +#ifdef HAVE_BUTTON_LIGHT + int button_light_timeout; +#endif }; /** global variables **/ diff --git a/apps/settings_list.c b/apps/settings_list.c index ce45074f36..49ec5b5f32 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -1175,6 +1175,13 @@ const struct settings_list settings[] = { "remote viewers iconset", "", ICON_DIR "/", ".bmp", MAX_FILENAME+1), #endif /* HAVE_REMOTE_LCD */ +#ifdef HAVE_BUTTON_LIGHT + INT_SETTING_W_CFGVALS(F_FLIPLIST, button_light_timeout, + LANG_BUTTONLIGHT_TIMEOUT, 6, + "button light timeout", backlight_times_conf, UNIT_SEC, + 0, 18, 1, backlight_formatter, backlight_getlang, + button_backlight_set_timeout), +#endif }; const int nb_settings = sizeof(settings)/sizeof(*settings); diff --git a/firmware/backlight.c b/firmware/backlight.c index 54737da647..2bdfe86c77 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -75,6 +75,10 @@ const signed char backlight_timeout_value[19] = #ifdef HAVE_LCD_SLEEP #define LCD_SLEEP 6 #endif +#ifdef HAVE_BUTTON_LIGHT +#define BUTTON_LIGHT_ON 7 +#define BUTTON_LIGHT_OFF 8 +#endif static void backlight_thread(void); static long backlight_stack[DEFAULT_STACK_SIZE/sizeof(long)]; @@ -93,6 +97,60 @@ static int backlight_timeout_plugged = 5*HZ; static int backlight_on_button_hold = 0; #endif +#ifdef HAVE_BUTTON_LIGHT +static int button_backlight_timer; +static int button_backlight_timeout = 5*HZ; + +/* external interface */ +void button_backlight_on(void) +{ + queue_remove_from_head(&backlight_queue, BUTTON_LIGHT_ON); + queue_post(&backlight_queue, BUTTON_LIGHT_ON, 0); +} + +void button_backlight_off(void) +{ + queue_post(&backlight_queue, BUTTON_LIGHT_OFF, 0); +} + +void button_backlight_set_timeout(int index) +{ + if((unsigned)index >= sizeof(backlight_timeout_value)) + /* if given a weird value, use default */ + index = 6; + button_backlight_timeout = HZ * backlight_timeout_value[index]; + if (index == 0) /* off */ + button_backlight_off(); + else if (index == 1) /* on */ + button_backlight_on(); + + if (button_backlight_timer) + button_backlight_timer = button_backlight_timeout; +} + +/* internal interface */ +static void _button_backlight_on(void) +{ + if (button_backlight_timeout < 0) + return; + button_backlight_timer = button_backlight_timeout; +#ifndef SIMULATOR + __button_backlight_on(); +#endif +} + +static void _button_backlight_off(void) +{ + if (button_backlight_timeout == 0) + return; + button_backlight_timer = 0; +#ifndef SIMULATOR + __button_backlight_off(); +#endif +} + +#endif + #ifdef HAVE_REMOTE_LCD static int remote_backlight_timer; static int remote_backlight_timeout = 5*HZ; @@ -444,6 +502,14 @@ void backlight_thread(void) lcd_sleep(); break; #endif +#ifdef HAVE_BUTTON_LIGHT + case BUTTON_LIGHT_ON: + _button_backlight_on(); + break; + case BUTTON_LIGHT_OFF: + _button_backlight_off(); + break; +#endif #ifdef X5_BACKLIGHT_SHUTDOWN case BACKLIGHT_QUIT: @@ -521,6 +587,16 @@ static void backlight_tick(void) } } #endif /* HAVE_REMOVE_LCD */ +#ifdef HAVE_BUTTON_LIGHT + if (button_backlight_timer) + { + button_backlight_timer--; + if (button_backlight_timer == 0) + { + button_backlight_off(); + } + } +#endif /* HAVE_BUTTON_LIGHT */ } void backlight_init(void) @@ -542,6 +618,9 @@ void backlight_init(void) #ifdef HAVE_REMOTE_LCD remote_backlight_on(); #endif +#ifdef HAVE_BUTTON_LIGHT + button_backlight_on(); +#endif create_thread(backlight_thread, backlight_stack, sizeof(backlight_stack), backlight_thread_name diff --git a/firmware/export/backlight.h b/firmware/export/backlight.h index 4b164c63d2..9bcb6e9d1d 100644 --- a/firmware/export/backlight.h +++ b/firmware/export/backlight.h @@ -80,4 +80,10 @@ void sim_remote_backlight(int value); void backlight_set_brightness(int val); #endif /* HAVE_BACKLIGHT_BRIGHTNESS */ +#ifdef HAVE_BUTTON_LIGHT +void button_backlight_on(void); +void button_backlight_off(void); +void button_backlight_set_timeout(int index); +#endif + #endif /* BACKLIGHT_H */ diff --git a/firmware/export/config-e200.h b/firmware/export/config-e200.h index ccff38dbf2..87d7e78fbb 100644 --- a/firmware/export/config-e200.h +++ b/firmware/export/config-e200.h @@ -22,6 +22,9 @@ #define MAX_BRIGHTNESS_SETTING 12 #define DEFAULT_BRIGHTNESS_SETTING 6 +/* define this if you have a light associated with the buttons */ +#define HAVE_BUTTON_LIGHT + /* define this if you have access to the quickscreen */ #define HAVE_QUICKSCREEN diff --git a/firmware/target/arm/sandisk/sansa-e200/backlight-e200.c b/firmware/target/arm/sandisk/sansa-e200/backlight-e200.c index 787f14b1a6..0ec19b4df1 100644 --- a/firmware/target/arm/sandisk/sansa-e200/backlight-e200.c +++ b/firmware/target/arm/sandisk/sansa-e200/backlight-e200.c @@ -39,3 +39,14 @@ void __backlight_off(void) { pp_i2c_send( 0x46, 0x23, 0x0); } + + +void __button_backlight_on(void) +{ + GPIOG_OUTPUT_VAL |=0x80; +} + +void __button_backlight_off(void) +{ + GPIOG_OUTPUT_VAL &=~ 0x80; +} diff --git a/firmware/target/arm/sandisk/sansa-e200/backlight-target.h b/firmware/target/arm/sandisk/sansa-e200/backlight-target.h index 16a02a4d11..2227278985 100644 --- a/firmware/target/arm/sandisk/sansa-e200/backlight-target.h +++ b/firmware/target/arm/sandisk/sansa-e200/backlight-target.h @@ -24,4 +24,6 @@ void __backlight_on(void); void __backlight_off(void); void __backlight_set_brightness(int brightness); +void __button_backlight_on(void); +void __button_backlight_off(void); #endif diff --git a/firmware/target/arm/sandisk/sansa-e200/button-e200.c b/firmware/target/arm/sandisk/sansa-e200/button-e200.c index fe0b1eaf18..bbe37bcd9a 100644 --- a/firmware/target/arm/sandisk/sansa-e200/button-e200.c +++ b/firmware/target/arm/sandisk/sansa-e200/button-e200.c @@ -31,18 +31,6 @@ static unsigned int old_wheel_value = 0; static unsigned int wheel_repeat = BUTTON_NONE; -/* Wheel backlight control */ -#define WHEEL_BACKLIGHT_TIMEOUT 5*HZ; -static unsigned int wheel_backlight_timer; - -void wheel_backlight_on(bool enable) -{ - if(enable) - GPIOG_OUTPUT_VAL |=0x80; - else - GPIOG_OUTPUT_VAL &=~ 0x80; -} - void button_init_device(void) { /* Enable all buttons */ @@ -52,7 +40,6 @@ void button_init_device(void) /* Scrollwheel light - enable control through GPIOG pin 7 and set timeout */ GPIOG_ENABLE = 0x80; GPIOG_OUTPUT_EN |= 0x80; - wheel_backlight_timer = WHEEL_BACKLIGHT_TIMEOUT; /* Read initial wheel value (bit 6-7 of GPIOH) */ old_wheel_value = GPIOH_INPUT_VAL & 0xc0; @@ -153,23 +140,13 @@ int button_read_device(void) old_wheel_value = new_wheel_value; } - if(wheel_backlight_timer>0){ - wheel_backlight_timer--; - if(wheel_backlight_timer==0){ - wheel_backlight_on(false); - } - } - if( (btn & BUTTON_SCROLL_UP) || (btn & BUTTON_SCROLL_DOWN) ){ /* only trigger once per click */ if ((new_wheel_value == 0x00) || (new_wheel_value == 0xc0)) { btn = btn&(~(BUTTON_SCROLL_UP|BUTTON_SCROLL_DOWN)); } - if(wheel_backlight_timer==0){ - wheel_backlight_on(true); - } - wheel_backlight_timer = WHEEL_BACKLIGHT_TIMEOUT; + button_backlight_on(); } return btn;