Index: apps/action.c =================================================================== --- apps/action.c (Revision 18478) +++ apps/action.c (Arbeitskopie) @@ -38,6 +38,7 @@ static intptr_t last_data = 0; static int last_action = ACTION_NONE; static bool repeated = false; +static int current_context = CONTEXT_STD; #ifdef HAVE_TOUCHSCREEN static bool short_press = false; @@ -90,6 +91,34 @@ CONTEXT_STD : items[i].action_code; } + +static bool backlight_on_action(int action) +{ + /* no backlight on volume change and pause/play */ + return (action != ACTION_WPS_VOLUP) + && (action != ACTION_WPS_VOLDOWN) + && (action != ACTION_WPS_PLAY); +} + +static bool backlight_on_keypress_oracle(int btn) +{ + /* TODO: check whether the button would fire an action */ + /* If yes, check whether that action should turn on the backlight */ + + const struct button_mapping *items = NULL; + int i = 0; + + if (current_context == CONTEXT_WPS) + { + items = get_context_mapping(current_context); + /* also check action for button release */ + return backlight_on_action(do_button_check(items, btn, BUTTON_NONE, &i)) + && backlight_on_action(do_button_check(items, btn | BUTTON_REL, btn, &i)); + } + else + return true; +} + /* * int get_action_worker(int context, struct button_mapping *user_mappings, int timeout) @@ -115,6 +144,9 @@ int ret = ACTION_UNKNOWN; static int last_context = CONTEXT_STD; + set_backlight_on_keypress_oracle(backlight_on_keypress_oracle); + current_context = context; + if (timeout == TIMEOUT_NOBLOCK) button = button_get(false); else if (timeout == TIMEOUT_BLOCK) Index: apps/action.h =================================================================== --- apps/action.h (Revision 18478) +++ apps/action.h (Arbeitskopie) @@ -237,6 +237,7 @@ int action_code; int button_code; int pre_button_code; + bool turn_on_backlight; }; /* use if you want to supply your own button mappings, PLUGINS ONLY */ /* get_context_map is a function which returns a button_mapping* depedning on the given context */ Index: firmware/export/button.h =================================================================== --- firmware/export/button.h (Revision 18478) +++ firmware/export/button.h (Arbeitskopie) @@ -43,6 +43,23 @@ #endif #ifdef HAVE_BACKLIGHT void set_backlight_filter_keypress(bool value); + +/* Callback function to tell whether the backlight should be turned on + * when a key is pressed. Called just after a key press. + * + * @param btn The button that was pressed + * + * Returns true iff the backlight should be turned on on key press. + */ +typedef bool (*backlight_on_keypress_oracle_func)(int btn); + +/* Sets the new 'oracle' to tell whether the backlight should be turned + * on when a key is pressed. Passing NULL as parameter will turn on the BL + * on every key press. + */ +void set_backlight_on_keypress_oracle(backlight_on_keypress_oracle_func func); +void backlight_on_by_button(int btn); + #ifdef HAVE_REMOTE_LCD void set_remote_backlight_filter_keypress(bool value); #endif Index: firmware/target/arm/sandisk/sansa-e200/button-e200.c =================================================================== --- firmware/target/arm/sandisk/sansa-e200/button-e200.c (Revision 18478) +++ firmware/target/arm/sandisk/sansa-e200/button-e200.c (Arbeitskopie) @@ -188,19 +188,18 @@ wheel_delta = 1; } - if (TIME_AFTER(current_tick, next_backlight_on) || - v <= 4) - { - /* poke backlight to turn it on or maintain it no more often - than every 1/4 second*/ - next_backlight_on = current_tick + HZ/4; - backlight_on(); - buttonlight_on(); - reset_poweroff_timer(); - } - if (btn != BUTTON_NONE) { + if (TIME_AFTER(current_tick, next_backlight_on) || + v <= 4) + { + /* poke backlight to turn it on or maintain it no more often + than every 1/4 second*/ + next_backlight_on = current_tick + HZ/4; + backlight_on_by_button(btn); + reset_poweroff_timer(); + } + wheel_click_count = 0; /* generate repeats if quick enough */ Index: firmware/drivers/button.c =================================================================== --- firmware/drivers/button.c (Revision 18478) +++ firmware/drivers/button.c (Arbeitskopie) @@ -34,6 +34,7 @@ #include "power.h" #include "powermgmt.h" #include "button-target.h" +#include "debug.h" #ifdef HAVE_REMOTE_LCD #include "lcd-remote.h" @@ -58,6 +59,7 @@ #endif #ifdef HAVE_BACKLIGHT static bool filter_first_keypress; +static backlight_on_keypress_oracle_func backlight_on_keypress_oracle = NULL; #ifdef HAVE_REMOTE_LCD static bool remote_filter_first_keypress; #endif @@ -95,6 +97,29 @@ } #endif +void backlight_on_by_button(int btn) +{ + bool bl_on; + if (backlight_on_keypress_oracle != NULL) + { + bl_on = (*backlight_on_keypress_oracle)(btn); + DEBUGF("BL oracle (%d) returned: %d\n", btn, bl_on); + } + else + { + bl_on = true; + DEBUGF("BL callback is NULL -> bl ON\n"); + } + if (bl_on) + { + backlight_on(); +#ifdef HAVE_BUTTON_LIGHT + buttonlight_on(); +#endif + } + +} + static void button_tick(void) { static int count = 0; @@ -260,10 +285,13 @@ skip_remote_release = true; } else -#endif - if (!filter_first_keypress || is_backlight_on(false) +#endif /* HAVE_REMOTE_LCD */ + if (!filter_first_keypress + || is_backlight_on(false) + || ((backlight_on_keypress_oracle != NULL) + && !(*backlight_on_keypress_oracle)(btn)) #if BUTTON_REMOTE - || (btn & BUTTON_REMOTE) + || (btn & BUTTON_REMOTE) #endif ) queue_post(&button_queue, btn, data); @@ -279,12 +307,7 @@ remote_backlight_on(); else #endif - { - backlight_on(); -#ifdef HAVE_BUTTON_LIGHT - buttonlight_on(); -#endif - } + backlight_on_by_button(btn); reset_poweroff_timer(); } @@ -403,6 +426,7 @@ #endif #ifdef HAVE_BACKLIGHT filter_first_keypress = false; + set_backlight_on_keypress_oracle(NULL); #ifdef HAVE_REMOTE_LCD remote_filter_first_keypress = false; #endif @@ -497,6 +521,11 @@ { filter_first_keypress = value; } +void set_backlight_on_keypress_oracle(backlight_on_keypress_oracle_func new_value) +{ + backlight_on_keypress_oracle = new_value; +} + #ifdef HAVE_REMOTE_LCD void set_remote_backlight_filter_keypress(bool value) { Index: uisimulator/sdl/button.c =================================================================== --- uisimulator/sdl/button.c (Revision 18478) +++ uisimulator/sdl/button.c (Arbeitskopie) @@ -73,6 +73,13 @@ { filter_first_keypress = value; } +static backlight_on_keypress_oracle_func backlight_on_keypress_oracle = NULL; +void set_backlight_on_keypress_oracle(backlight_on_keypress_oracle_func new_value) +{ + backlight_on_keypress_oracle = new_value; +} + + #ifdef HAVE_REMOTE_LCD static bool remote_filter_first_keypress; @@ -1044,7 +1051,10 @@ else #endif if (!filter_first_keypress - || is_backlight_on(false)) + || is_backlight_on(false) + || ((backlight_on_keypress_oracle != NULL) + && !(*backlight_on_keypress_oracle)(btn)) + ) queue_post(&button_queue, btn, data); else skip_release = true; @@ -1059,7 +1069,23 @@ remote_backlight_on(); else #endif - backlight_on(); + { + bool bl_on; + if (backlight_on_keypress_oracle != NULL) + { + bl_on = (*backlight_on_keypress_oracle)(btn); + DEBUGF("BL oracle (%d) returned: %d\n", btn, bl_on); + } + else + { + DEBUGF("BL callback is NULL -> bl ON\n"); + bl_on = true; + } + if (bl_on) + { + backlight_on(); + } + } } }