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 int alarm
[2] = {0, 0}, maxval
[2] = {24, 60};
32 static bool quit
= false, usb
= false, waiting
= false, done
= false;
34 static inline int get_button(void) {
35 return pluginlib_getaction(HZ
/2, plugin_contexts
, 2);
38 int rem_seconds(void) {
39 return (((alarm
[0] - rb
->get_time()->tm_hour
) * 3600)
40 +((alarm
[1] - rb
->get_time()->tm_min
) * 60)
41 -(rb
->get_time()->tm_sec
));
44 void draw_centered_string(struct screen
* display
, char * string
) {
46 display
->getstringsize(string
, &w
, &h
);
48 if (w
> display
->lcdwidth
|| h
> display
->lcdheight
) {
49 rb
->splash(0, string
);
51 display
->putsxy((display
->lcdwidth
- w
) / 2,
52 (display
->lcdheight
- h
) / 2,
58 void draw(struct screen
* display
) {
60 display
->clear_display();
62 int secs
= rem_seconds();
65 rb
->snprintf(info
, sizeof(info
), "Next alarm in %02dh,"
66 " %02dmn, and %02ds.",
67 secs
/ 3600, (secs
/ 60) % 60, secs
% 60);
70 rb
->snprintf(info
, sizeof(info
), "Set alarm at [%02d]:%02d.",
74 rb
->snprintf(info
, sizeof(info
), "Set alarm at %02d:[%02d].",
78 draw_centered_string(display
, info
);
82 int audio_status
= rb
->audio_status();
83 if ((!audio_status
&& rb
->global_status
->resume_index
!= -1)
84 && (rb
->playlist_resume() != -1)) {
87 else if (audio_status
& AUDIO_STATUS_PAUSE
)
94 int audio_status
= rb
->audio_status();
95 if (!audio_status
&& rb
->global_status
->resume_index
!= -1) {
96 if (rb
->playlist_resume() != -1) {
97 rb
->playlist_start(rb
->global_status
->resume_index
,
98 rb
->global_status
->resume_offset
);
101 else if (audio_status
& AUDIO_STATUS_PAUSE
)
105 enum plugin_status
plugin_start(const void* parameter
)
112 rb
->splash(4*HZ
, "No track to resume! This plugin will resume a track "
113 "at a specific time. Therefore, you need to first play"
114 " one, and then pause it and start the plugin again.");
119 button
= get_button();
121 if (button
== PLA_QUIT
)
125 draw(rb
->screens
[i
]);
128 if (rem_seconds() <= 0) {
137 alarm
[current
] = (alarm
[current
] + 1) % maxval
[current
];
141 case PLA_DOWN_REPEAT
:
142 alarm
[current
] = (alarm
[current
] + maxval
[current
] - 1)
147 case PLA_LEFT_REPEAT
:
149 case PLA_RIGHT_REPEAT
:
150 current
= (current
+ 1) % 2;
154 if (rem_seconds() < 0)
162 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
169 return (usb
) ? PLUGIN_USB_CONNECTED
170 : (done
? PLUGIN_GOTO_WPS
: PLUGIN_OK
);