FS#10779 - Permanent Sleep Timer Option

Attached to Project: Rockbox
Opened by Nick Peskett (nickp) - Friday, 13 November 2009, 04:56 GMT
Last edited by Nils Wallménius (nls) - Sunday, 13 December 2009, 09:42 GMT
Task Type Patches
Category Configuration
Status Closed
Assigned To No-one
Operating System All players
Severity Low
Priority Normal
Reported Version Release 3.4
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No


Permanent Sleep Timer Option.

This patch adds an additional option "Permanent Sleep Timer" under System->Time & Date (or System if CONFIG_RTC isn't set).

When set, it immediately sets the sleep timer with the given number of minutes and writes a configuration option "permasleep timer: {mins}".

On startup, if this configuration option is detected, it sets the sleep timer to this value.

If the value is set to "Off" the sleep timer is immediately reset and the config setting disappears.

Normal volatile timer settings can be initiated using the existing Sleep Timer option.

While it might have been better if I'd reworked the existing sleep timer, I'm very much a novice C coder, so thought it would be better to err on the side of caution and modify as little code as possible.

Tested on a Cowon D2.
This task depends upon

Closed by  Nils Wallménius (nls)
Sunday, 13 December 2009, 09:42 GMT
Reason for closing:  Out of Date
Additional comments about closing:  requsted to be closed by the poster, superceded by fs#10849
Comment by alex wallis (alexwallis646) - Friday, 13 November 2009, 23:38 GMT
so is this patch similar to what fs# 8630 did? I was all in favour of getting that committed.

also, does your patch simply create a default value in the config file for the sleep timer, or does it actually start the sleep timer each time you turn your player on? that wasn't very clear from the task description.
Comment by Nick Peskett (nickp) - Saturday, 14 November 2009, 00:02 GMT
The differences between this and patch #8630;
- This is a new menu entry, no changes have been made to the existing Sleep Timer option (setting it will be a one-off and be forgotten on restart).
- If you set a value in the new Permanent Sleep Timer option, a value gets written to the config file and the sleep timer starts there and then. It will then start the sleep timer to the config file value each time you turn the player on, until you go back into Permanent Sleep Timer and switch it off.

Initially I made these changes for myself, it was a feature I needed and was a coding exercise as much anything else, I didn't expect it to work. If anyone has suggestions how they'd like the implementation changed, I'd be more than happy to have a go.

The main feature I wanted was that I could start the player up and have it automatically be in sleep timer mode.

While I remember: I didn't mean to select "Reported Version - Release 3.4", this is actually a patch to the (current as then) SVN revision 23621.
Comment by Nick Peskett (nickp) - Saturday, 14 November 2009, 00:24 GMT
Another reason I made this a new menu option: I current use patch FS#10754 (Amend Sleep Timeout to Pause Timeout) and didn't want to cause any conflicts with it.

If it turns out that patch gets accepted into the truck, I could maybe use the new sleeptimer_period value it creates to make a new version that had persistent values in the existing Sleep Timer option and replace Permanent Sleep Timer with a boolean switch; whether you'd like sleep timer to be active on startup or not.

The problem with the persistence in the current Sleep Timer option is it doubles as a viewer on how much sleep time is left. If you set it to half an hour and go back ten minutes later, it shows 20 minutes. It's an issue both  FS#8630  & I avoided!
Comment by Sean Inglis (seani) - Friday, 27 November 2009, 13:33 GMT
Hi nickp, although it'd go against the "one feature per patch" guideline, I'd be interested in having a single patch with both these features in, even if it isn't for a general audience. I'll revisit FS10754 over the weekend with any luck.

I was also thinking of altering the way the pause timer works WRT track ending. At the moment, it plays in fixed increments (5, 10, 15 min etc) which means another bite at the cherry could straddle the boundary between two tracks (or podcasts in my case).

The behaviour I'm thinking of adding is that it adjusts the pause timeout to take account of this. As an example, if the pause timeout is 5 minutes and the track is 28 minutes, the timeout would operate for 5 sets of 5 and then one of 3. The next track would start with bites of five again.

This also sort of gives you "pause at the end of a track mode" for free; it you set the timeout to something large, it'll play the whole track in one go and then pause. I say almost, because the timeout seems to be out by a second or so sometimes. I must quantify that sometime, but it doesn't matter so much for audiobooks etc.
Comment by Nick Peskett (nickp) - Saturday, 28 November 2009, 07:25 GMT
Hi Sean, good to hear from you. It occurs to me that it would be neat if we could make all these features optional through a dedicated sleep timer menu.

Kind of like (take with a pinch of salt, this is off the top of my head!);

Timer Status: Off / X Minutes <- Not an option just a display of current status
Timer Minutes: 5, 10, 15, etc <- (sleeptimer_duration*) Drop down list with value set being persistent between sessions. Has a default if value hasn't been set?
Start Timer: Yes/ No <- Used to start the timer just for this session
Timer Behaviour: Power Down/ Pause <- (sleeptimer_action*) Feature your current patch handles. Maybe string value in case we think of other actions to perform?
Timer Starts on Power Up: Yes/ No <- (sleeptimer_on_startup*) Permanent sleep timer option.
Restrict to Boundary: Off/ Track/ Folder <- (sleeptimer_boundary_limit*) Extending the feature you describe above? Should this be a tolerance value instead?

* Option gets written to config file

This could either be a single patch, or if more palatable, a group of patches;

a) Implements Sleep Timer menu and persistent (but not permanent) timer value. Implements menu options 1, 2, 3
b) depends on a, implements menu option 4
c) depends on a, implements menu option 5
d) depends on a, implements menu option 6

I'll be away most of next week and a bit busy this weekend, apologies in advance if it takes me a while to respond.
Comment by Sean Inglis (seani) - Sunday, 29 November 2009, 17:50 GMT
Nick, I've has a quick try at pausing on track boundaries, and the naive method I was proposing to use won't work. The pause kicks in after an absolute elapsed time, and this time is set only when the play button is pressed; it isn't constantly revisited. This means that fastforwarding / rewinding through a track will result in it pausing in odd places. This can be addressed of course, but I don't think this is the patch for that change: it's crossed the boundary from being a useful side-effect of reworking the sleep timer into something that should really be separate.

Still worth looking at the other stuff I think, I'll poke around in it.
Comment by Nick Peskett (nickp) - Sunday, 13 December 2009, 09:19 GMT
This patch has now been superseded by  FS#10849 .