Index: apps/lang/english.lang =================================================================== --- apps/lang/english.lang (revision 30270) +++ apps/lang/english.lang (working copy) @@ -4427,7 +4427,7 @@ id: LANG_SLEEP_TIMER - desc: sleep timer setting + desc: sleep timer menu item user: core *: "Sleep Timer" @@ -4440,6 +4440,62 @@ + id: LANG_SLEEP_TIMER_START + desc: start sleep timer + user: core + + *: "Start Sleep Timer" + + + *: "Start Sleep Timer" + + + *: "Start Sleep Timer" + + + + id: LANG_SLEEP_TIMER_STOP + desc: stop sleep timer + user: core + + *: "Stop Sleep Timer" + + + *: "Stop Sleep Timer" + + + *: "Stop Sleep Timer" + + + + id: LANG_SLEEP_TIMER_DURATION + desc: sleep timer duration in minutes + user: core + + *: "Sleep Timer Duration" + + + *: "Sleep Timer Duration" + + + *: "Sleep Timer Duration" + + + + id: LANG_SLEEP_TIMER_ON_POWER_UP + desc: whether sleep timer starts on power up + user: core + + *: "Start Sleep Timer On Boot" + + + *: "Start Sleep Timer On Boot" + + + *: "Start Sleep Timer On Boot" + + + id: LANG_LIMITS_MENU desc: in the system sub menu user: core Index: apps/settings.h =================================================================== --- apps/settings.h (revision 30270) +++ apps/settings.h (working copy) @@ -786,6 +786,9 @@ int compressor_release_time; #endif + int sleeptimer_duration; + bool sleeptimer_on_startup; + #ifdef HAVE_MORSE_INPUT bool morse_input; /* text input method setting */ #endif Index: apps/menus/exported_menus.h =================================================================== --- apps/menus/exported_menus.h (revision 30270) +++ apps/menus/exported_menus.h (working copy) @@ -44,7 +44,8 @@ audiohw_eq_tone_controls, /* audiohw_eq_menu.c */ #endif radio_settings_menu, /* radio_menu.c */ - theme_menu; /* theme_menu.c */ + theme_menu, /* theme_menu.c */ + sleeptimer_menu; /* sleeptimer_menu.c */ struct browse_folder_info { const char* dir; Index: apps/menus/main_menu.c =================================================================== --- apps/menus/main_menu.c (revision 30270) +++ apps/menus/main_menu.c (working copy) @@ -392,46 +392,49 @@ MENUITEM_FUNCTION(show_info_item, 0, ID2P(LANG_ROCKBOX_INFO), (menu_function)show_info, NULL, NULL, Icon_NOICON); - -/* sleep Menu */ -static const char* sleep_timer_formatter(char* buffer, size_t buffer_size, - int value, const char* unit) +static char* get_current_sleeptimer_status(int selected_item, void * data, char *buffer) { - (void) unit; - int minutes, hours; - - if (value) { - hours = value / 60; - minutes = value - (hours * 60); - snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); - return buffer; - } else { - return str(LANG_OFF); + (void)selected_item; + (void)data; + int remain = get_sleep_timer(); + if (remain) + { + remain += 59; /* round up minutes */ + snprintf(buffer, MAX_PATH, "%s (%d:%02d)", + str(LANG_SLEEP_TIMER_STOP), + remain / 3600, + ( remain % 3600 ) / 60 + ); } + else + { + remain = global_settings.sleeptimer_duration; + snprintf(buffer, MAX_PATH, "%s (%d:%02d)", + str(LANG_SLEEP_TIMER_START), + remain / 60, + remain % 60 + ); + } + return buffer; } -static void sleep_timer_set(int minutes) +static int toggle_sleep_timer(void) { - set_sleep_timer(minutes * 60); + if (get_sleep_timer()) + set_sleep_timer(0); + else + set_sleep_timer(global_settings.sleeptimer_duration * 60); + return 0; } -static int sleep_timer(void) -{ - int minutes = (get_sleep_timer() + 59) / 60; /* round up */ - return (int)set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, - &sleep_timer_set, 5, 0, 300, sleep_timer_formatter); -} - - #if CONFIG_RTC int time_screen(void* ignored); MENUITEM_FUNCTION(timedate_item, MENU_FUNC_CHECK_RETVAL, ID2P(LANG_TIME_MENU), time_screen, NULL, NULL, Icon_Menu_setting ); #endif /* This item is in the time/date screen if there is a RTC */ -MENUITEM_FUNCTION(sleep_timer_call, 0, ID2P(LANG_SLEEP_TIMER), sleep_timer, - NULL, NULL, Icon_Menu_setting); /* make it look like a - setting to the user */ +MENUITEM_FUNCTION_DYNTEXT(sleep_timer_call, 0, toggle_sleep_timer, NULL, + get_current_sleeptimer_status, NULL, NULL, NULL, Icon_NOICON); MENUITEM_FUNCTION(show_credits_item, 0, ID2P(LANG_CREDITS), (menu_function)show_credits, NULL, NULL, Icon_NOICON); Index: apps/menus/settings_menu.c =================================================================== --- apps/menus/settings_menu.c (revision 30270) +++ apps/menus/settings_menu.c (working copy) @@ -332,6 +332,7 @@ &usb_hid, &usb_keypad_mode, #endif + &sleeptimer_menu, ); /* SYSTEM MENU */ Index: apps/menus/sleeptimer_menu.c =================================================================== --- apps/menus/sleeptimer_menu.c (revision 0) +++ apps/menus/sleeptimer_menu.c (revision 0) @@ -0,0 +1,56 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: sleep_timer_menu.c 23867 2009-12-05 11:24:50Z nickp $ + * + * Copyright (C) 2009 Nick Peskett + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include +#include +#include "config.h" +#include "string.h" +#include "lang.h" +#include "settings.h" +#include "menu.h" +#include "keyboard.h" +#include "exported_menus.h" +#include "powermgmt.h" +#include "action.h" + +static int initial_duration; +static int sleeptimer_duration_cb(int action,const struct menu_item_ex *this_item) +{ + (void)this_item; + switch (action) + { + case ACTION_ENTER_MENUITEM: + initial_duration = global_settings.sleeptimer_duration; + break; + case ACTION_EXIT_MENUITEM: + if (initial_duration != global_settings.sleeptimer_duration && get_sleep_timer()) + set_sleep_timer(global_settings.sleeptimer_duration * 60); + } + return action; +} + +MENUITEM_SETTING(menu_sleeptimer_duration, &global_settings.sleeptimer_duration, + sleeptimer_duration_cb); + +MENUITEM_SETTING(menu_sleeptimer_on_startup, &global_settings.sleeptimer_on_startup, NULL); + +MAKE_MENU(sleeptimer_menu, ID2P(LANG_SLEEP_TIMER), NULL, Icon_NOICON, + &menu_sleeptimer_duration, &menu_sleeptimer_on_startup); Index: apps/menu.h =================================================================== --- apps/menu.h (revision 30270) +++ apps/menu.h (working copy) @@ -197,9 +197,9 @@ text_cb_data, callback, icon) \ static const struct menu_get_name_and_icon name##_ \ = {callback,text_callback,voice_callback,text_cb_data,icon}; \ - static const struct menu_func name##__ = {{(void*)func}, param}; \ - static const struct menu_item_ex name = \ - { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ + static const struct menu_func name##__ = {{(void*)func}, param}; \ + const struct menu_item_ex name = \ + { MT_FUNCTION_CALL|MENU_DYNAMIC_DESC|flags, \ { .function = & name##__}, {.menu_get_name_and_icon = & name##_}}; /* Use this to actually create a menu. the ... argument is a list of pointers Index: apps/settings_list.c =================================================================== --- apps/settings_list.c (revision 30270) +++ apps/settings_list.c (working copy) @@ -519,6 +519,13 @@ memcpy(setting, defaultval, sizeof(struct touchscreen_parameter)); } #endif +static const char* sleeptimer_formatter(char* buffer, size_t buffer_size, + int value, const char* unit) +{ + (void) unit; + snprintf(buffer, buffer_size, "%d:%02d", value / 60, value % 60); + return buffer; +} #ifdef HAVE_HOTKEY static const char* hotkey_formatter(char* buffer, size_t buffer_size, int value, const char* unit) @@ -1723,6 +1730,9 @@ #endif /* CONFIG_CODEC == SWCODEC */ TEXT_SETTING(0, playlist_catalog_dir, "playlist catalog directory", PLAYLIST_CATALOG_DEFAULT_DIR, NULL, NULL), + INT_SETTING(0, sleeptimer_duration, LANG_SLEEP_TIMER_DURATION, 30, "sleeptimer duration", + UNIT_MIN, 5, 300, 5, sleeptimer_formatter, NULL, NULL), + OFFON_SETTING(0, sleeptimer_on_startup, LANG_SLEEP_TIMER_ON_POWER_UP, false, "sleeptimer on startup", NULL), #ifdef HAVE_TOUCHPAD_SENSITIVITY_SETTING CHOICE_SETTING(0, touchpad_sensitivity, LANG_TOUCHPAD_SENSITIVITY, 0, "touchpad sensitivity", "normal,high", touchpad_set_sensitivity, 2, Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 30270) +++ apps/SOURCES (working copy) @@ -41,6 +41,7 @@ #if CONFIG_RTC menus/time_menu.c #endif +menus/sleeptimer_menu.c misc.c mp3data.c onplay.c Index: apps/root_menu.c =================================================================== --- apps/root_menu.c (revision 30270) +++ apps/root_menu.c (working copy) @@ -661,6 +661,9 @@ next_screen = GO_TO_ROOT; #endif + if (global_settings.sleeptimer_on_startup) + set_sleep_timer(global_settings.sleeptimer_duration * 60); + while (true) { switch (next_screen) Index: manual/appendix/config_file_options.tex =================================================================== --- manual/appendix/config_file_options.tex (revision 30270) +++ manual/appendix/config_file_options.tex (working copy) @@ -363,6 +363,9 @@ jump scroll delay & 0 to 250 & 0.01~s\\ }% + sleeptimer duration & 5 to 300 (in steps of 5) + & minutes\\ + sleeptimer on startup & off, on & N/A\\ \bottomrule \end{longtable} Index: manual/configure_rockbox/system_options.tex =================================================================== --- manual/configure_rockbox/system_options.tex (revision 30270) +++ manual/configure_rockbox/system_options.tex (working copy) @@ -719,3 +719,18 @@ }} \end{description} } +\subsection{\label{ref:sleep_timer_submenu}Sleep Timer} + \setting{Sleep Timer} related menu options. + The \setting{Sleep Timer} powers off your \dap{} after a given time and is triggered from \setting{System + \opt{rtc}{ $\rightarrow$ \setting{Time and Date} }%\opt{rtc} + } (See \reference{ref:Info}). + \begin{description} + \item[Sleep Timer Duration:] + The number of minutes from when new timers are initiated to their completion. + The values range from 5 minutes to 5 hours in 5 minute steps. + If a timer is currently active, the timer's duration will be set to the newly entered value. + The value set is persistent between power cycles, see \reference{ref:config_file_options}. + \item[Start Sleep Timer On Boot:] + If set, a timer will be initiated when the device starts. + The value set is persistent. + \end{description} Index: manual/main_menu/main.tex =================================================================== --- manual/main_menu/main.tex (revision 30270) +++ manual/main_menu/main.tex (working copy) @@ -200,10 +200,13 @@ Time related menu options. Pressing \ActionStdContext{} will voice the current time if voice support is enabled \begin{description} \item[Set Time/Date:] Set current time and date. - \item[Sleep Timer:] - The \setting{Sleep Timer} powers off your \dap{} after playing for a given - time. It can be set from \setting{Off} to 5 hours in 5 minute steps. - The \setting{Sleep Timer} is reset on boot. + \item[Start Sleep Timer (\emph{duration}):] + Shown when the \setting{Sleep Timer} is inactive, this option will initiate the \setting{Sleep Timer}. + The \setting{Sleep Timer} powers off your \dap{} after playing for the duration shown in brackets. + The duration (in minutes) is set from \setting{Timer Duration} within \reference{ref:sleep_timer_submenu}). + \item[Stop Sleep Timer (\emph{remaining}):] + Shown when the \setting{Sleep Timer} is active, this option will disable the current \setting{Sleep Timer}. + The minutes remaining before completion is shown in brackets. \opt{alarm}{ \item[Wake-Up Alarm:] This option will make the \dap{} start up at the specified time. @@ -238,10 +241,13 @@ Display the list of contributors. \nopt{rtc}{ - \item[Sleep Timer:] - The \setting{Sleep Timer} powers off your \dap{} after playing for a given - time. It can be set from \setting{Off} to 5 hours in 5 minute steps. - The \setting{Sleep Timer} is reset on boot. + \item[Start Sleep Timer (\emph{duration}):] + Shown when the \setting{Sleep Timer} is inactive, this option will initiate the \setting{Sleep Timer}. + The \setting{Sleep Timer} powers off your \dap{} after playing for the duration shown in brackets. + The duration (in minutes) is set from \setting{Timer Duration} within \reference{ref:sleep_timer_submenu}). + \item[Stop Sleep Timer (\emph{remaining}):] + Shown when the \setting{Sleep Timer} is active, this option will disable the current \setting{Sleep Timer}. + The minutes remaining before completion is shown in brackets. } \item[Running Time:]