1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Clément Pit-Claudel
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
23 #include "lib/pluginlib_actions.h"
27 const struct button_mapping
*plugin_contexts
[] = {generic_directions
,
30 static int current
= 0;
31 static bool tomorrow
= false;
32 static int alarm
[2] = {0, 0}, maxval
[2] = {24, 60}, prev_tick
= 3600 * 24;
33 static bool quit
= false, usb
= false, waiting
= false, done
= false;
35 static inline int get_button(void) {
36 return pluginlib_getaction(HZ
/2, plugin_contexts
, 2);
39 int rem_seconds(void) {
40 int seconds
= (((alarm
[0] - rb
->get_time()->tm_hour
) * 3600)
41 +((alarm
[1] - rb
->get_time()->tm_min
) * 60)
42 -(rb
->get_time()->tm_sec
));
44 /* The tomorrow flag means that the alarm should ring on the next day */
45 if (seconds
> prev_tick
) tomorrow
= false;
48 return seconds
+ (tomorrow
? 24 * 3600 : 0);
51 void draw_centered_string(struct screen
* display
, char * string
) {
53 display
->getstringsize(string
, &w
, &h
);
55 if (w
> display
->lcdwidth
|| h
> display
->lcdheight
) {
56 rb
->splash(0, string
);
58 display
->putsxy((display
->lcdwidth
- w
) / 2,
59 (display
->lcdheight
- h
) / 2,
65 void draw(struct screen
* display
) {
67 display
->clear_display();
69 int secs
= rem_seconds();
72 rb
->snprintf(info
, sizeof(info
), "Next alarm in %02dh,"
73 " %02dmn, and %02ds.",
74 secs
/ 3600, (secs
/ 60) % 60, secs
% 60);
77 rb
->snprintf(info
, sizeof(info
), "Set alarm at [%02d]:%02d.",
81 rb
->snprintf(info
, sizeof(info
), "Set alarm at %02d:[%02d].",
85 draw_centered_string(display
, info
);
89 int audio_status
= rb
->audio_status();
90 if ((!audio_status
&& rb
->global_status
->resume_index
!= -1)
91 && (rb
->playlist_resume() != -1)) {
94 else if (audio_status
& AUDIO_STATUS_PAUSE
)
101 int audio_status
= rb
->audio_status();
102 if (!audio_status
&& rb
->global_status
->resume_index
!= -1) {
103 if (rb
->playlist_resume() != -1) {
104 rb
->playlist_start(rb
->global_status
->resume_index
,
105 rb
->global_status
->resume_offset
);
108 else if (audio_status
& AUDIO_STATUS_PAUSE
)
112 enum plugin_status
plugin_start(const void* parameter
)
119 rb
->splash(4*HZ
, "No track to resume! This plugin will resume a track "
120 "at a specific time. Therefore, you need to first play"
121 " one, and then pause it and start the plugin again.");
126 button
= get_button();
128 if (button
== PLA_QUIT
)
132 draw(rb
->screens
[i
]);
135 if (rem_seconds() <= 0) {
144 alarm
[current
] = (alarm
[current
] + 1) % maxval
[current
];
148 case PLA_DOWN_REPEAT
:
149 alarm
[current
] = (alarm
[current
] + maxval
[current
] - 1)
154 case PLA_LEFT_REPEAT
:
156 case PLA_RIGHT_REPEAT
:
157 current
= (current
+ 1) % 2;
161 if (rem_seconds() < 0)
169 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
176 return (usb
) ? PLUGIN_USB_CONNECTED
177 : (done
? PLUGIN_GOTO_WPS
: PLUGIN_OK
);