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
[] = { pla_main_ctx
};
29 static int current
= 0;
30 static bool tomorrow
= false;
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;
34 static inline int get_button(void)
36 return pluginlib_getaction(HZ
/2, plugin_contexts
,
37 ARRAYLEN(plugin_contexts
));
40 static int rem_seconds(void)
42 int seconds
= (((alarm
[0] - rb
->get_time()->tm_hour
) * 3600)
43 +((alarm
[1] - rb
->get_time()->tm_min
) * 60)
44 -(rb
->get_time()->tm_sec
));
46 /* The tomorrow flag means that the alarm should ring on the next day */
47 if (seconds
> prev_tick
) tomorrow
= false;
50 return seconds
+ (tomorrow
? 24 * 3600 : 0);
53 static void draw_centered_string(struct screen
* display
, char * string
)
56 display
->getstringsize(string
, &w
, &h
);
58 if (w
> display
->lcdwidth
|| h
> display
->lcdheight
) {
59 rb
->splash(0, string
);
61 display
->putsxy((display
->lcdwidth
- w
) / 2,
62 (display
->lcdheight
- h
) / 2,
68 static void draw(struct screen
* display
)
71 display
->clear_display();
73 int secs
= rem_seconds();
76 rb
->snprintf(info
, sizeof(info
), "Next alarm in %02dh,"
77 " %02dmn, and %02ds.",
78 secs
/ 3600, (secs
/ 60) % 60, secs
% 60);
81 rb
->snprintf(info
, sizeof(info
), "Set alarm at [%02d]:%02d.",
85 rb
->snprintf(info
, sizeof(info
), "Set alarm at %02d:[%02d].",
89 draw_centered_string(display
, info
);
92 static bool can_play(void)
94 int audio_status
= rb
->audio_status();
95 if ((!audio_status
&& rb
->global_status
->resume_index
!= -1)
96 && (rb
->playlist_resume() != -1)) {
99 else if (audio_status
& AUDIO_STATUS_PLAY
)
105 static void play(void)
107 int audio_status
= rb
->audio_status();
108 if (!audio_status
&& rb
->global_status
->resume_index
!= -1) {
109 if (rb
->playlist_resume() != -1) {
110 rb
->playlist_start(rb
->global_status
->resume_index
,
111 rb
->global_status
->resume_offset
);
114 else if (audio_status
& AUDIO_STATUS_PLAY
)
118 static void pause(void)
120 if (rb
->audio_status() & AUDIO_STATUS_PLAY
)
124 enum plugin_status
plugin_start(const void* parameter
)
131 rb
->splash(HZ
*2, "No track to resume! "
132 "Play or pause one first.");
138 button
= get_button();
140 if (button
== PLA_EXIT
|| button
== PLA_CANCEL
)
144 draw(rb
->screens
[i
]);
147 if (rem_seconds() <= 0) {
156 #ifdef HAVE_SCROLLWHEEL
158 case PLA_SCROLL_FWD_REPEAT
:
160 alarm
[current
] = (alarm
[current
] + 1) % maxval
[current
];
163 case PLA_DOWN_REPEAT
:
164 #ifdef HAVE_SCROLLWHEEL
165 case PLA_SCROLL_BACK
:
166 case PLA_SCROLL_BACK_REPEAT
:
168 alarm
[current
] = (alarm
[current
] + maxval
[current
] - 1)
173 case PLA_LEFT_REPEAT
:
175 case PLA_RIGHT_REPEAT
:
176 current
= (current
+ 1) % 2;
180 case PLA_SELECT_REPEAT
: {
181 if (rem_seconds() < 0)
189 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
196 return (usb
) ? PLUGIN_USB_CONNECTED
197 : (done
? PLUGIN_GOTO_WPS
: PLUGIN_OK
);