Don't objcopy simulator plugins.
[kugel-rb.git] / apps / plugins / clock / clock.c
blob9279a182ee16ae3791fa272a00c9a329d393e1b3
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 * 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 extern const struct plugin_api* rb;
61 /**************************
62 * Cleanup on plugin return
63 *************************/
64 void cleanup(void *parameter)
66 (void)parameter;
67 clock_draw_restore_colors();
68 if(clock_settings.general.save_settings == 1)
69 save_settings();
71 /* restore set backlight timeout */
72 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
75 /* puts the current time into the time struct */
76 void clock_update_time( struct time* time){
77 struct tm* current_time = rb->get_time();
78 time->hour = current_time->tm_hour;
79 time->minute = current_time->tm_min;
80 time->second = current_time->tm_sec;
82 /*********************
83 * Date info
84 *********************/
85 time->year = current_time->tm_year + 1900;
86 time->day = current_time->tm_mday;
87 time->month = current_time->tm_mon + 1;
91 void format_date(char* buffer, struct time* time, enum date_format format){
92 switch(format){
93 case JAPANESE:
94 rb->snprintf(buffer, 20, "%04d/%02d/%02d",
95 time->year, time->month, time->day);
96 break;
97 case EUROPEAN:
98 rb->snprintf(buffer, 20, "%02d/%02d/%04d",
99 time->day, time->month, time->year);
100 break;
101 case ENGLISH:
102 rb->snprintf(buffer, 20, "%02d/%02d/%04d",
103 time->month, time->day, time->year);
104 break;
105 case NONE:
106 default:
107 break;
111 /**********************************************************************
112 * Plugin starts here
113 **********************************************************************/
114 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter){
115 int button;
116 int last_second = -1;
117 bool redraw=true;
118 int i;
119 struct time time;
120 struct counter counter;
121 bool exit_clock = false;
122 (void)parameter;
123 rb = api;
125 #if LCD_DEPTH > 1
126 rb->lcd_set_backdrop(NULL);
127 #endif
129 load_settings();
131 /* init xlcd functions */
132 xlcd_init(rb);
133 counter_init(&counter);
134 clock_draw_set_colors();
136 while(!exit_clock){
137 clock_update_time(&time);
139 if(!clock_settings.general.idle_poweroff)
140 rb->reset_poweroff_timer();
142 /*************************
143 * Scan for button presses
144 ************************/
145 button = pluginlib_getaction(rb, HZ/10, plugin_contexts, PLA_ARRAY_COUNT);
146 redraw=true;/* we'll set it to false afterwards if there was no action */
147 switch (button){
148 case ACTION_COUNTER_TOGGLE: /* start/stop counter */
149 if(clock_settings.general.show_counter)
150 counter_toggle(&counter);
151 break;
153 case ACTION_COUNTER_RESET: /* reset counter */
154 if(clock_settings.general.show_counter)
155 counter_reset(&counter);
156 break;
158 case ACTION_MODE_NEXT_REPEAT:
159 case ACTION_MODE_NEXT:
160 clock_settings.mode++;
161 if(clock_settings.mode >= NB_CLOCK_MODES)
162 clock_settings.mode = 0;
163 break;
165 case ACTION_MODE_PREV_REPEAT:
166 case ACTION_MODE_PREV:
167 clock_settings.mode--;
168 if(clock_settings.mode < 0)
169 clock_settings.mode = NB_CLOCK_MODES-1;
170 break;
171 case ACTION_SKIN_PREV_REPEAT:
172 case ACTION_SKIN_PREV:
173 clock_settings_skin_next(&clock_settings);
174 break;
175 case ACTION_SKIN_NEXT_REPEAT:
176 case ACTION_SKIN_NEXT:
177 clock_settings_skin_previous(&clock_settings);
178 break;
179 case ACTION_MENU:
180 clock_draw_restore_colors();
181 exit_clock=main_menu();
182 break;
184 case ACTION_EXIT:
185 exit_clock=true;
186 break;
188 default:
189 if(rb->default_event_handler_ex(button, cleanup, NULL)
190 == SYS_USB_CONNECTED)
191 return PLUGIN_USB_CONNECTED;
192 if(time.second != last_second){
193 last_second=time.second;
194 redraw=true;
195 }else
196 redraw=false;
197 break;
200 if(redraw){
201 clock_draw_set_colors();
202 FOR_NB_SCREENS(i)
203 clock_draw(rb->screens[i], &time, &counter);
204 redraw=false;
208 cleanup(NULL);
209 return PLUGIN_OK;