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 * 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 ****************************************************************************/
22 #include "pluginlib_actions.h"
26 #include "clock_counter.h"
27 #include "clock_draw.h"
28 #include "clock_menu.h"
29 #include "clock_settings.h"
34 const struct button_mapping
* plugin_contexts
[]={
36 generic_increase_decrease
,
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
)
65 clock_draw_restore_colors();
66 if(clock_settings
.general
.save_settings
== 1)
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 /*********************
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
){
92 rb
->snprintf(buffer
, 20, "%04d/%02d/%02d",
93 time
->year
, time
->month
, time
->day
);
96 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
97 time
->day
, time
->month
, time
->year
);
100 rb
->snprintf(buffer
, 20, "%02d/%02d/%04d",
101 time
->month
, time
->day
, time
->year
);
109 /**********************************************************************
111 **********************************************************************/
112 enum plugin_status
plugin_start(const struct plugin_api
* api
, const void* parameter
){
114 int last_second
= -1;
118 struct counter counter
;
119 bool exit_clock
= false;
124 rb
->lcd_set_backdrop(NULL
);
129 /* init xlcd functions */
131 counter_init(&counter
);
132 clock_draw_set_colors();
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 */
146 case ACTION_COUNTER_TOGGLE
: /* start/stop counter */
147 if(clock_settings
.general
.show_counter
)
148 counter_toggle(&counter
);
151 case ACTION_COUNTER_RESET
: /* reset counter */
152 if(clock_settings
.general
.show_counter
)
153 counter_reset(&counter
);
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;
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;
169 case ACTION_SKIN_PREV_REPEAT
:
170 case ACTION_SKIN_PREV
:
171 clock_settings_skin_next(&clock_settings
);
173 case ACTION_SKIN_NEXT_REPEAT
:
174 case ACTION_SKIN_NEXT
:
175 clock_settings_skin_previous(&clock_settings
);
178 clock_draw_restore_colors();
179 exit_clock
=main_menu();
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
;
199 clock_draw_set_colors();
201 clock_draw(rb
->screens
[i
], &time
, &counter
);