Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: [PATCH] idle poweroff and sleep timer

[PATCH] idle poweroff and sleep timer

From: Lee Marlow <lmarlow_at_yahoo.com>
Date: Sat, 21 Sep 2002 15:33:17 -0700 (PDT)

This patch allows you to set an idle poweroff time, so
the unit will shut itself off if no music is playing
and there hasn't been any user interaction in the
specified time. Currently I check whether a song is
playing by calling mpeg_is_playing(), which will
return true if a song is playing or is paused, so
music has to actually be stopped for it to shutdown.

The sleep timer will shut the unit down after the
specified amount of time, regardless of user
interaction.

Plugging in USB will stop the countdown. The
countdown will be reset and started once the USB is
removed.

The menu options are located in General
Settings->System.

Enjoy

-Lee (mecraw)

P.S. poweroff.[ch] belong in the firmware directory.

__________________________________________________
Do you Yahoo!?
New DSL Internet Access from SBC & Yahoo!
http://sbc.yahoo.com

/***************************************************************************
 * __________ __ ___.
 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
 * \/ \/ \/ \/ \/
 * $Id$
 *
 * Copyright (C) 2002 by Daniel Stenberg
 *
 * 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 POWEROFF_H
#define POWEROFF_H

void poweroff_activity(void);
void poweroff_tick(void);
void poweroff_idle_time(int value);
void poweroff_sleep_time(int value);

void poweroff_stop_timer(void);
void poweroff_start_timer(void);

#endif


/***************************************************************************
 * __________ __ ___.
 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
 * \/ \/ \/ \/ \/
 * $Id$
 *
 * Copyright (C) 2002 by 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 "kernel.h"
#include "power.h"
#include "mpeg.h"

static bool counting = true;
static int poweroff_timer;
static int poweroff_idle_timeout = 0;
static int poweroff_sleep_timeout = 0;

static int poweroff_idle_timeout_value[19] =
{
    0, 10, 20, 30, 45, 60, 120, 180, 240, 300, 600, 900, 1200, 1800, 2700, 3600, 5400, 7200, 10800
};

static int poweroff_sleep_timeout_value[22] =
{
    0, 60, 120, 180, 240, 300, 600, 900, 1200, 1800, 2700, 3600, 5400, 7200, 10800, 14400, 18000, 21600, 25200, 28800, 32400, 36000
};

void poweroff_activity(void)
{
    if (!poweroff_sleep_timeout)
        poweroff_timer = HZ*poweroff_idle_timeout_value[poweroff_idle_timeout];
}

void poweroff_idle_time(int value)
{
    poweroff_idle_timeout = value;
    poweroff_activity();
}

void poweroff_sleep_time(int value)
{
    poweroff_sleep_timeout = value;
    poweroff_timer = HZ*poweroff_sleep_timeout_value[poweroff_sleep_timeout];
}

void poweroff_tick(void)
{
    if(poweroff_timer && counting
        && (poweroff_sleep_timeout || !mpeg_is_playing()))
    {
        poweroff_timer--;
        if(poweroff_timer == 0)
        {
            power_off();
        }
    }
}

/* used to stop the timer in case USB was connected */
void poweroff_stop_timer(void)
{
    counting = false;
}

/* used to start the timer after USB was disconnected */
void poweroff_start_timer(void)
{
    poweroff_sleep_time(poweroff_sleep_timeout);
    poweroff_idle_time(poweroff_idle_timeout);
    counting = true;
}



Index: backlight.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/backlight.c,v
retrieving revision 1.16
diff -u -b -r1.16 backlight.c
--- backlight.c 23 Aug 2002 09:36:49 -0000 1.16
+++ backlight.c 21 Sep 2002 22:11:53 -0000
_at__at_ -25,6 +25,7 _at__at_
 #include "debug.h"
 #include "rtc.h"
 #include "usb.h"
+#include "poweroff.h"
 
 #define BACKLIGHT_ON 1
 #define BACKLIGHT_OFF 2
_at__at_ -86,10 +87,12 _at__at_
                 /* Tell the USB thread that we are safe */
                 DEBUGF("backlight_thread got SYS_USB_CONNECTED\n");
                 usb_acknowledge(SYS_USB_CONNECTED_ACK);
+ poweroff_stop_timer();
                 break;
 
             case SYS_USB_DISCONNECTED:
                 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
+ poweroff_start_timer();
                 break;
         }
     }
Index: drivers/button.c
===================================================================
RCS file: /cvsroot/rockbox/firmware/drivers/button.c,v
retrieving revision 1.25
diff -u -b -r1.25 button.c
--- drivers/button.c 6 Sep 2002 10:04:24 -0000 1.25
+++ drivers/button.c 21 Sep 2002 22:11:53 -0000
_at__at_ -140,6 +140,7 _at__at_
                 else
                     queue_post(&button_queue, btn, NULL);
                 backlight_on();
+ poweroff_activity();
             }
         }
         else
_at__at_ -153,6 +154,7 _at__at_
     }
         
     backlight_tick();
+ poweroff_tick();
 }
 
 int button_get(bool block)


Index: settings.h
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.h,v
retrieving revision 1.42
diff -u -b -r1.42 settings.h
--- settings.h 18 Sep 2002 10:12:16 -0000 1.42
+++ settings.h 21 Sep 2002 22:06:10 -0000
_at__at_ -62,7 +62,8 _at__at_
     /* device settings */
 
     int contrast; /* lcd contrast: 0-100 0=low 100=high */
- int poweroff; /* power off timer: 0-100 0=never:each 1% = 60 secs */
+ int poweroff_idle; /* power off idle timer */
+ int poweroff_sleep; /* power off sleep timer */
     int backlight; /* backlight off timer: 0-100 0=never:each 1% = 10 secs */
     bool discharge; /* maintain charge of at least: false = 90%, true = 10% */
 
_at__at_ -142,7 +143,8 _at__at_
 #define DEFAULT_CONTRAST_SETTING 38
 #endif
 #define MIN_CONTRAST_SETTING 5
-#define DEFAULT_POWEROFF_SETTING 0
+#define DEFAULT_POWEROFF_IDLE_SETTING 0
+#define DEFAULT_POWEROFF_SLEEP_SETTING 0
 #define DEFAULT_BACKLIGHT_SETTING 5
 #define DEFAULT_FF_REWIND_MIN_STEP FF_REWIND_1000
 #define DEFAULT_FF_REWIND_ACCEL_SETTING 3
Index: settings.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings.c,v
retrieving revision 1.60
diff -u -b -r1.60 settings.c
--- settings.c 21 Sep 2002 14:21:31 -0000 1.60
+++ settings.c 21 Sep 2002 22:06:12 -0000
_at__at_ -35,6 +35,7 _at__at_
 #include "fat.h"
 #include "power.h"
 #include "backlight.h"
+#include "poweroff.h"
 #include "powermgmt.h"
 #include "status.h"
 #include "atoi.h"
_at__at_ -261,7 +262,7 _at__at_
     
     config_block[0xa] = (unsigned char)global_settings.contrast;
     config_block[0xb] = (unsigned char)global_settings.backlight;
- config_block[0xc] = (unsigned char)global_settings.poweroff;
+ config_block[0xc] = (unsigned char)global_settings.poweroff_idle;
     config_block[0xd] = (unsigned char)global_settings.resume;
     
     config_block[0xe] = (unsigned char)
_at__at_ -355,7 +356,7 _at__at_
         if (config_block[0xb] != 0xFF)
             global_settings.backlight = config_block[0xb];
         if (config_block[0xc] != 0xFF)
- global_settings.poweroff = config_block[0xc];
+ global_settings.poweroff_idle = config_block[0xc];
         if (config_block[0xd] != 0xFF)
             global_settings.resume = config_block[0xd];
         if (config_block[0xe] != 0xFF) {
_at__at_ -410,6 +411,7 _at__at_
     lcd_set_contrast(global_settings.contrast);
     lcd_scroll_speed(global_settings.scroll_speed);
     backlight_time(global_settings.backlight);
+ poweroff_idle_time(global_settings.poweroff_idle);
     ata_spindown(global_settings.disk_spindown);
 #ifdef HAVE_CHARGE_CTRL
     charge_restart_level = global_settings.discharge ? CHARGE_RESTART_LO : CHARGE_RESTART_HI;
_at__at_ -590,7 +592,8 _at__at_
     global_settings.channel_config = mpeg_sound_default(SOUND_CHANNELS);
     global_settings.resume = RESUME_ASK;
     global_settings.contrast = DEFAULT_CONTRAST_SETTING;
- global_settings.poweroff = DEFAULT_POWEROFF_SETTING;
+ global_settings.poweroff_idle = DEFAULT_POWEROFF_IDLE_SETTING;
+ global_settings.poweroff_sleep = DEFAULT_POWEROFF_SLEEP_SETTING;
     global_settings.backlight = DEFAULT_BACKLIGHT_SETTING;
     global_settings.mp3filter = true;
     global_settings.sort_case = false;
_at__at_ -630,7 +633,7 _at__at_
 
     DEBUGF( "contrast:\t%d\npoweroff:\t%d\nbacklight:\t%d\n",
             global_settings.contrast,
- global_settings.poweroff,
+ global_settings.poweroff_idle,
             global_settings.backlight );
 #endif
 }
Index: settings_menu.c
===================================================================
RCS file: /cvsroot/rockbox/apps/settings_menu.c,v
retrieving revision 1.57
diff -u -b -r1.57 settings_menu.c
--- settings_menu.c 21 Sep 2002 14:21:31 -0000 1.57
+++ settings_menu.c 21 Sep 2002 22:06:12 -0000
_at__at_ -31,6 +31,7 _at__at_
 #include "settings.h"
 #include "settings_menu.h"
 #include "backlight.h"
+#include "poweroff.h"
 #include "playlist.h" /* for playlist_shuffle */
 #include "fat.h" /* For dotfile settings */
 #include "powermgmt.h"
_at__at_ -99,6 +100,33 _at__at_
     return MENU_OK;
 }
 
+static Menu poweroff_idle_timer(void)
+{
+ char* names[] = { str(LANG_OFF),
+ "10s", "20s", "30s", "45s",
+ "1m ", "2m ", "3m ", "4m ",
+ "5m ", "10m", "15m", "20m",
+ "30m", "45m", "60m", "90m",
+ "2h ", "3h "};
+ set_option(str(LANG_POWEROFF_IDLE), &global_settings.poweroff_idle, names, 19,
+ poweroff_idle_time );
+ return MENU_OK;
+}
+
+static Menu poweroff_sleep_timer(void)
+{
+ char* names[] = { str(LANG_OFF),
+ "1m ", "2m ", "3m ", "4m ",
+ "5m ", "10m", "15m", "20m",
+ "30m", "45m", "60m", "90m",
+ "2h ", "3h ", "4h ", "5h ",
+ "6h ", "7h ", "8h ", "9h ",
+ "10h"};
+ set_option(str(LANG_SLEEP_TIMER), &global_settings.poweroff_sleep, names, 22,
+ poweroff_sleep_time );
+ return MENU_OK;
+}
+
 static Menu scroll_speed(void)
 {
     set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed,
_at__at_ -338,6 +366,8 _at__at_
         { str(LANG_TIME), timedate_set },
 #endif
         { str(LANG_RESET), reset_settings },
+ { str(LANG_POWEROFF_IDLE), poweroff_idle_timer },
+ { str(LANG_SLEEP_TIMER), poweroff_sleep_timer },
     };
     
     m=menu_init( items, sizeof items / sizeof(struct menu_items) );
Index: lang/english.lang
===================================================================
RCS file: /cvsroot/rockbox/apps/lang/english.lang,v
retrieving revision 1.4
diff -u -b -r1.4 english.lang
--- lang/english.lang 20 Sep 2002 06:34:56 -0000 1.4
+++ lang/english.lang 21 Sep 2002 22:06:13 -0000
_at__at_ -226,6 +226,16 _at__at_
 id: LANG_BACKLIGHT_ON
 desc: in settings_menu,
 
+id: LANG_POWEROFF_IDLE
+desc: in settings_menu
+eng: "Idle Poweroff"
+new:
+
+id: LANG_SLEEP_TIMER
+desc: in settings_menu
+eng: "Sleep Timer"
+new:
+
 id: LANG_SCROLL
 desc: in settings_menu
 eng: "Scroll Speed Setting Example"
Received on 2002-09-22

Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew -- Privacy Policy