Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
Nicolas Pennequin | 357ffb3 | 2008-05-05 10:32:46 +0000 | [diff] [blame] | 10 | * Copyright (C) 2002 Björn Stenberg |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame] | 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. |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
Kevin Ferrare | f57d022 | 2005-11-22 21:55:05 +0000 | [diff] [blame] | 21 | |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 22 | #include <stdbool.h> |
| 23 | #include <string.h> |
| 24 | #include <stdio.h> |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 25 | #include <stdlib.h> |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 26 | #include "backlight.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 27 | #include "action.h" |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 28 | #include "lcd.h" |
| 29 | #include "lang.h" |
| 30 | #include "icons.h" |
| 31 | #include "font.h" |
Linus Nielsen Feltzing | 8a237a8 | 2005-04-04 12:06:29 +0000 | [diff] [blame] | 32 | #include "audio.h" |
Jörg Hohensohn | f993365 | 2004-01-05 20:42:51 +0000 | [diff] [blame] | 33 | #include "mp3_playback.h" |
Tomer Shalev | dc19343 | 2009-10-19 21:28:18 +0000 | [diff] [blame] | 34 | #include "usb.h" |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 35 | #include "settings.h" |
Markus Braun | 88098be | 2002-10-11 08:56:23 +0000 | [diff] [blame] | 36 | #include "status.h" |
Björn Stenberg | b1b8bd4 | 2002-09-24 17:22:12 +0000 | [diff] [blame] | 37 | #include "playlist.h" |
Björn Stenberg | ba371fb | 2003-06-29 16:33:04 +0000 | [diff] [blame] | 38 | #include "kernel.h" |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 39 | #include "power.h" |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 40 | #include "system.h" |
| 41 | #include "powermgmt.h" |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 42 | #include "talk.h" |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 43 | #include "misc.h" |
Björn Stenberg | 51b45d5 | 2008-10-15 06:38:51 +0000 | [diff] [blame] | 44 | #include "metadata.h" |
Jens Arnold | 7f6b640 | 2004-10-12 00:02:51 +0000 | [diff] [blame] | 45 | #include "screens.h" |
Kjell Ericson | 6c2fb55 | 2004-10-19 16:17:35 +0000 | [diff] [blame] | 46 | #include "debug.h" |
Jörg Hohensohn | ce51bc4 | 2005-02-19 16:23:30 +0000 | [diff] [blame] | 47 | #include "led.h" |
Linus Nielsen Feltzing | 674eaca | 2005-04-01 13:41:03 +0000 | [diff] [blame] | 48 | #include "sound.h" |
Kevin Ferrare | e991bee | 2005-11-16 15:12:15 +0000 | [diff] [blame] | 49 | #include "splash.h" |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 50 | #include "statusbar.h" |
Kevin Ferrare | 74b6af9 | 2005-11-22 03:38:07 +0000 | [diff] [blame] | 51 | #include "screen_access.h" |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 52 | #include "list.h" |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 53 | #include "yesno.h" |
Dave Chapman | d746b79 | 2008-03-29 01:14:10 +0000 | [diff] [blame] | 54 | #include "backdrop.h" |
Jonathan Gordon | 95be4fe | 2008-05-11 14:08:46 +0000 | [diff] [blame] | 55 | #include "viewport.h" |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 56 | #include "language.h" |
Andree Buschmann | 71ceac0 | 2011-02-24 19:10:59 +0000 | [diff] [blame] | 57 | #include "replaygain.h" |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 58 | |
Boris Gjenero | 5cd8aec | 2011-12-31 18:31:47 +0000 | [diff] [blame] | 59 | #if defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2) |
| 60 | #include "adc.h" |
| 61 | #endif |
| 62 | |
Amaury Pouly | eb90d95 | 2011-07-23 11:45:22 +0000 | [diff] [blame] | 63 | #if (CONFIG_STORAGE & STORAGE_MMC) && (defined(ARCHOS_ONDIOSP) || defined(ARCHOS_ONDIOFM)) |
Jens Arnold | 7f6b640 | 2004-10-12 00:02:51 +0000 | [diff] [blame] | 64 | int mmc_remove_request(void) |
| 65 | { |
Michael Sevakis | a9b2fb5 | 2007-10-16 01:25:17 +0000 | [diff] [blame] | 66 | struct queue_event ev; |
Kevin Ferrare | 74b6af9 | 2005-11-22 03:38:07 +0000 | [diff] [blame] | 67 | FOR_NB_SCREENS(i) |
| 68 | screens[i].clear_display(); |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 69 | splash(0, ID2P(LANG_REMOVE_MMC)); |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 70 | |
Jens Arnold | 7f6b640 | 2004-10-12 00:02:51 +0000 | [diff] [blame] | 71 | while (1) |
| 72 | { |
| 73 | queue_wait_w_tmo(&button_queue, &ev, HZ/2); |
| 74 | switch (ev.id) |
| 75 | { |
Michael Sevakis | 1167e3c | 2007-06-30 02:08:27 +0000 | [diff] [blame] | 76 | case SYS_HOTSWAP_EXTRACTED: |
| 77 | return SYS_HOTSWAP_EXTRACTED; |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 78 | |
Jens Arnold | 7f6b640 | 2004-10-12 00:02:51 +0000 | [diff] [blame] | 79 | case SYS_USB_DISCONNECTED: |
| 80 | return SYS_USB_DISCONNECTED; |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | #endif |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 85 | #include "ctype.h" |
Jens Arnold | 7f6b640 | 2004-10-12 00:02:51 +0000 | [diff] [blame] | 86 | |
Nils Wallménius | 3f8c075 | 2007-07-08 15:32:56 +0000 | [diff] [blame] | 87 | /* the charging screen is only used for archos targets */ |
| 88 | #if CONFIG_CHARGING && !defined(HAVE_POWEROFF_WHILE_CHARGING) && defined(CPU_SH) |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 89 | |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 90 | #ifdef HAVE_LCD_BITMAP |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 91 | static void charging_display_info(bool animate) |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 92 | { |
| 93 | unsigned char charging_logo[36]; |
| 94 | const int pox_x = (LCD_WIDTH - sizeof(charging_logo)) / 2; |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 95 | const int pox_y = 32; |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 96 | static unsigned phase = 3; |
| 97 | unsigned i; |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 98 | |
Boris Gjenero | 5cd8aec | 2011-12-31 18:31:47 +0000 | [diff] [blame] | 99 | #if !defined(NEED_ATA_POWER_BATT_MEASURE) |
Jörg Hohensohn | eb28d43 | 2003-12-03 07:05:13 +0000 | [diff] [blame] | 100 | { |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 101 | int battv = battery_voltage(); |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 102 | lcd_putsf(0, 7, " Batt: %d.%02dV %d%% ", battv / 1000, |
Jens Arnold | 1d1d9a8 | 2007-08-15 23:57:27 +0000 | [diff] [blame] | 103 | (battv % 1000) / 10, battery_level()); |
Jörg Hohensohn | eb28d43 | 2003-12-03 07:05:13 +0000 | [diff] [blame] | 104 | } |
Boris Gjenero | 5cd8aec | 2011-12-31 18:31:47 +0000 | [diff] [blame] | 105 | #elif defined(ARCHOS_FMRECORDER) || defined(ARCHOS_RECORDERV2) |
| 106 | /* IDE power is normally off here, so display input current instead */ |
| 107 | lcd_putsf(7, 7, "%dmA ", |
| 108 | (adc_read(ADC_EXT_POWER) * EXT_SCALE_FACTOR) / 10000); |
| 109 | #endif |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 110 | |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 111 | #ifdef ARCHOS_RECORDER |
| 112 | lcd_puts(0, 2, "Charge mode:"); |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 113 | |
Nils Wallménius | e1439fa | 2009-10-12 18:47:33 +0000 | [diff] [blame] | 114 | const char *s; |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 115 | if (charge_state == CHARGING) |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 116 | s = str(LANG_BATTERY_CHARGE); |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 117 | else if (charge_state == TOPOFF) |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 118 | s = str(LANG_BATTERY_TOPOFF_CHARGE); |
Jens Arnold | 0dd1f8e | 2006-06-06 22:23:52 +0000 | [diff] [blame] | 119 | else if (charge_state == TRICKLE) |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 120 | s = str(LANG_BATTERY_TRICKLE_CHARGE); |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 121 | else |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 122 | s = "not charging"; |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 123 | |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 124 | lcd_puts(0, 3, s); |
Michael Sevakis | 3157e13 | 2008-12-24 16:58:41 +0000 | [diff] [blame] | 125 | if (!charger_enabled()) |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 126 | animate = false; |
Nils Wallménius | efdbcc1 | 2009-10-12 18:11:37 +0000 | [diff] [blame] | 127 | #endif /* ARCHOS_RECORDER */ |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 128 | |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 129 | /* middle part */ |
| 130 | memset(charging_logo+3, 0x00, 32); |
| 131 | charging_logo[0] = 0x3C; |
| 132 | charging_logo[1] = 0x24; |
| 133 | charging_logo[2] = charging_logo[35] = 0xFF; |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 134 | |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 135 | if (!animate) |
| 136 | { /* draw the outline */ |
| 137 | /* middle part */ |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 138 | lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, |
| 139 | sizeof(charging_logo), 8); |
Jens Arnold | 7e11acb | 2005-06-28 23:15:47 +0000 | [diff] [blame] | 140 | lcd_set_drawmode(DRMODE_FG); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 141 | /* upper line */ |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 142 | charging_logo[0] = charging_logo[1] = 0x00; |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 143 | memset(charging_logo+2, 0x80, 34); |
Jens Arnold | f894a4c | 2005-07-06 22:58:02 +0000 | [diff] [blame] | 144 | lcd_mono_bitmap(charging_logo, pox_x, pox_y, sizeof(charging_logo), 8); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 145 | /* lower line */ |
| 146 | memset(charging_logo+2, 0x01, 34); |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 147 | lcd_mono_bitmap(charging_logo, pox_x, pox_y + 16, |
| 148 | sizeof(charging_logo), 8); |
Jens Arnold | 7e11acb | 2005-06-28 23:15:47 +0000 | [diff] [blame] | 149 | lcd_set_drawmode(DRMODE_SOLID); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 150 | } |
| 151 | else |
| 152 | { /* animate the middle part */ |
| 153 | for (i = 3; i<MIN(sizeof(charging_logo)-1, phase); i++) |
| 154 | { |
| 155 | if ((i-phase) % 8 == 0) |
| 156 | { /* draw a "bubble" here */ |
| 157 | unsigned bitpos; |
| 158 | bitpos = (phase + i/8) % 15; /* "bounce" effect */ |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 159 | if (bitpos > 7) |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 160 | bitpos = 14 - bitpos; |
Jens Arnold | 1d6df54 | 2009-06-07 21:27:05 +0000 | [diff] [blame] | 161 | charging_logo[i] = BIT_N(bitpos); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 164 | lcd_mono_bitmap(charging_logo, pox_x, pox_y + 8, |
| 165 | sizeof(charging_logo), 8); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 166 | phase++; |
| 167 | } |
| 168 | lcd_update(); |
| 169 | } |
Jörg Hohensohn | 20caff2 | 2003-07-19 21:43:12 +0000 | [diff] [blame] | 170 | #else /* not HAVE_LCD_BITMAP */ |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 171 | |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 172 | static unsigned long logo_chars[4]; |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 173 | static const unsigned char logo_pattern[] = { |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 174 | 0x07, 0x04, 0x1c, 0x14, 0x1c, 0x04, 0x07, 0, /* char 1 */ |
| 175 | 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 2 */ |
| 176 | 0x1f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0, /* char 3 */ |
| 177 | 0x1f, 0x01, 0x01, 0x01, 0x01, 0x01, 0x1f, 0, /* char 4 */ |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 178 | }; |
| 179 | |
| 180 | static void logo_lock_patterns(bool on) |
| 181 | { |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 182 | int i; |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 183 | |
| 184 | if (on) |
| 185 | { |
| 186 | for (i = 0; i < 4; i++) |
| 187 | logo_chars[i] = lcd_get_locked_pattern(); |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 188 | } |
| 189 | else |
| 190 | { |
| 191 | for (i = 0; i < 4; i++) |
| 192 | lcd_unlock_pattern(logo_chars[i]); |
| 193 | } |
| 194 | } |
| 195 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 196 | static void charging_display_info(bool animate) |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 197 | { |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 198 | int battv; |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 199 | unsigned i, ypos; |
| 200 | static unsigned phase = 3; |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 201 | char buf[32]; |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 202 | |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 203 | battv = battery_voltage(); |
Nils Wallménius | f34a841 | 2009-10-17 18:02:48 +0000 | [diff] [blame] | 204 | lcd_putsf(4, 1, " %d.%02dV", battv / 1000, (battv % 1000) / 10); |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 205 | |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 206 | memcpy(buf, logo_pattern, 32); /* copy logo patterns */ |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 207 | |
| 208 | if (!animate) /* build the screen */ |
| 209 | { |
| 210 | lcd_double_height(false); |
| 211 | lcd_puts(0, 0, "[Charging]"); |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 212 | for (i = 0; i < 4; i++) |
| 213 | lcd_putc(i, 1, logo_chars[i]); |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 214 | } |
| 215 | else /* animate the logo */ |
| 216 | { |
| 217 | for (i = 3; i < MIN(19, phase); i++) |
| 218 | { |
| 219 | if ((i - phase) % 5 == 0) |
| 220 | { /* draw a "bubble" here */ |
| 221 | ypos = (phase + i/5) % 9; /* "bounce" effect */ |
| 222 | if (ypos > 4) |
| 223 | ypos = 8 - ypos; |
Jens Arnold | 6ed3ca7 | 2008-12-12 22:19:42 +0000 | [diff] [blame] | 224 | buf[5 - ypos + 8 * (i/5)] |= 0x10u >> (i%5); |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | phase++; |
| 228 | } |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 229 | |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 230 | for (i = 0; i < 4; i++) |
Jens Arnold | ad4e3d6 | 2007-03-26 07:52:13 +0000 | [diff] [blame] | 231 | lcd_define_pattern(logo_chars[i], buf + 8 * i); |
Teruaki Kawashima | 0a17284 | 2009-08-20 15:04:47 +0000 | [diff] [blame] | 232 | |
Jens Arnold | f9b90e9 | 2007-04-06 22:55:00 +0000 | [diff] [blame] | 233 | lcd_update(); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 234 | } |
Jens Arnold | 61753a8 | 2004-11-21 00:44:44 +0000 | [diff] [blame] | 235 | #endif /* (not) HAVE_LCD_BITMAP */ |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 236 | |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 237 | /* blocks while charging, returns on event: |
| 238 | 1 if charger cable was removed |
| 239 | 2 if Off/Stop key was pressed |
| 240 | 3 if On key was pressed |
| 241 | 4 if USB was connected */ |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 242 | |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 243 | int charging_screen(void) |
| 244 | { |
Jean-Philippe Bernardy | 06f1c0a | 2005-02-12 12:51:06 +0000 | [diff] [blame] | 245 | unsigned int button; |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 246 | int rc = 0; |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 247 | |
| 248 | ide_power_enable(false); /* power down the disk, else would be spinning */ |
| 249 | |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 250 | lcd_clear_display(); |
Jens Arnold | b3e31b9 | 2004-11-20 22:43:38 +0000 | [diff] [blame] | 251 | backlight_set_timeout(global_settings.backlight_timeout); |
Jens Arnold | 748c751 | 2005-05-30 05:57:19 +0000 | [diff] [blame] | 252 | #ifdef HAVE_REMOTE_LCD |
Christian Gmeiner | 7477c09 | 2005-05-30 00:00:22 +0000 | [diff] [blame] | 253 | remote_backlight_set_timeout(global_settings.remote_backlight_timeout); |
Jens Arnold | 748c751 | 2005-05-30 05:57:19 +0000 | [diff] [blame] | 254 | #endif |
Jens Arnold | a6d409d | 2005-11-23 20:12:33 +0000 | [diff] [blame] | 255 | backlight_set_timeout_plugged(global_settings.backlight_timeout_plugged); |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 256 | |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 257 | #ifdef HAVE_LCD_CHARCELLS |
| 258 | logo_lock_patterns(true); |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 259 | #endif |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 260 | charging_display_info(false); |
| 261 | |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 262 | do |
| 263 | { |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 264 | gui_syncstatusbar_draw(&statusbars, false); |
Jörg Hohensohn | b5b7304 | 2003-07-18 22:01:13 +0000 | [diff] [blame] | 265 | charging_display_info(true); |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 266 | button = get_action(CONTEXT_STD,HZ/3); |
| 267 | if (button == ACTION_STD_OK) |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 268 | rc = 2; |
Jens Arnold | b1e16d2 | 2008-07-06 12:14:13 +0000 | [diff] [blame] | 269 | else if (usb_detect() == USB_INSERTED) |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 270 | rc = 3; |
Boris Gjenero | 5cd8aec | 2011-12-31 18:31:47 +0000 | [diff] [blame] | 271 | /* do not depend on power management thread here */ |
| 272 | else if (!(power_input_status() & POWER_INPUT_MAIN_CHARGER)) |
Jens Arnold | 7c7dd43 | 2005-07-11 19:14:26 +0000 | [diff] [blame] | 273 | rc = 1; |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 274 | } while (!rc); |
| 275 | |
Jens Arnold | 2996d17 | 2004-11-21 00:17:59 +0000 | [diff] [blame] | 276 | #ifdef HAVE_LCD_CHARCELLS |
| 277 | logo_lock_patterns(false); |
| 278 | #endif |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 279 | return rc; |
| 280 | } |
Nils Wallménius | 3f8c075 | 2007-07-08 15:32:56 +0000 | [diff] [blame] | 281 | #endif /* CONFIG_CHARGING && !HAVE_POWEROFF_WHILE_CHARGING && defined(CPU_SH) */ |
Jörg Hohensohn | 5dd17b1 | 2003-07-17 20:29:51 +0000 | [diff] [blame] | 282 | |
Nils Wallménius | f28da1a | 2007-08-12 19:49:03 +0000 | [diff] [blame] | 283 | #if CONFIG_CHARGING |
Björn Stenberg | 461d6e3 | 2003-12-04 00:08:25 +0000 | [diff] [blame] | 284 | void charging_splash(void) |
| 285 | { |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 286 | splash(2*HZ, str(LANG_BATTERY_CHARGE)); |
Jens Arnold | 3c348df | 2005-01-26 22:48:25 +0000 | [diff] [blame] | 287 | button_clear_queue(); |
Björn Stenberg | 461d6e3 | 2003-12-04 00:08:25 +0000 | [diff] [blame] | 288 | } |
Jens Arnold | cd0bb1c | 2005-05-07 01:30:16 +0000 | [diff] [blame] | 289 | #endif |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 290 | |
| 291 | |
Jens Arnold | 2c7b127 | 2007-03-16 23:47:03 +0000 | [diff] [blame] | 292 | #if defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 293 | |
| 294 | /* little helper function for voice output */ |
Jens Arnold | 8fb3361 | 2004-08-18 01:09:31 +0000 | [diff] [blame] | 295 | static void say_time(int cursorpos, const struct tm *tm) |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 296 | { |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 297 | int value = 0; |
Nils Wallménius | 537b27d | 2007-10-24 10:29:45 +0000 | [diff] [blame] | 298 | int unit = 0; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 299 | |
Steve Bavin | 32a9575 | 2007-10-19 15:31:42 +0000 | [diff] [blame] | 300 | if (!global_settings.talk_menu) |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 301 | return; |
| 302 | |
| 303 | switch(cursorpos) |
| 304 | { |
| 305 | case 0: |
| 306 | value = tm->tm_hour; |
Nils Wallménius | 537b27d | 2007-10-24 10:29:45 +0000 | [diff] [blame] | 307 | unit = UNIT_HOUR; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 308 | break; |
| 309 | case 1: |
| 310 | value = tm->tm_min; |
Nils Wallménius | 537b27d | 2007-10-24 10:29:45 +0000 | [diff] [blame] | 311 | unit = UNIT_MIN; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 312 | break; |
| 313 | case 2: |
| 314 | value = tm->tm_sec; |
Nils Wallménius | 537b27d | 2007-10-24 10:29:45 +0000 | [diff] [blame] | 315 | unit = UNIT_SEC; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 316 | break; |
| 317 | case 3: |
| 318 | value = tm->tm_year + 1900; |
| 319 | break; |
| 320 | case 5: |
| 321 | value = tm->tm_mday; |
| 322 | break; |
| 323 | } |
Magnus Holmgren | 1e5119b | 2005-07-05 19:33:33 +0000 | [diff] [blame] | 324 | |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 325 | if (cursorpos == 4) /* month */ |
Linus Nielsen Feltzing | 08ebcad | 2004-04-21 21:40:26 +0000 | [diff] [blame] | 326 | talk_id(LANG_MONTH_JANUARY + tm->tm_mon, false); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 327 | else |
Nils Wallménius | 537b27d | 2007-10-24 10:29:45 +0000 | [diff] [blame] | 328 | talk_value(value, unit, false); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | |
| 332 | #define INDEX_X 0 |
| 333 | #define INDEX_Y 1 |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 334 | |
| 335 | #define SEPARATOR ":" |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 336 | |
| 337 | #define IDX_HOURS 0 |
| 338 | #define IDX_MINUTES 1 |
| 339 | #define IDX_SECONDS 2 |
| 340 | #define IDX_YEAR 3 |
| 341 | #define IDX_MONTH 4 |
| 342 | #define IDX_DAY 5 |
| 343 | |
| 344 | #define OFF_HOURS 0 |
| 345 | #define OFF_MINUTES 3 |
| 346 | #define OFF_SECONDS 6 |
| 347 | #define OFF_YEAR 9 |
| 348 | #define OFF_DAY 14 |
| 349 | |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 350 | bool set_time_screen(const char* title, struct tm *tm) |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 351 | { |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 352 | struct viewport viewports[NB_SCREENS]; |
| 353 | bool done = false, usb = false; |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 354 | int cursorpos = 0; |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 355 | unsigned char offsets_ptr[] = |
| 356 | { OFF_HOURS, OFF_MINUTES, OFF_SECONDS, OFF_YEAR, 0, OFF_DAY }; |
Jens Arnold | 033ba16 | 2004-08-26 20:30:22 +0000 | [diff] [blame] | 357 | |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 358 | if (lang_is_rtl()) |
| 359 | { |
| 360 | offsets_ptr[IDX_HOURS] = OFF_SECONDS; |
| 361 | offsets_ptr[IDX_SECONDS] = OFF_HOURS; |
| 362 | offsets_ptr[IDX_YEAR] = OFF_DAY; |
| 363 | offsets_ptr[IDX_DAY] = OFF_YEAR; |
| 364 | } |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 365 | |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 366 | /* speak selection when screen is entered */ |
| 367 | say_time(cursorpos, tm); |
| 368 | |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 369 | #ifdef HAVE_TOUCHSCREEN |
| 370 | enum touchscreen_mode old_mode = touchscreen_get_mode(); |
| 371 | touchscreen_set_mode(TOUCHSCREEN_BUTTON); |
| 372 | #endif |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 373 | while (!done) { |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 374 | int button; |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 375 | unsigned int i, realyear, min, max; |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 376 | unsigned char *ptr[6]; |
Frank Gevaerts | 3665eec | 2019-07-20 17:11:32 +0200 | [diff] [blame] | 377 | #if (CONFIG_PLATFORM & PLATFORM_HOSTED) |
| 378 | /* The format strings in the snprintf can in theory need 60 characters |
| 379 | This will not happen in practice (because seconds are 0..60 and not |
| 380 | full-range integers etc.), but -D_FORTIFY_SOURCE will still warn |
| 381 | about it, so we use 60 characters for HOSTED to make the compiler |
| 382 | happy. Native builds still use 20, which is enough in practice. */ |
| 383 | unsigned char buffer[60]; |
| 384 | #else |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 385 | unsigned char buffer[20]; |
Frank Gevaerts | 3665eec | 2019-07-20 17:11:32 +0200 | [diff] [blame] | 386 | #endif |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 387 | int *valptr = NULL; |
| 388 | static unsigned char daysinmonth[] = |
| 389 | {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; |
| 390 | |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 391 | /* for easy acess in the drawing loop */ |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 392 | for (i = 0; i < 6; i++) |
| 393 | ptr[i] = buffer + offsets_ptr[i]; |
| 394 | ptr[IDX_MONTH] = str(LANG_MONTH_JANUARY + tm->tm_mon); /* month name */ |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 395 | |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 396 | /* calculate the number of days in febuary */ |
| 397 | realyear = tm->tm_year + 1900; |
| 398 | if((realyear % 4 == 0 && !(realyear % 100 == 0)) || realyear % 400 == 0) |
| 399 | daysinmonth[1] = 29; |
| 400 | else |
| 401 | daysinmonth[1] = 28; |
| 402 | |
| 403 | /* fix day if month or year changed */ |
| 404 | if (tm->tm_mday > daysinmonth[tm->tm_mon]) |
| 405 | tm->tm_mday = daysinmonth[tm->tm_mon]; |
| 406 | |
| 407 | /* calculate day of week */ |
Frank Gevaerts | 2dc5047 | 2009-08-11 19:30:19 +0000 | [diff] [blame] | 408 | set_day_of_week(tm); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 409 | |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 410 | /* put all the numbers we want from the tm struct into |
| 411 | an easily printable buffer */ |
Nils Wallménius | ede3731 | 2007-07-02 19:52:19 +0000 | [diff] [blame] | 412 | snprintf(buffer, sizeof(buffer), |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 413 | "%02d " "%02d " "%02d " "%04d " "%02d", |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 414 | tm->tm_hour, tm->tm_min, tm->tm_sec, |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 415 | tm->tm_year+1900, tm->tm_mday); |
Nils Wallménius | ede3731 | 2007-07-02 19:52:19 +0000 | [diff] [blame] | 416 | |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 417 | /* convert spaces in the buffer to '\0' to make it possible to work |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 418 | directly on the buffer */ |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 419 | for(i=0; i < sizeof(buffer); i++) |
| 420 | { |
| 421 | if(buffer[i] == ' ') |
| 422 | buffer[i] = '\0'; |
| 423 | } |
| 424 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 425 | FOR_NB_SCREENS(s) |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 426 | { |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 427 | int pos, nb_lines; |
| 428 | unsigned int separator_width, weekday_width; |
| 429 | unsigned int j, width, prev_line_height; |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 430 | /* 6 possible cursor possitions, 2 values stored for each: x, y */ |
| 431 | unsigned int cursor[6][2]; |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 432 | struct viewport *vp = &viewports[s]; |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 433 | struct screen *screen = &screens[s]; |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 434 | static unsigned char rtl_idx[] = |
| 435 | { IDX_SECONDS, IDX_MINUTES, IDX_HOURS, IDX_DAY, IDX_MONTH, IDX_YEAR }; |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 436 | |
| 437 | viewport_set_defaults(vp, s); |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 438 | screen->set_viewport(vp); |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 439 | nb_lines = viewport_get_nb_lines(vp); |
| 440 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 441 | /* minimum lines needed is 2 + title line */ |
Jonathan Gordon | aff220c | 2008-05-11 13:59:27 +0000 | [diff] [blame] | 442 | if (nb_lines < 4) |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 443 | { |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 444 | vp->font = FONT_SYSFIXED; |
| 445 | nb_lines = viewport_get_nb_lines(vp); |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 446 | } |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 447 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 448 | /* recalculate the positions and offsets */ |
Jonathan Gordon | aff220c | 2008-05-11 13:59:27 +0000 | [diff] [blame] | 449 | if (nb_lines >= 3) |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 450 | screen->getstringsize(title, NULL, &prev_line_height); |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 451 | else |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 452 | prev_line_height = 0; |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 453 | |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 454 | screen->getstringsize(SEPARATOR, &separator_width, NULL); |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 455 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 456 | /* weekday */ |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 457 | screen->getstringsize(str(LANG_WEEKDAY_SUNDAY + tm->tm_wday), |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 458 | &weekday_width, NULL); |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 459 | screen->getstringsize(" ", &separator_width, NULL); |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 460 | |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 461 | for(i=0, j=0; i < 6; i++) |
| 462 | { |
| 463 | if(i==3) /* second row */ |
| 464 | { |
Bertrik Sikken | 4f87abf | 2009-03-04 18:15:06 +0000 | [diff] [blame] | 465 | j = weekday_width + separator_width; |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 466 | prev_line_height *= 2; |
| 467 | } |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 468 | screen->getstringsize(ptr[i], &width, NULL); |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 469 | cursor[i][INDEX_Y] = prev_line_height; |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 470 | cursor[i][INDEX_X] = j; |
| 471 | j += width + separator_width; |
| 472 | } |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 473 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 474 | /* draw the screen */ |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 475 | screen->set_viewport(vp); |
| 476 | screen->clear_viewport(); |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 477 | /* display the screen title */ |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 478 | screen->puts_scroll(0, 0, title); |
Nils Wallménius | aedf68a | 2007-07-21 08:28:48 +0000 | [diff] [blame] | 479 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 480 | /* these are not selectable, so we draw them outside the loop */ |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 481 | /* name of the week day */ |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 482 | screen->putsxy(0, cursor[3][INDEX_Y], |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 483 | str(LANG_WEEKDAY_SUNDAY + tm->tm_wday)); |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 484 | |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 485 | pos = lang_is_rtl() ? rtl_idx[cursorpos] : cursorpos; |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 486 | /* draw the selected item with drawmode set to |
| 487 | DRMODE_SOLID|DRMODE_INVERSEVID, all other selectable |
| 488 | items with drawmode DRMODE_SOLID */ |
| 489 | for(i=0; i<6; i++) |
| 490 | { |
Tomer Shalev | 71753a3 | 2009-10-06 16:57:01 +0000 | [diff] [blame] | 491 | if (pos == (int)i) |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 492 | vp->drawmode = (DRMODE_SOLID|DRMODE_INVERSEVID); |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 493 | |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 494 | screen->putsxy(cursor[i][INDEX_X], |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 495 | cursor[i][INDEX_Y], ptr[i]); |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 496 | |
Tomer Shalev | fafd18c | 2009-10-06 08:20:12 +0000 | [diff] [blame] | 497 | vp->drawmode = DRMODE_SOLID; |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 498 | |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 499 | screen->putsxy(cursor[i/4 +1][INDEX_X] - separator_width, |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 500 | cursor[0][INDEX_Y], SEPARATOR); |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* print help text */ |
Jonathan Gordon | aff220c | 2008-05-11 13:59:27 +0000 | [diff] [blame] | 504 | if (nb_lines > 4) |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 505 | screen->puts(0, 4, str(LANG_TIME_SET_BUTTON)); |
Jonathan Gordon | aff220c | 2008-05-11 13:59:27 +0000 | [diff] [blame] | 506 | if (nb_lines > 5) |
Tomer Shalev | d996804 | 2009-10-06 08:32:37 +0000 | [diff] [blame] | 507 | screen->puts(0, 5, str(LANG_TIME_REVERT)); |
| 508 | screen->update_viewport(); |
| 509 | screen->set_viewport(NULL); |
Nils Wallménius | 2e80610 | 2007-07-01 12:08:45 +0000 | [diff] [blame] | 510 | } |
Nils Wallménius | 3f8c075 | 2007-07-08 15:32:56 +0000 | [diff] [blame] | 511 | |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 512 | /* set the most common numbers */ |
| 513 | min = 0; |
| 514 | max = 59; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 515 | /* calculate the minimum and maximum for the number under cursor */ |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 516 | switch(cursorpos) { |
| 517 | case 0: /* hour */ |
| 518 | max = 23; |
| 519 | valptr = &tm->tm_hour; |
| 520 | break; |
| 521 | case 1: /* minute */ |
| 522 | valptr = &tm->tm_min; |
| 523 | break; |
| 524 | case 2: /* second */ |
| 525 | valptr = &tm->tm_sec; |
| 526 | break; |
| 527 | case 3: /* year */ |
| 528 | min = 1; |
| 529 | max = 200; |
| 530 | valptr = &tm->tm_year; |
| 531 | break; |
| 532 | case 4: /* month */ |
| 533 | max = 11; |
| 534 | valptr = &tm->tm_mon; |
| 535 | break; |
| 536 | case 5: /* day */ |
| 537 | min = 1; |
| 538 | max = daysinmonth[tm->tm_mon]; |
| 539 | valptr = &tm->tm_mday; |
| 540 | break; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 541 | } |
| 542 | |
Jonathan Gordon | 3d73b8e | 2007-07-15 10:30:11 +0000 | [diff] [blame] | 543 | button = get_action(CONTEXT_SETTINGS_TIME, TIMEOUT_BLOCK); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 544 | switch ( button ) { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 545 | case ACTION_STD_PREV: |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 546 | cursorpos = clamp_value_wrap(--cursorpos, 5, 0); |
| 547 | say_time(cursorpos, tm); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 548 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 549 | case ACTION_STD_NEXT: |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 550 | cursorpos = clamp_value_wrap(++cursorpos, 5, 0); |
| 551 | say_time(cursorpos, tm); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 552 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 553 | case ACTION_SETTINGS_INC: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 554 | case ACTION_SETTINGS_INCREPEAT: |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 555 | *valptr = clamp_value_wrap(++(*valptr), max, min); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 556 | say_time(cursorpos, tm); |
| 557 | break; |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 558 | case ACTION_SETTINGS_DEC: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 559 | case ACTION_SETTINGS_DECREPEAT: |
Nils Wallménius | 7567e99 | 2007-11-22 19:46:27 +0000 | [diff] [blame] | 560 | *valptr = clamp_value_wrap(--(*valptr), max, min); |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 561 | say_time(cursorpos, tm); |
| 562 | break; |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 563 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 564 | case ACTION_STD_OK: |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 565 | done = true; |
| 566 | break; |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 567 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 568 | case ACTION_STD_CANCEL: |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 569 | done = true; |
| 570 | tm->tm_year = -1; |
| 571 | break; |
| 572 | |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 573 | default: |
| 574 | if (default_event_handler(button) == SYS_USB_CONNECTED) |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 575 | done = usb = true; |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 576 | break; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 577 | } |
| 578 | } |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 579 | FOR_NB_SCREENS(s) |
Thomas Martitz | 1c5d0b4 | 2013-04-03 16:33:23 +0200 | [diff] [blame] | 580 | screens[s].scroll_stop_viewport(&viewports[s]); |
Teruaki Kawashima | 93f9e7c | 2010-02-11 10:41:06 +0000 | [diff] [blame] | 581 | #ifdef HAVE_TOUCHSCREEN |
| 582 | touchscreen_set_mode(old_mode); |
| 583 | #endif |
| 584 | return usb; |
Linus Nielsen Feltzing | 1de3dd5 | 2004-04-21 06:49:12 +0000 | [diff] [blame] | 585 | } |
Jens Arnold | 2c7b127 | 2007-03-16 23:47:03 +0000 | [diff] [blame] | 586 | #endif /* defined(HAVE_LCD_BITMAP) && (CONFIG_RTC != 0) */ |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 587 | |
Jens Arnold | e23348a | 2005-06-22 22:22:23 +0000 | [diff] [blame] | 588 | #if (CONFIG_KEYPAD == RECORDER_PAD) && !defined(HAVE_SW_POWEROFF) |
Thomas Martitz | ed5b853 | 2013-12-15 00:47:21 +0100 | [diff] [blame] | 589 | #include "scroll_engine.h" |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 590 | bool shutdown_screen(void) |
| 591 | { |
| 592 | int button; |
| 593 | bool done = false; |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 594 | long time_entered = current_tick; |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 595 | |
Thomas Martitz | 1c5d0b4 | 2013-04-03 16:33:23 +0200 | [diff] [blame] | 596 | lcd_scroll_stop(); |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 597 | |
Nils Wallménius | 01729e7 | 2008-08-15 08:27:39 +0000 | [diff] [blame] | 598 | splash(0, str(LANG_CONFIRM_SHUTDOWN)); |
Linus Nielsen Feltzing | bdbb0ef | 2004-07-24 21:35:38 +0000 | [diff] [blame] | 599 | |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 600 | while(!done && TIME_BEFORE(current_tick,time_entered+HZ*2)) |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 601 | { |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 602 | button = get_action(CONTEXT_STD,HZ); |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 603 | switch(button) |
| 604 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 605 | case ACTION_STD_CANCEL: |
Linus Nielsen Feltzing | 91216a5 | 2005-09-14 09:08:26 +0000 | [diff] [blame] | 606 | sys_poweroff(); |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 607 | break; |
| 608 | |
Jens Arnold | c897c24 | 2007-07-22 13:08:00 +0000 | [diff] [blame] | 609 | /* do nothing here, because ACTION_NONE might be caused |
Michael Sevakis | 9e8fe0e | 2006-10-30 11:33:38 +0000 | [diff] [blame] | 610 | * by timeout or button release. In case of timeout the loop |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 611 | * is terminated by TIME_BEFORE */ |
Jens Arnold | c897c24 | 2007-07-22 13:08:00 +0000 | [diff] [blame] | 612 | case ACTION_NONE: |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 613 | break; |
| 614 | |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 615 | default: |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 616 | if(default_event_handler(button) == SYS_USB_CONNECTED) |
| 617 | return true; |
Jonathan Gordon | 8055825 | 2006-10-09 12:14:25 +0000 | [diff] [blame] | 618 | done = true; |
Linus Nielsen Feltzing | 5b5003d | 2004-07-24 21:26:41 +0000 | [diff] [blame] | 619 | break; |
| 620 | } |
| 621 | } |
| 622 | return false; |
| 623 | } |
Linus Nielsen Feltzing | bdbb0ef | 2004-07-24 21:35:38 +0000 | [diff] [blame] | 624 | #endif |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 625 | |
Magnus Holmgren | 87e41e8 | 2007-02-11 08:06:24 +0000 | [diff] [blame] | 626 | static const int id3_headers[]= |
| 627 | { |
| 628 | LANG_ID3_TITLE, |
| 629 | LANG_ID3_ARTIST, |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 630 | LANG_ID3_COMPOSER, |
Magnus Holmgren | 87e41e8 | 2007-02-11 08:06:24 +0000 | [diff] [blame] | 631 | LANG_ID3_ALBUM, |
| 632 | LANG_ID3_ALBUMARTIST, |
Dan Everton | eecfe9f | 2007-08-08 10:19:56 +0000 | [diff] [blame] | 633 | LANG_ID3_GROUPING, |
Dan Everton | f4a61f0 | 2007-08-03 10:00:42 +0000 | [diff] [blame] | 634 | LANG_ID3_DISCNUM, |
Magnus Holmgren | 87e41e8 | 2007-02-11 08:06:24 +0000 | [diff] [blame] | 635 | LANG_ID3_TRACKNUM, |
| 636 | LANG_ID3_COMMENT, |
| 637 | LANG_ID3_GENRE, |
| 638 | LANG_ID3_YEAR, |
| 639 | LANG_ID3_LENGTH, |
| 640 | LANG_ID3_PLAYLIST, |
| 641 | LANG_ID3_BITRATE, |
Barry Wardell | 8a52d70 | 2007-07-28 16:32:24 +0000 | [diff] [blame] | 642 | LANG_ID3_FREQUENCY, |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 643 | #if CONFIG_CODEC == SWCODEC |
Magnus Holmgren | 87e41e8 | 2007-02-11 08:06:24 +0000 | [diff] [blame] | 644 | LANG_ID3_TRACK_GAIN, |
| 645 | LANG_ID3_ALBUM_GAIN, |
Magnus Holmgren | eab21c6 | 2005-08-11 18:21:14 +0000 | [diff] [blame] | 646 | #endif |
Mustapha Senhaji | 5e1e05f | 2010-12-24 03:31:40 +0000 | [diff] [blame] | 647 | LANG_FILESIZE, |
Magnus Holmgren | 87e41e8 | 2007-02-11 08:06:24 +0000 | [diff] [blame] | 648 | LANG_ID3_PATH, |
| 649 | }; |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 650 | |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 651 | struct id3view_info { |
| 652 | struct mp3entry* id3; |
| 653 | int count; |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 654 | int info_id[ARRAYLEN(id3_headers)]; |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 655 | }; |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 656 | |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 657 | /* Spell out a buffer, but when successive digits are encountered, say |
| 658 | the whole number. Useful for some ID3 tags that usually contain a |
| 659 | number but are in fact free-form. */ |
| 660 | static void say_number_and_spell(char *buf, bool year_style) |
| 661 | { |
| 662 | char *ptr = buf; |
| 663 | while(*ptr) { |
| 664 | if(isdigit(*ptr)) { |
| 665 | /* parse the number */ |
| 666 | int n = atoi(ptr); |
| 667 | /* skip over digits to rest of string */ |
| 668 | while(isdigit(*++ptr)); |
| 669 | /* say the number */ |
| 670 | if(year_style) |
| 671 | talk_value(n, UNIT_DATEYEAR, true); |
| 672 | else talk_number(n, true); |
| 673 | }else{ |
| 674 | /* Spell a sequence of non-digits */ |
| 675 | char tmp, *start = ptr; |
| 676 | while(*++ptr && !isdigit(*ptr)); |
| 677 | /* temporarily truncate the string here */ |
| 678 | tmp = *ptr; |
| 679 | *ptr = '\0'; |
| 680 | talk_spell(start, true); |
| 681 | *ptr = tmp; /* restore string */ |
| 682 | } |
| 683 | } |
| 684 | } |
| 685 | |
Solomon Peachy | c2308bd | 2018-12-15 13:09:07 -0500 | [diff] [blame] | 686 | #if CONFIG_CODEC == SWCODEC |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 687 | /* Say a replaygain ID3 value from its text form */ |
| 688 | static void say_gain(char *buf) |
| 689 | { |
| 690 | /* Expected form is "-5.74 dB". We'll try to parse out the number |
| 691 | until the dot, say it (forcing the + sign), then say dot and |
| 692 | spell the following numbers, and then say the decibel unit. */ |
| 693 | char *ptr = buf; |
| 694 | if(*ptr == '-' || *ptr == '+') |
| 695 | /* skip sign */ |
| 696 | ++ptr; |
| 697 | /* See if we can parse out a number. */ |
| 698 | if(isdigit(*ptr)) { |
| 699 | char tmp; |
| 700 | /* skip successive digits */ |
| 701 | while(isdigit(*++ptr)); |
| 702 | /* temporarily truncate the string here */ |
| 703 | tmp = *ptr; |
| 704 | *ptr = '\0'; |
| 705 | /* parse out the number we just skipped */ |
| 706 | talk_value(atoi(buf), UNIT_SIGNED, true); /* say the number with sign */ |
| 707 | *ptr = tmp; /* restore the string */ |
| 708 | if(*ptr == '.') { |
| 709 | /* found the dot, get fractional part */ |
| 710 | buf = ptr; |
| 711 | while (isdigit(*++ptr)); |
| 712 | while (*--ptr == '0'); |
| 713 | if (ptr > buf) { |
| 714 | tmp = *++ptr; |
| 715 | *ptr = '\0'; |
| 716 | talk_id(LANG_POINT, true); |
| 717 | while (*++buf == '0') |
| 718 | talk_id(VOICE_ZERO, true); |
| 719 | talk_number(atoi(buf), true); |
| 720 | *ptr = tmp; |
| 721 | } |
| 722 | ptr = buf; |
| 723 | while (isdigit(*++ptr)); |
| 724 | } |
| 725 | buf = ptr; |
| 726 | if(strlen(buf) >2 && !strcmp(buf+strlen(buf)-2, "dB")) { |
| 727 | /* String does end with "dB" */ |
| 728 | /* point to that "dB" */ |
| 729 | ptr = buf+strlen(buf)-2; |
| 730 | /* backup any spaces */ |
| 731 | while (ptr >buf && ptr[-1] == ' ') |
| 732 | --ptr; |
| 733 | if (ptr > buf) |
| 734 | talk_spell(buf, true); |
| 735 | else talk_id(VOICE_DB, true); /* say the dB unit */ |
| 736 | }else /* doesn't end with dB, just spell everything after the |
| 737 | number of dot. */ |
| 738 | talk_spell(buf, true); |
| 739 | }else /* we didn't find a number, just spell everything */ |
| 740 | talk_spell(buf, true); |
| 741 | } |
Solomon Peachy | c2308bd | 2018-12-15 13:09:07 -0500 | [diff] [blame] | 742 | #endif |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 743 | |
| 744 | static const char * id3_get_or_speak_info(int selected_item, void* data, |
| 745 | char *buffer, size_t buffer_len, |
| 746 | bool say_it) |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 747 | { |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 748 | struct id3view_info *info = (struct id3view_info*)data; |
| 749 | struct mp3entry* id3 =info->id3; |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 750 | int info_no=selected_item/2; |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 751 | if(!(selected_item%2)) |
| 752 | {/* header */ |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 753 | if(say_it) |
| 754 | talk_id(id3_headers[info->info_id[info_no]], false); |
Thomas Martitz | 0bd45b3 | 2009-10-31 12:40:20 +0000 | [diff] [blame] | 755 | snprintf(buffer, buffer_len, |
| 756 | "[%s]", str(id3_headers[info->info_id[info_no]])); |
| 757 | return buffer; |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 758 | } |
| 759 | else |
| 760 | {/* data */ |
| 761 | |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 762 | char * val=NULL; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 763 | switch(id3_headers[info->info_id[info_no]]) |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 764 | { |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 765 | case LANG_ID3_TITLE: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 766 | val=id3->title; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 767 | if(say_it && val) |
| 768 | talk_spell(val, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 769 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 770 | case LANG_ID3_ARTIST: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 771 | val=id3->artist; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 772 | if(say_it && val) |
| 773 | talk_spell(val, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 774 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 775 | case LANG_ID3_ALBUM: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 776 | val=id3->album; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 777 | if(say_it && val) |
| 778 | talk_spell(val, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 779 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 780 | case LANG_ID3_ALBUMARTIST: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 781 | val=id3->albumartist; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 782 | if(say_it && val) |
| 783 | talk_spell(val, true); |
Miika Pekkarinen | 4e97664 | 2007-02-10 12:09:28 +0000 | [diff] [blame] | 784 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 785 | case LANG_ID3_GROUPING: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 786 | val=id3->grouping; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 787 | if(say_it && val) |
| 788 | talk_spell(val, true); |
Dan Everton | eecfe9f | 2007-08-08 10:19:56 +0000 | [diff] [blame] | 789 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 790 | case LANG_ID3_DISCNUM: |
Dan Everton | f4a61f0 | 2007-08-03 10:00:42 +0000 | [diff] [blame] | 791 | if (id3->disc_string) |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 792 | { |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 793 | val = id3->disc_string; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 794 | if(say_it) |
| 795 | say_number_and_spell(val, true); |
| 796 | } |
Dan Everton | f4a61f0 | 2007-08-03 10:00:42 +0000 | [diff] [blame] | 797 | else if (id3->discnum) |
Magnus Holmgren | 0e2852b | 2007-10-28 12:47:49 +0000 | [diff] [blame] | 798 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 799 | snprintf(buffer, buffer_len, "%d", id3->discnum); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 800 | val = buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 801 | if(say_it) |
| 802 | talk_number(id3->discnum, true); |
Dan Everton | f4a61f0 | 2007-08-03 10:00:42 +0000 | [diff] [blame] | 803 | } |
| 804 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 805 | case LANG_ID3_TRACKNUM: |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 806 | if (id3->track_string) |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 807 | { |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 808 | val = id3->track_string; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 809 | if(say_it) |
| 810 | say_number_and_spell(val, true); |
| 811 | } |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 812 | else if (id3->tracknum) |
| 813 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 814 | snprintf(buffer, buffer_len, "%d", id3->tracknum); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 815 | val = buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 816 | if(say_it) |
| 817 | talk_number(id3->tracknum, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 818 | } |
| 819 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 820 | case LANG_ID3_COMMENT: |
Jonathan Gordon | 55b21c1 | 2010-02-18 05:50:44 +0000 | [diff] [blame] | 821 | if (!id3->comment) |
| 822 | return NULL; |
Jonathan Gordon | c647e62 | 2010-02-18 05:43:51 +0000 | [diff] [blame] | 823 | snprintf(buffer, buffer_len, "%s", id3->comment); |
| 824 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 825 | if(say_it && val) |
| 826 | talk_spell(val, true); |
Miika Pekkarinen | 4e97664 | 2007-02-10 12:09:28 +0000 | [diff] [blame] | 827 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 828 | case LANG_ID3_GENRE: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 829 | val = id3->genre_string; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 830 | if(say_it && val) |
| 831 | talk_spell(val, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 832 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 833 | case LANG_ID3_YEAR: |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 834 | if (id3->year_string) |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 835 | { |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 836 | val = id3->year_string; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 837 | if(say_it && val) |
| 838 | say_number_and_spell(val, true); |
| 839 | } |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 840 | else if (id3->year) |
| 841 | { |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 842 | snprintf(buffer, buffer_len, "%d", id3->year); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 843 | val = buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 844 | if(say_it) |
| 845 | talk_value(id3->year, UNIT_DATEYEAR, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 846 | } |
| 847 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 848 | case LANG_ID3_LENGTH: |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 849 | format_time(buffer, buffer_len, id3->length); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 850 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 851 | if(say_it) |
| 852 | talk_value(id3->length /1000, UNIT_TIME, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 853 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 854 | case LANG_ID3_PLAYLIST: |
Peter D'Hoye | 8ed3b32 | 2008-05-23 21:43:40 +0000 | [diff] [blame] | 855 | snprintf(buffer, buffer_len, "%d/%d", |
| 856 | playlist_get_display_index(), playlist_amount()); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 857 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 858 | if(say_it) |
| 859 | { |
| 860 | talk_number(playlist_get_display_index(), true); |
| 861 | talk_id(VOICE_OF, true); |
| 862 | talk_number(playlist_amount(), true); |
| 863 | } |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 864 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 865 | case LANG_ID3_BITRATE: |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 866 | snprintf(buffer, buffer_len, "%d kbps%s", id3->bitrate, |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 867 | id3->vbr ? str(LANG_ID3_VBR) : (const unsigned char*) ""); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 868 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 869 | if(say_it) |
| 870 | { |
| 871 | talk_value(id3->bitrate, UNIT_KBIT, true); |
| 872 | if(id3->vbr) |
| 873 | talk_id(LANG_ID3_VBR, true); |
| 874 | } |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 875 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 876 | case LANG_ID3_FREQUENCY: |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 877 | snprintf(buffer, buffer_len, "%ld Hz", id3->frequency); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 878 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 879 | if(say_it) |
| 880 | talk_value(id3->frequency, UNIT_HERTZ, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 881 | break; |
Jonathan Gordon | 9296150 | 2010-05-30 15:33:37 +0000 | [diff] [blame] | 882 | #if CONFIG_CODEC == SWCODEC |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 883 | case LANG_ID3_TRACK_GAIN: |
Andree Buschmann | d1766a1 | 2011-04-04 15:21:44 +0000 | [diff] [blame] | 884 | replaygain_itoa(buffer, buffer_len, id3->track_level); |
| 885 | val=(id3->track_level) ? buffer : NULL; /* only show level!=0 */ |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 886 | if(say_it && val) |
| 887 | say_gain(val); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 888 | break; |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 889 | case LANG_ID3_ALBUM_GAIN: |
Andree Buschmann | d1766a1 | 2011-04-04 15:21:44 +0000 | [diff] [blame] | 890 | replaygain_itoa(buffer, buffer_len, id3->album_level); |
| 891 | val=(id3->album_level) ? buffer : NULL; /* only show level!=0 */ |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 892 | if(say_it && val) |
| 893 | say_gain(val); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 894 | break; |
Jonathan Gordon | 9296150 | 2010-05-30 15:33:37 +0000 | [diff] [blame] | 895 | #endif |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 896 | case LANG_ID3_PATH: |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 897 | val=id3->path; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 898 | if(say_it && val) |
| 899 | talk_fullpath(val, true); |
Jonathan Gordon | 1593b05 | 2010-05-30 15:25:15 +0000 | [diff] [blame] | 900 | break; |
| 901 | case LANG_ID3_COMPOSER: |
| 902 | val=id3->composer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 903 | if(say_it && val) |
| 904 | talk_spell(val, true); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 905 | break; |
Mustapha Senhaji | 5e1e05f | 2010-12-24 03:31:40 +0000 | [diff] [blame] | 906 | case LANG_FILESIZE: /* not LANG_ID3_FILESIZE because the string is shared */ |
William Wilgus | 62a5ed4 | 2018-12-09 12:09:40 -0600 | [diff] [blame] | 907 | output_dyn_value(buffer, buffer_len, id3->filesize, byte_units, 4, true); |
Mustapha Senhaji | 5e1e05f | 2010-12-24 03:31:40 +0000 | [diff] [blame] | 908 | val=buffer; |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 909 | if(say_it && val) |
Solomon Peachy | d8ce84c | 2018-12-15 12:10:36 -0500 | [diff] [blame] | 910 | output_dyn_value(NULL, 0, id3->filesize, byte_units, 4, true); |
Mustapha Senhaji | 5e1e05f | 2010-12-24 03:31:40 +0000 | [diff] [blame] | 911 | break; |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 912 | } |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 913 | if((!val || !*val) && say_it) |
| 914 | talk_id(LANG_ID3_NO_INFO, true); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 915 | return val && *val ? val : NULL; |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 919 | /* gui_synclist callback */ |
| 920 | static const char* id3_get_info(int selected_item, void* data, |
| 921 | char *buffer, size_t buffer_len) |
| 922 | { |
| 923 | return id3_get_or_speak_info(selected_item, data, buffer, |
| 924 | buffer_len, false); |
| 925 | } |
| 926 | |
| 927 | static int id3_speak_item(int selected_item, void* data) |
| 928 | { |
| 929 | char buffer[MAX_PATH]; |
| 930 | selected_item &= ~1; /* Make sure it's even, to indicate the header */ |
| 931 | /* say field name */ |
| 932 | id3_get_or_speak_info(selected_item, data, buffer, MAX_PATH, true); |
| 933 | /* and field value */ |
| 934 | id3_get_or_speak_info(selected_item+1, data, buffer, MAX_PATH, true); |
| 935 | return 0; |
| 936 | } |
| 937 | |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 938 | bool browse_id3(void) |
| 939 | { |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 940 | struct gui_synclist id3_lists; |
| 941 | struct mp3entry* id3 = audio_current_track(); |
| 942 | int key; |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 943 | unsigned int i; |
| 944 | struct id3view_info info; |
| 945 | info.count = 0; |
| 946 | info.id3 = id3; |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 947 | bool ret = false; |
| 948 | push_current_activity(ACTIVITY_ID3SCREEN); |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 949 | for (i = 0; i < ARRAYLEN(id3_headers); i++) |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 950 | { |
| 951 | char temp[8]; |
| 952 | info.info_id[i] = i; |
| 953 | if (id3_get_info((i*2)+1, &info, temp, 8) != NULL) |
| 954 | info.info_id[info.count++] = i; |
| 955 | } |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 956 | |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 957 | gui_synclist_init(&id3_lists, &id3_get_info, &info, true, 2, NULL); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 958 | if(global_settings.talk_menu) |
| 959 | gui_synclist_set_voice_callback(&id3_lists, id3_speak_item); |
Jonathan Gordon | 5320a6a | 2008-10-19 03:58:33 +0000 | [diff] [blame] | 960 | gui_synclist_set_nb_items(&id3_lists, info.count*2); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 961 | gui_synclist_draw(&id3_lists); |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 962 | gui_synclist_speak_item(&id3_lists); |
Kevin Ferrare | f77ac7a | 2006-07-02 12:28:27 +0000 | [diff] [blame] | 963 | while (true) { |
Solomon Peachy | 4adad0b | 2018-10-30 09:45:26 -0400 | [diff] [blame] | 964 | if(!list_do_action(CONTEXT_LIST,HZ/2, |
| 965 | &id3_lists, &key,LIST_WRAP_UNLESS_HELD) |
| 966 | && key!=ACTION_NONE && key!=ACTION_UNKNOWN) |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 967 | { |
Thomas Martitz | b779fcc | 2011-10-07 22:59:06 +0000 | [diff] [blame] | 968 | if (key == ACTION_STD_OK || key == ACTION_STD_CANCEL) |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 969 | { |
| 970 | ret = false; |
| 971 | break; |
| 972 | } |
Thomas Martitz | b779fcc | 2011-10-07 22:59:06 +0000 | [diff] [blame] | 973 | else if (key == ACTION_STD_MENU || |
| 974 | default_event_handler(key) == SYS_USB_CONNECTED) |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 975 | { |
| 976 | ret = true; |
| 977 | break; |
| 978 | } |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 979 | } |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 980 | } |
Osborne Jacobs | d5e676b | 2012-03-02 23:30:07 -0500 | [diff] [blame] | 981 | |
| 982 | pop_current_activity(); |
| 983 | return ret; |
Björn Stenberg | 6c33c51 | 2004-09-19 21:58:37 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Nils Wallménius | 3200d04 | 2009-08-20 16:47:44 +0000 | [diff] [blame] | 986 | static const char* runtime_get_data(int selected_item, void* data, |
| 987 | char* buffer, size_t buffer_len) |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 988 | { |
Teruaki Kawashima | 0a17284 | 2009-08-20 15:04:47 +0000 | [diff] [blame] | 989 | (void)data; |
William Wilgus | a06d9c8 | 2018-12-17 22:27:55 -0600 | [diff] [blame] | 990 | long t; |
Bertrik Sikken | 7a4c333 | 2008-08-02 21:32:48 +0000 | [diff] [blame] | 991 | switch (selected_item) |
| 992 | { |
| 993 | case 0: return str(LANG_RUNNING_TIME); |
| 994 | case 1: t = global_status.runtime; break; |
| 995 | case 2: return str(LANG_TOP_TIME); |
| 996 | case 3: t = global_status.topruntime; break; |
| 997 | default: |
| 998 | return ""; |
| 999 | } |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1000 | |
William Wilgus | a06d9c8 | 2018-12-17 22:27:55 -0600 | [diff] [blame] | 1001 | format_time_auto(buffer, buffer_len, t, UNIT_SEC, false); |
| 1002 | |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1003 | return buffer; |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1006 | static int runtime_speak_data(int selected_item, void* data) |
| 1007 | { |
Jonathan Gordon | c14430a | 2007-11-07 09:28:07 +0000 | [diff] [blame] | 1008 | (void) data; |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1009 | talk_ids(false, |
Bertrik Sikken | 7a4c333 | 2008-08-02 21:32:48 +0000 | [diff] [blame] | 1010 | (selected_item < 2) ? LANG_RUNNING_TIME : LANG_TOP_TIME, |
| 1011 | TALK_ID((selected_item < 2) ? global_status.runtime |
Andree Buschmann | 460d549 | 2011-02-20 15:23:18 +0000 | [diff] [blame] | 1012 | : global_status.topruntime, UNIT_TIME)); |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1013 | return 0; |
| 1014 | } |
| 1015 | |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1016 | |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1017 | int view_runtime(void) |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1018 | { |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 1019 | static const char *lines[]={ID2P(LANG_CLEAR_TIME)}; |
| 1020 | static const struct text_message message={lines, 1}; |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1021 | |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1022 | struct gui_synclist lists; |
| 1023 | int action; |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 1024 | gui_synclist_init(&lists, runtime_get_data, NULL, false, 2, NULL); |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1025 | #if !defined(HAVE_LCD_CHARCELLS) |
| 1026 | gui_synclist_set_title(&lists, str(LANG_RUNNING_TIME), NOICON); |
| 1027 | #else |
| 1028 | gui_synclist_set_title(&lists, NULL, NOICON); |
Jonathan Gordon | 5dd08e1 | 2007-02-17 10:59:30 +0000 | [diff] [blame] | 1029 | #endif |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1030 | if(global_settings.talk_menu) |
| 1031 | gui_synclist_set_voice_callback(&lists, runtime_speak_data); |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1032 | gui_synclist_set_icon_callback(&lists, NULL); |
| 1033 | gui_synclist_set_nb_items(&lists, 4); |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1034 | gui_synclist_speak_item(&lists); |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1035 | while(1) |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1036 | { |
Michael Giacomelli | 1fefb48 | 2010-02-27 22:47:49 +0000 | [diff] [blame] | 1037 | global_status.runtime += ((current_tick - lasttime) / HZ); |
| 1038 | |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1039 | lasttime = current_tick; |
| 1040 | gui_synclist_draw(&lists); |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1041 | list_do_action(CONTEXT_STD, HZ, |
| 1042 | &lists, &action, LIST_WRAP_UNLESS_HELD); |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1043 | if(action == ACTION_STD_CANCEL) |
| 1044 | break; |
| 1045 | if(action == ACTION_STD_OK) { |
| 1046 | if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) |
| 1047 | { |
| 1048 | if (!(gui_synclist_get_sel_pos(&lists)/2)) |
| 1049 | global_status.runtime = 0; |
| 1050 | else |
| 1051 | global_status.topruntime = 0; |
Stéphane Doyon | 22e3d56 | 2007-11-07 03:58:13 +0000 | [diff] [blame] | 1052 | gui_synclist_speak_item(&lists); |
Dominik Riebeling | 339d812 | 2007-04-10 20:56:15 +0000 | [diff] [blame] | 1053 | } |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1054 | } |
Dominik Riebeling | a3f1e9f | 2007-04-10 21:40:44 +0000 | [diff] [blame] | 1055 | if(default_event_handler(action) == SYS_USB_CONNECTED) |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1056 | return 1; |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1057 | } |
William Wilgus | dd40c46 | 2018-10-15 23:04:04 -0400 | [diff] [blame] | 1058 | return 0; |
Jonathan Gordon | d152b64 | 2006-12-19 12:26:03 +0000 | [diff] [blame] | 1059 | } |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1060 | |
| 1061 | #ifdef HAVE_TOUCHSCREEN |
| 1062 | static int get_sample(struct touchscreen_calibration *cal, int x, int y, int i, |
| 1063 | struct screen* screen) |
| 1064 | { |
| 1065 | int action; |
| 1066 | short ts_x, ts_y; |
| 1067 | |
| 1068 | /* Draw a cross */ |
| 1069 | screen->drawline(x - 10, y, x - 2, y); |
| 1070 | screen->drawline(x + 2, y, x + 10, y); |
| 1071 | screen->drawline(x, y - 10, x, y - 2); |
| 1072 | screen->drawline(x, y + 2, x, y + 10); |
| 1073 | screen->update(); |
| 1074 | |
| 1075 | /* Wait for a touchscreen press */ |
| 1076 | while(true) |
| 1077 | { |
| 1078 | action = get_action(CONTEXT_STD, TIMEOUT_BLOCK); |
| 1079 | if(action == ACTION_TOUCHSCREEN) |
| 1080 | { |
| 1081 | if(action_get_touchscreen_press(&ts_x, &ts_y) == BUTTON_REL) |
| 1082 | break; |
| 1083 | } |
| 1084 | else if(action == ACTION_STD_CANCEL) |
| 1085 | return -1; |
| 1086 | } |
| 1087 | |
| 1088 | cal->x[i][0] = ts_x; |
| 1089 | cal->y[i][0] = ts_y; |
| 1090 | cal->x[i][1] = x; |
| 1091 | cal->y[i][1] = y; |
| 1092 | |
| 1093 | return 0; |
| 1094 | } |
| 1095 | |
| 1096 | |
| 1097 | int calibrate(void) |
| 1098 | { |
| 1099 | short points[3][2] = { |
| 1100 | {LCD_WIDTH/10, LCD_HEIGHT/10}, |
| 1101 | {7*LCD_WIDTH/8, LCD_HEIGHT/2}, |
| 1102 | {LCD_WIDTH/2, 7*LCD_HEIGHT/8} |
| 1103 | }; |
| 1104 | struct screen* screen = &screens[SCREEN_MAIN]; |
| 1105 | enum touchscreen_mode old_mode = touchscreen_get_mode(); |
| 1106 | struct touchscreen_calibration cal; |
| 1107 | int i, ret = 0; |
Rob Purchase | aee58ef | 2009-11-04 23:57:37 +0000 | [diff] [blame] | 1108 | |
| 1109 | /* hide the statusbar */ |
Jonathan Gordon | b2eb44c | 2009-12-09 07:25:46 +0000 | [diff] [blame] | 1110 | viewportmanager_theme_enable(SCREEN_MAIN, false, NULL); |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1111 | |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1112 | touchscreen_disable_mapping(); /* set raw mode */ |
| 1113 | touchscreen_set_mode(TOUCHSCREEN_POINT); |
Rob Purchase | 27f1787 | 2009-11-04 23:44:27 +0000 | [diff] [blame] | 1114 | |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1115 | for(i=0; i<3; i++) |
| 1116 | { |
| 1117 | screen->clear_display(); |
| 1118 | |
| 1119 | if(get_sample(&cal, points[i][0], points[i][1], i, screen)) |
| 1120 | { |
| 1121 | ret = -1; |
| 1122 | break; |
| 1123 | } |
| 1124 | } |
| 1125 | |
| 1126 | if(ret == 0) |
| 1127 | touchscreen_calibrate(&cal); |
| 1128 | else |
| 1129 | touchscreen_reset_mapping(); |
Rob Purchase | 27f1787 | 2009-11-04 23:44:27 +0000 | [diff] [blame] | 1130 | |
| 1131 | memcpy(&global_settings.ts_calibration_data, &calibration_parameters, |
| 1132 | sizeof(struct touchscreen_parameter)); |
| 1133 | |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1134 | touchscreen_set_mode(old_mode); |
Jonathan Gordon | 9d1832c | 2009-12-21 05:19:12 +0000 | [diff] [blame] | 1135 | viewportmanager_theme_undo(SCREEN_MAIN, false); |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1136 | |
Rob Purchase | 27f1787 | 2009-11-04 23:44:27 +0000 | [diff] [blame] | 1137 | settings_save(); |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1138 | return ret; |
| 1139 | } |
| 1140 | |
| 1141 | int reset_mapping(void) |
| 1142 | { |
| 1143 | touchscreen_reset_mapping(); |
Rob Purchase | 27f1787 | 2009-11-04 23:44:27 +0000 | [diff] [blame] | 1144 | |
| 1145 | memcpy(&global_settings.ts_calibration_data, &calibration_parameters, |
| 1146 | sizeof(struct touchscreen_parameter)); |
| 1147 | |
| 1148 | settings_save(); |
Maurus Cuelenaere | b8435f5 | 2009-06-16 17:04:47 +0000 | [diff] [blame] | 1149 | return 0; |
| 1150 | } |
| 1151 | #endif |