set svn:keywords property
[kugel-rb.git] / apps / plugins / clock / clock.c
blob1937954a0f129ffc8b0fcb4ca04b19d5a0c4f29d
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
22 #include "plugin.h"
23 #include "time.h"
24 #include "lib/pluginlib_actions.h"
25 #include "lib/xlcd.h"
27 #include "clock.h"
28 #include "clock_counter.h"
29 #include "clock_draw.h"
30 #include "clock_menu.h"
31 #include "clock_settings.h"
33 PLUGIN_HEADER
35 /* Keymaps */
36 const struct button_mapping* plugin_contexts[]={
37 generic_actions,
38 generic_increase_decrease,
39 generic_directions,
40 #if NB_SCREENS == 2
41 remote_directions
42 #endif
44 #define PLA_ARRAY_COUNT sizeof(plugin_contexts)/sizeof(plugin_contexts[0])
46 #define ACTION_COUNTER_TOGGLE PLA_FIRE
47 #define ACTION_COUNTER_RESET PLA_FIRE_REPEAT
48 #define ACTION_MENU PLA_MENU
49 #define ACTION_EXIT PLA_QUIT
50 #define ACTION_MODE_NEXT PLA_RIGHT
51 #define ACTION_MODE_NEXT_REPEAT PLA_RIGHT_REPEAT
52 #define ACTION_MODE_PREV PLA_LEFT
53 #define ACTION_MODE_PREV_REPEAT PLA_LEFT_REPEAT
54 #define ACTION_SKIN_NEXT PLA_INC
55 #define ACTION_SKIN_NEXT_REPEAT PLA_INC_REPEAT
56 #define ACTION_SKIN_PREV PLA_DEC
57 #define ACTION_SKIN_PREV_REPEAT PLA_DEC_REPEAT
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 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;
122 #if LCD_DEPTH > 1
123 rb->lcd_set_backdrop(NULL);
124 #endif
126 load_settings();
128 /* init xlcd functions */
129 counter_init(&counter);
130 clock_draw_set_colors();
132 while(!exit_clock){
133 clock_update_time(&time);
135 if(!clock_settings.general.idle_poweroff)
136 rb->reset_poweroff_timer();
138 /*************************
139 * Scan for button presses
140 ************************/
141 button = pluginlib_getaction(HZ/10, plugin_contexts, PLA_ARRAY_COUNT);
142 redraw=true;/* we'll set it to false afterwards if there was no action */
143 switch (button){
144 case ACTION_COUNTER_TOGGLE: /* start/stop counter */
145 if(clock_settings.general.show_counter)
146 counter_toggle(&counter);
147 break;
149 case ACTION_COUNTER_RESET: /* reset counter */
150 if(clock_settings.general.show_counter)
151 counter_reset(&counter);
152 break;
154 case ACTION_MODE_NEXT_REPEAT:
155 case ACTION_MODE_NEXT:
156 clock_settings.mode++;
157 if(clock_settings.mode >= NB_CLOCK_MODES)
158 clock_settings.mode = 0;
159 break;
161 case ACTION_MODE_PREV_REPEAT:
162 case ACTION_MODE_PREV:
163 clock_settings.mode--;
164 if(clock_settings.mode < 0)
165 clock_settings.mode = NB_CLOCK_MODES-1;
166 break;
167 case ACTION_SKIN_PREV_REPEAT:
168 case ACTION_SKIN_PREV:
169 clock_settings_skin_next(&clock_settings);
170 break;
171 case ACTION_SKIN_NEXT_REPEAT:
172 case ACTION_SKIN_NEXT:
173 clock_settings_skin_previous(&clock_settings);
174 break;
175 case ACTION_MENU:
176 clock_draw_restore_colors();
177 exit_clock=main_menu();
178 break;
180 case ACTION_EXIT:
181 exit_clock=true;
182 break;
184 default:
185 if(rb->default_event_handler_ex(button, cleanup, NULL)
186 == SYS_USB_CONNECTED)
187 return PLUGIN_USB_CONNECTED;
188 if(time.second != last_second){
189 last_second=time.second;
190 redraw=true;
191 }else
192 redraw=false;
193 break;
196 if(redraw){
197 clock_draw_set_colors();
198 FOR_NB_SCREENS(i)
199 clock_draw(rb->screens[i], &time, &counter);
200 redraw=false;
204 cleanup(NULL);
205 return PLUGIN_OK;