Fixed time/date setting for new font system.
[kugel-rb/myfork.git] / apps / settings_menu.c
blob5ad7a1e79ce95b62320723c4c81d53646096c680
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Robert Hak
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 ****************************************************************************/
20 #include "config.h"
22 #include <stdio.h>
23 #include <stdbool.h>
25 #include "lcd.h"
26 #include "menu.h"
27 #include "mpeg.h"
28 #include "button.h"
29 #include "kernel.h"
30 #include "sprintf.h"
31 #include "settings.h"
32 #include "settings_menu.h"
33 #include "backlight.h"
34 #include "playlist.h" /* for playlist_shuffle */
35 #include "fat.h" /* For dotfile settings */
36 #include "powermgmt.h"
37 #include "rtc.h"
38 #include "ata.h"
39 #include "lang.h"
41 static Menu show_hidden_files(void)
43 set_bool_options( str(LANG_HIDDEN), &global_settings.show_hidden_files,
44 str(LANG_HIDDEN_SHOW), str(LANG_HIDDEN_HIDE) );
45 return MENU_OK;
48 static Menu contrast(void)
50 set_int( str(LANG_CONTRAST), "", &global_settings.contrast,
51 lcd_set_contrast, 1, 0, MAX_CONTRAST_SETTING );
52 return MENU_OK;
55 #ifndef HAVE_RECORDER_KEYPAD
56 static Menu shuffle(void)
58 set_bool( str(LANG_SHUFFLE), &global_settings.playlist_shuffle );
59 return MENU_OK;
61 #endif
63 static Menu play_selected(void)
65 set_bool( str(LANG_PLAY_SELECTED), &global_settings.play_selected );
66 return MENU_OK;
69 static Menu mp3_filter(void)
71 set_bool( str(LANG_MP3FILTER), &global_settings.mp3filter );
72 return MENU_OK;
75 static Menu sort_case(void)
77 set_bool( str(LANG_SORT_CASE), &global_settings.sort_case );
78 return MENU_OK;
81 static Menu resume(void)
83 char* names[] = { str(LANG_OFF),
84 str(LANG_RESUME_SETTING_ASK),
85 str(LANG_ON) };
86 set_option( str(LANG_RESUME), &global_settings.resume, names, 3, NULL );
87 return MENU_OK;
90 static Menu backlight_timer(void)
92 char* names[] = { str(LANG_OFF), str(LANG_ON),
93 "1s ", "2s ", "3s ", "4s ", "5s ",
94 "6s ", "7s ", "8s ", "9s ", "10s",
95 "15s", "20s", "25s", "30s", "45s",
96 "60s", "90s"};
97 set_option(str(LANG_BACKLIGHT), &global_settings.backlight, names, 19,
98 backlight_time );
99 return MENU_OK;
102 static Menu scroll_speed(void)
104 set_int(str(LANG_SCROLL), "", &global_settings.scroll_speed,
105 &lcd_scroll_speed, 1, 1, 30 );
106 return MENU_OK;
109 #ifdef HAVE_CHARGE_CTRL
110 static Menu deep_discharge(void)
112 set_bool( str(LANG_DISCHARGE), &global_settings.discharge );
113 charge_restart_level = global_settings.discharge ?
114 CHARGE_RESTART_LO : CHARGE_RESTART_HI;
115 return MENU_OK;
117 #endif
119 #ifdef HAVE_LCD_BITMAP
120 static Menu timedate_set(void)
122 int timedate[7]; /* hour,minute,second,year,month,day,dayofweek */
124 #ifdef HAVE_RTC
125 timedate[0] = rtc_read(0x03); /* hour */
126 timedate[1] = rtc_read(0x02); /* minute */
127 timedate[2] = rtc_read(0x01); /* second */
128 timedate[3] = rtc_read(0x07); /* year */
129 timedate[4] = rtc_read(0x06); /* month */
130 timedate[5] = rtc_read(0x05); /* day */
131 /* day of week not read, calculated */
132 /* hour */
133 timedate[0] = ((timedate[0] & 0x30) >> 4) * 10 + (timedate[0] & 0x0f);
134 /* minute */
135 timedate[1] = ((timedate[1] & 0x70) >> 4) * 10 + (timedate[1] & 0x0f);
136 /* second */
137 timedate[2] = ((timedate[2] & 0x70) >> 4) * 10 + (timedate[2] & 0x0f);
138 /* year */
139 timedate[3] = ((timedate[3] & 0xf0) >> 4) * 10 + (timedate[3] & 0x0f);
140 /* month */
141 timedate[4] = ((timedate[4] & 0x10) >> 4) * 10 + (timedate[4] & 0x0f);
142 /* day */
143 timedate[5] = ((timedate[5] & 0x30) >> 4) * 10 + (timedate[5] & 0x0f);
144 #else /* SIMULATOR */
145 /* hour */
146 timedate[0] = 0;
147 /* minute */
148 timedate[1] = 0;
149 /* second */
150 timedate[2] = 0;
151 /* year */
152 timedate[3] = 0;
153 /* month */
154 timedate[4] = 1;
155 /* day */
156 timedate[5] = 1;
157 #endif
159 set_time(str(LANG_TIME),timedate);
161 #ifdef HAVE_RTC
162 if(timedate[0] != -1) {
163 /* hour */
164 timedate[0] = ((timedate[0]/10) << 4 | timedate[0]%10) & 0x3f;
165 /* minute */
166 timedate[1] = ((timedate[1]/10) << 4 | timedate[1]%10) & 0x7f;
167 /* second */
168 timedate[2] = ((timedate[2]/10) << 4 | timedate[2]%10) & 0x7f;
169 /* year */
170 timedate[3] = ((timedate[3]/10) << 4 | timedate[3]%10) & 0xff;
171 /* month */
172 timedate[4] = ((timedate[4]/10) << 4 | timedate[4]%10) & 0x1f;
173 /* day */
174 timedate[5] = ((timedate[5]/10) << 4 | timedate[5]%10) & 0x3f;
176 rtc_write(0x03, timedate[0] | (rtc_read(0x03) & 0xc0)); /* hour */
177 rtc_write(0x02, timedate[1] | (rtc_read(0x02) & 0x80)); /* minute */
178 rtc_write(0x01, timedate[2] | (rtc_read(0x01) & 0x80)); /* second */
179 rtc_write(0x07, timedate[3]); /* year */
180 rtc_write(0x06, timedate[4] | (rtc_read(0x06) & 0xe0)); /* month */
181 rtc_write(0x05, timedate[5] | (rtc_read(0x05) & 0xc0)); /* day */
182 rtc_write(0x04, timedate[6] | (rtc_read(0x04) & 0xf8)); /* dayofweek */
183 rtc_write(0x00, 0x00); /* 0.1 + 0.01 seconds */
185 #endif
186 return MENU_OK;
188 #endif
190 static Menu spindown(void)
192 set_int(str(LANG_SPINDOWN), "s", &global_settings.disk_spindown,
193 ata_spindown, 1, 3, 254 );
194 return MENU_OK;
197 static Menu ff_rewind_min_step(void)
199 char* names[] = { "1s", "2s", "3s", "4s",
200 "5s", "6s", "8s", "10s",
201 "15s", "20s", "25s", "30s",
202 "45s", "60s" };
203 set_option(str(LANG_FFRW_STEP), &global_settings.ff_rewind_min_step,
204 names, 14, NULL );
205 return MENU_OK;
208 static Menu ff_rewind_accel(void)
210 char* names[] = { str(LANG_OFF), "2x/1s", "2x/2s", "2x/3s",
211 "2x/4s", "2x/5s", "2x/6s", "2x/7s",
212 "2x/8s", "2x/9s", "2x/10s", "2x/11s",
213 "2x/12s", "2x/13s", "2x/14s", "2x/15s", };
214 set_option(str(LANG_FFRW_ACCEL), &global_settings.ff_rewind_accel,
215 names, 16, NULL );
216 return MENU_OK;
219 static Menu browse_current(void)
221 set_bool( str(LANG_FOLLOW), &global_settings.browse_current );
222 return MENU_OK;
225 Menu playback_settings_menu(void)
227 int m;
228 Menu result;
230 struct menu_items items[] = {
231 #ifndef HAVE_RECORDER_KEYPAD
232 { str(LANG_SHUFFLE), shuffle },
233 #endif
234 { str(LANG_PLAY_SELECTED), play_selected },
235 { str(LANG_RESUME), resume },
236 { str(LANG_FFRW_STEP), ff_rewind_min_step },
237 { str(LANG_FFRW_ACCEL), ff_rewind_accel },
240 bool old_shuffle = global_settings.playlist_shuffle;
242 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
243 result = menu_run(m);
244 menu_exit(m);
246 if (old_shuffle != global_settings.playlist_shuffle)
248 if (global_settings.playlist_shuffle)
250 randomise_playlist(current_tick);
252 else
254 sort_playlist(true);
257 return result;
260 static Menu reset_settings(void)
262 int button = 0;
264 lcd_clear_display();
265 #ifdef HAVE_LCD_CHARCELLS
266 lcd_puts(0,0,str(LANG_RESET_ASK_PLAYER));
267 lcd_puts(0,1,str(LANG_RESET_CONFIRM_PLAYER));
268 #else
269 lcd_puts(0,0,str(LANG_RESET_ASK_RECORDER));
270 lcd_puts(0,1,str(LANG_RESET_CONFIRM_RECORDER));
271 lcd_puts(0,2,str(LANG_RESET_CANCEL_RECORDER));
272 #endif
273 lcd_update();
274 button = button_get(true);
275 if (button == BUTTON_PLAY) {
276 settings_reset();
277 lcd_clear_display();
278 lcd_puts(0,0,str(LANG_RESET_DONE_SETTING));
279 lcd_puts(0,1,str(LANG_RESET_DONE_CLEAR));
280 lcd_update();
281 sleep(HZ);
282 return(true);
283 } else {
284 lcd_clear_display();
285 lcd_puts(0,0,str(LANG_RESET_DONE_CANCEL));
286 lcd_update();
287 sleep(HZ);
288 return(false);
292 static Menu fileview_settings_menu(void)
294 int m;
295 Menu result;
297 struct menu_items items[] = {
298 { str(LANG_CASE_MENU), sort_case },
299 { str(LANG_MP3FILTER), mp3_filter },
300 { str(LANG_HIDDEN), show_hidden_files },
301 { str(LANG_FOLLOW), browse_current },
304 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
305 result = menu_run(m);
306 menu_exit(m);
307 return result;
310 static Menu display_settings_menu(void)
312 int m;
313 Menu result;
315 struct menu_items items[] = {
316 { str(LANG_SCROLL_MENU), scroll_speed },
317 { str(LANG_BACKLIGHT), backlight_timer },
318 { str(LANG_CONTRAST), contrast },
321 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
322 result = menu_run(m);
323 menu_exit(m);
324 return result;
327 static Menu system_settings_menu(void)
329 int m;
330 Menu result;
332 struct menu_items items[] = {
333 { str(LANG_SPINDOWN), spindown },
334 #ifdef HAVE_CHARGE_CTRL
335 { str(LANG_DISCHARGE), deep_discharge },
336 #endif
337 #ifdef HAVE_LCD_BITMAP
338 { str(LANG_TIME), timedate_set },
339 #endif
340 { str(LANG_RESET), reset_settings },
343 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
344 result = menu_run(m);
345 menu_exit(m);
346 return result;
349 Menu settings_menu(void)
351 int m;
352 Menu result;
354 struct menu_items items[] = {
355 { str(LANG_PLAYBACK), playback_settings_menu },
356 { str(LANG_FILE), fileview_settings_menu },
357 { str(LANG_DISPLAY), display_settings_menu },
358 { str(LANG_SYSTEM), system_settings_menu },
361 m=menu_init( items, sizeof items / sizeof(struct menu_items) );
362 result = menu_run(m);
363 menu_exit(m);
364 return result;