diff options
Diffstat (limited to 'apps/plugins/clock/clock.c')
-rw-r--r-- | apps/plugins/clock/clock.c | 199 |
1 files changed, 199 insertions, 0 deletions
diff --git a/apps/plugins/clock/clock.c b/apps/plugins/clock/clock.c new file mode 100644 index 0000000000..46d167ba54 --- /dev/null +++ b/apps/plugins/clock/clock.c | |||
@@ -0,0 +1,199 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id: clock.c 14095 2007-07-31 10:53:53Z nls $ | ||
9 | * | ||
10 | * Copyright (C) 2007 Kévin Ferrare | ||
11 | * | ||
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. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "plugin.h" | ||
21 | #include "time.h" | ||
22 | #include "pluginlib_actions.h" | ||
23 | #include "xlcd.h" | ||
24 | |||
25 | #include "clock.h" | ||
26 | #include "clock_counter.h" | ||
27 | #include "clock_draw.h" | ||
28 | #include "clock_menu.h" | ||
29 | #include "clock_settings.h" | ||
30 | |||
31 | PLUGIN_HEADER | ||
32 | |||
33 | /* Keymaps */ | ||
34 | const struct button_mapping* plugin_contexts[]={ | ||
35 | generic_actions, | ||
36 | generic_directions, | ||
37 | #if NB_SCREENS == 2 | ||
38 | remote_directions | ||
39 | #endif | ||
40 | }; | ||
41 | #define NB_ACTION_CONTEXTS sizeof(plugin_contexts)/sizeof(plugin_contexts[0]) | ||
42 | #define ACTION_COUNTER_TOGGLE PLA_FIRE | ||
43 | #define ACTION_COUNTER_RESET PLA_FIRE_REPEAT | ||
44 | #define ACTION_MENU PLA_MENU | ||
45 | #define ACTION_EXIT PLA_QUIT | ||
46 | #define ACTION_MODE_NEXT PLA_RIGHT | ||
47 | #define ACTION_MODE_PREV PLA_LEFT | ||
48 | #define ACTION_SKIN_NEXT PLA_UP | ||
49 | #define ACTION_SKIN_PREV PLA_DOWN | ||
50 | |||
51 | extern struct plugin_api* rb; | ||
52 | |||
53 | /************************** | ||
54 | * Cleanup on plugin return | ||
55 | *************************/ | ||
56 | void cleanup(void *parameter) | ||
57 | { | ||
58 | (void)parameter; | ||
59 | clock_draw_restore_colors(); | ||
60 | if(clock_settings.general.save_settings == 1) | ||
61 | save_settings(); | ||
62 | |||
63 | /* restore set backlight timeout */ | ||
64 | rb->backlight_set_timeout(rb->global_settings->backlight_timeout); | ||
65 | } | ||
66 | |||
67 | /* puts the current time into the time struct */ | ||
68 | void clock_update_time( struct time* time){ | ||
69 | struct tm* current_time = rb->get_time(); | ||
70 | time->hour = current_time->tm_hour; | ||
71 | time->minute = current_time->tm_min; | ||
72 | time->second = current_time->tm_sec; | ||
73 | |||
74 | /********************* | ||
75 | * Date info | ||
76 | *********************/ | ||
77 | time->year = current_time->tm_year + 1900; | ||
78 | time->day = current_time->tm_mday; | ||
79 | time->month = current_time->tm_mon + 1; | ||
80 | |||
81 | } | ||
82 | |||
83 | void format_date(char* buffer, struct time* time, enum date_format format){ | ||
84 | switch(format){ | ||
85 | case JAPANESE: | ||
86 | rb->snprintf(buffer, 20, "%04d/%02d/%02d", | ||
87 | time->year, time->month, time->day); | ||
88 | break; | ||
89 | case EUROPEAN: | ||
90 | rb->snprintf(buffer, 20, "%02d/%02d/%04d", | ||
91 | time->day, time->month, time->year); | ||
92 | break; | ||
93 | case ENGLISH: | ||
94 | rb->snprintf(buffer, 20, "%02d/%02d/%04d", | ||
95 | time->month, time->day, time->year); | ||
96 | break; | ||
97 | case NONE: | ||
98 | default: | ||
99 | break; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | /********************************************************************** | ||
104 | * Plugin starts here | ||
105 | **********************************************************************/ | ||
106 | enum plugin_status plugin_start(struct plugin_api* api, void* parameter){ | ||
107 | int button; | ||
108 | int last_second = -1; | ||
109 | bool redraw=true; | ||
110 | int i; | ||
111 | struct time time; | ||
112 | struct counter counter; | ||
113 | bool exit_clock = false; | ||
114 | (void)parameter; | ||
115 | rb = api; | ||
116 | |||
117 | #if LCD_DEPTH > 1 | ||
118 | rb->lcd_set_backdrop(NULL); | ||
119 | #endif | ||
120 | |||
121 | load_settings(); | ||
122 | |||
123 | /* init xlcd functions */ | ||
124 | xlcd_init(rb); | ||
125 | counter_init(&counter); | ||
126 | clock_draw_set_colors(); | ||
127 | |||
128 | while(!exit_clock){ | ||
129 | clock_update_time(&time); | ||
130 | |||
131 | if(!clock_settings.general.idle_poweroff) | ||
132 | rb->reset_poweroff_timer(); | ||
133 | |||
134 | /************************* | ||
135 | * Scan for button presses | ||
136 | ************************/ | ||
137 | button = pluginlib_getaction(rb, HZ/10, plugin_contexts, NB_ACTION_CONTEXTS); | ||
138 | redraw=true;/* we'll set it to false afterwards if there was no action */ | ||
139 | switch (button){ | ||
140 | case ACTION_COUNTER_TOGGLE: /* start/stop counter */ | ||
141 | if(clock_settings.general.show_counter) | ||
142 | counter_toggle(&counter); | ||
143 | break; | ||
144 | |||
145 | case ACTION_COUNTER_RESET: /* reset counter */ | ||
146 | if(clock_settings.general.show_counter) | ||
147 | counter_reset(&counter); | ||
148 | break; | ||
149 | |||
150 | case ACTION_MODE_NEXT: | ||
151 | clock_settings.mode++; | ||
152 | if(clock_settings.mode >= NB_CLOCK_MODES) | ||
153 | clock_settings.mode = 0; | ||
154 | break; | ||
155 | |||
156 | case ACTION_MODE_PREV: | ||
157 | clock_settings.mode--; | ||
158 | if(clock_settings.mode < 0) | ||
159 | clock_settings.mode = NB_CLOCK_MODES-1; | ||
160 | break; | ||
161 | case ACTION_SKIN_PREV: | ||
162 | clock_settings_skin_next(&clock_settings); | ||
163 | break; | ||
164 | case ACTION_SKIN_NEXT: | ||
165 | clock_settings_skin_previous(&clock_settings); | ||
166 | break; | ||
167 | case ACTION_MENU: | ||
168 | clock_draw_restore_colors(); | ||
169 | exit_clock=main_menu(); | ||
170 | break; | ||
171 | |||
172 | case ACTION_EXIT: | ||
173 | /*clock_draw_restore_colors(); | ||
174 | exit_clock=main_menu();*/ | ||
175 | exit_clock=true; | ||
176 | break; | ||
177 | |||
178 | default: | ||
179 | redraw=false; | ||
180 | if(rb->default_event_handler_ex(button, cleanup, NULL) | ||
181 | == SYS_USB_CONNECTED) | ||
182 | return PLUGIN_USB_CONNECTED; | ||
183 | break; | ||
184 | } | ||
185 | if(time.second != last_second){ | ||
186 | last_second=time.second; | ||
187 | redraw=true; | ||
188 | } | ||
189 | if(redraw){ | ||
190 | clock_draw_set_colors(); | ||
191 | FOR_NB_SCREENS(i) | ||
192 | clock_draw(rb->screens[i], &time, &counter); | ||
193 | redraw=false; | ||
194 | } | ||
195 | } | ||
196 | |||
197 | cleanup(NULL); | ||
198 | return PLUGIN_OK; | ||
199 | } | ||