1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
24 #include "lib/pluginlib_actions.h"
28 #include "clock_counter.h"
29 #include "clock_draw.h"
30 #include "clock_menu.h"
31 #include "clock_settings.h"
36 const struct button_mapping
* plugin_contexts
[]={
38 generic_increase_decrease
,
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
)
67 clock_draw_restore_colors();
68 if(clock_settings
.general
.save_settings
== 1)
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 /*********************
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
){
94 rb
->snprintf(buffer
, 20, "%04d/%02d/%02d",
95 time
->year
, time
->month
, time
->day
);
98 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
99 time
->day
, time
->month
, time
->year
);
102 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
103 time
->month
, time
->day
, time
->year
);
111 /**********************************************************************
113 **********************************************************************/
114 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
){
116 int last_second
= -1;
120 struct counter counter
;
121 bool exit_clock
= false;
126 rb
->lcd_set_backdrop(NULL
);
131 /* init xlcd functions */
133 counter_init(&counter
);
134 clock_draw_set_colors();
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 */
148 case ACTION_COUNTER_TOGGLE
: /* start/stop counter */
149 if(clock_settings
.general
.show_counter
)
150 counter_toggle(&counter
);
153 case ACTION_COUNTER_RESET
: /* reset counter */
154 if(clock_settings
.general
.show_counter
)
155 counter_reset(&counter
);
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;
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;
171 case ACTION_SKIN_PREV_REPEAT
:
172 case ACTION_SKIN_PREV
:
173 clock_settings_skin_next(&clock_settings
);
175 case ACTION_SKIN_NEXT_REPEAT
:
176 case ACTION_SKIN_NEXT
:
177 clock_settings_skin_previous(&clock_settings
);
180 clock_draw_restore_colors();
181 exit_clock
=main_menu();
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
;
201 clock_draw_set_colors();
203 clock_draw(rb
->screens
[i
], &time
, &counter
);