summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeruaki Kawashima <teru@rockbox.org>2010-10-07 13:19:21 +0000
committerTeruaki Kawashima <teru@rockbox.org>2010-10-07 13:19:21 +0000
commitd9a328872e5779c92e63fc8fe8e09c0061e116d7 (patch)
treed296de10e3752fdbf6b8f2489197a29f9f9e8e46
parent2d86417c46fcdb37b36df3354cfd9650e0bc986e (diff)
downloadrockbox-d9a328872e5779c92e63fc8fe8e09c0061e116d7.tar.gz
rockbox-d9a328872e5779c92e63fc8fe8e09c0061e116d7.zip
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
-rw-r--r--apps/plugins/alarmclock.c37
-rw-r--r--manual/plugins/alarmclock.tex4
2 files changed, 26 insertions, 15 deletions
diff --git a/apps/plugins/alarmclock.c b/apps/plugins/alarmclock.c
index 3ccb0c3ebd..0afd7a1c13 100644
--- a/apps/plugins/alarmclock.c
+++ b/apps/plugins/alarmclock.c
@@ -31,12 +31,14 @@ static bool tomorrow = false;
31static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24; 31static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24;
32static bool quit = false, usb = false, waiting = false, done = false; 32static bool quit = false, usb = false, waiting = false, done = false;
33 33
34static inline int get_button(void) { 34static inline int get_button(void)
35{
35 return pluginlib_getaction(HZ/2, plugin_contexts, 36 return pluginlib_getaction(HZ/2, plugin_contexts,
36 ARRAYLEN(plugin_contexts)); 37 ARRAYLEN(plugin_contexts));
37} 38}
38 39
39int rem_seconds(void) { 40static int rem_seconds(void)
41{
40 int seconds = (((alarm[0] - rb->get_time()->tm_hour) * 3600) 42 int seconds = (((alarm[0] - rb->get_time()->tm_hour) * 3600)
41 +((alarm[1] - rb->get_time()->tm_min) * 60) 43 +((alarm[1] - rb->get_time()->tm_min) * 60)
42 -(rb->get_time()->tm_sec)); 44 -(rb->get_time()->tm_sec));
@@ -48,7 +50,8 @@ int rem_seconds(void) {
48 return seconds + (tomorrow ? 24 * 3600 : 0); 50 return seconds + (tomorrow ? 24 * 3600 : 0);
49} 51}
50 52
51void draw_centered_string(struct screen * display, char * string) { 53static void draw_centered_string(struct screen * display, char * string)
54{
52 int w, h; 55 int w, h;
53 display->getstringsize(string, &w, &h); 56 display->getstringsize(string, &w, &h);
54 57
@@ -62,7 +65,8 @@ void draw_centered_string(struct screen * display, char * string) {
62 } 65 }
63} 66}
64 67
65void draw(struct screen * display) { 68static void draw(struct screen * display)
69{
66 char info[128]; 70 char info[128];
67 display->clear_display(); 71 display->clear_display();
68 72
@@ -85,19 +89,21 @@ void draw(struct screen * display) {
85 draw_centered_string(display, info); 89 draw_centered_string(display, info);
86} 90}
87 91
88bool can_play(void) { 92static bool can_play(void)
93{
89 int audio_status = rb->audio_status(); 94 int audio_status = rb->audio_status();
90 if ((!audio_status && rb->global_status->resume_index != -1) 95 if ((!audio_status && rb->global_status->resume_index != -1)
91 && (rb->playlist_resume() != -1)) { 96 && (rb->playlist_resume() != -1)) {
92 return true; 97 return true;
93 } 98 }
94 else if (audio_status & AUDIO_STATUS_PAUSE) 99 else if (audio_status & AUDIO_STATUS_PLAY)
95 return true; 100 return true;
96 101
97 return false; 102 return false;
98} 103}
99 104
100void play(void) { 105static void play(void)
106{
101 int audio_status = rb->audio_status(); 107 int audio_status = rb->audio_status();
102 if (!audio_status && rb->global_status->resume_index != -1) { 108 if (!audio_status && rb->global_status->resume_index != -1) {
103 if (rb->playlist_resume() != -1) { 109 if (rb->playlist_resume() != -1) {
@@ -105,10 +111,16 @@ void play(void) {
105 rb->global_status->resume_offset); 111 rb->global_status->resume_offset);
106 } 112 }
107 } 113 }
108 else if (audio_status & AUDIO_STATUS_PAUSE) 114 else if (audio_status & AUDIO_STATUS_PLAY)
109 rb->audio_resume(); 115 rb->audio_resume();
110} 116}
111 117
118static void pause(void)
119{
120 if (rb->audio_status() & AUDIO_STATUS_PLAY)
121 rb->audio_pause();
122}
123
112enum plugin_status plugin_start(const void* parameter) 124enum plugin_status plugin_start(const void* parameter)
113{ 125{
114 int button; 126 int button;
@@ -116,11 +128,11 @@ enum plugin_status plugin_start(const void* parameter)
116 (void)parameter; 128 (void)parameter;
117 129
118 if (!can_play()) { 130 if (!can_play()) {
119 rb->splash(4*HZ, "No track to resume! This plugin will resume a track " 131 rb->splash(HZ*2, "No track to resume! "
120 "at a specific time. Therefore, you need to first play" 132 "Play or pause one first.");
121 " one, and then pause it and start the plugin again."); 133 return PLUGIN_ERROR;
122 quit = true;
123 } 134 }
135 pause();
124 136
125 while(!quit) { 137 while(!quit) {
126 button = get_button(); 138 button = get_button();
@@ -184,4 +196,3 @@ enum plugin_status plugin_start(const void* parameter)
184 return (usb) ? PLUGIN_USB_CONNECTED 196 return (usb) ? PLUGIN_USB_CONNECTED
185 : (done ? PLUGIN_GOTO_WPS : PLUGIN_OK); 197 : (done ? PLUGIN_GOTO_WPS : PLUGIN_OK);
186} 198}
187
diff --git a/manual/plugins/alarmclock.tex b/manual/plugins/alarmclock.tex
index d427bd4532..617a208fdb 100644
--- a/manual/plugins/alarmclock.tex
+++ b/manual/plugins/alarmclock.tex
@@ -23,6 +23,6 @@ This plugin is an alarm clock, which resumes a paused song at a given time.
23\end{btnmap} 23\end{btnmap}
24 24
25\subsubsection{Setting an alarm} 25\subsubsection{Setting an alarm}
26First select a track and play it, then pause the track and launch the 26First select a track and play it, then launch the ``alarmclock'' plugin. The
27``alarmclock'' plugin. Enter a 24h-time (e.g. 13:58) and set the alarm. 27plugin pauses the playback. Enter a 24h-time (e.g. 13:58) and set the alarm.
28Music playback will resume when the set time is reached. 28Music playback will resume when the set time is reached.