Don't define pitch_speed_enum() on MAS3507D. Fixes yellow
[kugel-rb.git] / apps / gui / statusbar.c
blob4710ebac42fc7ee02f03d51f01339add119c82b1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) Robert E. Hak (2002), Linus Nielsen Feltzing (2002)
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 ****************************************************************************/
22 #include "config.h"
23 #include "font.h"
24 #include "kernel.h"
25 #include "string.h" /* for memcmp oO*/
26 #include "sprintf.h"
27 #include "sound.h"
28 #include "settings.h"
29 #include "viewport.h"
30 #if CONFIG_CODEC == SWCODEC
31 #include "metadata.h"
32 #endif
33 #include "icons.h"
34 #include "powermgmt.h"
35 #include "usb.h"
36 #include "led.h"
37 #include "screen_access.h"
39 #include "status.h" /* needed for battery_state global var */
40 #include "action.h" /* for keys_locked */
41 #include "statusbar.h"
42 #ifdef HAVE_RECORDING
43 #include "audio.h"
44 #include "recording.h"
45 #include "pcm_record.h"
46 #endif
47 #include "appevents.h"
48 #include "timefuncs.h"
50 /* FIXME: should be removed from icon.h to avoid redefinition,
51 but still needed for compatibility with old system */
52 #define ICONS_SPACING 2
53 #define STATUSBAR_BATTERY_X_POS 0*ICONS_SPACING
54 #define STATUSBAR_BATTERY_WIDTH 18
55 #define STATUSBAR_PLUG_X_POS STATUSBAR_X_POS + \
56 STATUSBAR_BATTERY_WIDTH + \
57 ICONS_SPACING
58 #define STATUSBAR_PLUG_WIDTH 7
59 #define STATUSBAR_VOLUME_X_POS STATUSBAR_X_POS + \
60 STATUSBAR_BATTERY_WIDTH + \
61 STATUSBAR_PLUG_WIDTH + \
62 2*ICONS_SPACING
63 #define STATUSBAR_VOLUME_WIDTH 16
64 #define STATUSBAR_ENCODER_X_POS STATUSBAR_X_POS + \
65 STATUSBAR_BATTERY_WIDTH + \
66 STATUSBAR_PLUG_WIDTH + \
67 2*ICONS_SPACING - 1
68 #define STATUSBAR_ENCODER_WIDTH 18
69 #define STATUSBAR_PLAY_STATE_X_POS STATUSBAR_X_POS + \
70 STATUSBAR_BATTERY_WIDTH + \
71 STATUSBAR_PLUG_WIDTH + \
72 STATUSBAR_VOLUME_WIDTH + \
73 3*ICONS_SPACING
74 #define STATUSBAR_PLAY_STATE_WIDTH 7
75 #define STATUSBAR_PLAY_MODE_X_POS STATUSBAR_X_POS + \
76 STATUSBAR_BATTERY_WIDTH + \
77 STATUSBAR_PLUG_WIDTH + \
78 STATUSBAR_VOLUME_WIDTH + \
79 STATUSBAR_PLAY_STATE_WIDTH + \
80 4*ICONS_SPACING
81 #define STATUSBAR_PLAY_MODE_WIDTH 7
82 #define STATUSBAR_RECFREQ_X_POS STATUSBAR_X_POS + \
83 STATUSBAR_BATTERY_WIDTH + \
84 STATUSBAR_PLUG_WIDTH + \
85 STATUSBAR_VOLUME_WIDTH + \
86 STATUSBAR_PLAY_STATE_WIDTH + \
87 3*ICONS_SPACING
88 #define STATUSBAR_RECFREQ_WIDTH 12
89 #define STATUSBAR_RECCHANNELS_X_POS STATUSBAR_X_POS + \
90 STATUSBAR_BATTERY_WIDTH + \
91 STATUSBAR_PLUG_WIDTH + \
92 STATUSBAR_VOLUME_WIDTH + \
93 STATUSBAR_PLAY_STATE_WIDTH + \
94 STATUSBAR_RECFREQ_WIDTH + \
95 4*ICONS_SPACING
96 #define STATUSBAR_RECCHANNELS_WIDTH 5
97 #define STATUSBAR_SHUFFLE_X_POS STATUSBAR_X_POS + \
98 STATUSBAR_BATTERY_WIDTH + \
99 STATUSBAR_PLUG_WIDTH + \
100 STATUSBAR_VOLUME_WIDTH + \
101 STATUSBAR_PLAY_STATE_WIDTH + \
102 STATUSBAR_PLAY_MODE_WIDTH + \
103 5*ICONS_SPACING
104 #define STATUSBAR_SHUFFLE_WIDTH 7
105 #define STATUSBAR_LOCKM_X_POS STATUSBAR_X_POS + \
106 STATUSBAR_BATTERY_WIDTH + \
107 STATUSBAR_PLUG_WIDTH + \
108 STATUSBAR_VOLUME_WIDTH + \
109 STATUSBAR_PLAY_STATE_WIDTH + \
110 STATUSBAR_PLAY_MODE_WIDTH + \
111 STATUSBAR_SHUFFLE_WIDTH + \
112 6*ICONS_SPACING
113 #define STATUSBAR_LOCKM_WIDTH 5
114 #define STATUSBAR_LOCKR_X_POS STATUSBAR_X_POS + \
115 STATUSBAR_BATTERY_WIDTH + \
116 STATUSBAR_PLUG_WIDTH + \
117 STATUSBAR_VOLUME_WIDTH + \
118 STATUSBAR_PLAY_STATE_WIDTH + \
119 STATUSBAR_PLAY_MODE_WIDTH + \
120 STATUSBAR_SHUFFLE_WIDTH + \
121 STATUSBAR_LOCKM_WIDTH + \
122 7*ICONS_SPACING
123 #define STATUSBAR_LOCKR_WIDTH 5
125 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
126 #define STATUSBAR_DISK_WIDTH 12
127 #define STATUSBAR_DISK_X_POS(statusbar_width) statusbar_width - \
128 STATUSBAR_DISK_WIDTH
129 #else
130 #define STATUSBAR_DISK_WIDTH 0
131 #endif
132 #define STATUSBAR_TIME_X_END(statusbar_width) statusbar_width - 1 - \
133 STATUSBAR_DISK_WIDTH
134 struct gui_syncstatusbar statusbars;
136 /* Prototypes */
137 #ifdef HAVE_LCD_BITMAP
138 static void gui_statusbar_icon_battery(struct screen * display, int percent,
139 int batt_charge_step);
140 static bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume);
141 static void gui_statusbar_icon_play_state(struct screen * display, int state);
142 static void gui_statusbar_icon_play_mode(struct screen * display, int mode);
143 static void gui_statusbar_icon_shuffle(struct screen * display);
144 static void gui_statusbar_icon_lock(struct screen * display);
145 #ifdef HAS_REMOTE_BUTTON_HOLD
146 static void gui_statusbar_icon_lock_remote(struct screen * display);
147 #endif
148 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
149 static void gui_statusbar_led(struct screen * display);
150 #endif
151 #ifdef HAVE_RECORDING
152 static void gui_statusbar_icon_recording_info(struct screen * display);
153 #endif
154 #if CONFIG_RTC
155 static void gui_statusbar_time(struct screen * display, struct tm *time);
156 #endif
157 #endif
159 /* End prototypes */
163 * Initializes a status bar
164 * - bar : the bar to initialize
166 static void gui_statusbar_init(struct gui_statusbar * bar)
168 bar->redraw_volume = true;
169 bar->volume_icon_switch_tick = bar->battery_icon_switch_tick = current_tick;
170 memset((void*)&(bar->lastinfo), 0, sizeof(struct status_info));
171 #if CONFIG_RTC
172 bar->last_tm_min = 0;
173 #endif
176 #define GET_RECT(vp, vals,display) do { \
177 viewport_set_fullscreen(&(vp), (display)->screen_type); \
178 (vp).flags &= ~VP_FLAG_ALIGN_RIGHT; \
179 (vp).height = STATUSBAR_HEIGHT; \
180 (vp).x = STATUSBAR_X_POS; \
181 if ((vals) != STATUSBAR_BOTTOM) \
182 (vp).y = 0; \
183 else \
184 (vp).y = (display)->lcdheight - STATUSBAR_HEIGHT; \
185 } while(0)
187 void gui_statusbar_draw(struct gui_statusbar * bar, bool force_redraw)
189 struct screen * display = bar->display;
191 if (!display)
192 return;
194 #ifdef HAVE_LCD_CHARCELLS
195 int val;
196 (void)force_redraw; /* The Player always has "redraw" */
197 #endif /* HAVE_LCD_CHARCELLS */
199 bar->info.battlevel = battery_level();
200 #ifdef HAVE_USB_POWER
201 bar->info.usb_inserted = usb_inserted();
202 #endif
203 #if CONFIG_CHARGING
204 bar->info.inserted = (charger_input_state == CHARGER);
205 if (bar->info.inserted)
207 bar->info.battery_state = true;
209 #if CONFIG_CHARGING >= CHARGING_MONITOR
211 /* zero battery run time if charging */
212 if (charge_state > DISCHARGING)
213 lasttime = current_tick;
215 /* animate battery if charging */
216 if ((charge_state == DISCHARGING) || (charge_state == TRICKLE))
218 bar->info.batt_charge_step = -1;
220 else
222 #else /* CONFIG_CHARGING < CHARGING_MONITOR */
223 lasttime = current_tick;
225 #endif /* CONFIG_CHARGING < CHARGING_MONITOR */
226 /* animate in (max.) 4 steps, starting near the current charge level */
227 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick))
229 if (++bar->info.batt_charge_step > 3)
230 bar->info.batt_charge_step = bar->info.battlevel / 34;
231 bar->battery_icon_switch_tick = current_tick + HZ;
235 else
236 #endif /* CONFIG_CHARGING */
238 bar->info.batt_charge_step = -1;
239 if (battery_level_safe())
240 bar->info.battery_state = true;
241 else
242 /* blink battery if level is low */
243 if (TIME_AFTER(current_tick, bar->battery_icon_switch_tick) &&
244 (bar->info.battlevel > -1))
246 bar->info.battery_state = !bar->info.battery_state;
247 bar->battery_icon_switch_tick = current_tick + HZ;
251 bar->info.volume = global_settings.volume;
252 #ifdef HAVE_LCD_BITMAP
253 bar->info.shuffle = global_settings.playlist_shuffle;
254 #ifdef HAS_BUTTON_HOLD
255 bar->info.keylock = button_hold();
256 #else
257 bar->info.keylock = is_keys_locked();
258 #endif /* HAS_BUTTON_HOLD */
259 #ifdef HAS_REMOTE_BUTTON_HOLD
260 bar->info.keylockremote = remote_button_hold();
261 #endif
262 bar->info.repeat = global_settings.repeat_mode;
263 bar->info.playmode = current_playmode();
265 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
266 if(!display->has_disk_led)
267 bar->info.led = led_read(HZ/2); /* delay should match polling interval */
268 #endif
269 #if CONFIG_RTC
270 bar->time = get_time();
271 #endif /* CONFIG_RTC */
273 /* only redraw if forced to, or info has changed */
274 if (force_redraw || bar->redraw_volume ||
275 #if CONFIG_RTC
276 (bar->time->tm_min != bar->last_tm_min) ||
277 #endif
278 memcmp(&(bar->info), &(bar->lastinfo), sizeof(struct status_info)))
280 struct viewport vp;
282 GET_RECT(vp,statusbar_position(display->screen_type),display);
283 display->set_viewport(&vp);
284 display->set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
285 display->fillrect(0, 0, display->getwidth(), STATUSBAR_HEIGHT);
286 display->set_drawmode(DRMODE_SOLID);
288 if (bar->info.battery_state)
289 gui_statusbar_icon_battery(display, bar->info.battlevel,
290 bar->info.batt_charge_step);
291 #ifdef HAVE_USB_POWER
292 if (bar->info.usb_inserted)
293 display->mono_bitmap(bitmap_icons_7x8[Icon_USBPlug],
294 STATUSBAR_PLUG_X_POS,
295 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
296 STATUSBAR_HEIGHT);
297 #endif /* HAVE_USB_POWER */
298 #if CONFIG_CHARGING
299 #ifdef HAVE_USB_POWER
300 else
301 #endif
302 /* draw power plug if charging */
303 if (bar->info.inserted)
304 display->mono_bitmap(bitmap_icons_7x8[Icon_Plug],
305 STATUSBAR_PLUG_X_POS,
306 STATUSBAR_Y_POS, STATUSBAR_PLUG_WIDTH,
307 STATUSBAR_HEIGHT);
308 #endif /* CONFIG_CHARGING */
309 #ifdef HAVE_RECORDING
310 /* turn off volume display in recording screen */
311 bool recscreen_on = in_recording_screen();
312 if (!recscreen_on)
313 #endif
314 bar->redraw_volume = gui_statusbar_icon_volume(bar, bar->info.volume);
315 gui_statusbar_icon_play_state(display, current_playmode() + Icon_Play);
317 #ifdef HAVE_RECORDING
318 /* If in recording screen, replace repeat mode, volume
319 and shuffle icons with recording info */
320 if (recscreen_on)
321 gui_statusbar_icon_recording_info(display);
322 else
323 #endif
325 switch (bar->info.repeat) {
326 #ifdef AB_REPEAT_ENABLE
327 case REPEAT_AB:
328 gui_statusbar_icon_play_mode(display, Icon_RepeatAB);
329 break;
330 #endif /* AB_REPEAT_ENABLE == 1 */
332 case REPEAT_ONE:
333 gui_statusbar_icon_play_mode(display, Icon_RepeatOne);
334 break;
336 case REPEAT_ALL:
337 case REPEAT_SHUFFLE:
338 gui_statusbar_icon_play_mode(display, Icon_Repeat);
339 break;
341 if (bar->info.shuffle)
342 gui_statusbar_icon_shuffle(display);
344 if (bar->info.keylock)
345 gui_statusbar_icon_lock(display);
346 #ifdef HAS_REMOTE_BUTTON_HOLD
347 if (bar->info.keylockremote)
348 gui_statusbar_icon_lock_remote(display);
349 #endif
350 #if CONFIG_RTC
351 gui_statusbar_time(display, bar->time);
352 bar->last_tm_min = bar->time->tm_min;
353 #endif /* CONFIG_RTC */
354 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
355 if(!display->has_disk_led && bar->info.led)
356 gui_statusbar_led(display);
357 #endif
358 display->update_viewport();
359 display->set_viewport(NULL);
360 bar->lastinfo = bar->info;
362 #endif /* HAVE_LCD_BITMAP */
365 #ifdef HAVE_LCD_CHARCELLS
366 display->icon(ICON_BATTERY, bar->info.battery_state);
368 if (bar->info.batt_charge_step > -1)
369 val = bar->info.batt_charge_step;
370 else
371 val = (bar->info.battlevel * 3 + 50) / 100;
372 display->icon(ICON_BATTERY_1, val >= 1);
373 display->icon(ICON_BATTERY_2, val >= 2);
374 display->icon(ICON_BATTERY_3, val >= 3);
376 val = 10 * (bar->info.volume - sound_min(SOUND_VOLUME))
377 / (sound_max(SOUND_VOLUME) - sound_min(SOUND_VOLUME));
378 display->icon(ICON_VOLUME, true);
379 display->icon(ICON_VOLUME_1, val >= 1);
380 display->icon(ICON_VOLUME_2, val >= 3);
381 display->icon(ICON_VOLUME_3, val >= 5);
382 display->icon(ICON_VOLUME_4, val >= 7);
383 display->icon(ICON_VOLUME_5, val >= 9);
385 display->icon(ICON_PLAY, current_playmode() == STATUS_PLAY);
386 display->icon(ICON_PAUSE, current_playmode() == STATUS_PAUSE);
388 display->icon(ICON_REPEAT, global_settings.repeat_mode != REPEAT_OFF);
389 display->icon(ICON_1, global_settings.repeat_mode == REPEAT_ONE);
391 display->icon(ICON_RECORD, record);
392 display->icon(ICON_AUDIO, audio);
393 display->icon(ICON_PARAM, param);
394 display->icon(ICON_USB, usb);
395 #endif /* HAVE_LCD_CHARCELLS */
398 #ifdef HAVE_LCD_BITMAP
399 /* from icon.c */
401 * Print battery icon to status bar
403 static void gui_statusbar_icon_battery(struct screen * display, int percent,
404 int batt_charge_step)
406 int fill, endfill;
407 char buffer[5];
408 unsigned int width, height;
409 #if LCD_DEPTH > 1
410 unsigned int prevfg = 0;
411 #endif
413 #if CONFIG_CHARGING
414 if (batt_charge_step >= 0)
416 fill = percent * (STATUSBAR_BATTERY_WIDTH-3) / 100;
417 endfill = 34 * batt_charge_step * (STATUSBAR_BATTERY_WIDTH-3) / 100;
419 else
420 #else
421 (void)batt_charge_step;
422 #endif
424 fill = endfill = (percent * (STATUSBAR_BATTERY_WIDTH-3) + 50) / 100;
427 #if CONFIG_CHARGING == CHARGING_MONITOR && !defined(SIMULATOR)
428 /* Certain charge controlled targets */
429 /* show graphical animation when charging instead of numbers */
430 if ((global_settings.battery_display) &&
431 (charge_state != CHARGING) &&
432 (percent > -1)) {
433 #else /* all others */
434 if (global_settings.battery_display && (percent > -1)) {
435 #endif
436 /* Numeric display */
437 display->setfont(FONT_SYSFIXED);
438 snprintf(buffer, sizeof(buffer), "%3d", percent);
439 display->getstringsize(buffer, &width, &height);
440 if (height <= STATUSBAR_HEIGHT)
441 display->putsxy(STATUSBAR_BATTERY_X_POS
442 + STATUSBAR_BATTERY_WIDTH / 2
443 - width/2, STATUSBAR_Y_POS, buffer);
444 display->setfont(FONT_UI);
447 else {
448 /* draw battery */
449 display->drawrect(STATUSBAR_BATTERY_X_POS, STATUSBAR_Y_POS, 17, 7);
450 display->vline(STATUSBAR_BATTERY_X_POS + 17, STATUSBAR_Y_POS + 2,
451 STATUSBAR_Y_POS + 4);
453 display->fillrect(STATUSBAR_BATTERY_X_POS + 1, STATUSBAR_Y_POS + 1,
454 fill, 5);
455 #if LCD_DEPTH > 1
456 if (display->depth > 1)
458 prevfg = display->get_foreground();
459 display->set_foreground(LCD_DARKGRAY);
461 #endif
462 display->fillrect(STATUSBAR_BATTERY_X_POS + 1 + fill,
463 STATUSBAR_Y_POS + 1, endfill - fill, 5);
464 #if LCD_DEPTH > 1
465 if (display->depth > 1)
466 display->set_foreground(prevfg);
467 #endif
470 if (percent == -1) {
471 display->setfont(FONT_SYSFIXED);
472 display->putsxy(STATUSBAR_BATTERY_X_POS + STATUSBAR_BATTERY_WIDTH / 2
473 - 4, STATUSBAR_Y_POS, "?");
474 display->setfont(FONT_UI);
479 * Print volume gauge to status bar
481 static bool gui_statusbar_icon_volume(struct gui_statusbar * bar, int volume)
483 int i;
484 int vol;
485 char buffer[4];
486 unsigned int width, height;
487 bool needs_redraw = false;
488 int type = global_settings.volume_type;
489 struct screen * display=bar->display;
490 const int minvol = sound_min(SOUND_VOLUME);
491 const int maxvol = sound_max(SOUND_VOLUME);
493 if (volume < minvol)
494 volume = minvol;
495 if (volume > maxvol)
496 volume = maxvol;
498 if (volume == minvol) {
499 display->mono_bitmap(bitmap_icons_7x8[Icon_Mute],
500 STATUSBAR_VOLUME_X_POS + STATUSBAR_VOLUME_WIDTH / 2 - 4,
501 STATUSBAR_Y_POS, 7, STATUSBAR_HEIGHT);
503 else {
504 /* We want to redraw the icon later on */
505 if (bar->last_volume != volume && bar->last_volume >= minvol) {
506 bar->volume_icon_switch_tick = current_tick + HZ;
509 /* If the timeout hasn't yet been reached, we show it numerically
510 and tell the caller that we want to be called again */
511 if (TIME_BEFORE(current_tick,bar->volume_icon_switch_tick)) {
512 type = 1;
513 needs_redraw = true;
516 /* display volume level numerical? */
517 if (type)
519 display->setfont(FONT_SYSFIXED);
520 snprintf(buffer, sizeof(buffer), "%2d", volume);
521 display->getstringsize(buffer, &width, &height);
522 if (height <= STATUSBAR_HEIGHT)
524 display->putsxy(STATUSBAR_VOLUME_X_POS
525 + STATUSBAR_VOLUME_WIDTH / 2
526 - width/2, STATUSBAR_Y_POS, buffer);
528 display->setfont(FONT_UI);
529 } else {
530 /* display volume bar */
531 vol = (volume - minvol) * 14 / (maxvol - minvol);
532 for(i=0; i < vol; i++) {
533 display->vline(STATUSBAR_VOLUME_X_POS + i,
534 STATUSBAR_Y_POS + 6 - i / 2,
535 STATUSBAR_Y_POS + 6);
539 bar->last_volume = volume;
541 return needs_redraw;
545 * Print play state to status bar
547 static void gui_statusbar_icon_play_state(struct screen * display, int state)
549 display->mono_bitmap(bitmap_icons_7x8[state], STATUSBAR_PLAY_STATE_X_POS,
550 STATUSBAR_Y_POS, STATUSBAR_PLAY_STATE_WIDTH,
551 STATUSBAR_HEIGHT);
555 * Print play mode to status bar
557 static void gui_statusbar_icon_play_mode(struct screen * display, int mode)
559 display->mono_bitmap(bitmap_icons_7x8[mode], STATUSBAR_PLAY_MODE_X_POS,
560 STATUSBAR_Y_POS, STATUSBAR_PLAY_MODE_WIDTH,
561 STATUSBAR_HEIGHT);
565 * Print shuffle mode to status bar
567 static void gui_statusbar_icon_shuffle(struct screen * display)
569 display->mono_bitmap(bitmap_icons_7x8[Icon_Shuffle],
570 STATUSBAR_SHUFFLE_X_POS, STATUSBAR_Y_POS,
571 STATUSBAR_SHUFFLE_WIDTH, STATUSBAR_HEIGHT);
575 * Print lock when keys are locked
577 static void gui_statusbar_icon_lock(struct screen * display)
579 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Main],
580 STATUSBAR_LOCKM_X_POS, STATUSBAR_Y_POS,
581 STATUSBAR_LOCKM_WIDTH, STATUSBAR_HEIGHT);
584 #ifdef HAS_REMOTE_BUTTON_HOLD
586 * Print remote lock when remote hold is enabled
588 static void gui_statusbar_icon_lock_remote(struct screen * display)
590 display->mono_bitmap(bitmap_icons_5x8[Icon_Lock_Remote],
591 STATUSBAR_LOCKR_X_POS, STATUSBAR_Y_POS,
592 STATUSBAR_LOCKR_WIDTH, STATUSBAR_HEIGHT);
594 #endif
596 #if (CONFIG_LED == LED_VIRTUAL) || defined(HAVE_REMOTE_LCD)
598 * no real LED: disk activity in status bar
600 static void gui_statusbar_led(struct screen * display)
602 display->mono_bitmap(bitmap_icon_disk,
603 STATUSBAR_DISK_X_POS(display->getwidth()),
604 STATUSBAR_Y_POS, STATUSBAR_DISK_WIDTH,
605 STATUSBAR_HEIGHT);
607 #endif
609 #if CONFIG_RTC
611 * Print time to status bar
613 static void gui_statusbar_time(struct screen * display, struct tm *time)
615 unsigned char buffer[6];
616 const unsigned char *p = buffer;
617 unsigned int width, height;
618 int hour, minute;
619 if ( valid_time(time) ) {
620 hour = time->tm_hour;
621 minute = time->tm_min;
622 if ( global_settings.timeformat ) { /* 12 hour clock */
623 hour %= 12;
624 if ( hour == 0 ) {
625 hour += 12;
628 snprintf(buffer, sizeof(buffer), "%02d:%02d", hour, minute);
630 else {
631 p = "--:--";
633 display->setfont(FONT_SYSFIXED);
634 display->getstringsize(p, &width, &height);
635 if (height <= STATUSBAR_HEIGHT) {
636 display->putsxy(STATUSBAR_TIME_X_END(display->getwidth()) - width,
637 STATUSBAR_Y_POS, p);
639 display->setfont(FONT_UI);
641 #endif
643 #ifdef HAVE_RECORDING
644 #if CONFIG_CODEC == SWCODEC
646 * Write a number to the display using bitmaps and return new position
648 static int write_bitmap_number(struct screen * display, int value,
649 int x, int y)
651 char buf[12], *ptr;
652 snprintf(buf, sizeof(buf), "%d", value);
654 for (ptr = buf; *ptr != '\0'; ptr++, x += BM_GLYPH_WIDTH)
655 display->mono_bitmap(bitmap_glyphs_4x8[*ptr - '0'], x, y,
656 BM_GLYPH_WIDTH, STATUSBAR_HEIGHT);
657 return x;
661 * Write format info bitmaps - right justified
663 static void gui_statusbar_write_format_info(struct screen * display)
665 /* Can't fit info for sw codec targets in statusbar using FONT_SYSFIXED
666 so must use icons */
667 int rec_format = global_settings.rec_format;
668 unsigned bitrk = 0; /* compiler warns about unitialized use !! */
669 int xpos = STATUSBAR_ENCODER_X_POS;
670 int width = STATUSBAR_ENCODER_WIDTH;
671 const unsigned char *bm = bitmap_formats_18x8[rec_format];
673 if (rec_format == REC_FORMAT_MPA_L3)
675 /* Special handling for mp3 */
676 bitrk = global_settings.mp3_enc_config.bitrate;
677 bitrk = mp3_enc_bitr[bitrk];
679 width = BM_MPA_L3_M_WIDTH;
681 /* Slide 'M' to right if fewer than three digits used */
682 if (bitrk > 999)
683 bitrk = 999; /* neurotic safety check if corrupted */
684 else
686 if (bitrk < 100)
687 xpos += BM_GLYPH_WIDTH;
688 if (bitrk < 10)
689 xpos += BM_GLYPH_WIDTH;
694 /* Show bitmap - clipping right edge if needed */
695 display->mono_bitmap_part(bm, 0, 0, STATUSBAR_ENCODER_WIDTH,
696 xpos, STATUSBAR_Y_POS, width, STATUSBAR_HEIGHT);
698 if (rec_format == REC_FORMAT_MPA_L3)
700 xpos += BM_MPA_L3_M_WIDTH; /* to right of 'M' */
701 write_bitmap_number(display, bitrk, xpos, STATUSBAR_Y_POS);
706 * Write sample rate using bitmaps - left justified
708 static void gui_statusbar_write_samplerate_info(struct screen * display)
710 unsigned long samprk;
711 int xpos;
713 #ifdef SIMULATOR
714 samprk = 44100;
715 #else
716 #ifdef HAVE_SPDIF_REC
717 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
718 /* Use rate in use, not current measured rate if it changed */
719 samprk = pcm_rec_sample_rate();
720 else
721 #endif
722 samprk = rec_freq_sampr[global_settings.rec_frequency];
723 #endif /* SIMULATOR */
725 samprk /= 1000;
726 if (samprk > 99)
727 samprk = 99; /* Limit to 3 glyphs */
729 xpos = write_bitmap_number(display, (unsigned)samprk,
730 STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS);
732 /* write the 'k' */
733 display->mono_bitmap(bitmap_glyphs_4x8[Glyph_4x8_k], xpos,
734 STATUSBAR_Y_POS, BM_GLYPH_WIDTH,
735 STATUSBAR_HEIGHT);
737 #endif /* CONFIG_CODEC == SWCODEC */
739 static void gui_statusbar_icon_recording_info(struct screen * display)
741 #if CONFIG_CODEC != SWCODEC
742 char buffer[3];
743 const char *p = buffer;
744 int width, height;
745 display->setfont(FONT_SYSFIXED);
746 #endif /* CONFIG_CODEC != SWCODEC */
748 /* Display Codec info in statusbar */
749 #if CONFIG_CODEC == SWCODEC
750 gui_statusbar_write_format_info(display);
751 #else /* !SWCODEC */
752 display->mono_bitmap(bitmap_icons_5x8[Icon_q],
753 STATUSBAR_ENCODER_X_POS + 8, STATUSBAR_Y_POS,
754 5, STATUSBAR_HEIGHT);
756 snprintf(buffer, sizeof(buffer), "%d", global_settings.rec_quality);
757 display->getstringsize(buffer, &width, &height);
758 if (height <= STATUSBAR_HEIGHT)
759 display->putsxy(STATUSBAR_ENCODER_X_POS + 13, STATUSBAR_Y_POS, buffer);
760 #endif /* CONFIG_CODEC == SWCODEC */
762 /* Display Samplerate info in statusbar */
763 #if CONFIG_CODEC == SWCODEC
764 /* SWCODEC targets use bitmaps for glyphs */
765 gui_statusbar_write_samplerate_info(display);
766 #else /* !SWCODEC */
767 /* hwcodec targets have sysfont characters */
768 #ifdef HAVE_SPDIF_REC
769 if (global_settings.rec_source == AUDIO_SRC_SPDIF)
771 /* Can't measure S/PDIF sample rate on Archos/Sim yet */
772 p = "--";
774 else
775 #endif /* HAVE_SPDIF_IN */
777 static const char * const freq_strings[] =
778 {"44", "48", "32", "22", "24", "16"};
779 p = freq_strings[global_settings.rec_frequency];
782 display->getstringsize(p, &width, &height);
784 if (height <= STATUSBAR_HEIGHT)
785 display->putsxy(STATUSBAR_RECFREQ_X_POS, STATUSBAR_Y_POS, p);
787 display->setfont(FONT_UI);
788 #endif /* CONFIG_CODEC == SWCODEC */
790 /* Display Channel status in status bar */
791 if(global_settings.rec_channels)
793 display->mono_bitmap(bitmap_icons_5x8[Icon_Mono],
794 STATUSBAR_RECCHANNELS_X_POS , STATUSBAR_Y_POS,
795 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
797 else
799 display->mono_bitmap(bitmap_icons_5x8[Icon_Stereo],
800 STATUSBAR_RECCHANNELS_X_POS, STATUSBAR_Y_POS,
801 STATUSBAR_RECCHANNELS_WIDTH, STATUSBAR_HEIGHT);
804 #endif /* HAVE_RECORDING */
806 #endif /* HAVE_LCD_BITMAP */
808 void gui_syncstatusbar_init(struct gui_syncstatusbar * bars)
810 int i;
811 FOR_NB_SCREENS(i) {
812 gui_statusbar_init( &(bars->statusbars[i]) );
813 gui_statusbar_set_screen( &(bars->statusbars[i]), &(screens[i]) );
817 void gui_syncstatusbar_draw(struct gui_syncstatusbar * bars,
818 bool force_redraw)
820 #ifdef HAVE_LCD_BITMAP
821 if(!global_settings.statusbar)
822 return;
823 #endif /* HAVE_LCD_BITMAP */
824 int i;
825 FOR_NB_SCREENS(i) {
826 gui_statusbar_draw( &(bars->statusbars[i]), force_redraw );
830 #ifdef HAVE_LCD_BITMAP
831 void gui_statusbar_changed( enum screen_type screen,
832 enum statusbar_values old)
834 /* clear and update the statusbar area to remove old parts */
835 enum statusbar_values bar = statusbar_position(screen);
837 struct screen *display = &screens[screen];
838 struct viewport vp;
840 if (old != STATUSBAR_OFF && old != bar)
842 GET_RECT(vp, old, display);
843 display->set_viewport(&vp);
844 display->clear_viewport();
845 display->update_viewport();
846 display->set_viewport(NULL);
849 #endif
851 #ifdef HAVE_REMOTE_LCD
852 enum statusbar_values statusbar_position(int screen)
854 if (screen == SCREEN_REMOTE)
855 return global_settings.remote_statusbar;
856 return global_settings.statusbar;
858 #endif