1
0
Fork 0
forked from len0rd/rockbox

alarm clock: don't have user pause the playback manually. make the plugin pause it.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28217 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-10-07 13:19:21 +00:00
parent 2d86417c46
commit d9a328872e
2 changed files with 26 additions and 15 deletions

View file

@ -31,12 +31,14 @@ static bool tomorrow = false;
static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24; static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24;
static bool quit = false, usb = false, waiting = false, done = false; static bool quit = false, usb = false, waiting = false, done = false;
static inline int get_button(void) { static inline int get_button(void)
{
return pluginlib_getaction(HZ/2, plugin_contexts, return pluginlib_getaction(HZ/2, plugin_contexts,
ARRAYLEN(plugin_contexts)); ARRAYLEN(plugin_contexts));
} }
int rem_seconds(void) { static int rem_seconds(void)
{
int seconds = (((alarm[0] - rb->get_time()->tm_hour) * 3600) int seconds = (((alarm[0] - rb->get_time()->tm_hour) * 3600)
+((alarm[1] - rb->get_time()->tm_min) * 60) +((alarm[1] - rb->get_time()->tm_min) * 60)
-(rb->get_time()->tm_sec)); -(rb->get_time()->tm_sec));
@ -48,7 +50,8 @@ int rem_seconds(void) {
return seconds + (tomorrow ? 24 * 3600 : 0); return seconds + (tomorrow ? 24 * 3600 : 0);
} }
void draw_centered_string(struct screen * display, char * string) { static void draw_centered_string(struct screen * display, char * string)
{
int w, h; int w, h;
display->getstringsize(string, &w, &h); display->getstringsize(string, &w, &h);
@ -62,7 +65,8 @@ void draw_centered_string(struct screen * display, char * string) {
} }
} }
void draw(struct screen * display) { static void draw(struct screen * display)
{
char info[128]; char info[128];
display->clear_display(); display->clear_display();
@ -85,19 +89,21 @@ void draw(struct screen * display) {
draw_centered_string(display, info); draw_centered_string(display, info);
} }
bool can_play(void) { static bool can_play(void)
{
int audio_status = rb->audio_status(); int audio_status = rb->audio_status();
if ((!audio_status && rb->global_status->resume_index != -1) if ((!audio_status && rb->global_status->resume_index != -1)
&& (rb->playlist_resume() != -1)) { && (rb->playlist_resume() != -1)) {
return true; return true;
} }
else if (audio_status & AUDIO_STATUS_PAUSE) else if (audio_status & AUDIO_STATUS_PLAY)
return true; return true;
return false; return false;
} }
void play(void) { static void play(void)
{
int audio_status = rb->audio_status(); int audio_status = rb->audio_status();
if (!audio_status && rb->global_status->resume_index != -1) { if (!audio_status && rb->global_status->resume_index != -1) {
if (rb->playlist_resume() != -1) { if (rb->playlist_resume() != -1) {
@ -105,10 +111,16 @@ void play(void) {
rb->global_status->resume_offset); rb->global_status->resume_offset);
} }
} }
else if (audio_status & AUDIO_STATUS_PAUSE) else if (audio_status & AUDIO_STATUS_PLAY)
rb->audio_resume(); rb->audio_resume();
} }
static void pause(void)
{
if (rb->audio_status() & AUDIO_STATUS_PLAY)
rb->audio_pause();
}
enum plugin_status plugin_start(const void* parameter) enum plugin_status plugin_start(const void* parameter)
{ {
int button; int button;
@ -116,11 +128,11 @@ enum plugin_status plugin_start(const void* parameter)
(void)parameter; (void)parameter;
if (!can_play()) { if (!can_play()) {
rb->splash(4*HZ, "No track to resume! This plugin will resume a track " rb->splash(HZ*2, "No track to resume! "
"at a specific time. Therefore, you need to first play" "Play or pause one first.");
" one, and then pause it and start the plugin again."); return PLUGIN_ERROR;
quit = true;
} }
pause();
while(!quit) { while(!quit) {
button = get_button(); button = get_button();
@ -184,4 +196,3 @@ enum plugin_status plugin_start(const void* parameter)
return (usb) ? PLUGIN_USB_CONNECTED return (usb) ? PLUGIN_USB_CONNECTED
: (done ? PLUGIN_GOTO_WPS : PLUGIN_OK); : (done ? PLUGIN_GOTO_WPS : PLUGIN_OK);
} }

View file

@ -23,6 +23,6 @@ This plugin is an alarm clock, which resumes a paused song at a given time.
\end{btnmap} \end{btnmap}
\subsubsection{Setting an alarm} \subsubsection{Setting an alarm}
First select a track and play it, then pause the track and launch the First select a track and play it, then launch the ``alarmclock'' plugin. The
``alarmclock'' plugin. Enter a 24h-time (e.g. 13:58) and set the alarm. plugin pauses the playback. Enter a 24h-time (e.g. 13:58) and set the alarm.
Music playback will resume when the set time is reached. Music playback will resume when the set time is reached.