1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 /**************************
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 void* parameter
){
114 int last_second
= -1;
118 struct counter counter
;
119 bool exit_clock
= false;
123 rb
->lcd_set_backdrop(NULL
);
128 /* init xlcd functions */
129 counter_init(&counter
);
130 clock_draw_set_colors();
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 */
144 case ACTION_COUNTER_TOGGLE
: /* start/stop counter */
145 if(clock_settings
.general
.show_counter
)
146 counter_toggle(&counter
);
149 case ACTION_COUNTER_RESET
: /* reset counter */
150 if(clock_settings
.general
.show_counter
)
151 counter_reset(&counter
);
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;
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;
167 case ACTION_SKIN_PREV_REPEAT
:
168 case ACTION_SKIN_PREV
:
169 clock_settings_skin_next(&clock_settings
);
171 case ACTION_SKIN_NEXT_REPEAT
:
172 case ACTION_SKIN_NEXT
:
173 clock_settings_skin_previous(&clock_settings
);
176 clock_draw_restore_colors();
177 exit_clock
=main_menu();
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
;
197 clock_draw_set_colors();
199 clock_draw(rb
->screens
[i
], &time
, &counter
);