1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2007 Copyright Kévin Ferrare based on Zakk Roberts's work
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 ****************************************************************************/
23 #include "clock_bitmaps.h"
24 #include "clock_draw.h"
25 #include "clock_settings.h"
26 #include "lib/picture.h"
28 static int max_skin
[]={
43 enum settings_file_status
{
48 struct clock_settings clock_settings
;
50 /* The settings as they exist on the hard disk, so that
51 * we can know at saving time if changes have been made */
52 struct clock_settings hdd_clock_settings
;
54 bool settings_needs_saving(struct clock_settings
* settings
){
55 return(rb
->memcmp(settings
, &hdd_clock_settings
, sizeof(*settings
)));
58 void clock_settings_reset(struct clock_settings
* settings
){
59 settings
->mode
= ANALOG
;
61 for(i
=0;i
<NB_CLOCK_MODES
;i
++){
64 settings
->general
.hour_format
= H12
;
65 settings
->general
.date_format
= EUROPEAN
;
66 settings
->general
.show_counter
= true;
67 settings
->general
.save_settings
= true;
68 settings
->general
.idle_poweroff
=true;
69 settings
->general
.backlight
= ROCKBOX_SETTING
;
71 settings
->analog
.show_date
= false;
72 settings
->analog
.show_seconds
= true;
73 settings
->analog
.show_border
= true;
75 settings
->digital
.show_seconds
= true;
76 settings
->digital
.blinkcolon
= false;
77 apply_backlight_setting(settings
->general
.backlight
);
80 void apply_backlight_setting(int backlight_setting
)
82 if(backlight_setting
== ALWAS_OFF
)
83 rb
->backlight_set_timeout(-1);
84 else if(backlight_setting
== ROCKBOX_SETTING
)
85 rb
->backlight_set_timeout(rb
->global_settings
->backlight_timeout
);
86 else if(backlight_setting
== ALWAYS_ON
)
87 rb
->backlight_set_timeout(0);
90 void clock_settings_skin_next(struct clock_settings
* settings
){
91 settings
->skin
[settings
->mode
]++;
92 if(settings
->skin
[settings
->mode
]>=max_skin
[settings
->mode
])
93 settings
->skin
[settings
->mode
]=0;
96 void clock_settings_skin_previous(struct clock_settings
* settings
){
97 settings
->skin
[settings
->mode
]--;
98 if(settings
->skin
[settings
->mode
]<0)
99 settings
->skin
[settings
->mode
]=max_skin
[settings
->mode
]-1;
102 enum settings_file_status
clock_settings_load(struct clock_settings
* settings
,
104 int fd
= rb
->open(filename
, O_RDONLY
);
105 if(fd
>= 0){ /* does file exist? */
106 /* basic consistency check */
107 if(rb
->filesize(fd
) == sizeof(*settings
)){
108 rb
->read(fd
, settings
, sizeof(*settings
));
110 apply_backlight_setting(settings
->general
.backlight
);
111 rb
->memcpy(&hdd_clock_settings
, settings
, sizeof(*settings
));
115 /* Initializes the settings with default values at least */
116 clock_settings_reset(settings
);
120 enum settings_file_status
clock_settings_save(struct clock_settings
* settings
,
122 int fd
= rb
->creat(filename
, 0666);
123 if(fd
>= 0){ /* does file exist? */
124 rb
->write (fd
, settings
, sizeof(*settings
));
131 void draw_logo(struct screen
* display
){
132 #ifdef HAVE_LCD_COLOR
133 if(display
->is_color
){
134 display
->set_foreground(LCD_BLACK
);
135 display
->set_background(LCD_RGBPACK(180,200,230));
139 const struct picture
* logo
= &(logos
[display
->screen_type
]);
140 display
->clear_display();
141 picture_draw(display
, logo
, 0, 0);
144 void draw_message(struct screen
* display
, int msg
, int y
){
145 const struct picture
* message
= &(messages
[display
->screen_type
]);
146 display
->set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
147 display
->fillrect(0, display
->getheight()-message
->slide_height
,
148 display
->getwidth(), message
->slide_height
);
149 display
->set_drawmode(DRMODE_SOLID
);
150 vertical_picture_draw_sprite(display
, message
, msg
,
151 0, display
->getheight() -
152 (message
->slide_height
*y
));
155 void load_settings(void){
157 struct screen
* display
;
159 display
=rb
->screens
[i
];
160 display
->clear_display();
162 draw_message(display
, MESSAGE_LOADING
, 1);
166 enum settings_file_status load_status
=
167 clock_settings_load(&clock_settings
, settings_filename
);
170 display
=rb
->screens
[i
];
171 if(load_status
==LOADED
)
172 draw_message(display
, MESSAGE_LOADED
, 1);
174 draw_message(display
, MESSAGE_ERRLOAD
, 1);
181 void save_settings(void){
183 struct screen
* display
;
184 if(!settings_needs_saving(&clock_settings
))
188 display
=rb
->screens
[i
];
189 display
->clear_display();
192 draw_message(display
, MESSAGE_SAVING
, 1);
196 enum settings_file_status load_status
=
197 clock_settings_save(&clock_settings
, settings_filename
);
200 display
=rb
->screens
[i
];
202 if(load_status
==SAVED
)
203 draw_message(display
, MESSAGE_SAVED
, 1);
205 draw_message(display
, MESSAGE_ERRSAVE
, 1);
211 void save_settings_wo_gui(void){
212 clock_settings_save(&clock_settings
, settings_filename
);