1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Jonathan Gordon
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 ****************************************************************************/
38 #include "alarm_menu.h"
44 static int timedate_set(void)
46 /* Make a local copy of the time struct */
47 struct tm tm
= *get_time();
50 /* do some range checks */
51 /* This prevents problems with time/date setting after a power loss */
54 /* Macros to convert a 2-digit string to a decimal constant.
55 (YEAR), MONTH and DAY are set by the date command, which outputs
56 DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
57 misinterpretation as an octal constant. */
58 #define S100(x) 1 ## x
59 #define C2DIG2DEC(x) (S100(x)-100)
64 tm
.tm_mday
= C2DIG2DEC(DAY
);
65 tm
.tm_mon
= C2DIG2DEC(MONTH
)-1;
67 tm
.tm_year
= YEAR
-1900;
70 result
= (int)set_time_screen(str(LANG_SET_TIME
), &tm
);
72 if(tm
.tm_year
!= -1) {
78 MENUITEM_FUNCTION(time_set
, 0, ID2P(LANG_SET_TIME
),
79 timedate_set
, NULL
, NULL
, Icon_NOICON
);
80 MENUITEM_SETTING(timeformat
, &global_settings
.timeformat
, NULL
);
82 MENUITEM_FUNCTION(alarm_screen_call
, 0, ID2P(LANG_ALARM_MOD_ALARM_MENU
),
83 (menu_function
)alarm_screen
, NULL
, NULL
, Icon_NOICON
);
84 #if CONFIG_TUNER || defined(HAVE_RECORDING)
86 #if CONFIG_TUNER && !defined(HAVE_RECORDING)
87 /* This need only be shown if we dont have recording, because if we do
88 then always show the setting item, because there will always be at least
90 static int alarm_callback(int action
,const struct menu_item_ex
*this_item
)
95 case ACTION_REQUEST_MENUITEM
:
96 if (radio_hardware_present() == 0)
97 return ACTION_EXIT_MENUITEM
;
103 #define alarm_callback NULL
104 #endif /* CONFIG_TUNER && !HAVE_RECORDING */
105 /* have to do this manually because the setting screen
106 doesnt handle variable item count */
107 static int alarm_setting(void)
109 struct opt_items items
[ALARM_START_COUNT
];
111 items
[i
].string
= str(LANG_RESUME_PLAYBACK
);
112 items
[i
].voice_id
= LANG_RESUME_PLAYBACK
;
115 if (radio_hardware_present())
117 items
[i
].string
= str(LANG_FM_RADIO
);
118 items
[i
].voice_id
= LANG_FM_RADIO
;
122 #ifdef HAVE_RECORDING
123 items
[i
].string
= str(LANG_RECORDING
);
124 items
[i
].voice_id
= LANG_RECORDING
;
127 return set_option(str(LANG_ALARM_WAKEUP_SCREEN
),
128 &global_settings
.alarm_wake_up_screen
,
129 INT
, items
, i
, NULL
);
132 MENUITEM_FUNCTION(alarm_wake_up_screen
, 0, ID2P(LANG_ALARM_WAKEUP_SCREEN
),
133 alarm_setting
, NULL
, alarm_callback
, Icon_Menu_setting
);
134 #endif /* CONFIG_TUNER || defined(HAVE_RECORDING) */
136 #endif /* HAVE_RTC_ALARM */
138 void talk_timedate(void)
140 struct tm
*tm
= get_time();
141 if (!global_settings
.talk_menu
)
143 talk_id(VOICE_CURRENT_TIME
, false);
147 talk_date(get_time(), true);
151 talk_id(LANG_UNKNOWN
, true);
155 static void draw_timedate(struct viewport
*vp
, struct screen
*display
)
157 struct tm
*tm
= get_time();
159 char time
[16], date
[16];
160 const char *t
= time
, *d
= date
;
163 display
->set_viewport(vp
);
164 display
->clear_viewport();
165 if (viewport_get_nb_lines(vp
) >= 4)
172 snprintf(time
, sizeof(time
), "%02d:%02d:%02d%s",
173 global_settings
.timeformat
== 0 ? tm
->tm_hour
:
174 ((tm
->tm_hour
+ 11) % 12) + 1,
177 global_settings
.timeformat
== 0 ? "" :
178 tm
->tm_hour
>11 ? " P" : " A");
179 snprintf(date
, sizeof(date
), "%s %d %d",
180 str(LANG_MONTH_JANUARY
+ tm
->tm_mon
),
187 d
= str(LANG_UNKNOWN
);
190 display
->puts(0, line
++, t
);
191 display
->puts(0, line
, d
);
193 display
->update_viewport();
194 display
->set_viewport(NULL
);
198 static struct viewport clock_vps
[NB_SCREENS
], menu
[NB_SCREENS
];
199 static bool menu_was_pressed
;
200 static int time_menu_callback(int action
,
201 const struct menu_item_ex
*this_item
)
204 static int last_redraw
= 0;
207 if (TIME_BEFORE(last_redraw
+HZ
/2, current_tick
))
214 case ACTION_STD_CONTEXT
:
216 action
= ACTION_NONE
;
218 /* need to tell do_menu() to return, but then get time_screen()
219 to return 0! ACTION_STD_MENU will return GO_TO_PREVIOUS from here
220 so check do_menu()'s return val and menu_was_pressed */
221 case ACTION_STD_MENU
:
222 menu_was_pressed
= true;
227 last_redraw
= current_tick
;
229 draw_timedate(&clock_vps
[i
], &screens
[i
]);
235 MAKE_MENU(time_menu
, ID2P(LANG_TIME_MENU
), time_menu_callback
, Icon_NOICON
,
237 #ifdef HAVE_RTC_ALARM
239 #if defined(HAVE_RECORDING) || CONFIG_TUNER
240 &alarm_wake_up_screen
,
245 int time_screen(void* ignored
)
248 int nb_lines
, font_h
, ret
;
249 menu_was_pressed
= false;
251 push_current_activity(ACTIVITY_TIMEDATESCREEN
);
255 viewport_set_defaults(&clock_vps
[i
], i
);
256 #ifdef HAVE_BUTTONBAR
257 if (global_settings
.buttonbar
)
259 clock_vps
[i
].height
-= BUTTONBAR_HEIGHT
;
262 nb_lines
= viewport_get_nb_lines(&clock_vps
[i
]);
264 gui_synclist_set_viewport_defaults(&menu
[i
], i
);
265 /* force time to be drawn centered */
266 clock_vps
[i
].flags
|= VP_FLAG_ALIGN_CENTER
;
268 font_h
= clock_vps
[i
].line_height
?: (int)font_get(clock_vps
[i
].font
)->height
;
269 nb_lines
-= 2; /* at least 2 lines for menu */
273 clock_vps
[i
].height
= nb_lines
*font_h
;
274 else /* disable the clock_vps drawing */
275 clock_vps
[i
].height
= 0;
276 menu
[i
].y
+= clock_vps
[i
].height
;
277 menu
[i
].height
-= clock_vps
[i
].height
;
278 draw_timedate(&clock_vps
[i
], &screens
[i
]);
281 ret
= do_menu(&time_menu
, NULL
, menu
, false);
282 pop_current_activity();
283 /* see comments above in the button callback */
284 if (!menu_was_pressed
&& ret
== GO_TO_PREVIOUS
)