1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Kévin Ferrare, graphic design 2003 Zakk Roberts
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 ****************************************************************************/
24 #include "lib/pluginlib_actions.h"
25 #include "lib/pluginlib_exit.h"
29 #include "clock_counter.h"
30 #include "clock_draw.h"
31 #include "clock_menu.h"
32 #include "clock_settings.h"
37 const struct button_mapping
* plugin_contexts
[]={
39 #ifdef HAVE_REMOTE_LCD
43 #define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
45 #define ACTION_COUNTER_TOGGLE PLA_SELECT
46 #define ACTION_COUNTER_RESET PLA_SELECT_REPEAT
47 #define ACTION_MENU PLA_CANCEL
48 #define ACTION_MODE_NEXT PLA_RIGHT
49 #define ACTION_MODE_NEXT_REPEAT PLA_RIGHT_REPEAT
50 #define ACTION_MODE_PREV PLA_LEFT
51 #define ACTION_MODE_PREV_REPEAT PLA_LEFT_REPEAT
52 #define ACTION_SKIN_NEXT PLA_UP
53 #define ACTION_SKIN_NEXT_REPEAT PLA_UP_REPEAT
54 #define ACTION_SKIN_PREV PLA_DOWN
55 #define ACTION_SKIN_PREV_REPEAT PLA_DOWN_REPEAT
57 /**************************
58 * Cleanup on plugin return
59 *************************/
60 static void cleanup(void)
62 clock_draw_restore_colors();
63 if(clock_settings
.general
.save_settings
== 1)
66 /* restore set backlight timeout */
67 rb
->backlight_set_timeout(rb
->global_settings
->backlight_timeout
);
70 /* puts the current time into the time struct */
71 static void clock_update_time( struct time
* time
){
72 struct tm
* current_time
= rb
->get_time();
73 time
->hour
= current_time
->tm_hour
;
74 time
->minute
= current_time
->tm_min
;
75 time
->second
= current_time
->tm_sec
;
77 /*********************
79 *********************/
80 time
->year
= current_time
->tm_year
+ 1900;
81 time
->day
= current_time
->tm_mday
;
82 time
->month
= current_time
->tm_mon
+ 1;
86 void format_date(char* buffer
, struct time
* time
, enum date_format format
){
89 rb
->snprintf(buffer
, 20, "%04d/%02d/%02d",
90 time
->year
, time
->month
, time
->day
);
93 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
94 time
->day
, time
->month
, time
->year
);
97 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
98 time
->month
, time
->day
, time
->year
);
106 /**********************************************************************
108 **********************************************************************/
109 enum plugin_status
plugin_start(const void* parameter
){
111 int last_second
= -1;
114 struct counter counter
;
115 bool exit_clock
= false;
120 rb
->lcd_set_backdrop(NULL
);
125 /* init xlcd functions */
126 counter_init(&counter
);
127 clock_draw_set_colors();
130 clock_update_time(&time
);
132 if(!clock_settings
.general
.idle_poweroff
)
133 rb
->reset_poweroff_timer();
135 /*************************
136 * Scan for button presses
137 ************************/
138 button
= pluginlib_getaction(HZ
/10, plugin_contexts
, PLA_ARRAY_COUNT
);
139 redraw
=true;/* we'll set it to false afterwards if there was no action */
141 case ACTION_COUNTER_TOGGLE
: /* start/stop counter */
142 if(clock_settings
.general
.show_counter
)
143 counter_toggle(&counter
);
146 case ACTION_COUNTER_RESET
: /* reset counter */
147 if(clock_settings
.general
.show_counter
)
148 counter_reset(&counter
);
151 case ACTION_MODE_NEXT_REPEAT
:
152 case ACTION_MODE_NEXT
:
153 clock_settings
.mode
++;
154 if(clock_settings
.mode
>= NB_CLOCK_MODES
)
155 clock_settings
.mode
= 0;
158 case ACTION_MODE_PREV_REPEAT
:
159 case ACTION_MODE_PREV
:
160 clock_settings
.mode
--;
161 if(clock_settings
.mode
< 0)
162 clock_settings
.mode
= NB_CLOCK_MODES
-1;
164 case ACTION_SKIN_PREV_REPEAT
:
165 case ACTION_SKIN_PREV
:
166 clock_settings_skin_next(&clock_settings
);
168 case ACTION_SKIN_NEXT_REPEAT
:
169 case ACTION_SKIN_NEXT
:
170 clock_settings_skin_previous(&clock_settings
);
173 clock_draw_restore_colors();
174 exit_clock
=main_menu();
178 if(time
.second
!= last_second
){
179 last_second
=time
.second
;
187 clock_draw_set_colors();
189 clock_draw(rb
->screens
[i
], &time
, &counter
);