1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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 ****************************************************************************/
27 #include "mp3_playback.h"
30 #include "timefuncs.h"
32 #ifdef HAVE_LCD_BITMAP
36 #include "powermgmt.h"
38 static enum playmode current_mode
= STATUS_STOP
;
40 static long switch_tick
;
41 static int battery_charge_step
= 0;
42 static bool plug_state
;
43 static bool battery_state
= true;
58 void status_init(void)
60 status_set_playmode(STATUS_STOP
);
63 void status_set_playmode(enum playmode mode
)
69 #if defined(HAVE_LCD_CHARCELLS)
70 static bool record
= false;
71 static bool audio
= false;
72 static bool param
= false;
73 static bool usb
= false;
75 void status_set_record(bool b
)
80 void status_set_audio(bool b
)
85 void status_set_param(bool b
)
90 void status_set_usb(bool b
)
95 #endif /* HAVE_LCD_CHARCELLS */
97 void status_draw(bool force_redraw
)
99 struct status_info info
;
101 #ifdef HAVE_LCD_BITMAP
102 static struct status_info lastinfo
;
105 if ( !global_settings
.statusbar
)
108 (void)force_redraw
; /* players always "redraw" */
111 info
.volume
= mpeg_val2phys(SOUND_VOLUME
, global_settings
.volume
);
112 info
.inserted
= charger_inserted();
113 info
.battlevel
= battery_level();
114 info
.battery_safe
= battery_level_safe();
116 #ifdef HAVE_LCD_BITMAP
118 info
.hour
= tm
->tm_hour
;
119 info
.minute
= tm
->tm_min
;
120 info
.shuffle
= global_settings
.playlist_shuffle
;
121 info
.keylock
= keys_locked
;
122 info
.repeat
= global_settings
.repeat_mode
;
123 info
.playmode
= current_mode
;
125 /* only redraw if forced to, or info has changed */
128 !info
.battery_safe
||
129 memcmp(&info
, &lastinfo
, sizeof(struct status_info
)))
131 lcd_clearrect(0,0,LCD_WIDTH
,8);
133 /* players always "redraw" */
138 battery_state
= true;
140 #if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION)
141 /* zero battery run time if charging */
142 if (charge_state
> 0) {
143 global_settings
.runtime
= 0;
144 lasttime
= current_tick
;
147 /* animate battery if charging */
148 if ((charge_state
== 1) ||
149 (charge_state
== 2)) {
151 global_settings
.runtime
= 0;
152 lasttime
= current_tick
;
155 /* animate in three steps (34% per step for a better look) */
156 info
.battlevel
= battery_charge_step
* 34;
157 if (info
.battlevel
> 100)
158 info
.battlevel
= 100;
159 if(TIME_AFTER(current_tick
, switch_tick
)) {
160 battery_charge_step
=(battery_charge_step
+1)%4;
161 switch_tick
= current_tick
+ HZ
;
167 if (info
.battery_safe
)
168 battery_state
= true;
170 /* blink battery if level is low */
171 if(TIME_AFTER(current_tick
, switch_tick
) &&
172 (info
.battlevel
> -1)) {
173 switch_tick
= current_tick
+HZ
;
174 battery_state
=! battery_state
;
179 #ifdef HAVE_LCD_BITMAP
181 statusbar_icon_battery(info
.battlevel
, plug_state
);
183 statusbar_icon_volume(info
.volume
);
184 statusbar_icon_play_state(current_mode
+ Icon_Play
);
185 switch (info
.repeat
) {
187 statusbar_icon_play_mode(Icon_RepeatOne
);
191 statusbar_icon_play_mode(Icon_Repeat
);
195 statusbar_icon_shuffle();
197 statusbar_icon_lock();
199 statusbar_time(info
.hour
, info
.minute
);
201 lcd_update_rect(0, 0, LCD_WIDTH
, STATUSBAR_HEIGHT
);
207 #if defined(HAVE_LCD_CHARCELLS)
208 if (info
.battlevel
> -1)
209 lcd_icon(ICON_BATTERY
, battery_state
);
210 lcd_icon(ICON_BATTERY_1
, info
.battlevel
> 25);
211 lcd_icon(ICON_BATTERY_2
, info
.battlevel
> 50);
212 lcd_icon(ICON_BATTERY_3
, info
.battlevel
> 75);
214 lcd_icon(ICON_VOLUME
, true);
215 lcd_icon(ICON_VOLUME_1
, info
.volume
> 10);
216 lcd_icon(ICON_VOLUME_2
, info
.volume
> 30);
217 lcd_icon(ICON_VOLUME_3
, info
.volume
> 50);
218 lcd_icon(ICON_VOLUME_4
, info
.volume
> 70);
219 lcd_icon(ICON_VOLUME_5
, info
.volume
> 90);
221 lcd_icon(ICON_PLAY
, current_mode
== STATUS_PLAY
);
222 lcd_icon(ICON_PAUSE
, current_mode
== STATUS_PAUSE
);
224 lcd_icon(ICON_REPEAT
, global_settings
.repeat_mode
!= REPEAT_OFF
);
225 lcd_icon(ICON_1
, global_settings
.repeat_mode
== REPEAT_ONE
);
227 lcd_icon(ICON_RECORD
, record
);
228 lcd_icon(ICON_AUDIO
, audio
);
229 lcd_icon(ICON_PARAM
, param
);
230 lcd_icon(ICON_USB
, usb
);
235 #ifdef HAVE_LCD_BITMAP
236 static void draw_buttonbar_btn(int num
, char* caption
)
238 int xpos
, ypos
, button_width
, text_width
;
241 lcd_setfont(FONT_SYSFIXED
);
242 lcd_getstringsize("M", &fw
, &fh
);
244 button_width
= LCD_WIDTH
/3;
245 xpos
= num
* button_width
;
246 ypos
= LCD_HEIGHT
- fh
;
250 /* center the text */
251 text_width
= fw
* strlen(caption
);
252 lcd_putsxy(xpos
+ (button_width
- text_width
)/2, ypos
, caption
);
255 lcd_invertrect(xpos
, ypos
, button_width
- 1, fh
);
258 static char stored_caption1
[8];
259 static char stored_caption2
[8];
260 static char stored_caption3
[8];
262 void buttonbar_set(char* caption1
, char *caption2
, char *caption3
)
267 strncpy(stored_caption1
, caption1
, 7);
268 stored_caption1
[7] = 0;
272 strncpy(stored_caption2
, caption2
, 7);
273 stored_caption2
[7] = 0;
277 strncpy(stored_caption3
, caption3
, 7);
278 stored_caption3
[7] = 0;
282 void buttonbar_unset(void)
284 stored_caption1
[0] = 0;
285 stored_caption2
[0] = 0;
286 stored_caption3
[0] = 0;
289 void buttonbar_draw(void)
291 lcd_clearrect(0, LCD_HEIGHT
-8, LCD_WIDTH
, 8);
292 draw_buttonbar_btn(0, stored_caption1
);
293 draw_buttonbar_btn(1, stored_caption2
);
294 draw_buttonbar_btn(2, stored_caption3
);
297 bool buttonbar_isset(void)
299 /* If all buttons are unset, the button bar is considered disabled */
300 return (global_settings
.buttonbar
&&
301 ((stored_caption1
[0] != 0) ||
302 (stored_caption2
[0] != 0) ||
303 (stored_caption3
[0] != 0)));