blob: 02c61a4f4076a6a453abd7a5daf56e8d601af2b4 [file] [log] [blame]
Björn Stenbergb1b8bd42002-09-24 17:22:12 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
Nicolas Pennequin357ffb32008-05-05 10:32:46 +000010 * Copyright (C) 2002 Björn Stenberg
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000011 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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.
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Kevin Ferraref57d0222005-11-22 21:55:05 +000021
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000022#include <stdbool.h>
23#include <string.h>
24#include <stdio.h>
25#include "backlight.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000026#include "action.h"
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000027#include "lcd.h"
Dave Chapmanfc865cb2006-10-12 20:45:31 +000028#ifdef HAVE_REMOTE_LCD
29#include "lcd-remote.h"
30#endif
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000031#include "lang.h"
32#include "icons.h"
33#include "font.h"
Linus Nielsen Feltzing8a237a82005-04-04 12:06:29 +000034#include "audio.h"
Jörg Hohensohnf9933652004-01-05 20:42:51 +000035#include "mp3_playback.h"
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000036#include "usb.h"
37#include "settings.h"
Markus Braun88098be2002-10-11 08:56:23 +000038#include "status.h"
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000039#include "playlist.h"
Daniel Stenberg79a6cb62003-02-15 00:03:23 +000040#include "sprintf.h"
Björn Stenbergba371fb2003-06-29 16:33:04 +000041#include "kernel.h"
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +000042#include "power.h"
Jörg Hohensohnb5b73042003-07-18 22:01:13 +000043#include "system.h"
44#include "powermgmt.h"
45#include "adc.h"
Linus Nielsen Feltzing10b92c42004-03-12 10:20:33 +000046#include "action.h"
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +000047#include "talk.h"
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +000048#include "misc.h"
Magnus Holmgren1e5119b2005-07-05 19:33:33 +000049#include "id3.h"
Jens Arnold7f6b6402004-10-12 00:02:51 +000050#include "screens.h"
Kjell Ericson6c2fb552004-10-19 16:17:35 +000051#include "debug.h"
Jörg Hohensohnce51bc42005-02-19 16:23:30 +000052#include "led.h"
Linus Nielsen Feltzing674eaca2005-04-01 13:41:03 +000053#include "sound.h"
Kevin Ferraree991bee2005-11-16 15:12:15 +000054#include "splash.h"
Kevin Ferrare1a1abf22005-11-20 01:02:14 +000055#include "statusbar.h"
Kevin Ferrare74b6af92005-11-22 03:38:07 +000056#include "screen_access.h"
Zakk Roberts35d36582006-04-21 06:20:02 +000057#include "pcmbuf.h"
Kevin Ferraref77ac7a2006-07-02 12:28:27 +000058#include "list.h"
Jonathan Gordond152b642006-12-19 12:26:03 +000059#include "yesno.h"
Dave Chapmand746b792008-03-29 01:14:10 +000060#include "backdrop.h"
Jonathan Gordon95be4fe2008-05-11 14:08:46 +000061#include "viewport.h"
Kevin Ferrare1a1abf22005-11-20 01:02:14 +000062
Dave Chapmanfc865cb2006-10-12 20:45:31 +000063#ifdef HAVE_LCD_BITMAP
64#include <bitmaps/usblogo.h>
65#endif
66
67#ifdef HAVE_REMOTE_LCD
68#include <bitmaps/remote_usblogo.h>
69#endif
70
Jörg Hohensohnce51bc42005-02-19 16:23:30 +000071#ifdef HAVE_MMC
72#include "ata_mmc.h"
73#endif
Magnus Holmgren4b711c22005-09-24 15:22:48 +000074#if CONFIG_CODEC == SWCODEC
75#include "dsp.h"
76#endif
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000077
Markus Braun88098be2002-10-11 08:56:23 +000078#ifdef HAVE_LCD_BITMAP
Magnus Holmgreneab21c62005-08-11 18:21:14 +000079#define SCROLLBAR_WIDTH 6
Markus Braun88098be2002-10-11 08:56:23 +000080#endif
81
Nils Wallménius2e2cbfe2007-11-22 19:56:57 +000082/* only used in set_time screen */
83#if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
Nils Wallménius7567e992007-11-22 19:46:27 +000084static int clamp_value_wrap(int value, int max, int min)
85{
86 if (value > max)
87 return min;
88 if (value < min)
89 return max;
90 return value;
91}
Nils Wallménius2e2cbfe2007-11-22 19:56:57 +000092#endif
Nils Wallménius7567e992007-11-22 19:46:27 +000093
Björn Stenbergb1b8bd42002-09-24 17:22:12 +000094void usb_screen(void)
95{
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +000096#ifdef USB_NONE
97 /* nothing here! */
98#else
Kevin Ferrare74b6af92005-11-22 03:38:07 +000099 int i;
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000100 bool statusbar = global_settings.statusbar; /* force the statusbar */
101 global_settings.statusbar = true;
Dave Chapman6c31a9a2007-06-06 17:30:01 +0000102#if LCD_DEPTH > 1
Peter D'Hoye93b899d2006-05-21 11:00:02 +0000103 show_main_backdrop();
104#endif
Nicolas Pennequin7fdfa562007-04-25 21:44:56 +0000105#if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
106 show_remote_main_backdrop();
107#endif
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000108 FOR_NB_SCREENS(i)
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000109 {
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000110 screens[i].backlight_on();
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000111 screens[i].clear_display();
112#if NB_SCREENS > 1
113 if (i == SCREEN_REMOTE)
114 {
115 screens[i].bitmap(remote_usblogo,
Marianne Arnold99975e92006-11-20 10:56:22 +0000116 (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo),
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000117 (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2,
118 BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo);
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000119 }
120 else
121 {
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000122#endif
Jens Arnoldd6e92902006-10-21 12:02:14 +0000123#ifdef HAVE_LCD_BITMAP
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000124 screens[i].transparent_bitmap(usblogo,
125 (LCD_WIDTH-BMPWIDTH_usblogo),
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000126 (LCD_HEIGHT-BMPHEIGHT_usblogo)/2,
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000127 BMPWIDTH_usblogo, BMPHEIGHT_usblogo);
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000128#else
Jens Arnold022d0262007-08-18 12:36:15 +0000129 screens[i].double_height(false);
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000130 screens[i].puts_scroll(0, 0, "[USB Mode]");
131 status_set_param(false);
132 status_set_audio(false);
133 status_set_usb(true);
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000134#endif /* HAVE_LCD_BITMAP */
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000135#if NB_SCREENS > 1
136 }
137#endif
138 screens[i].update();
139 }
Dave Chapmanfc865cb2006-10-12 20:45:31 +0000140
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000141 gui_syncstatusbar_draw(&statusbars, true);
142#ifdef SIMULATOR
143 while (button_get(true) & BUTTON_REL);
144#else
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000145 usb_acknowledge(SYS_USB_CONNECTED_ACK);
Markus Braun88098be2002-10-11 08:56:23 +0000146 while(usb_wait_for_disconnect_w_tmo(&button_queue, HZ)) {
147 if(usb_inserted()) {
Jörg Hohensohn7e1d36f2005-02-19 14:45:34 +0000148#ifdef HAVE_MMC /* USB-MMC bridge can report activity */
149 led(mmc_usb_active(HZ));
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000150#endif /* HAVE_MMC */
Kevin Ferrare1a1abf22005-11-20 01:02:14 +0000151 gui_syncstatusbar_draw(&statusbars, false);
Markus Braun88098be2002-10-11 08:56:23 +0000152 }
153 }
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000154#endif /* SIMULATOR */
Hardeep Sidhu12d18442003-01-09 03:53:46 +0000155#ifdef HAVE_LCD_CHARCELLS
156 status_set_usb(false);
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000157#endif /* HAVE_LCD_CHARCELLS */
158 FOR_NB_SCREENS(i)
159 screens[i].backlight_on();
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000160 global_settings.statusbar = statusbar;
Daniel Stenberg8e43ccb2003-12-12 13:34:27 +0000161#endif /* USB_NONE */
Björn Stenbergb1b8bd42002-09-24 17:22:12 +0000162}
163
Jens Arnold7f6b6402004-10-12 00:02:51 +0000164#ifdef HAVE_MMC
165int mmc_remove_request(void)
166{
Michael Sevakisa9b2fb52007-10-16 01:25:17 +0000167 struct queue_event ev;
Kevin Ferrare6919d1e2005-11-22 04:15:27 +0000168 int i;
Kevin Ferrare74b6af92005-11-22 03:38:07 +0000169 FOR_NB_SCREENS(i)
170 screens[i].clear_display();
Jens Arnold4d6374c2007-03-16 21:56:08 +0000171 gui_syncsplash(1, str(LANG_REMOVE_MMC));
Steve Bavin32a95752007-10-19 15:31:42 +0000172 if (global_settings.talk_menu)
Jens Arnold1f6c4802004-11-12 22:19:29 +0000173 talk_id(LANG_REMOVE_MMC, false);
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000174
Jens Arnold7f6b6402004-10-12 00:02:51 +0000175 while (1)
176 {
177 queue_wait_w_tmo(&button_queue, &ev, HZ/2);
178 switch (ev.id)
179 {
Michael Sevakis1167e3c2007-06-30 02:08:27 +0000180 case SYS_HOTSWAP_EXTRACTED:
181 return SYS_HOTSWAP_EXTRACTED;
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000182
Jens Arnold7f6b6402004-10-12 00:02:51 +0000183 case SYS_USB_DISCONNECTED:
184 return SYS_USB_DISCONNECTED;
185 }
186 }
187}
188#endif
189
Nils Wallménius3f8c0752007-07-08 15:32:56 +0000190/* the charging screen is only used for archos targets */
191#if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH)
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000192
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000193#ifdef HAVE_LCD_BITMAP
Jens Arnold2597a132006-12-25 14:01:47 +0000194static void charging_display_info(bool animate)
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000195{
196 unsigned char charging_logo[36];
197 const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2;
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000198 const int pox_y = 32;
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000199 static unsigned phase = 3;
200 unsigned i;
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000201 char buf[32];
Jörg Hohensohneb28d432003-12-03 07:05:13 +0000202 (void)buf;
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000203
Jörg Hohensohneb28d432003-12-03 07:05:13 +0000204#ifdef NEED_ATA_POWER_BATT_MEASURE
205 if (ide_powered()) /* FM and V2 can only measure when ATA power is on */
206#endif
207 {
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000208 int battv = battery_voltage();
Jens Arnold1d1d9a82007-08-15 23:57:27 +0000209 snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 1000,
210 (battv % 1000) / 10, battery_level());
Jörg Hohensohneb28d432003-12-03 07:05:13 +0000211 lcd_puts(0, 7, buf);
212 }
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000213
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000214#if CONFIG_CHARGING == CHARGING_CONTROL
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000215
216 snprintf(buf, 32, "Charge mode:");
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000217 lcd_puts(0, 2, buf);
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000218
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000219 if (charge_state == CHARGING)
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000220 snprintf(buf, 32, str(LANG_BATTERY_CHARGE));
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000221 else if (charge_state == TOPOFF)
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000222 snprintf(buf, 32, str(LANG_BATTERY_TOPOFF_CHARGE));
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000223 else if (charge_state == TRICKLE)
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000224 snprintf(buf, 32, str(LANG_BATTERY_TRICKLE_CHARGE));
225 else
226 snprintf(buf, 32, "not charging");
227
228 lcd_puts(0, 3, buf);
Linus Nielsen Feltzingae815a02004-10-12 08:42:11 +0000229 if (!charger_enabled)
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000230 animate = false;
Jens Arnold0dd1f8e2006-06-06 22:23:52 +0000231#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000232
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000233
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000234 /* middle part */
235 memset(charging_logo+3, 0x00, 32);
236 charging_logo[0] = 0x3C;
237 charging_logo[1] = 0x24;
238 charging_logo[2] = charging_logo[35] = 0xFF;
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000239
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000240 if (!animate)
241 { /* draw the outline */
242 /* middle part */
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000243 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
244 sizeof(charging_logo), 8);
Jens Arnold7e11acb2005-06-28 23:15:47 +0000245 lcd_set_drawmode(DRMODE_FG);
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000246 /* upper line */
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000247 charging_logo[0] = charging_logo[1] = 0x00;
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000248 memset(charging_logo+2, 0x80, 34);
Jens Arnoldf894a4c2005-07-06 22:58:02 +0000249 lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8);
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000250 /* lower line */
251 memset(charging_logo+2, 0x01, 34);
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000252 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16,
253 sizeof(charging_logo), 8);
Jens Arnold7e11acb2005-06-28 23:15:47 +0000254 lcd_set_drawmode(DRMODE_SOLID);
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000255 }
256 else
257 { /* animate the middle part */
258 for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++)
259 {
260 if ((i-phase) % 8 == 0)
261 { /* draw a "bubble" here */
262 unsigned bitpos;
263 bitpos = (phase + i/8) % 15; /* "bounce" effect */
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000264 if (bitpos > 7)
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000265 bitpos = 14 - bitpos;
266 charging_logo[i] = 0x01 << bitpos;
267 }
268 }
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000269 lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8,
270 sizeof(charging_logo), 8);
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000271 phase++;
272 }
273 lcd_update();
274}
Jörg Hohensohn20caff22003-07-19 21:43:12 +0000275#else /* not HAVE_LCD_BITMAP */
Jens Arnold2996d172004-11-21 00:17:59 +0000276
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000277static unsigned long logo_chars[4];
Jens Arnold2996d172004-11-21 00:17:59 +0000278static const unsigned char logo_pattern[] = {
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000279 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */
280 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */
281 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */
282 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */
Jens Arnold2996d172004-11-21 00:17:59 +0000283};
284
285static void logo_lock_patterns(bool on)
286{
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000287 int i;
Jens Arnold2996d172004-11-21 00:17:59 +0000288
289 if (on)
290 {
291 for (i = 0; i < 4; i++)
292 logo_chars[i] = lcd_get_locked_pattern();
Jens Arnold2996d172004-11-21 00:17:59 +0000293 }
294 else
295 {
296 for (i = 0; i < 4; i++)
297 lcd_unlock_pattern(logo_chars[i]);
298 }
299}
300
Jens Arnold2597a132006-12-25 14:01:47 +0000301static void charging_display_info(bool animate)
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000302{
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000303 int battv;
Jens Arnold2996d172004-11-21 00:17:59 +0000304 unsigned i, ypos;
305 static unsigned phase = 3;
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000306 char buf[32];
Jens Arnold2996d172004-11-21 00:17:59 +0000307
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000308 battv = battery_voltage();
Jens Arnold1d1d9a82007-08-15 23:57:27 +0000309 snprintf(buf, sizeof(buf), " %d.%02dV", battv / 1000, (battv % 1000) / 10);
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000310 lcd_puts(4, 1, buf);
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000311
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000312 memcpy(buf, logo_pattern, 32); /* copy logo patterns */
Jens Arnold2996d172004-11-21 00:17:59 +0000313
314 if (!animate) /* build the screen */
315 {
316 lcd_double_height(false);
317 lcd_puts(0, 0, "[Charging]");
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000318 for (i = 0; i < 4; i++)
319 lcd_putc(i, 1, logo_chars[i]);
Jens Arnold2996d172004-11-21 00:17:59 +0000320 }
321 else /* animate the logo */
322 {
323 for (i = 3; i < MIN(19, phase); i++)
324 {
325 if ((i - phase) % 5 == 0)
326 { /* draw a "bubble" here */
327 ypos = (phase + i/5) % 9; /* "bounce" effect */
328 if (ypos > 4)
329 ypos = 8 - ypos;
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000330 buf[5 - ypos + 8 * (i/5)] |= 0x10 >> (i%5);
Jens Arnold2996d172004-11-21 00:17:59 +0000331 }
332 }
333 phase++;
334 }
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000335
Jens Arnold2996d172004-11-21 00:17:59 +0000336 for (i = 0; i < 4; i++)
Jens Arnoldad4e3d62007-03-26 07:52:13 +0000337 lcd_define_pattern(logo_chars[i], buf + 8 * i);
Jens Arnoldf9b90e92007-04-06 22:55:00 +0000338
339 lcd_update();
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000340}
Jens Arnold61753a82004-11-21 00:44:44 +0000341#endif /* (not) HAVE_LCD_BITMAP */
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000342
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000343/* blocks while charging, returns on event:
344 1 if charger cable was removed
345 2 if Off/Stop key was pressed
346 3 if On key was pressed
347 4 if USB was connected */
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000348
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000349int charging_screen(void)
350{
Jean-Philippe Bernardy06f1c0a2005-02-12 12:51:06 +0000351 unsigned int button;
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000352 int rc = 0;
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000353
354 ide_power_enable(false); /* power down the disk, else would be spinning */
355
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000356 lcd_clear_display();
Jens Arnoldb3e31b92004-11-20 22:43:38 +0000357 backlight_set_timeout(global_settings.backlight_timeout);
Jens Arnold748c7512005-05-30 05:57:19 +0000358#ifdef HAVE_REMOTE_LCD
Christian Gmeiner7477c092005-05-30 00:00:22 +0000359 remote_backlight_set_timeout(global_settings.remote_backlight_timeout);
Jens Arnold748c7512005-05-30 05:57:19 +0000360#endif
Jens Arnolda6d409d2005-11-23 20:12:33 +0000361 backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged);
Kevin Ferrare1a1abf22005-11-20 01:02:14 +0000362 gui_syncstatusbar_draw(&statusbars, true);
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000363
Jens Arnold2996d172004-11-21 00:17:59 +0000364#ifdef HAVE_LCD_CHARCELLS
365 logo_lock_patterns(true);
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000366#endif
Jens Arnold2996d172004-11-21 00:17:59 +0000367 charging_display_info(false);
368
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000369 do
370 {
Kevin Ferrare1a1abf22005-11-20 01:02:14 +0000371 gui_syncstatusbar_draw(&statusbars, false);
Jörg Hohensohnb5b73042003-07-18 22:01:13 +0000372 charging_display_info(true);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000373 button = get_action(CONTEXT_STD,HZ/3);
374 if (button == ACTION_STD_OK)
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000375 rc = 2;
Jens Arnold7c7dd432005-07-11 19:14:26 +0000376 else if (usb_detect())
377 rc = 3;
378 else if (!charger_inserted())
379 rc = 1;
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000380 } while (!rc);
381
Jens Arnold2996d172004-11-21 00:17:59 +0000382#ifdef HAVE_LCD_CHARCELLS
383 logo_lock_patterns(false);
384#endif
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000385 return rc;
386}
Nils Wallménius3f8c0752007-07-08 15:32:56 +0000387#endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */
Jörg Hohensohn5dd17b12003-07-17 20:29:51 +0000388
Nils Wallméniusf28da1a2007-08-12 19:49:03 +0000389#if CONFIG_CHARGING
Björn Stenberg461d6e32003-12-04 00:08:25 +0000390void charging_splash(void)
391{
Jens Arnold4d6374c2007-03-16 21:56:08 +0000392 gui_syncsplash(2*HZ, (unsigned char *)str(LANG_BATTERY_CHARGE));
Jens Arnold3c348df2005-01-26 22:48:25 +0000393 button_clear_queue();
Björn Stenberg461d6e32003-12-04 00:08:25 +0000394}
Jens Arnoldcd0bb1c2005-05-07 01:30:16 +0000395#endif
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000396
397
Jens Arnold2c7b1272007-03-16 23:47:03 +0000398#if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0)
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000399
400/* little helper function for voice output */
Jens Arnold8fb33612004-08-18 01:09:31 +0000401static void say_time(int cursorpos, const struct tm *tm)
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000402{
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000403 int value = 0;
Nils Wallménius537b27d2007-10-24 10:29:45 +0000404 int unit = 0;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000405
Steve Bavin32a95752007-10-19 15:31:42 +0000406 if (!global_settings.talk_menu)
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000407 return;
408
409 switch(cursorpos)
410 {
411 case 0:
412 value = tm->tm_hour;
Nils Wallménius537b27d2007-10-24 10:29:45 +0000413 unit = UNIT_HOUR;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000414 break;
415 case 1:
416 value = tm->tm_min;
Nils Wallménius537b27d2007-10-24 10:29:45 +0000417 unit = UNIT_MIN;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000418 break;
419 case 2:
420 value = tm->tm_sec;
Nils Wallménius537b27d2007-10-24 10:29:45 +0000421 unit = UNIT_SEC;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000422 break;
423 case 3:
424 value = tm->tm_year + 1900;
425 break;
426 case 5:
427 value = tm->tm_mday;
428 break;
429 }
Magnus Holmgren1e5119b2005-07-05 19:33:33 +0000430
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000431 if (cursorpos == 4) /* month */
Linus Nielsen Feltzing08ebcad2004-04-21 21:40:26 +0000432 talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000433 else
Nils Wallménius537b27d2007-10-24 10:29:45 +0000434 talk_value(value, unit, false);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000435}
436
437
438#define INDEX_X 0
439#define INDEX_Y 1
Nils Wallménius2e806102007-07-01 12:08:45 +0000440
441#define SEPARATOR ":"
Nils Wallménius2e806102007-07-01 12:08:45 +0000442bool set_time_screen(const char* title, struct tm *tm)
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000443{
444 bool done = false;
445 int button;
Nils Wallménius7567e992007-11-22 19:46:27 +0000446 unsigned int i, j, s;
447 int cursorpos = 0;
Nils Wallménius2e806102007-07-01 12:08:45 +0000448 unsigned int julianday;
449 unsigned int realyear;
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000450 unsigned int width;
Nils Wallménius7567e992007-11-22 19:46:27 +0000451 unsigned int min, max;
Nils Wallménius3f8c0752007-07-08 15:32:56 +0000452 unsigned int statusbar_height = 0;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000453 unsigned int separator_width, weekday_width;
Nils Wallménius7567e992007-11-22 19:46:27 +0000454 unsigned int prev_line_height;
455 int daysinmonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000456 unsigned char buffer[20];
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000457 struct viewport vp[NB_SCREENS];
458 int nb_lines;
Jens Arnold033ba162004-08-26 20:30:22 +0000459
Nils Wallménius7567e992007-11-22 19:46:27 +0000460 /* 6 possible cursor possitions, 2 values stored for each: x, y */
461 unsigned int cursor[6][2];
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000462
463 int *valptr = NULL;
Nils Wallménius2e806102007-07-01 12:08:45 +0000464 unsigned char *ptr[6];
Nils Wallménius2e806102007-07-01 12:08:45 +0000465
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000466 if(global_settings.statusbar)
Nils Wallménius2e806102007-07-01 12:08:45 +0000467 statusbar_height = STATUSBAR_HEIGHT;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000468
Nils Wallménius7567e992007-11-22 19:46:27 +0000469 /* speak selection when screen is entered */
470 say_time(cursorpos, tm);
471
472 while (!done) {
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000473 /* for easy acess in the drawing loop */
474 ptr[0] = buffer; /* hours */
475 ptr[1] = buffer + 3; /* minutes */
476 ptr[2] = buffer + 6; /* seconds */
477 ptr[3] = buffer + 9; /* year */
Steve Bavinfda41b82007-10-24 15:34:36 +0000478 ptr[4] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* monthname */
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000479 ptr[5] = buffer + 14; /* day of month */
480
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000481 /* calculate the number of days in febuary */
482 realyear = tm->tm_year + 1900;
483 if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0)
484 daysinmonth[1] = 29;
485 else
486 daysinmonth[1] = 28;
487
488 /* fix day if month or year changed */
489 if (tm->tm_mday > daysinmonth[tm->tm_mon])
490 tm->tm_mday = daysinmonth[tm->tm_mon];
491
492 /* calculate day of week */
Nils Wallménius7567e992007-11-22 19:46:27 +0000493 julianday = tm->tm_mday;
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000494 for(i = 0; (int)i < tm->tm_mon; i++) {
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000495 julianday += daysinmonth[i];
496 }
Nils Wallménius7567e992007-11-22 19:46:27 +0000497
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000498 tm->tm_wday = (realyear + julianday + (realyear - 1) / 4 -
499 (realyear - 1) / 100 + (realyear - 1) / 400 + 7 - 1) % 7;
500
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000501 /* put all the numbers we want from the tm struct into
502 an easily printable buffer */
Nils Wallméniusede37312007-07-02 19:52:19 +0000503 snprintf(buffer, sizeof(buffer),
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000504 "%02d " "%02d " "%02d " "%04d " "%02d",
Nils Wallménius2e806102007-07-01 12:08:45 +0000505 tm->tm_hour, tm->tm_min, tm->tm_sec,
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000506 tm->tm_year+1900, tm->tm_mday);
Nils Wallméniusede37312007-07-02 19:52:19 +0000507
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000508 /* convert spaces in the buffer to '\0' to make it possible to work
Nils Wallménius2e806102007-07-01 12:08:45 +0000509 directly on the buffer */
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000510 for(i=0; i < sizeof(buffer); i++)
511 {
512 if(buffer[i] == ' ')
513 buffer[i] = '\0';
514 }
515
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000516 FOR_NB_SCREENS(s)
Nils Wallménius2e806102007-07-01 12:08:45 +0000517 {
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000518 viewport_set_defaults(&vp[s], s);
519 nb_lines = viewport_get_nb_lines(&vp[s]);
520
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000521 /* minimum lines needed is 2 + title line */
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000522 if (nb_lines < 4)
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000523 {
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000524 vp[s].font = FONT_SYSFIXED;
525 nb_lines = viewport_get_nb_lines(&vp[s]);
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000526 }
527
528 /* recalculate the positions and offsets */
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000529 if (nb_lines >= 3)
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000530 screens[s].getstringsize(title, NULL, &prev_line_height);
Nils Wallménius2e806102007-07-01 12:08:45 +0000531 else
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000532 prev_line_height = 0;
Nils Wallménius7567e992007-11-22 19:46:27 +0000533
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000534 screens[s].getstringsize(SEPARATOR, &separator_width, NULL);
535
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000536 /* weekday */
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000537 screens[s].getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday),
538 &weekday_width, NULL);
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000539 screens[s].getstringsize(" ", &separator_width, NULL);
540
Nils Wallménius7567e992007-11-22 19:46:27 +0000541 for(i=0, j=0; i < 6; i++)
542 {
543 if(i==3) /* second row */
544 {
545 j = weekday_width + separator_width;;
546 prev_line_height *= 2;
547 }
548 screens[s].getstringsize(ptr[i], &width, NULL);
549 cursor[i][INDEX_Y] = prev_line_height + statusbar_height;
550 cursor[i][INDEX_X] = j;
551 j += width + separator_width;
552 }
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000553
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000554 /* draw the screen */
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000555 screens[s].set_viewport(&vp[s]);
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000556 screens[s].clear_viewport();
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000557 /* display the screen title */
558 screens[s].puts_scroll(0, 0, title);
Nils Wallméniusaedf68a2007-07-21 08:28:48 +0000559
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000560 /* these are not selectable, so we draw them outside the loop */
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000561 /* name of the week day */
562 screens[s].putsxy(0, cursor[3][INDEX_Y],
563 str(LANG_WEEKDAY_SUNDAY + tm->tm_wday));
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000564
565 /* draw the selected item with drawmode set to
566 DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable
567 items with drawmode DRMODE_SOLID */
568 for(i=0; i<6; i++)
569 {
Nils Wallménius7567e992007-11-22 19:46:27 +0000570 if (cursorpos == (int)i)
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000571 vp[s].drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID);
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000572
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000573 screens[s].putsxy(cursor[i][INDEX_X],
574 cursor[i][INDEX_Y], ptr[i]);
Nils Wallménius7567e992007-11-22 19:46:27 +0000575
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000576 vp[s].drawmode = DRMODE_SOLID;
Nils Wallménius7567e992007-11-22 19:46:27 +0000577
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000578 screens[s].putsxy(cursor[i/4 +1][INDEX_X] - separator_width,
Nils Wallménius7567e992007-11-22 19:46:27 +0000579 cursor[0][INDEX_Y], SEPARATOR);
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000580 }
581
582 /* print help text */
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000583 if (nb_lines > 4)
Nils Wallméniusb3113672007-08-05 19:19:39 +0000584 screens[s].puts(0, 4, str(LANG_TIME_SET_BUTTON));
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000585 if (nb_lines > 5)
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000586 screens[s].puts(0, 5, str(LANG_TIME_REVERT));
Jonathan Gordonaff220c2008-05-11 13:59:27 +0000587 screens[s].update_viewport();
588 screens[s].set_viewport(NULL);
Nils Wallménius2e806102007-07-01 12:08:45 +0000589 }
Kevin Ferrare1a1abf22005-11-20 01:02:14 +0000590 gui_syncstatusbar_draw(&statusbars, true);
Nils Wallménius3f8c0752007-07-08 15:32:56 +0000591
Nils Wallménius7567e992007-11-22 19:46:27 +0000592 /* set the most common numbers */
593 min = 0;
594 max = 59;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000595 /* calculate the minimum and maximum for the number under cursor */
Nils Wallménius7567e992007-11-22 19:46:27 +0000596 switch(cursorpos) {
597 case 0: /* hour */
598 max = 23;
599 valptr = &tm->tm_hour;
600 break;
601 case 1: /* minute */
602 valptr = &tm->tm_min;
603 break;
604 case 2: /* second */
605 valptr = &tm->tm_sec;
606 break;
607 case 3: /* year */
608 min = 1;
609 max = 200;
610 valptr = &tm->tm_year;
611 break;
612 case 4: /* month */
613 max = 11;
614 valptr = &tm->tm_mon;
615 break;
616 case 5: /* day */
617 min = 1;
618 max = daysinmonth[tm->tm_mon];
619 valptr = &tm->tm_mday;
620 break;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000621 }
622
Jonathan Gordon3d73b8e2007-07-15 10:30:11 +0000623 button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000624 switch ( button ) {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000625 case ACTION_STD_PREV:
Nils Wallménius7567e992007-11-22 19:46:27 +0000626 cursorpos = clamp_value_wrap(--cursorpos, 5, 0);
627 say_time(cursorpos, tm);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000628 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000629 case ACTION_STD_NEXT:
Nils Wallménius7567e992007-11-22 19:46:27 +0000630 cursorpos = clamp_value_wrap(++cursorpos, 5, 0);
631 say_time(cursorpos, tm);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000632 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000633 case ACTION_SETTINGS_INC:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000634 case ACTION_SETTINGS_INCREPEAT:
Nils Wallménius7567e992007-11-22 19:46:27 +0000635 *valptr = clamp_value_wrap(++(*valptr), max, min);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000636 say_time(cursorpos, tm);
637 break;
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000638 case ACTION_SETTINGS_DEC:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000639 case ACTION_SETTINGS_DECREPEAT:
Nils Wallménius7567e992007-11-22 19:46:27 +0000640 *valptr = clamp_value_wrap(--(*valptr), max, min);
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000641 say_time(cursorpos, tm);
642 break;
Björn Stenberg6c33c512004-09-19 21:58:37 +0000643
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000644 case ACTION_STD_OK:
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000645 done = true;
646 break;
Björn Stenberg6c33c512004-09-19 21:58:37 +0000647
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000648 case ACTION_STD_CANCEL:
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000649 done = true;
650 tm->tm_year = -1;
651 break;
652
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000653 default:
654 if (default_event_handler(button) == SYS_USB_CONNECTED)
655 return true;
656 break;
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000657 }
658 }
Linus Nielsen Feltzing1de3dd52004-04-21 06:49:12 +0000659 return false;
660}
Jens Arnold2c7b1272007-03-16 23:47:03 +0000661#endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000662
Jens Arnolde23348a2005-06-22 22:22:23 +0000663#if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF)
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000664bool shutdown_screen(void)
665{
666 int button;
667 bool done = false;
Jonathan Gordon80558252006-10-09 12:14:25 +0000668 long time_entered = current_tick;
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000669
670 lcd_stop_scroll();
671
Jens Arnold4d6374c2007-03-16 21:56:08 +0000672 gui_syncsplash(0, str(LANG_CONFIRM_SHUTDOWN));
Linus Nielsen Feltzingbdbb0ef2004-07-24 21:35:38 +0000673
Jonathan Gordon80558252006-10-09 12:14:25 +0000674 while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2))
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000675 {
Jonathan Gordon80558252006-10-09 12:14:25 +0000676 button = get_action(CONTEXT_STD,HZ);
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000677 switch(button)
678 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000679 case ACTION_STD_CANCEL:
Linus Nielsen Feltzing91216a52005-09-14 09:08:26 +0000680 sys_poweroff();
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000681 break;
682
Jens Arnoldc897c242007-07-22 13:08:00 +0000683 /* do nothing here, because ACTION_NONE might be caused
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000684 * by timeout or button release. In case of timeout the loop
Jonathan Gordon80558252006-10-09 12:14:25 +0000685 * is terminated by TIME_BEFORE */
Jens Arnoldc897c242007-07-22 13:08:00 +0000686 case ACTION_NONE:
Jonathan Gordon80558252006-10-09 12:14:25 +0000687 break;
688
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000689 default:
Linus Nielsen Feltzingade5d7b2004-07-26 16:06:59 +0000690 if(default_event_handler(button) == SYS_USB_CONNECTED)
691 return true;
Jonathan Gordon80558252006-10-09 12:14:25 +0000692 done = true;
Linus Nielsen Feltzing5b5003d2004-07-24 21:26:41 +0000693 break;
694 }
695 }
696 return false;
697}
Linus Nielsen Feltzingbdbb0ef2004-07-24 21:35:38 +0000698#endif
Björn Stenberg6c33c512004-09-19 21:58:37 +0000699
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000700static const int id3_headers[]=
701{
702 LANG_ID3_TITLE,
703 LANG_ID3_ARTIST,
704 LANG_ID3_ALBUM,
705 LANG_ID3_ALBUMARTIST,
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000706 LANG_ID3_GROUPING,
Dan Evertonf4a61f02007-08-03 10:00:42 +0000707 LANG_ID3_DISCNUM,
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000708 LANG_ID3_TRACKNUM,
709 LANG_ID3_COMMENT,
710 LANG_ID3_GENRE,
711 LANG_ID3_YEAR,
712 LANG_ID3_LENGTH,
713 LANG_ID3_PLAYLIST,
714 LANG_ID3_BITRATE,
Barry Wardell8a52d702007-07-28 16:32:24 +0000715 LANG_ID3_FREQUENCY,
Jens Arnoldd6c05452005-08-29 21:15:27 +0000716#if CONFIG_CODEC == SWCODEC
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000717 LANG_ID3_TRACK_GAIN,
718 LANG_ID3_ALBUM_GAIN,
Magnus Holmgreneab21c62005-08-11 18:21:14 +0000719#endif
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000720 LANG_ID3_PATH,
721};
Magnus Holmgreneab21c62005-08-11 18:21:14 +0000722
Nils Wallménius68489612008-04-09 15:25:17 +0000723static char * id3_get_info(int selected_item, void* data,
724 char *buffer, size_t buffer_len)
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000725{
726 struct mp3entry* id3 =(struct mp3entry*)data;
727 int info_no=selected_item/2;
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000728 if(!(selected_item%2))
729 {/* header */
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000730 return( str(id3_headers[info_no]));
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000731 }
732 else
733 {/* data */
734
735 char * info=NULL;
736 switch(info_no)
737 {
738 case 0:/*LANG_ID3_TITLE*/
739 info=id3->title;
740 break;
741 case 1:/*LANG_ID3_ARTIST*/
742 info=id3->artist;
743 break;
744 case 2:/*LANG_ID3_ALBUM*/
745 info=id3->album;
746 break;
Miika Pekkarinen4e976642007-02-10 12:09:28 +0000747 case 3:/*LANG_ID3_ALBUMARTIST*/
748 info=id3->albumartist;
749 break;
Magnus Holmgrenead3de32007-08-08 12:34:19 +0000750 case 4:/*LANG_ID3_GROUPING*/
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000751 info=id3->grouping;
752 break;
753 case 5:/*LANG_ID3_DISCNUM*/
Dan Evertonf4a61f02007-08-03 10:00:42 +0000754 if (id3->disc_string)
755 info = id3->disc_string;
756 else if (id3->discnum)
Magnus Holmgren0e2852b2007-10-28 12:47:49 +0000757 {
Nils Wallménius68489612008-04-09 15:25:17 +0000758 snprintf(buffer, buffer_len, "%d", id3->discnum);
Dan Evertonf4a61f02007-08-03 10:00:42 +0000759 info = buffer;
760 }
761 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000762 case 6:/*LANG_ID3_TRACKNUM*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000763 if (id3->track_string)
764 info = id3->track_string;
765 else if (id3->tracknum)
766 {
Nils Wallménius68489612008-04-09 15:25:17 +0000767 snprintf(buffer, buffer_len, "%d", id3->tracknum);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000768 info = buffer;
769 }
770 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000771 case 7:/*LANG_ID3_COMMENT*/
Miika Pekkarinen4e976642007-02-10 12:09:28 +0000772 info=id3->comment;
773 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000774 case 8:/*LANG_ID3_GENRE*/
Robert Kukla79a2a932007-03-02 21:49:42 +0000775 info = id3->genre_string;
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000776 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000777 case 9:/*LANG_ID3_YEAR*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000778 if (id3->year_string)
779 info = id3->year_string;
780 else if (id3->year)
781 {
Nils Wallménius68489612008-04-09 15:25:17 +0000782 snprintf(buffer, buffer_len, "%d", id3->year);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000783 info = buffer;
784 }
785 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000786 case 10:/*LANG_ID3_LENGTH*/
Nils Wallménius68489612008-04-09 15:25:17 +0000787 format_time(buffer, buffer_len, id3->length);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000788 info=buffer;
789 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000790 case 11:/*LANG_ID3_PLAYLIST*/
Peter D'Hoye8ed3b322008-05-23 21:43:40 +0000791 snprintf(buffer, buffer_len, "%d/%d",
792 playlist_get_display_index(), playlist_amount());
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000793 info=buffer;
794 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000795 case 12:/*LANG_ID3_BITRATE*/
Nils Wallménius68489612008-04-09 15:25:17 +0000796 snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate,
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000797 id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) "");
798 info=buffer;
799 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000800 case 13:/*LANG_ID3_FREQUENCY*/
Nils Wallménius68489612008-04-09 15:25:17 +0000801 snprintf(buffer, buffer_len, "%ld Hz", id3->frequency);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000802 info=buffer;
803 break;
804#if CONFIG_CODEC == SWCODEC
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000805 case 14:/*LANG_ID3_TRACK_GAIN*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000806 info=id3->track_gain_string;
807 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000808 case 15:/*LANG_ID3_ALBUM_GAIN*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000809 info=id3->album_gain_string;
810 break;
Dan Evertoneecfe9f2007-08-08 10:19:56 +0000811 case 16:/*LANG_ID3_PATH*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000812#else
Magnus Holmgrenead3de32007-08-08 12:34:19 +0000813 case 14:/*LANG_ID3_PATH*/
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000814#endif
815 info=id3->path;
816 break;
817 }
Magnus Holmgren2a20bfe2007-05-02 17:01:02 +0000818 return info && *info ? info : (char*) str(LANG_ID3_NO_INFO);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000819 }
820}
821
Björn Stenberg6c33c512004-09-19 21:58:37 +0000822bool browse_id3(void)
823{
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000824 struct gui_synclist id3_lists;
825 struct mp3entry* id3 = audio_current_track();
826 int key;
Björn Stenberg6c33c512004-09-19 21:58:37 +0000827
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000828 gui_synclist_init(&id3_lists, &id3_get_info, id3, true, 2, NULL);
Magnus Holmgren87e41e82007-02-11 08:06:24 +0000829 gui_synclist_set_nb_items(&id3_lists,
830 sizeof(id3_headers)/sizeof(id3_headers[0])*2);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000831 gui_synclist_draw(&id3_lists);
Jonathan Gordonbc0943e2006-09-12 08:55:47 +0000832 gui_syncstatusbar_draw(&statusbars, true);
Kevin Ferraref77ac7a2006-07-02 12:28:27 +0000833 while (true) {
Jonathan Gordon07d3db22006-08-17 09:28:04 +0000834 gui_syncstatusbar_draw(&statusbars, false);
Jonathan Gordon10af9662006-08-17 05:40:14 +0000835 key = get_action(CONTEXT_LIST,HZ/2);
Michael Sevakis9e8fe0e2006-10-30 11:33:38 +0000836 if(key!=ACTION_NONE && key!=ACTION_UNKNOWN
Jonathan Gordoncf1cef52007-09-17 10:08:50 +0000837 && !gui_synclist_do_button(&id3_lists, &key,LIST_WRAP_UNLESS_HELD))
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000838 {
Kevin Ferraref64280f2006-07-02 16:18:59 +0000839 return(default_event_handler(key) == SYS_USB_CONNECTED);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000840 }
Björn Stenberg6c33c512004-09-19 21:58:37 +0000841 }
Björn Stenberg6c33c512004-09-19 21:58:37 +0000842}
843
Nils Wallménius68489612008-04-09 15:25:17 +0000844static char* runtime_get_data(int selected_item, void* data,
845 char* buffer, size_t buffer_len)
Dominik Riebeling339d8122007-04-10 20:56:15 +0000846{
Nils Wallménius68489612008-04-09 15:25:17 +0000847 (void)data;
Dominik Riebeling339d8122007-04-10 20:56:15 +0000848 unsigned char *headers[] = {str(LANG_RUNNING_TIME), str(LANG_TOP_TIME) };
849 int t;
850 if(!(selected_item%2))
851 return headers[selected_item/2];
852
Nils Wallménius68489612008-04-09 15:25:17 +0000853 if(selected_item/2)
854 t = global_status.topruntime;
855
Dominik Riebeling339d8122007-04-10 20:56:15 +0000856 else t = global_status.runtime;
857
Nils Wallménius68489612008-04-09 15:25:17 +0000858 snprintf(buffer, buffer_len, "%dh %dm %ds",
Dominik Riebeling339d8122007-04-10 20:56:15 +0000859 t / 3600, (t % 3600) / 60, t % 60);
860 return buffer;
Dominik Riebeling339d8122007-04-10 20:56:15 +0000861}
862
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000863static int runtime_speak_data(int selected_item, void* data)
864{
Jonathan Gordonc14430a2007-11-07 09:28:07 +0000865 (void) data;
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000866 long title_ids[] = {LANG_RUNNING_TIME, LANG_TOP_TIME};
867 talk_ids(false,
868 title_ids[selected_item/2],
869 TALK_ID((selected_item == 0) ? global_status.runtime
870 : global_status.topruntime, UNIT_TIME));
871 return 0;
872}
873
Dominik Riebeling339d8122007-04-10 20:56:15 +0000874
Jonathan Gordond152b642006-12-19 12:26:03 +0000875bool view_runtime(void)
876{
Nils Wallménius33c44462008-04-26 09:30:24 +0000877 static const char *lines[]={ID2P(LANG_CLEAR_TIME)};
878 static const struct text_message message={lines, 1};
Jonathan Gordond152b642006-12-19 12:26:03 +0000879
Dominik Riebeling339d8122007-04-10 20:56:15 +0000880 struct gui_synclist lists;
881 int action;
Jonathan Gordon5ca15392008-03-26 03:35:24 +0000882 gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL);
Dominik Riebeling339d8122007-04-10 20:56:15 +0000883#if !defined(HAVE_LCD_CHARCELLS)
884 gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON);
885#else
886 gui_synclist_set_title(&lists, NULL, NOICON);
Jonathan Gordon5dd08e12007-02-17 10:59:30 +0000887#endif
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000888 if(global_settings.talk_menu)
889 gui_synclist_set_voice_callback(&lists, runtime_speak_data);
Dominik Riebeling339d8122007-04-10 20:56:15 +0000890 gui_synclist_set_icon_callback(&lists, NULL);
891 gui_synclist_set_nb_items(&lists, 4);
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000892 gui_synclist_speak_item(&lists);
Dominik Riebeling339d8122007-04-10 20:56:15 +0000893 while(1)
Jonathan Gordond152b642006-12-19 12:26:03 +0000894 {
Jonathan Gordon9a6f4192007-02-18 05:32:06 +0000895#if CONFIG_CHARGING
Dominik Riebeling339d8122007-04-10 20:56:15 +0000896 if (charger_inserted()
Jonathan Gordond152b642006-12-19 12:26:03 +0000897#ifdef HAVE_USB_POWER
Dominik Riebeling339d8122007-04-10 20:56:15 +0000898 || usb_powered()
Jonathan Gordond152b642006-12-19 12:26:03 +0000899#endif
Dominik Riebeling339d8122007-04-10 20:56:15 +0000900 )
Jonathan Gordond152b642006-12-19 12:26:03 +0000901 {
Dominik Riebeling339d8122007-04-10 20:56:15 +0000902 global_status.runtime = 0;
Jonathan Gordond152b642006-12-19 12:26:03 +0000903 }
Dominik Riebeling339d8122007-04-10 20:56:15 +0000904 else
905#endif
906 {
907 global_status.runtime += ((current_tick - lasttime) / HZ);
908 }
909 lasttime = current_tick;
910 gui_synclist_draw(&lists);
911 gui_syncstatusbar_draw(&statusbars, true);
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000912 list_do_action(CONTEXT_STD, HZ,
913 &lists, &action, LIST_WRAP_UNLESS_HELD);
Dominik Riebeling339d8122007-04-10 20:56:15 +0000914 if(action == ACTION_STD_CANCEL)
915 break;
916 if(action == ACTION_STD_OK) {
917 if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
918 {
919 if (!(gui_synclist_get_sel_pos(&lists)/2))
920 global_status.runtime = 0;
921 else
922 global_status.topruntime = 0;
Stéphane Doyon22e3d562007-11-07 03:58:13 +0000923 gui_synclist_speak_item(&lists);
Dominik Riebeling339d8122007-04-10 20:56:15 +0000924 }
Jonathan Gordond152b642006-12-19 12:26:03 +0000925 }
Dominik Riebelinga3f1e9f2007-04-10 21:40:44 +0000926 if(default_event_handler(action) == SYS_USB_CONNECTED)
927 return true;
Jonathan Gordond152b642006-12-19 12:26:03 +0000928 }
Jonathan Gordond152b642006-12-19 12:26:03 +0000929 return false;
930}