diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/plugins/alarmclock.c | 37 |
1 files changed, 24 insertions, 13 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; | |||
31 | static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24; | 31 | static int alarm[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24; |
32 | static bool quit = false, usb = false, waiting = false, done = false; | 32 | static bool quit = false, usb = false, waiting = false, done = false; |
33 | 33 | ||
34 | static inline int get_button(void) { | 34 | static 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 | ||
39 | int rem_seconds(void) { | 40 | static 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 | ||
51 | void draw_centered_string(struct screen * display, char * string) { | 53 | static 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 | ||
65 | void draw(struct screen * display) { | 68 | static 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 | ||
88 | bool can_play(void) { | 92 | static 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 | ||
100 | void play(void) { | 105 | static 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 | ||
118 | static void pause(void) | ||
119 | { | ||
120 | if (rb->audio_status() & AUDIO_STATUS_PLAY) | ||
121 | rb->audio_pause(); | ||
122 | } | ||
123 | |||
112 | enum plugin_status plugin_start(const void* parameter) | 124 | enum 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 | |||