Add effective clockrate for realtime decoding to the displayed results of test_codec...
[kugel-rb.git] / apps / plugins / clock / clock.c
blob588112cf634881beea43e79134e8b2985291c983
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: clock.c 14095 2007-07-31 10:53:53Z nls $
10 * Copyright (C) 2007 Kévin Ferrare, graphic design 2003 Zakk Roberts
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #include "plugin.h"
21 #include "time.h"
22 #include "pluginlib_actions.h"
23 #include "xlcd.h"
25 #include "clock.h"
26 #include "clock_counter.h"
27 #include "clock_draw.h"
28 #include "clock_menu.h"
29 #include "clock_settings.h"
31 PLUGIN_HEADER
33 /* Keymaps */
34 const struct button_mapping* plugin_contexts[]={
35 generic_actions,
36 generic_increase_decrease,
37 generic_directions,
38 #if NB_SCREENS == 2
39 remote_directions
40 #endif
42 #define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
44 #define ACTION_COUNTER_TOGGLE PLA_FIRE
45 #define ACTION_COUNTER_RESET PLA_FIRE_REPEAT
46 #define ACTION_MENU PLA_MENU
47 #define ACTION_EXIT PLA_QUIT
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_INC
53 #define ACTION_SKIN_NEXT_REPEAT PLA_INC_REPEAT
54 #define ACTION_SKIN_PREV PLA_DEC
55 #define ACTION_SKIN_PREV_REPEAT PLA_DEC_REPEAT
57 extern const struct plugin_api* rb;
59 /**************************
60 * Cleanup on plugin return
61 *************************/
62 void cleanup(void *parameter)
64 (void)parameter;
65 clock_draw_restore_colors();
66 if(clock_settings.general.save_settings == 1)
67 save_settings();
69 /* restore set backlight timeout */
70 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
73 /* puts the current time into the time struct */
74 void clock_update_time( struct time* time){
75 struct tm* current_time = rb->get_time();
76 time->hour = current_time->tm_hour;
77 time->minute = current_time->tm_min;
78 time->second = current_time->tm_sec;
80 /*********************
81 * Date info
82 *********************/
83 time->year = current_time->tm_year + 1900;
84 time->day = current_time->tm_mday;
85 time->month = current_time->tm_mon + 1;
89 void format_date(char* buffer, struct time* time, enum date_format format){
90 switch(format){
91 case JAPANESE:
92 rb->snprintf(buffer, 20, "%04d/%02d/%02d",
93 time->year, time->month, time->day);
94 break;
95 case EUROPEAN:
96 rb->snprintf(buffer, 20, "%02d/%02d/%04d",
97 time->day, time->month, time->year);
98 break;
99 case ENGLISH:
100 rb->snprintf(buffer, 20, "%02d/%02d/%04d",
101 time->month, time->day, time->year);
102 break;
103 case NONE:
104 default:
105 break;
109 /**********************************************************************
110 * Plugin starts here
111 **********************************************************************/
112 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter){
113 int button;
114 int last_second = -1;
115 bool redraw=true;
116 int i;
117 struct time time;
118 struct counter counter;
119 bool exit_clock = false;
120 (void)parameter;
121 rb = api;
123 #if LCD_DEPTH > 1
124 rb->lcd_set_backdrop(NULL);
125 #endif
127 load_settings();
129 /* init xlcd functions */
130 xlcd_init(rb);
131 counter_init(&counter);
132 clock_draw_set_colors();
134 while(!exit_clock){
135 clock_update_time(&time);
137 if(!clock_settings.general.idle_poweroff)
138 rb->reset_poweroff_timer();
140 /*************************
141 * Scan for button presses
142 ************************/
143 button = pluginlib_getaction(rb, HZ/10, plugin_contexts, PLA_ARRAY_COUNT);
144 redraw=true;/* we'll set it to false afterwards if there was no action */
145 switch (button){
146 case ACTION_COUNTER_TOGGLE: /* start/stop counter */
147 if(clock_settings.general.show_counter)
148 counter_toggle(&counter);
149 break;
151 case ACTION_COUNTER_RESET: /* reset counter */
152 if(clock_settings.general.show_counter)
153 counter_reset(&counter);
154 break;
156 case ACTION_MODE_NEXT_REPEAT:
157 case ACTION_MODE_NEXT:
158 clock_settings.mode++;
159 if(clock_settings.mode >= NB_CLOCK_MODES)
160 clock_settings.mode = 0;
161 break;
163 case ACTION_MODE_PREV_REPEAT:
164 case ACTION_MODE_PREV:
165 clock_settings.mode--;
166 if(clock_settings.mode < 0)
167 clock_settings.mode = NB_CLOCK_MODES-1;
168 break;
169 case ACTION_SKIN_PREV_REPEAT:
170 case ACTION_SKIN_PREV:
171 clock_settings_skin_next(&clock_settings);
172 break;
173 case ACTION_SKIN_NEXT_REPEAT:
174 case ACTION_SKIN_NEXT:
175 clock_settings_skin_previous(&clock_settings);
176 break;
177 case ACTION_MENU:
178 clock_draw_restore_colors();
179 exit_clock=main_menu();
180 break;
182 case ACTION_EXIT:
183 exit_clock=true;
184 break;
186 default:
187 if(rb->default_event_handler_ex(button, cleanup, NULL)
188 == SYS_USB_CONNECTED)
189 return PLUGIN_USB_CONNECTED;
190 if(time.second != last_second){
191 last_second=time.second;
192 redraw=true;
193 }else
194 redraw=false;
195 break;
198 if(redraw){
199 clock_draw_set_colors();
200 FOR_NB_SCREENS(i)
201 clock_draw(rb->screens[i], &time, &counter);
202 redraw=false;
206 cleanup(NULL);
207 return PLUGIN_OK;