2010-02-25 14:45:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Clément Pit-Claudel
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "lib/pluginlib_actions.h"
|
|
|
|
|
2010-08-24 14:30:46 +00:00
|
|
|
|
2010-02-25 14:45:06 +00:00
|
|
|
|
2010-05-20 17:41:28 +00:00
|
|
|
const struct button_mapping *plugin_contexts[] = { pla_main_ctx };
|
2010-02-25 14:45:06 +00:00
|
|
|
|
|
|
|
static int current = 0;
|
2010-05-15 15:20:45 +00:00
|
|
|
static bool tomorrow = false;
|
2014-02-23 22:36:11 +00:00
|
|
|
static int alarms[2] = {0, 0}, maxval[2] = {24, 60}, prev_tick = 3600 * 24;
|
2010-02-25 14:45:06 +00:00
|
|
|
static bool quit = false, usb = false, waiting = false, done = false;
|
|
|
|
|
2010-10-07 13:19:21 +00:00
|
|
|
static inline int get_button(void)
|
|
|
|
{
|
2010-05-20 17:41:28 +00:00
|
|
|
return pluginlib_getaction(HZ/2, plugin_contexts,
|
|
|
|
ARRAYLEN(plugin_contexts));
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 13:19:21 +00:00
|
|
|
static int rem_seconds(void)
|
|
|
|
{
|
2014-02-23 22:36:11 +00:00
|
|
|
int seconds = (((alarms[0] - rb->get_time()->tm_hour) * 3600)
|
|
|
|
+((alarms[1] - rb->get_time()->tm_min) * 60)
|
2010-05-15 15:20:45 +00:00
|
|
|
-(rb->get_time()->tm_sec));
|
|
|
|
|
|
|
|
/* The tomorrow flag means that the alarm should ring on the next day */
|
|
|
|
if (seconds > prev_tick) tomorrow = false;
|
|
|
|
prev_tick = seconds;
|
|
|
|
|
|
|
|
return seconds + (tomorrow ? 24 * 3600 : 0);
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 13:19:21 +00:00
|
|
|
static void draw_centered_string(struct screen * display, char * string)
|
|
|
|
{
|
2010-02-26 07:38:18 +00:00
|
|
|
int w, h;
|
|
|
|
display->getstringsize(string, &w, &h);
|
|
|
|
|
|
|
|
if (w > display->lcdwidth || h > display->lcdheight) {
|
|
|
|
rb->splash(0, string);
|
|
|
|
} else {
|
|
|
|
display->putsxy((display->lcdwidth - w) / 2,
|
|
|
|
(display->lcdheight - h) / 2,
|
|
|
|
string);
|
|
|
|
display->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-07 13:19:21 +00:00
|
|
|
static void draw(struct screen * display)
|
|
|
|
{
|
2010-02-25 14:45:06 +00:00
|
|
|
char info[128];
|
2010-02-26 07:38:18 +00:00
|
|
|
display->clear_display();
|
2010-02-25 14:45:06 +00:00
|
|
|
|
|
|
|
int secs = rem_seconds();
|
|
|
|
|
|
|
|
if (waiting)
|
|
|
|
rb->snprintf(info, sizeof(info), "Next alarm in %02dh,"
|
|
|
|
" %02dmn, and %02ds.",
|
|
|
|
secs / 3600, (secs / 60) % 60, secs % 60);
|
|
|
|
else {
|
|
|
|
if (current == 0)
|
|
|
|
rb->snprintf(info, sizeof(info), "Set alarm at [%02d]:%02d.",
|
2014-02-23 22:36:11 +00:00
|
|
|
alarms[0],
|
|
|
|
alarms[1]);
|
2010-02-25 14:45:06 +00:00
|
|
|
else
|
|
|
|
rb->snprintf(info, sizeof(info), "Set alarm at %02d:[%02d].",
|
2014-02-23 22:36:11 +00:00
|
|
|
alarms[0],
|
|
|
|
alarms[1]);
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
2010-02-26 07:38:18 +00:00
|
|
|
draw_centered_string(display, info);
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
|
|
|
|
2010-10-07 13:19:21 +00:00
|
|
|
static bool can_play(void)
|
|
|
|
{
|
2010-02-25 14:45:06 +00:00
|
|
|
int audio_status = rb->audio_status();
|
|
|
|
if ((!audio_status && rb->global_status->resume_index != -1)
|
|
|
|
&& (rb->playlist_resume() != -1)) {
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-07 13:19:21 +00:00
|
|
|
else if (audio_status & AUDIO_STATUS_PLAY)
|
2010-02-25 14:45:06 +00:00
|
|
|
return true;
|
|
|
|
|
2010-05-15 15:20:45 +00:00
|
|
|
return false;
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 22:36:11 +00:00
|
|
|
static void resume_audio(void)
|
2010-10-07 13:19:21 +00:00
|
|
|
{
|
2010-02-25 14:45:06 +00:00
|
|
|
int audio_status = rb->audio_status();
|
|
|
|
if (!audio_status && rb->global_status->resume_index != -1) {
|
|
|
|
if (rb->playlist_resume() != -1) {
|
2012-12-09 20:04:17 +00:00
|
|
|
rb->playlist_resume_track(rb->global_status->resume_index,
|
|
|
|
rb->global_status->resume_crc32,
|
2010-02-25 14:45:06 +00:00
|
|
|
rb->global_status->resume_offset);
|
|
|
|
}
|
|
|
|
}
|
2010-10-07 13:19:21 +00:00
|
|
|
else if (audio_status & AUDIO_STATUS_PLAY)
|
2010-02-25 14:45:06 +00:00
|
|
|
rb->audio_resume();
|
|
|
|
}
|
|
|
|
|
2014-02-23 22:36:11 +00:00
|
|
|
static void pause_audio(void)
|
2010-10-07 13:19:21 +00:00
|
|
|
{
|
|
|
|
if (rb->audio_status() & AUDIO_STATUS_PLAY)
|
|
|
|
rb->audio_pause();
|
|
|
|
}
|
|
|
|
|
2010-02-25 14:45:06 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
if (!can_play()) {
|
2010-10-07 13:19:21 +00:00
|
|
|
rb->splash(HZ*2, "No track to resume! "
|
|
|
|
"Play or pause one first.");
|
|
|
|
return PLUGIN_ERROR;
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
2014-02-23 22:36:11 +00:00
|
|
|
pause_audio();
|
2010-02-25 14:45:06 +00:00
|
|
|
|
|
|
|
while(!quit) {
|
|
|
|
button = get_button();
|
|
|
|
|
2010-05-28 21:08:52 +00:00
|
|
|
if (button == PLA_EXIT || button == PLA_CANCEL)
|
2010-02-25 14:45:06 +00:00
|
|
|
quit = true;
|
|
|
|
|
2010-02-26 07:38:18 +00:00
|
|
|
FOR_NB_SCREENS(i) {
|
|
|
|
draw(rb->screens[i]);
|
|
|
|
}
|
2010-02-25 14:45:06 +00:00
|
|
|
if (waiting) {
|
|
|
|
if (rem_seconds() <= 0) {
|
|
|
|
quit = done = true;
|
2014-02-23 22:36:11 +00:00
|
|
|
resume_audio();
|
2010-02-25 14:45:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (button) {
|
|
|
|
case PLA_UP:
|
|
|
|
case PLA_UP_REPEAT:
|
2010-05-28 21:08:52 +00:00
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
|
|
|
case PLA_SCROLL_FWD:
|
|
|
|
case PLA_SCROLL_FWD_REPEAT:
|
|
|
|
#endif
|
2014-02-23 22:36:11 +00:00
|
|
|
alarms[current] = (alarms[current] + 1) % maxval[current];
|
2010-02-25 14:45:06 +00:00
|
|
|
break;
|
|
|
|
case PLA_DOWN:
|
|
|
|
case PLA_DOWN_REPEAT:
|
2010-05-28 21:08:52 +00:00
|
|
|
#ifdef HAVE_SCROLLWHEEL
|
|
|
|
case PLA_SCROLL_BACK:
|
|
|
|
case PLA_SCROLL_BACK_REPEAT:
|
|
|
|
#endif
|
2014-02-23 22:36:11 +00:00
|
|
|
alarms[current] = (alarms[current] + maxval[current] - 1)
|
2010-02-25 14:45:06 +00:00
|
|
|
% maxval[current];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PLA_LEFT:
|
|
|
|
case PLA_LEFT_REPEAT:
|
|
|
|
case PLA_RIGHT:
|
|
|
|
case PLA_RIGHT_REPEAT:
|
|
|
|
current = (current + 1) % 2;
|
|
|
|
break;
|
|
|
|
|
2010-05-20 17:41:28 +00:00
|
|
|
case PLA_SELECT:
|
|
|
|
case PLA_SELECT_REPEAT: {
|
2010-02-25 14:45:06 +00:00
|
|
|
if (rem_seconds() < 0)
|
2010-05-15 15:20:45 +00:00
|
|
|
tomorrow = true;
|
2010-02-25 14:45:06 +00:00
|
|
|
|
|
|
|
waiting = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
quit = usb = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return (usb) ? PLUGIN_USB_CONNECTED
|
|
|
|
: (done ? PLUGIN_GOTO_WPS : PLUGIN_OK);
|
|
|
|
}
|