diff --git a/apps/SOURCES b/apps/SOURCES index dee4e6e002..e872531408 100644 --- a/apps/SOURCES +++ b/apps/SOURCES @@ -19,7 +19,6 @@ plugin.c screens.c settings.c settings_menu.c -sleeptimer.c sound_menu.c status.c #if !defined(SIMULATOR) || CONFIG_CODEC == SWCODEC diff --git a/apps/settings_menu.c b/apps/settings_menu.c index 70703a23ce..5141416ecb 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -36,7 +36,6 @@ #include "backlight.h" #include "playlist.h" /* for playlist_shuffle */ #include "fat.h" /* For dotfile settings */ -#include "sleeptimer.h" #include "powermgmt.h" #include "rtc.h" #include "ata.h" @@ -799,6 +798,35 @@ static bool poweroff_idle_timer(void) INT, names, 15, set_poweroff_timeout); } +static void sleep_timer_formatter(char* buffer, int buffer_size, int value, + const char* unit) +{ + int minutes, hours; + + (void) unit; + + if (value) { + hours = value / 60; + minutes = value - (hours * 60); + snprintf(buffer, buffer_size, "%d:%02d", hours, minutes); + } else { + snprintf(buffer, buffer_size, "%s", str(LANG_OFF)); + } +} + +static void sleep_timer_set(int minutes) +{ + set_sleep_timer(minutes * 60); +} + +static bool sleep_timer(void) +{ + int minutes = get_sleep_timer() / 60; + + return set_int(str(LANG_SLEEP_TIMER), "", UNIT_MIN, &minutes, + &sleep_timer_set, 15, 0, 300, sleep_timer_formatter); +} + static bool scroll_speed(void) { return set_int(str(LANG_SCROLL), "", UNIT_INT, @@ -1864,7 +1892,7 @@ static bool system_settings_menu(void) { ID2P(LANG_TIME_MENU), time_settings_menu }, #endif { ID2P(LANG_POWEROFF_IDLE), poweroff_idle_timer }, - { ID2P(LANG_SLEEP_TIMER), sleeptimer_screen }, + { ID2P(LANG_SLEEP_TIMER), sleep_timer }, #ifdef HAVE_ALARM_MOD { ID2P(LANG_ALARM_MOD_ALARM_MENU), alarm_screen }, #endif diff --git a/apps/sleeptimer.c b/apps/sleeptimer.c deleted file mode 100644 index e9b0924388..0000000000 --- a/apps/sleeptimer.c +++ /dev/null @@ -1,164 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 Linus Nielsen Feltzing - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#include "config.h" -#include "options.h" - -#include "lcd.h" -#include "font.h" -#include "button.h" -#include "kernel.h" -#include "sprintf.h" -#include -#include "settings.h" -#include "power.h" -#include "powermgmt.h" -#include "statusbar.h" -#include "debug.h" -#include "talk.h" -#include "icons.h" - -#include "lang.h" - -#define SMALL_STEP_SIZE 15*60 /* Seconds */ -#define LARGE_STEP_SIZE 30*60 /* Seconds */ -#define THRESHOLD 60 /* Minutes */ -#define MAX_TIME 5*60*60 /* Hours */ - -bool sleeptimer_screen(void) -{ - unsigned long seconds; - int hours, minutes; - int button; - bool done = false; - char buf[32]; - int oldtime, newtime; - int amount = 0; - int org_timer=get_sleep_timer(); - bool changed=false; - bool sayit = true; - -#ifdef HAVE_LCD_BITMAP - if (global_settings.statusbar) - lcd_setmargins(0, STATUSBAR_HEIGHT); - else - lcd_setmargins(0, 0); -#endif - - lcd_clear_display(); - lcd_puts_scroll(0, 0, str(LANG_SLEEP_TIMER)); - - while(!done) - { - button = button_get_w_tmo(HZ); - switch(button) - { -#ifdef SETTINGS_OK2 - case SETTINGS_OK2: -#endif - case SETTINGS_OK: - done = true; - break; - - case SETTINGS_CANCEL: - if (changed) { - lcd_stop_scroll(); - lcd_puts(0, 0, str(LANG_MENU_SETTING_CANCEL)); - lcd_update(); - set_sleep_timer(org_timer); - sleep(HZ/2); - } - done = true; - break; - - case SETTINGS_INC: - oldtime = (get_sleep_timer()+59) / 60; - if(oldtime < THRESHOLD) - amount = SMALL_STEP_SIZE; - else - amount = LARGE_STEP_SIZE; - - newtime = oldtime * 60 + amount; - if(newtime > MAX_TIME) - newtime = MAX_TIME; - - changed = sayit = true; - set_sleep_timer(newtime); - break; - - case SETTINGS_DEC: - oldtime = (get_sleep_timer()+59) / 60; - if(oldtime <= THRESHOLD) - amount = SMALL_STEP_SIZE; - else - amount = LARGE_STEP_SIZE; - - newtime = oldtime*60 - amount; - if(newtime < 0) - newtime = 0; - - changed = sayit = true; - set_sleep_timer(newtime); - break; - } - - seconds = get_sleep_timer(); - - if(seconds) - { - seconds += 59; /* Round up for a "friendlier" display */ - hours = seconds / 3600; - minutes = (seconds - (hours * 3600)) / 60; - snprintf(buf, 32, "%d:%02d", - hours, minutes); - lcd_puts(0, 1, (unsigned char *)buf); - - if (sayit && global_settings.talk_menu) - { - bool enqueue = false; /* first one should not ne queued */ - - if (hours) - { - talk_value(hours, UNIT_HOUR, enqueue); - enqueue = true; /* queue any following */ - } - if (minutes) - { - talk_value(minutes, UNIT_MIN, enqueue); - } - - sayit = false; - } - } - else - { - lcd_puts(0, 1, str(LANG_OFF)); - if (sayit && global_settings.talk_menu) - { - talk_id(LANG_OFF, false); - sayit = false; - } - } - - gui_syncstatusbar_draw(&statusbars, true); - - lcd_update(); - } - lcd_stop_scroll(); - return false; -} diff --git a/apps/sleeptimer.h b/apps/sleeptimer.h deleted file mode 100644 index b57580dc3a..0000000000 --- a/apps/sleeptimer.h +++ /dev/null @@ -1,24 +0,0 @@ -/*************************************************************************** - * __________ __ ___. - * Open \______ \ ____ ____ | | _\_ |__ _______ ___ - * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / - * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < - * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ - * \/ \/ \/ \/ \/ - * $Id$ - * - * Copyright (C) 2002 Linus Nielsen Feltzing - * - * All files in this archive are subject to the GNU General Public License. - * See the file COPYING in the source tree root for full license agreement. - * - * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY - * KIND, either express or implied. - * - ****************************************************************************/ -#ifndef _SLEEPTIMER_H_ -#define _SLEEPTIMER_H_ - -bool sleeptimer_screen(void); - -#endif