Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2003 Linus Nielsen Feltzing |
| 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. |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +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 | ****************************************************************************/ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include <stdio.h> |
| 24 | #include <stdbool.h> |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 25 | #include <stdlib.h> |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 26 | #include "sprintf.h" |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 27 | #include "mas.h" |
| 28 | #include "settings.h" |
| 29 | #include "button.h" |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 30 | #include "status.h" |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 31 | #include "thread.h" |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 32 | #include "mpeg.h" |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 33 | #include "audio.h" |
Jörg Hohensohn | 881b53f | 2004-01-05 22:46:54 +0000 | [diff] [blame] | 34 | #include "mp3_playback.h" |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 35 | #include "ctype.h" |
| 36 | #include "file.h" |
| 37 | #include "errno.h" |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 38 | #include "string.h" |
| 39 | #include "system.h" |
| 40 | #include "radio.h" |
| 41 | #include "menu.h" |
| 42 | #include "misc.h" |
| 43 | #include "keyboard.h" |
| 44 | #include "screens.h" |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 45 | #include "peakmeter.h" |
| 46 | #include "lang.h" |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 47 | #include "font.h" |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 48 | #include "sound_menu.h" |
Marianne Arnold | af97e93 | 2007-10-02 21:04:10 +0000 | [diff] [blame] | 49 | #ifdef HAVE_RECORDING |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 50 | #include "recording.h" |
Marianne Arnold | af97e93 | 2007-10-02 21:04:10 +0000 | [diff] [blame] | 51 | #endif |
Jörg Hohensohn | fa97f16 | 2004-03-19 22:15:53 +0000 | [diff] [blame] | 52 | #include "talk.h" |
Jörg Hohensohn | 8f8fbac | 2004-10-15 21:41:46 +0000 | [diff] [blame] | 53 | #include "tuner.h" |
Jörg Hohensohn | 91f9350 | 2004-10-17 08:53:18 +0000 | [diff] [blame] | 54 | #include "power.h" |
Linus Nielsen Feltzing | d204183 | 2005-04-01 14:09:41 +0000 | [diff] [blame] | 55 | #include "sound.h" |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 56 | #include "screen_access.h" |
| 57 | #include "statusbar.h" |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 58 | #include "splash.h" |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 59 | #include "yesno.h" |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 60 | #include "buttonbar.h" |
Anton Oleynikov | c94557e | 2005-11-19 19:23:44 +0000 | [diff] [blame] | 61 | #include "power.h" |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 62 | #include "tree.h" |
| 63 | #include "dir.h" |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 64 | #include "action.h" |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 65 | #include "list.h" |
| 66 | #include "menus/exported_menus.h" |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 67 | #include "root_menu.h" |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 68 | #include "viewport.h" |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 69 | |
Jens Arnold | c652218 | 2007-02-18 08:46:12 +0000 | [diff] [blame] | 70 | #if CONFIG_TUNER |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 71 | |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 72 | #if CONFIG_KEYPAD == RECORDER_PAD |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 73 | #define FM_RECORD |
| 74 | #define FM_PRESET_ADD |
| 75 | #define FM_PRESET_ACTION |
| 76 | #define FM_PRESET |
Martin Scarratt | a2ac8f4 | 2006-09-23 11:05:13 +0000 | [diff] [blame] | 77 | #define FM_MODE |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 78 | |
Linus Nielsen Feltzing | a4b15a4 | 2005-12-15 01:11:19 +0000 | [diff] [blame] | 79 | #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD) |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 80 | #define FM_PRESET |
Martin Scarratt | a2ac8f4 | 2006-09-23 11:05:13 +0000 | [diff] [blame] | 81 | #define FM_MODE |
Martin Scarratt | 5dc08bb | 2006-09-23 12:22:01 +0000 | [diff] [blame] | 82 | #define FM_NEXT_PRESET |
| 83 | #define FM_PREV_PRESET |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 84 | |
Barry Wardell | c495cda | 2007-11-11 16:00:33 +0000 | [diff] [blame] | 85 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD |
| 86 | #define FM_PRESET |
| 87 | #define FM_MODE |
| 88 | |
Jens Arnold | 85a226d | 2007-03-16 23:02:39 +0000 | [diff] [blame] | 89 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 90 | #define FM_PRESET |
Martin Scarratt | a2ac8f4 | 2006-09-23 11:05:13 +0000 | [diff] [blame] | 91 | #define FM_MODE |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 92 | /* This should be removeable if the whole tuning thing is sorted out since |
| 93 | proper tuning quiets the screen almost entirely in that extreme measures |
| 94 | have to be taken to hear any interference. */ |
| 95 | #define HAVE_NOISY_IDLE_MODE |
Linus Nielsen Feltzing | ed4d7a3 | 2006-07-21 08:42:28 +0000 | [diff] [blame] | 96 | |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 97 | #elif CONFIG_KEYPAD == ONDIO_PAD |
| 98 | #define FM_RECORD_DBLPRE |
| 99 | #define FM_RECORD |
Marianne Arnold | af97e93 | 2007-10-02 21:04:10 +0000 | [diff] [blame] | 100 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || (CONFIG_KEYPAD == SANSA_C200_PAD) |
Michael Sevakis | 21a4a87 | 2007-06-06 19:23:48 +0000 | [diff] [blame] | 101 | #define FM_MENU |
| 102 | #define FM_PRESET |
| 103 | #define FM_STOP |
| 104 | #define FM_MODE |
| 105 | #define FM_EXIT |
| 106 | #define FM_PLAY |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 107 | #endif |
| 108 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 109 | #define RADIO_SCAN_MODE 0 |
| 110 | #define RADIO_PRESET_MODE 1 |
| 111 | |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 112 | static int curr_preset = -1; |
Linus Nielsen Feltzing | 3e92dbe | 2004-07-12 13:28:44 +0000 | [diff] [blame] | 113 | static int curr_freq; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 114 | static int radio_mode = RADIO_SCAN_MODE; |
Michael Sevakis | 62e0a51 | 2007-03-29 01:55:47 +0000 | [diff] [blame] | 115 | static int search_dir = 0; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 116 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 117 | static int radio_status = FMRADIO_OFF; |
| 118 | static bool in_screen = false; |
| 119 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 120 | #define MAX_PRESETS 64 |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 121 | static bool presets_loaded = false, presets_changed = false; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 122 | static struct fmstation presets[MAX_PRESETS]; |
| 123 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 124 | static char filepreset[MAX_PATH]; /* preset filename variable */ |
Linus Nielsen Feltzing | ed100ca | 2003-05-04 22:58:12 +0000 | [diff] [blame] | 125 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 126 | static int num_presets = 0; /* The number of presets in the preset list */ |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 127 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 128 | static void radio_save_presets(void); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 129 | static int handle_radio_presets(void); |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 130 | static bool radio_menu(void); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 131 | static int radio_add_preset(void); |
| 132 | static int save_preset_list(void); |
| 133 | static int load_preset_list(void); |
| 134 | static int clear_preset_list(void); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 135 | |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 136 | static int scan_presets(void *viewports); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 137 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 138 | /* Function to manipulate all yesno dialogues. |
| 139 | This function needs the output text as an argument. */ |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 140 | static bool yesno_pop(const char* text) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 141 | { |
| 142 | int i; |
Nils Wallménius | 33c4446 | 2008-04-26 09:30:24 +0000 | [diff] [blame] | 143 | const char *lines[]={text}; |
| 144 | const struct text_message message={lines, 1}; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 145 | bool ret = (gui_syncyesno_run(&message,NULL,NULL)== YESNO_YES); |
| 146 | FOR_NB_SCREENS(i) |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 147 | screens[i].clear_viewport(); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 148 | return ret; |
| 149 | } |
| 150 | |
Jörg Hohensohn | 8f8fbac | 2004-10-15 21:41:46 +0000 | [diff] [blame] | 151 | void radio_init(void) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 152 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 153 | tuner_init(); |
Linus Nielsen Feltzing | 47e8773 | 2004-11-22 06:34:14 +0000 | [diff] [blame] | 154 | radio_stop(); |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Anton Oleynikov | c94557e | 2005-11-19 19:23:44 +0000 | [diff] [blame] | 157 | int get_radio_status(void) |
| 158 | { |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 159 | return radio_status; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 160 | } |
| 161 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 162 | bool in_radio_screen(void) |
| 163 | { |
| 164 | return in_screen; |
| 165 | } |
| 166 | |
Michael Sevakis | 21a4a87 | 2007-06-06 19:23:48 +0000 | [diff] [blame] | 167 | /* TODO: Move some more of the control functionality to an HAL and clean up the |
| 168 | mess */ |
| 169 | |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 170 | /* secret flag for starting paused - prevents unmute */ |
| 171 | #define FMRADIO_START_PAUSED 0x8000 |
| 172 | void radio_start(void) |
| 173 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 174 | const struct fm_region_data *fmr; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 175 | bool start_paused; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 176 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 177 | if(radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 178 | return; |
| 179 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 180 | fmr = &fm_region_data[global_settings.fm_region]; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 181 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 182 | start_paused = radio_status & FMRADIO_START_PAUSED; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 183 | /* clear flag before any yielding */ |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 184 | radio_status &= ~FMRADIO_START_PAUSED; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 185 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 186 | if(radio_status == FMRADIO_OFF) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 187 | tuner_power(true); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 188 | |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 189 | curr_freq = global_status.last_frequency |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 190 | * fmr->freq_step + fmr->freq_min; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 191 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 192 | tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */ |
Michael Sevakis | 21a4a87 | 2007-06-06 19:23:48 +0000 | [diff] [blame] | 193 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 194 | if(radio_status == FMRADIO_OFF) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 195 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 196 | #ifdef HAVE_RADIO_REGION |
| 197 | tuner_set(RADIO_REGION, global_settings.fm_region); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 198 | #endif |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 199 | tuner_set(RADIO_FORCE_MONO, global_settings.fm_force_mono); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 202 | tuner_set(RADIO_FREQUENCY, curr_freq); |
| 203 | |
| 204 | #ifdef HAVE_RADIO_MUTE_TIMEOUT |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 205 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 206 | unsigned long mute_timeout = current_tick + HZ; |
| 207 | if (radio_status != FMRADIO_OFF) |
| 208 | { |
| 209 | /* paused */ |
| 210 | mute_timeout += HZ; |
| 211 | } |
| 212 | |
| 213 | while(!tuner_get(RADIO_STEREO) && !tuner_get(RADIO_TUNED)) |
| 214 | { |
| 215 | if(TIME_AFTER(current_tick, mute_timeout)) |
| 216 | break; |
| 217 | yield(); |
| 218 | } |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 219 | } |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 220 | #endif |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 221 | |
| 222 | /* keep radio from sounding initially */ |
| 223 | if(!start_paused) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 224 | tuner_set(RADIO_MUTE, 0); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 225 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 226 | radio_status = FMRADIO_PLAYING; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 227 | } /* radio_start */ |
| 228 | |
| 229 | void radio_pause(void) |
| 230 | { |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 231 | if(radio_status == FMRADIO_PAUSED) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 232 | return; |
| 233 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 234 | if(radio_status == FMRADIO_OFF) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 235 | { |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 236 | radio_status |= FMRADIO_START_PAUSED; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 237 | radio_start(); |
| 238 | } |
| 239 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 240 | tuner_set(RADIO_MUTE, 1); |
| 241 | tuner_set(RADIO_SLEEP, 1); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 242 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 243 | radio_status = FMRADIO_PAUSED; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 244 | } /* radio_pause */ |
| 245 | |
Linus Nielsen Feltzing | af2b7ad | 2003-05-09 00:14:59 +0000 | [diff] [blame] | 246 | void radio_stop(void) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 247 | { |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 248 | if(radio_status == FMRADIO_OFF) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 249 | return; |
| 250 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 251 | tuner_set(RADIO_MUTE, 1); |
| 252 | tuner_set(RADIO_SLEEP, 1); /* low power mode, if available */ |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 253 | radio_status = FMRADIO_OFF; |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 254 | tuner_power(false); /* status update, power off if avail. */ |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 255 | } /* radio_stop */ |
Linus Nielsen Feltzing | af2b7ad | 2003-05-09 00:14:59 +0000 | [diff] [blame] | 256 | |
Linus Nielsen Feltzing | ef8fd8e | 2003-12-19 01:24:02 +0000 | [diff] [blame] | 257 | bool radio_hardware_present(void) |
| 258 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 259 | return tuner_get(RADIO_PRESENT); |
Linus Nielsen Feltzing | ef8fd8e | 2003-12-19 01:24:02 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 262 | /* Keep freq on the grid for the current region */ |
| 263 | static int snap_freq_to_grid(int freq) |
| 264 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 265 | const struct fm_region_data * const fmr = |
| 266 | &fm_region_data[global_settings.fm_region]; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 267 | |
| 268 | /* Range clamp if out of range or just round to nearest */ |
| 269 | if (freq < fmr->freq_min) |
| 270 | freq = fmr->freq_min; |
| 271 | else if (freq > fmr->freq_max) |
| 272 | freq = fmr->freq_max; |
| 273 | else |
| 274 | freq = (freq - fmr->freq_min + fmr->freq_step/2) / |
| 275 | fmr->freq_step * fmr->freq_step + fmr->freq_min; |
| 276 | |
| 277 | return freq; |
| 278 | } |
| 279 | |
| 280 | /* Find a matching preset to freq */ |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 281 | static int find_preset(int freq) |
| 282 | { |
| 283 | int i; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 284 | if(num_presets < 1) |
| 285 | return -1; |
Linus Nielsen Feltzing | 8d8b8d1 | 2003-05-04 13:05:30 +0000 | [diff] [blame] | 286 | for(i = 0;i < MAX_PRESETS;i++) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 287 | { |
Linus Nielsen Feltzing | 8d8b8d1 | 2003-05-04 13:05:30 +0000 | [diff] [blame] | 288 | if(freq == presets[i].frequency) |
| 289 | return i; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | return -1; |
| 293 | } |
| 294 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 295 | /* Return the first preset encountered in the search direction with |
| 296 | wraparound. */ |
| 297 | static int find_closest_preset(int freq, int direction) |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 298 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 299 | int i; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 300 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 301 | if (direction == 0) /* direction == 0 isn't really used */ |
| 302 | return 0; |
| 303 | |
| 304 | for (i = 0; i < MAX_PRESETS; i++) |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 305 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 306 | int preset_frequency = presets[i].frequency; |
| 307 | |
| 308 | if (preset_frequency == freq) |
| 309 | return i; /* Exact match = stop */ |
| 310 | /* Stop when the preset frequency exeeds freq so that we can |
| 311 | pick the correct one based on direction */ |
| 312 | if (preset_frequency > freq) |
| 313 | break; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 314 | } |
| 315 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 316 | /* wrap around depending on direction */ |
| 317 | if (i == 0 || i >= num_presets - 1) |
| 318 | i = direction < 0 ? num_presets - 1 : 0; |
| 319 | else if (direction < 0) |
| 320 | i--; /* use previous */ |
| 321 | |
| 322 | return i; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Linus Nielsen Feltzing | 3e92dbe | 2004-07-12 13:28:44 +0000 | [diff] [blame] | 325 | static void remember_frequency(void) |
| 326 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 327 | const struct fm_region_data * const fmr = |
| 328 | &fm_region_data[global_settings.fm_region]; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 329 | global_status.last_frequency = (curr_freq - fmr->freq_min) |
| 330 | / fmr->freq_step; |
Jonathan Gordon | 228d62d | 2007-01-24 02:19:22 +0000 | [diff] [blame] | 331 | status_save(); |
Linus Nielsen Feltzing | 3e92dbe | 2004-07-12 13:28:44 +0000 | [diff] [blame] | 332 | } |
| 333 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 334 | static void next_preset(int direction) |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 335 | { |
| 336 | if (num_presets < 1) |
| 337 | return; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 338 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 339 | if (curr_preset == -1) |
| 340 | curr_preset = find_closest_preset(curr_freq, direction); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 341 | else |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 342 | curr_preset = (curr_preset + direction + num_presets) % num_presets; |
| 343 | |
| 344 | /* Must stay on the current grid for the region */ |
| 345 | curr_freq = snap_freq_to_grid(presets[curr_preset].frequency); |
| 346 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 347 | tuner_set(RADIO_FREQUENCY, curr_freq); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 348 | remember_frequency(); |
| 349 | } |
| 350 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 351 | /* Step to the next or previous frequency */ |
| 352 | static int step_freq(int freq, int direction) |
| 353 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 354 | const struct fm_region_data * const fmr = |
| 355 | &fm_region_data[global_settings.fm_region]; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 356 | |
| 357 | freq += direction*fmr->freq_step; |
| 358 | |
| 359 | /* Wrap first or snapping to grid will not let us on the band extremes */ |
| 360 | if (freq > fmr->freq_max) |
| 361 | freq = direction > 0 ? fmr->freq_min : fmr->freq_max; |
| 362 | else if (freq < fmr->freq_min) |
| 363 | freq = direction < 0 ? fmr->freq_max : fmr->freq_min; |
| 364 | else |
| 365 | freq = snap_freq_to_grid(freq); |
| 366 | |
| 367 | return freq; |
| 368 | } |
| 369 | |
| 370 | /* Step to the next or previous station */ |
| 371 | static void next_station(int direction) |
| 372 | { |
| 373 | if (direction != 0 && radio_mode != RADIO_SCAN_MODE) |
| 374 | { |
| 375 | next_preset(direction); |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | curr_freq = step_freq(curr_freq, direction); |
| 380 | |
| 381 | if (radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 382 | tuner_set(RADIO_MUTE, 1); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 383 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 384 | tuner_set(RADIO_FREQUENCY, curr_freq); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 385 | |
| 386 | if (radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 387 | tuner_set(RADIO_MUTE, 0); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 388 | |
| 389 | curr_preset = find_preset(curr_freq); |
| 390 | remember_frequency(); |
| 391 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 392 | |
Michael Sevakis | 62e0a51 | 2007-03-29 01:55:47 +0000 | [diff] [blame] | 393 | /* Ends an in-progress search */ |
| 394 | static void end_search(void) |
| 395 | { |
| 396 | if (search_dir != 0 && radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 397 | tuner_set(RADIO_MUTE, 0); |
Michael Sevakis | 62e0a51 | 2007-03-29 01:55:47 +0000 | [diff] [blame] | 398 | search_dir = 0; |
| 399 | } |
| 400 | |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 401 | /* Speak a frequency. */ |
| 402 | static void talk_freq(int freq, bool enqueue) |
| 403 | { |
| 404 | freq /= 10000; |
| 405 | talk_number(freq / 100, enqueue); |
| 406 | talk_id(LANG_POINT, true); |
| 407 | talk_number(freq % 100 / 10, true); |
| 408 | if (freq % 10) |
| 409 | talk_number(freq % 10, true); |
| 410 | } |
| 411 | |
| 412 | /* Speak a preset by number or by spelling its name, depending on settings. */ |
| 413 | static void talk_preset(int preset, bool fallback, bool enqueue) |
| 414 | { |
| 415 | if (global_settings.talk_file == 1) /* number */ |
| 416 | talk_number(preset + 1, enqueue); |
| 417 | else |
| 418 | { /* spell */ |
| 419 | if(presets[preset].name[0]) |
| 420 | talk_spell(presets[preset].name, enqueue); |
| 421 | else if(fallback) |
| 422 | talk_freq(presets[preset].frequency, enqueue); |
| 423 | } |
| 424 | } |
| 425 | |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 426 | int radio_screen(void) |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 427 | { |
Linus Nielsen Feltzing | ef7293f | 2004-01-21 14:58:40 +0000 | [diff] [blame] | 428 | char buf[MAX_PATH]; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 429 | bool done = false; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 430 | int ret_val = GO_TO_ROOT; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 431 | int button; |
| 432 | int i; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 433 | bool stereo = false, last_stereo = false; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 434 | int fh; |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 435 | int top_of_screen = 0; |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 436 | bool update_screen = true; |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 437 | bool screen_freeze = false; |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 438 | bool keep_playing = false; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 439 | bool statusbar = global_settings.statusbar; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 440 | bool talk = false; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 441 | #ifdef FM_RECORD_DBLPRE |
| 442 | int lastbutton = BUTTON_NONE; |
| 443 | unsigned long rec_lastclick = 0; |
| 444 | #endif |
| 445 | #if CONFIG_CODEC != SWCODEC |
| 446 | bool have_recorded = false; |
| 447 | int timeout = current_tick + HZ/10; |
| 448 | unsigned int seconds = 0; |
| 449 | unsigned int last_seconds = 0; |
| 450 | int hours, minutes; |
| 451 | struct audio_recording_options rec_options; |
| 452 | #endif /* CONFIG_CODEC != SWCODEC */ |
| 453 | #ifndef HAVE_NOISY_IDLE_MODE |
Hristo Kovachev | 3de0db0 | 2006-03-07 11:49:06 +0000 | [diff] [blame] | 454 | int button_timeout = current_tick + (2*HZ); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 455 | #endif |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 456 | struct viewport vp[NB_SCREENS]; |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 457 | #ifdef HAVE_BUTTONBAR |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 458 | struct gui_buttonbar buttonbar; |
| 459 | gui_buttonbar_init(&buttonbar); |
| 460 | gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); |
| 461 | #endif |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 462 | |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 463 | /* change status to "in screen" */ |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 464 | in_screen = true; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 465 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 466 | /* always display status bar in radio screen for now */ |
Jonathan Gordon | 4d238c1 | 2008-01-10 06:46:04 +0000 | [diff] [blame] | 467 | global_status.statusbar_forced = statusbar?0:1; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 468 | global_settings.statusbar = true; |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 469 | gui_syncstatusbar_draw(&statusbars,true); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 470 | FOR_NB_SCREENS(i) |
| 471 | { |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 472 | viewport_set_defaults(&vp[i], i); |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 473 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 474 | if (global_settings.buttonbar) |
| 475 | vp[i].height -= BUTTONBAR_HEIGHT; |
| 476 | #endif |
| 477 | screens[i].set_viewport(&vp[i]); |
| 478 | screens[i].clear_viewport(); |
| 479 | screens[i].update_viewport(); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 480 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 481 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 482 | fh = font_get(FONT_UI)->height; |
| 483 | |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 484 | /* Adjust for font size, trying to center the information vertically */ |
| 485 | if(fh < 10) |
| 486 | top_of_screen = 1; |
| 487 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 488 | if(num_presets <= 0) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 489 | { |
| 490 | memset(presets, 0, sizeof(presets)); |
| 491 | radio_load_presets(global_settings.fmr_file); |
| 492 | } |
| 493 | |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 494 | if(radio_status == FMRADIO_OFF) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 495 | audio_stop(); |
Jonathan Gordon | 67b3206 | 2007-03-07 09:16:20 +0000 | [diff] [blame] | 496 | #ifndef SIMULATOR |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 497 | |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 498 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | 3405d13 | 2004-06-04 12:34:29 +0000 | [diff] [blame] | 499 | if(rec_create_directory() > 0) |
| 500 | have_recorded = true; |
Linus Nielsen Feltzing | 8c7589b | 2005-08-13 17:35:02 +0000 | [diff] [blame] | 501 | |
Peter D'Hoye | 67ff262 | 2006-04-30 23:18:21 +0000 | [diff] [blame] | 502 | audio_init_recording(talk_get_bufsize()); |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 503 | |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 504 | sound_settings_apply(); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 505 | /* Yes, we use the D/A for monitoring */ |
| 506 | peak_meter_playback(true); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 507 | |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 508 | peak_meter_enabled = true; |
| 509 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 510 | rec_init_recording_options(&rec_options); |
| 511 | rec_options.rec_source = AUDIO_SRC_LINEIN; |
| 512 | rec_set_recording_options(&rec_options); |
Jörg Hohensohn | fa97f16 | 2004-03-19 22:15:53 +0000 | [diff] [blame] | 513 | |
Jens Arnold | a238ab9 | 2006-05-14 23:34:24 +0000 | [diff] [blame] | 514 | audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 515 | sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN); |
| 516 | |
| 517 | #endif /* CONFIG_CODEC != SWCODEC */ |
| 518 | #endif /* ndef SIMULATOR */ |
| 519 | |
| 520 | /* turn on radio */ |
| 521 | #if CONFIG_CODEC == SWCODEC |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 522 | audio_set_input_source(AUDIO_SRC_FMRADIO, |
| 523 | (radio_status == FMRADIO_PAUSED) ? |
| 524 | SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 525 | #else |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 526 | if (radio_status == FMRADIO_OFF) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 527 | radio_start(); |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 528 | #endif |
Linus Nielsen Feltzing | 3e92dbe | 2004-07-12 13:28:44 +0000 | [diff] [blame] | 529 | |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 530 | if(num_presets < 1 && yesno_pop(ID2P(LANG_FM_FIRST_AUTOSCAN))) |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 531 | scan_presets(vp); |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 532 | |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 533 | curr_preset = find_preset(curr_freq); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 534 | if(curr_preset != -1) |
| 535 | radio_mode = RADIO_PRESET_MODE; |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 536 | |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 537 | #ifdef HAVE_BUTTONBAR |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 538 | gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU), |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 539 | str(LANG_PRESET), str(LANG_FM_BUTTONBAR_RECORD)); |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 540 | #endif |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 541 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 542 | #ifndef HAVE_NOISY_IDLE_MODE |
Linus Nielsen Feltzing | 8b9c64f | 2005-09-29 11:19:55 +0000 | [diff] [blame] | 543 | cpu_idle_mode(true); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 544 | #endif |
| 545 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 546 | while(!done) |
| 547 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 548 | if(search_dir != 0) |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 549 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 550 | curr_freq = step_freq(curr_freq, search_dir); |
| 551 | update_screen = true; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 552 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 553 | if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq)) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 554 | { |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 555 | curr_preset = find_preset(curr_freq); |
Linus Nielsen Feltzing | 3e92dbe | 2004-07-12 13:28:44 +0000 | [diff] [blame] | 556 | remember_frequency(); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 557 | end_search(); |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 558 | talk = true; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 559 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 560 | |
| 561 | trigger_cpu_boost(); |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 562 | } |
| 563 | |
Michael Sevakis | fadbf0a | 2007-11-20 03:44:25 +0000 | [diff] [blame] | 564 | if (!update_screen) |
| 565 | { |
| 566 | cancel_cpu_boost(); |
| 567 | } |
| 568 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 569 | #if CONFIG_CODEC != SWCODEC |
| 570 | /* TODO: Can we timeout at HZ when recording since peaks aren't |
| 571 | displayed? This should quiet recordings too. */ |
| 572 | button = get_action(CONTEXT_FM, |
| 573 | update_screen ? TIMEOUT_NOBLOCK : HZ / PEAK_METER_FPS); |
| 574 | #else |
| 575 | button = get_action(CONTEXT_FM, |
| 576 | update_screen ? TIMEOUT_NOBLOCK : HZ); |
| 577 | #endif |
| 578 | |
| 579 | #ifndef HAVE_NOISY_IDLE_MODE |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 580 | if (button != ACTION_NONE) |
Hristo Kovachev | 3de0db0 | 2006-03-07 11:49:06 +0000 | [diff] [blame] | 581 | { |
| 582 | cpu_idle_mode(false); |
| 583 | button_timeout = current_tick + (2*HZ); |
| 584 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 585 | #endif |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 586 | switch(button) |
| 587 | { |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 588 | case ACTION_FM_STOP: |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 589 | #if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR) |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 590 | if(audio_status() == AUDIO_STATUS_RECORD) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 591 | { |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 592 | audio_stop(); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 593 | } |
| 594 | else |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 595 | #endif |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 596 | { |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 597 | done = true; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 598 | if(presets_changed) |
| 599 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 600 | if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES))) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 601 | { |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 602 | if(filepreset[0] == '\0') |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 603 | save_preset_list(); |
| 604 | else |
| 605 | radio_save_presets(); |
| 606 | } |
| 607 | } |
| 608 | /* Clear the preset list on exit. */ |
| 609 | clear_preset_list(); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 610 | } |
| 611 | update_screen = true; |
Linus Nielsen Feltzing | af2b7ad | 2003-05-09 00:14:59 +0000 | [diff] [blame] | 612 | break; |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 613 | |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 614 | #ifdef FM_RECORD |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 615 | case ACTION_FM_RECORD: |
Jens Arnold | 1e0b5aa | 2005-09-05 19:17:23 +0000 | [diff] [blame] | 616 | #ifdef FM_RECORD_DBLPRE |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 617 | if (lastbutton != ACTION_FM_RECORD_DBLPRE) |
Jens Arnold | 1e0b5aa | 2005-09-05 19:17:23 +0000 | [diff] [blame] | 618 | { |
| 619 | rec_lastclick = 0; |
| 620 | break; |
| 621 | } |
| 622 | if (current_tick - rec_lastclick > HZ/2) |
| 623 | { |
| 624 | rec_lastclick = current_tick; |
| 625 | break; |
| 626 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 627 | #endif /* FM_RECORD_DBLPRE */ |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 628 | #ifndef SIMULATOR |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 629 | if(audio_status() == AUDIO_STATUS_RECORD) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 630 | { |
Peter D'Hoye | 583f186 | 2007-08-25 15:53:54 +0000 | [diff] [blame] | 631 | rec_command(RECORDING_CMD_START_NEWFILE); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 632 | update_screen = true; |
| 633 | } |
| 634 | else |
| 635 | { |
Linus Nielsen Feltzing | 74976c1 | 2003-12-31 03:13:29 +0000 | [diff] [blame] | 636 | have_recorded = true; |
Peter D'Hoye | 583f186 | 2007-08-25 15:53:54 +0000 | [diff] [blame] | 637 | rec_command(RECORDING_CMD_START); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 638 | update_screen = true; |
| 639 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 640 | #endif /* SIMULATOR */ |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 641 | last_seconds = 0; |
| 642 | break; |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 643 | #endif /* #ifdef FM_RECORD */ |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 644 | |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 645 | case ACTION_FM_EXIT: |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 646 | #if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR) |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 647 | if(audio_status() == AUDIO_STATUS_RECORD) |
| 648 | audio_stop(); |
Jens Arnold | 59483d6 | 2005-03-06 18:03:01 +0000 | [diff] [blame] | 649 | #endif |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 650 | keep_playing = true; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 651 | done = true; |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 652 | ret_val = GO_TO_ROOT; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 653 | if(presets_changed) |
| 654 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 655 | if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES))) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 656 | { |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 657 | if(filepreset[0] == '\0') |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 658 | save_preset_list(); |
| 659 | else |
| 660 | radio_save_presets(); |
| 661 | } |
| 662 | } |
| 663 | |
| 664 | /* Clear the preset list on exit. */ |
| 665 | clear_preset_list(); |
Jonathan Gordon | 91cb68a | 2007-03-01 11:14:46 +0000 | [diff] [blame] | 666 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 667 | break; |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 668 | |
| 669 | case ACTION_STD_PREV: |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 670 | case ACTION_STD_NEXT: |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 671 | next_station(button == ACTION_STD_PREV ? -1 : 1); |
| 672 | end_search(); |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 673 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 674 | talk = true; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 675 | break; |
| 676 | |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 677 | case ACTION_STD_PREVREPEAT: |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 678 | case ACTION_STD_NEXTREPEAT: |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 679 | { |
| 680 | int dir = search_dir; |
| 681 | search_dir = button == ACTION_STD_PREVREPEAT ? -1 : 1; |
| 682 | if (radio_mode != RADIO_SCAN_MODE) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 683 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 684 | next_preset(search_dir); |
| 685 | end_search(); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 686 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 687 | talk = true; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 688 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 689 | else if (dir == 0) |
| 690 | { |
| 691 | /* Starting auto scan */ |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 692 | tuner_set(RADIO_MUTE, 1); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 693 | update_screen = true; |
| 694 | } |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 695 | break; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 696 | } |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 697 | |
| 698 | case ACTION_SETTINGS_INC: |
| 699 | case ACTION_SETTINGS_INCREPEAT: |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 700 | global_settings.volume++; |
Nils Wallménius | f46657e | 2007-05-30 17:57:32 +0000 | [diff] [blame] | 701 | setvol(); |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 702 | update_screen = true; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 703 | break; |
| 704 | |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 705 | case ACTION_SETTINGS_DEC: |
| 706 | case ACTION_SETTINGS_DECREPEAT: |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 707 | global_settings.volume--; |
Nils Wallménius | f46657e | 2007-05-30 17:57:32 +0000 | [diff] [blame] | 708 | setvol(); |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 709 | update_screen = true; |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 710 | break; |
| 711 | |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 712 | case ACTION_FM_PLAY: |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 713 | if (radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 714 | radio_pause(); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 715 | else |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 716 | radio_start(); |
| 717 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 718 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 719 | talk = false; |
| 720 | talk_shutup(); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 721 | break; |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 722 | |
| 723 | case ACTION_FM_MENU: |
Linus Nielsen Feltzing | af2b7ad | 2003-05-09 00:14:59 +0000 | [diff] [blame] | 724 | radio_menu(); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 725 | curr_preset = find_preset(curr_freq); |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 726 | FOR_NB_SCREENS(i) |
| 727 | { |
| 728 | screens[i].set_viewport(&vp[i]); |
| 729 | screens[i].clear_viewport(); |
| 730 | screens[i].update_viewport(); |
| 731 | screens[i].set_viewport(NULL); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 732 | } |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 733 | #ifdef HAVE_BUTTONBAR |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 734 | gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU), |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 735 | str(LANG_PRESET), |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 736 | str(LANG_FM_BUTTONBAR_RECORD)); |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 737 | #endif |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 738 | update_screen = true; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 739 | break; |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 740 | |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 741 | #ifdef FM_PRESET |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 742 | case ACTION_FM_PRESET: |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 743 | if(num_presets < 1) |
| 744 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 745 | gui_syncsplash(HZ, ID2P(LANG_FM_NO_PRESETS)); |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 746 | update_screen = true; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 747 | FOR_NB_SCREENS(i) |
| 748 | { |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 749 | screens[i].set_viewport(&vp[i]); |
| 750 | screens[i].clear_viewport(); |
| 751 | screens[i].update_viewport(); |
| 752 | screens[i].set_viewport(NULL); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 753 | } |
| 754 | |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 755 | break; |
| 756 | } |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 757 | handle_radio_presets(); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 758 | FOR_NB_SCREENS(i) |
| 759 | { |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 760 | screens[i].set_viewport(&vp[i]); |
| 761 | screens[i].clear_viewport(); |
| 762 | screens[i].update_viewport(); |
| 763 | screens[i].set_viewport(NULL); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 764 | } |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 765 | #ifdef HAVE_BUTTONBAR |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 766 | gui_buttonbar_set(&buttonbar, |
| 767 | str(LANG_BUTTONBAR_MENU), |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 768 | str(LANG_PRESET), |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 769 | str(LANG_FM_BUTTONBAR_RECORD)); |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 770 | #endif |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 771 | update_screen = true; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 772 | break; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 773 | #endif /* FM_PRESET */ |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 774 | |
Jörg Hohensohn | 120d863 | 2004-10-10 17:12:43 +0000 | [diff] [blame] | 775 | #ifdef FM_FREEZE |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 776 | case ACTION_FM_FREEZE: |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 777 | if(!screen_freeze) |
| 778 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 779 | gui_syncsplash(HZ, str(LANG_FM_FREEZE)); |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 780 | screen_freeze = true; |
| 781 | } |
| 782 | else |
| 783 | { |
| 784 | update_screen = true; |
| 785 | screen_freeze = false; |
| 786 | } |
| 787 | break; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 788 | #endif /* FM_FREEZE */ |
| 789 | |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 790 | case SYS_USB_CONNECTED: |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 791 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 792 | /* Only accept USB connection when not recording */ |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 793 | if(audio_status() != AUDIO_STATUS_RECORD) |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 794 | #endif |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 795 | { |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 796 | default_event_handler(SYS_USB_CONNECTED); |
Linus Nielsen Feltzing | 74976c1 | 2003-12-31 03:13:29 +0000 | [diff] [blame] | 797 | screen_freeze = true; /* Cosmetic: makes sure the |
| 798 | radio screen doesn't redraw */ |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 799 | done = true; |
| 800 | } |
| 801 | break; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 802 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 803 | #ifdef FM_MODE |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 804 | case ACTION_FM_MODE: |
| 805 | if(radio_mode == RADIO_SCAN_MODE) |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 806 | { |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 807 | /* Force scan mode if there are no presets. */ |
| 808 | if(num_presets > 0) |
| 809 | radio_mode = RADIO_PRESET_MODE; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 810 | } |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 811 | else |
| 812 | radio_mode = RADIO_SCAN_MODE; |
| 813 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 814 | cond_talk_ids_fq(radio_mode ? |
| 815 | LANG_PRESET : LANG_RADIO_SCAN_MODE); |
| 816 | talk = true; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 817 | break; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 818 | #endif /* FM_MODE */ |
| 819 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 820 | #ifdef FM_NEXT_PRESET |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 821 | case ACTION_FM_NEXT_PRESET: |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 822 | next_preset(1); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 823 | end_search(); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 824 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 825 | talk = true; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 826 | break; |
| 827 | #endif |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 828 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 829 | #ifdef FM_PREV_PRESET |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 830 | case ACTION_FM_PREV_PRESET: |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 831 | next_preset(-1); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 832 | end_search(); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 833 | update_screen = true; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 834 | talk = true; |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 835 | break; |
| 836 | #endif |
Linus Nielsen Feltzing | ade5d7b | 2004-07-26 16:06:59 +0000 | [diff] [blame] | 837 | |
| 838 | default: |
| 839 | default_event_handler(button); |
| 840 | break; |
Hristo Kovachev | 3de0db0 | 2006-03-07 11:49:06 +0000 | [diff] [blame] | 841 | } /*switch(button)*/ |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 842 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 843 | #ifdef FM_RECORD_DBLPRE |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 844 | if (button != ACTION_NONE) |
Linus Nielsen Feltzing | 8c7589b | 2005-08-13 17:35:02 +0000 | [diff] [blame] | 845 | lastbutton = button; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 846 | #endif |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 847 | |
Peter D'Hoye | c7838b8 | 2006-03-03 19:41:16 +0000 | [diff] [blame] | 848 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 849 | peak_meter_peek(); |
Peter D'Hoye | c7838b8 | 2006-03-03 19:41:16 +0000 | [diff] [blame] | 850 | #endif |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 851 | |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 852 | if(!screen_freeze) |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 853 | { |
Linus Nielsen Feltzing | 74976c1 | 2003-12-31 03:13:29 +0000 | [diff] [blame] | 854 | /* Only display the peak meter when not recording */ |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 855 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 856 | if(!audio_status()) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 857 | { |
Dan Everton | b66477a | 2006-03-25 13:35:31 +0000 | [diff] [blame] | 858 | FOR_NB_SCREENS(i) |
| 859 | { |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 860 | screens[i].set_viewport(&vp[i]); |
Dan Everton | b66477a | 2006-03-25 13:35:31 +0000 | [diff] [blame] | 861 | peak_meter_screen(&screens[i],0, |
| 862 | STATUSBAR_HEIGHT + fh*(top_of_screen + 4), fh); |
| 863 | screens[i].update_rect(0, STATUSBAR_HEIGHT + fh*(top_of_screen + 4), |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 864 | screens[i].width, fh); |
| 865 | screens[i].set_viewport(NULL); |
Dan Everton | b66477a | 2006-03-25 13:35:31 +0000 | [diff] [blame] | 866 | } |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 867 | } |
Jens Arnold | 99a0598 | 2005-08-29 20:07:17 +0000 | [diff] [blame] | 868 | |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 869 | if(TIME_AFTER(current_tick, timeout)) |
| 870 | { |
| 871 | timeout = current_tick + HZ; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 872 | #else /* SWCODEC */ |
| 873 | { |
| 874 | #endif /* CONFIG_CODEC == SWCODEC */ |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 875 | |
| 876 | /* keep "mono" from always being displayed when paused */ |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 877 | if (radio_status != FMRADIO_PAUSED) |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 878 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 879 | stereo = tuner_get(RADIO_STEREO) && |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 880 | !global_settings.fm_force_mono; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 881 | |
| 882 | if(stereo != last_stereo) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 883 | { |
| 884 | update_screen = true; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 885 | last_stereo = stereo; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 886 | } |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 887 | } |
| 888 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 889 | |
| 890 | #if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR) |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 891 | seconds = audio_recorded_time() / HZ; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 892 | if (update_screen || seconds > last_seconds) |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 893 | { |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 894 | last_seconds = seconds; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 895 | #else |
| 896 | if (update_screen) |
| 897 | { |
| 898 | #endif |
| 899 | int freq; |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 900 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 901 | FOR_NB_SCREENS(i) |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 902 | { |
| 903 | screens[i].set_viewport(&vp[i]); |
| 904 | } |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 905 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 906 | snprintf(buf, 128, curr_preset >= 0 ? "%d. %s" : " ", |
| 907 | curr_preset + 1, presets[curr_preset].name); |
| 908 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 909 | FOR_NB_SCREENS(i) |
| 910 | screens[i].puts_scroll(0, top_of_screen, buf); |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 911 | |
Dominik Riebeling | e66b2ec | 2006-10-05 12:40:13 +0000 | [diff] [blame] | 912 | freq = curr_freq / 10000; |
| 913 | snprintf(buf, 128, str(LANG_FM_STATION), freq / 100, freq % 100); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 914 | FOR_NB_SCREENS(i) |
| 915 | screens[i].puts_scroll(0, top_of_screen + 1, buf); |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 916 | |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 917 | snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO): |
| 918 | str(LANG_CHANNEL_MONO)); |
| 919 | FOR_NB_SCREENS(i) |
| 920 | screens[i].puts_scroll(0, top_of_screen + 2, buf); |
| 921 | |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 922 | snprintf(buf, 128, "%s %s", str(LANG_MODE), |
| 923 | radio_mode ? str(LANG_PRESET) : |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 924 | str(LANG_RADIO_SCAN_MODE)); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 925 | FOR_NB_SCREENS(i) |
| 926 | screens[i].puts_scroll(0, top_of_screen + 3, buf); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 927 | |
Peter D'Hoye | c7838b8 | 2006-03-03 19:41:16 +0000 | [diff] [blame] | 928 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 929 | if(audio_status() == AUDIO_STATUS_RECORD) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 930 | { |
| 931 | hours = seconds / 3600; |
| 932 | minutes = (seconds - (hours * 3600)) / 60; |
| 933 | snprintf(buf, 32, "%s %02d:%02d:%02d", |
| 934 | str(LANG_RECORDING_TIME), |
| 935 | hours, minutes, seconds%60); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 936 | FOR_NB_SCREENS(i) |
| 937 | screens[i].puts_scroll(0, top_of_screen + 4, buf); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 938 | } |
Linus Nielsen Feltzing | 74976c1 | 2003-12-31 03:13:29 +0000 | [diff] [blame] | 939 | else |
| 940 | { |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 941 | if(rec_options.rec_prerecord_time) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 942 | { |
| 943 | snprintf(buf, 32, "%s %02d", |
| 944 | str(LANG_RECORD_PRERECORD), seconds%60); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 945 | FOR_NB_SCREENS(i) |
| 946 | screens[i].puts_scroll(0, top_of_screen + 4, buf); |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 947 | } |
Linus Nielsen Feltzing | 74976c1 | 2003-12-31 03:13:29 +0000 | [diff] [blame] | 948 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 949 | #endif /* CONFIG_CODEC != SWCODEC */ |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 950 | |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 951 | FOR_NB_SCREENS(i) |
| 952 | { |
| 953 | screens[i].update_viewport(); |
| 954 | screens[i].set_viewport(NULL); |
| 955 | } |
| 956 | |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 957 | #ifdef HAVE_BUTTONBAR |
Kevin Ferrare | 1a1abf2 | 2005-11-20 01:02:14 +0000 | [diff] [blame] | 958 | gui_buttonbar_draw(&buttonbar); |
| 959 | #endif |
Linus Nielsen Feltzing | 9e95757 | 2003-11-06 00:47:47 +0000 | [diff] [blame] | 960 | } |
Jens Arnold | ae45d97 | 2004-12-26 18:36:48 +0000 | [diff] [blame] | 961 | /* Only force the redraw if update_screen is true */ |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 962 | gui_syncstatusbar_draw(&statusbars,true); |
Linus Nielsen Feltzing | f13410a | 2003-11-05 09:46:08 +0000 | [diff] [blame] | 963 | } |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 964 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 965 | update_screen = false; |
| 966 | |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 967 | if (global_settings.talk_file && talk |
| 968 | && radio_status == FMRADIO_PAUSED) |
| 969 | { |
| 970 | talk = false; |
| 971 | bool enqueue = false; |
| 972 | if (radio_mode == RADIO_SCAN_MODE) |
| 973 | { |
| 974 | talk_freq(curr_freq, enqueue); |
| 975 | enqueue = true; |
| 976 | } |
| 977 | if (curr_preset >= 0) |
| 978 | talk_preset(curr_preset, radio_mode == RADIO_PRESET_MODE, |
| 979 | enqueue); |
| 980 | } |
| 981 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 982 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 983 | if(audio_status() & AUDIO_STATUS_ERROR) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 984 | { |
| 985 | done = true; |
| 986 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 987 | #endif |
| 988 | |
| 989 | #ifndef HAVE_NOISY_IDLE_MODE |
Hristo Kovachev | 3de0db0 | 2006-03-07 11:49:06 +0000 | [diff] [blame] | 990 | if (TIME_AFTER(current_tick, button_timeout)) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 991 | { |
| 992 | cpu_idle_mode(true); |
| 993 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 994 | #endif |
Hristo Kovachev | 3de0db0 | 2006-03-07 11:49:06 +0000 | [diff] [blame] | 995 | } /*while(!done)*/ |
Linus Nielsen Feltzing | 23b0fda | 2003-05-03 15:39:40 +0000 | [diff] [blame] | 996 | |
Linus Nielsen Feltzing | afd7421 | 2004-07-02 07:43:49 +0000 | [diff] [blame] | 997 | #ifndef SIMULATOR |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 998 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 999 | if(audio_status() & AUDIO_STATUS_ERROR) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1000 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 1001 | gui_syncsplash(0, str(LANG_DISK_FULL)); |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 1002 | gui_syncstatusbar_draw(&statusbars,true); |
| 1003 | FOR_NB_SCREENS(i) |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1004 | { |
| 1005 | screens[i].set_viewport(&vp[i]); |
| 1006 | screens[i].update_viewport(); |
| 1007 | screens[i].set_viewport(NULL); |
| 1008 | } |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 1009 | audio_error_clear(); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1010 | |
| 1011 | while(1) |
| 1012 | { |
Martin Scarratt | a982365 | 2006-09-22 12:18:58 +0000 | [diff] [blame] | 1013 | button = get_action(CONTEXT_FM, TIMEOUT_BLOCK); |
Martin Scarratt | 3bf676e | 2006-09-25 19:59:37 +0000 | [diff] [blame] | 1014 | if(button == ACTION_FM_STOP) |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1015 | break; |
| 1016 | } |
| 1017 | } |
| 1018 | |
Linus Nielsen Feltzing | e1f7058 | 2005-04-04 12:36:06 +0000 | [diff] [blame] | 1019 | audio_init_playback(); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1020 | #endif /* CONFIG_CODEC != SWCODEC */ |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1021 | |
Linus Nielsen Feltzing | 7bade1a | 2004-07-06 12:17:14 +0000 | [diff] [blame] | 1022 | sound_settings_apply(); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1023 | #endif /* SIMULATOR */ |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1024 | |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1025 | if(keep_playing) |
| 1026 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1027 | /* Catch FMRADIO_PLAYING status for the sim. */ |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1028 | #ifndef SIMULATOR |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 1029 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1030 | /* Enable the Left and right A/D Converter */ |
Andy | e6e5496 | 2005-11-12 04:00:56 +0000 | [diff] [blame] | 1031 | audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN), |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1032 | sound_default(SOUND_RIGHT_GAIN), |
| 1033 | AUDIO_GAIN_LINEIN); |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1034 | mas_codec_writereg(6, 0x4000); |
Linus Nielsen Feltzing | 8c7589b | 2005-08-13 17:35:02 +0000 | [diff] [blame] | 1035 | #endif |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1036 | end_search(); |
| 1037 | #endif /* SIMULATOR */ |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1038 | } |
Jörg Hohensohn | ef8d508 | 2004-10-19 08:20:38 +0000 | [diff] [blame] | 1039 | else |
| 1040 | { |
Jens Arnold | d6c0545 | 2005-08-29 21:15:27 +0000 | [diff] [blame] | 1041 | #if CONFIG_CODEC == SWCODEC |
Michael Sevakis | 2d48d0f | 2007-06-08 23:42:04 +0000 | [diff] [blame] | 1042 | audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1043 | #else |
| 1044 | radio_stop(); |
Linus Nielsen Feltzing | 8c7589b | 2005-08-13 17:35:02 +0000 | [diff] [blame] | 1045 | #endif |
Jörg Hohensohn | ef8d508 | 2004-10-19 08:20:38 +0000 | [diff] [blame] | 1046 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1047 | |
| 1048 | #ifndef HAVE_NOISY_IDLE_MODE |
Linus Nielsen Feltzing | 8b9c64f | 2005-09-29 11:19:55 +0000 | [diff] [blame] | 1049 | cpu_idle_mode(false); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1050 | #endif |
Anton Oleynikov | 697e832 | 2005-11-13 21:03:53 +0000 | [diff] [blame] | 1051 | |
| 1052 | /* restore status bar settings */ |
| 1053 | global_settings.statusbar = statusbar; |
Jonathan Gordon | 4d238c1 | 2008-01-10 06:46:04 +0000 | [diff] [blame] | 1054 | global_status.statusbar_forced = 0; |
Michael Sevakis | 0f17532 | 2007-02-08 10:36:49 +0000 | [diff] [blame] | 1055 | in_screen = false; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1056 | #if CONFIG_CODEC != SWCODEC |
Linus Nielsen Feltzing | aaa99e7 | 2003-11-20 00:33:43 +0000 | [diff] [blame] | 1057 | return have_recorded; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1058 | #else |
| 1059 | return false; |
| 1060 | #endif |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1061 | } /* radio_screen */ |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1062 | |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1063 | static void radio_save_presets(void) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1064 | { |
| 1065 | int fd; |
| 1066 | int i; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1067 | |
Jens Arnold | 67eb154 | 2007-02-01 23:08:15 +0000 | [diff] [blame] | 1068 | fd = creat(filepreset); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1069 | if(fd >= 0) |
| 1070 | { |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1071 | for(i = 0;i < num_presets;i++) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1072 | { |
Daniel Stenberg | 6610f8e | 2005-02-22 12:48:36 +0000 | [diff] [blame] | 1073 | fdprintf(fd, "%d:%s\n", presets[i].frequency, presets[i].name); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1074 | } |
| 1075 | close(fd); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1076 | |
| 1077 | if(!strncasecmp(FMPRESET_PATH, filepreset, strlen(FMPRESET_PATH))) |
| 1078 | set_file(filepreset, global_settings.fmr_file, MAX_FILENAME); |
| 1079 | presets_changed = false; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1080 | } |
| 1081 | else |
| 1082 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1083 | gui_syncsplash(HZ, ID2P(LANG_FM_PRESET_SAVE_FAILED)); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1084 | } |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1085 | } |
| 1086 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1087 | void radio_load_presets(char *filename) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1088 | { |
| 1089 | int fd; |
| 1090 | int rc; |
| 1091 | char buf[128]; |
| 1092 | char *freq; |
| 1093 | char *name; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1094 | bool done = false; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1095 | int f; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1096 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1097 | memset(presets, 0, sizeof(presets)); |
| 1098 | num_presets = 0; |
| 1099 | |
| 1100 | /* No Preset in configuration. */ |
| 1101 | if(filename[0] == '\0') |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1102 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1103 | filepreset[0] = '\0'; |
| 1104 | return; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1105 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1106 | /* Temporary preset, loaded until player shuts down. */ |
| 1107 | else if(filename[0] == '/') |
| 1108 | strncpy(filepreset, filename, sizeof(filepreset)); |
| 1109 | /* Preset from default directory. */ |
| 1110 | else |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1111 | snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr", |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1112 | FMPRESET_PATH, filename); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1113 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1114 | fd = open(filepreset, O_RDONLY); |
| 1115 | if(fd >= 0) |
| 1116 | { |
| 1117 | while(!done && num_presets < MAX_PRESETS) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1118 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1119 | rc = read_line(fd, buf, 128); |
| 1120 | if(rc > 0) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1121 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1122 | if(settings_parseline(buf, &freq, &name)) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1123 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1124 | f = atoi(freq); |
| 1125 | if(f) /* For backwards compatibility */ |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1126 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1127 | struct fmstation * const fms = &presets[num_presets]; |
| 1128 | fms->frequency = f; |
| 1129 | strncpy(fms->name, name, MAX_FMPRESET_LEN); |
| 1130 | fms->name[MAX_FMPRESET_LEN] = '\0'; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1131 | num_presets++; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1132 | } |
| 1133 | } |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1134 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1135 | else |
| 1136 | done = true; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1137 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1138 | close(fd); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1139 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1140 | else /* invalid file name? */ |
| 1141 | filepreset[0] = '\0'; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1142 | |
| 1143 | presets_loaded = num_presets > 0; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1144 | presets_changed = false; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1145 | } |
| 1146 | |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1147 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1148 | static int radio_add_preset(void) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1149 | { |
Magnus Holmgren | a967523 | 2007-05-05 12:06:35 +0000 | [diff] [blame] | 1150 | char buf[MAX_FMPRESET_LEN + 1]; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1151 | |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1152 | if(num_presets < MAX_PRESETS) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1153 | { |
Hristo Kovachev | f709ad7 | 2006-04-03 10:06:39 +0000 | [diff] [blame] | 1154 | memset(buf, 0, MAX_FMPRESET_LEN); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1155 | |
Hristo Kovachev | f709ad7 | 2006-04-03 10:06:39 +0000 | [diff] [blame] | 1156 | if (!kbd_input(buf, MAX_FMPRESET_LEN)) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1157 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1158 | struct fmstation * const fms = &presets[num_presets]; |
| 1159 | buf[MAX_FMPRESET_LEN] = '\0'; |
| 1160 | strcpy(fms->name, buf); |
| 1161 | fms->frequency = curr_freq; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1162 | num_presets++; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1163 | presets_changed = true; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1164 | presets_loaded = num_presets > 0; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | else |
| 1168 | { |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1169 | gui_syncsplash(HZ, ID2P(LANG_FM_NO_FREE_PRESETS)); |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1170 | } |
| 1171 | return true; |
| 1172 | } |
| 1173 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1174 | /* needed to know which preset we are edit/delete-ing */ |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1175 | static int selected_preset = -1; |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1176 | static int radio_edit_preset(void) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1177 | { |
Peter D'Hoye | d3f1070 | 2007-06-04 21:38:23 +0000 | [diff] [blame] | 1178 | char buf[MAX_FMPRESET_LEN + 1]; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1179 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1180 | if (num_presets > 0) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1181 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1182 | struct fmstation * const fms = &presets[selected_preset]; |
| 1183 | |
| 1184 | strncpy(buf, fms->name, MAX_FMPRESET_LEN); |
| 1185 | |
| 1186 | if (!kbd_input(buf, MAX_FMPRESET_LEN)) |
| 1187 | { |
| 1188 | buf[MAX_FMPRESET_LEN] = '\0'; |
| 1189 | strcpy(fms->name, buf); |
| 1190 | presets_changed = true; |
| 1191 | } |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1192 | } |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1193 | |
Jonathan Gordon | dd40a2e | 2007-03-18 07:57:36 +0000 | [diff] [blame] | 1194 | return 1; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1197 | static int radio_delete_preset(void) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1198 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1199 | if (num_presets > 0) |
| 1200 | { |
| 1201 | struct fmstation * const fms = &presets[selected_preset]; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1202 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1203 | if (selected_preset >= --num_presets) |
| 1204 | selected_preset = num_presets - 1; |
| 1205 | |
| 1206 | memmove(fms, fms + 1, (uintptr_t)(fms + num_presets) - |
| 1207 | (uintptr_t)fms); |
| 1208 | |
| 1209 | } |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1210 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1211 | /* Don't ask to save when all presets are deleted. */ |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1212 | presets_changed = num_presets > 0; |
| 1213 | |
| 1214 | if (!presets_changed) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1215 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1216 | /* The preset list will be cleared, switch to Scan Mode. */ |
| 1217 | radio_mode = RADIO_SCAN_MODE; |
| 1218 | presets_loaded = false; |
| 1219 | } |
| 1220 | |
Jonathan Gordon | dd40a2e | 2007-03-18 07:57:36 +0000 | [diff] [blame] | 1221 | return 1; |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1222 | } |
| 1223 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1224 | static int load_preset_list(void) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1225 | { |
| 1226 | return !rockbox_browse(FMPRESET_PATH, SHOW_FMR); |
| 1227 | } |
| 1228 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1229 | static int save_preset_list(void) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1230 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1231 | if(num_presets > 0) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1232 | { |
Peter D'Hoye | ab90b1d | 2006-04-25 00:14:21 +0000 | [diff] [blame] | 1233 | bool bad_file_name = true; |
| 1234 | |
Nils Wallménius | a019964 | 2008-04-16 19:51:43 +0000 | [diff] [blame] | 1235 | if(!dir_exists(FMPRESET_PATH)) /* Check if there is preset folder */ |
| 1236 | mkdir(FMPRESET_PATH); |
| 1237 | |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 1238 | create_numbered_filename(filepreset, FMPRESET_PATH, "preset", |
| 1239 | ".fmr", 2 IF_CNFN_NUM_(, NULL)); |
Peter D'Hoye | ab90b1d | 2006-04-25 00:14:21 +0000 | [diff] [blame] | 1240 | |
| 1241 | while(bad_file_name) |
| 1242 | { |
| 1243 | if(!kbd_input(filepreset, sizeof(filepreset))) |
| 1244 | { |
| 1245 | /* check the name: max MAX_FILENAME (20) chars */ |
| 1246 | char* p2; |
| 1247 | char* p1; |
| 1248 | int len; |
| 1249 | p1 = strrchr(filepreset, '/'); |
| 1250 | p2 = p1; |
| 1251 | while((p1) && (*p2) && (*p2 != '.')) |
| 1252 | p2++; |
| 1253 | len = (int)(p2-p1) - 1; |
| 1254 | if((!p1) || (len > MAX_FILENAME) || (len == 0)) |
| 1255 | { |
| 1256 | /* no slash, too long or too short */ |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1257 | gui_syncsplash(HZ, ID2P(LANG_INVALID_FILENAME)); |
Peter D'Hoye | ab90b1d | 2006-04-25 00:14:21 +0000 | [diff] [blame] | 1258 | } |
| 1259 | else |
| 1260 | { |
| 1261 | /* add correct extension (easier to always write) |
| 1262 | at this point, p2 points to 0 or the extension dot */ |
| 1263 | *p2 = '\0'; |
| 1264 | strcat(filepreset,".fmr"); |
| 1265 | bad_file_name = false; |
| 1266 | radio_save_presets(); |
| 1267 | } |
| 1268 | } |
| 1269 | else |
| 1270 | { |
| 1271 | /* user aborted */ |
| 1272 | return false; |
| 1273 | } |
| 1274 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1275 | } |
| 1276 | else |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1277 | gui_syncsplash(HZ, ID2P(LANG_FM_NO_PRESETS)); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1278 | |
| 1279 | return true; |
| 1280 | } |
| 1281 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1282 | static int clear_preset_list(void) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1283 | { |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1284 | /* Clear all the preset entries */ |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1285 | memset(presets, 0, sizeof (presets)); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1286 | |
| 1287 | num_presets = 0; |
| 1288 | presets_loaded = false; |
| 1289 | /* The preset list will be cleared switch to Scan Mode. */ |
| 1290 | radio_mode = RADIO_SCAN_MODE; |
| 1291 | |
| 1292 | presets_changed = false; /* Don't ask to save when clearing the list. */ |
| 1293 | |
| 1294 | return true; |
| 1295 | } |
| 1296 | |
Jonathan Gordon | dd40a2e | 2007-03-18 07:57:36 +0000 | [diff] [blame] | 1297 | MENUITEM_FUNCTION(radio_edit_preset_item, MENU_FUNC_CHECK_RETVAL, |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1298 | ID2P(LANG_FM_EDIT_PRESET), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1299 | radio_edit_preset, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | dd40a2e | 2007-03-18 07:57:36 +0000 | [diff] [blame] | 1300 | MENUITEM_FUNCTION(radio_delete_preset_item, MENU_FUNC_CHECK_RETVAL, |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1301 | ID2P(LANG_FM_DELETE_PRESET), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1302 | radio_delete_preset, NULL, NULL, Icon_NOICON); |
Bertrik Sikken | e15f8a2 | 2008-05-03 08:35:14 +0000 | [diff] [blame] | 1303 | static int radio_preset_callback(int action, |
| 1304 | const struct menu_item_ex *this_item) |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 1305 | { |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 1306 | if (action == ACTION_STD_OK) |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1307 | action = ACTION_EXIT_AFTER_THIS_MENUITEM; |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 1308 | return action; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1309 | (void)this_item; |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 1310 | } |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 1311 | MAKE_MENU(handle_radio_preset_menu, ID2P(LANG_PRESET), |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 1312 | radio_preset_callback, Icon_NOICON, &radio_edit_preset_item, |
Jonathan Gordon | 9144be5 | 2007-02-27 09:16:47 +0000 | [diff] [blame] | 1313 | &radio_delete_preset_item); |
Jörg Hohensohn | c100a42 | 2004-10-19 22:50:34 +0000 | [diff] [blame] | 1314 | /* present a list of preset stations */ |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 1315 | static char * presets_get_name(int selected_item, void *data, |
| 1316 | char *buffer, size_t buffer_len) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1317 | { |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1318 | (void)data; |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1319 | struct fmstation *p = &presets[selected_item]; |
| 1320 | if(p->name[0]) |
| 1321 | return p->name; |
| 1322 | int freq = p->frequency / 10000; |
| 1323 | int frac = freq % 100; |
| 1324 | freq /= 100; |
Nils Wallménius | 6848961 | 2008-04-09 15:25:17 +0000 | [diff] [blame] | 1325 | snprintf(buffer, buffer_len, |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1326 | str(LANG_FM_DEFAULT_PRESET_NAME), freq, frac); |
| 1327 | return buffer; |
| 1328 | } |
| 1329 | |
| 1330 | static int presets_speak_name(int selected_item, void * data) |
| 1331 | { |
| 1332 | (void)data; |
| 1333 | talk_preset(selected_item, true, false); |
| 1334 | return 0; |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1335 | } |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1336 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1337 | static int handle_radio_presets(void) |
| 1338 | { |
| 1339 | struct gui_synclist lists; |
| 1340 | int result = 0; |
| 1341 | int action = ACTION_NONE; |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 1342 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1343 | struct gui_buttonbar buttonbar; |
| 1344 | #endif |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1345 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1346 | if(presets_loaded == false) |
| 1347 | return result; |
| 1348 | |
Peter D'Hoye | f76122f | 2008-05-29 20:32:39 +0000 | [diff] [blame] | 1349 | #ifdef HAVE_BUTTONBAR |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1350 | gui_buttonbar_init(&buttonbar); |
| 1351 | gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) ); |
| 1352 | gui_buttonbar_set(&buttonbar, str(LANG_FM_BUTTONBAR_ADD), |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1353 | str(LANG_FM_BUTTONBAR_EXIT), |
| 1354 | str(LANG_FM_BUTTONBAR_ACTION)); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1355 | gui_buttonbar_draw(&buttonbar); |
| 1356 | #endif |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 1357 | gui_synclist_init(&lists, presets_get_name, NULL, false, 1, NULL); |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 1358 | gui_synclist_set_title(&lists, str(LANG_PRESET), NOICON); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1359 | gui_synclist_set_icon_callback(&lists, NULL); |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1360 | if(global_settings.talk_file) |
| 1361 | gui_synclist_set_voice_callback(&lists, presets_speak_name); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1362 | gui_synclist_set_nb_items(&lists, num_presets); |
| 1363 | gui_synclist_select_item(&lists, curr_preset<0 ? 0 : curr_preset); |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1364 | gui_synclist_speak_item(&lists); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1365 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1366 | while (result == 0) |
| 1367 | { |
| 1368 | gui_synclist_draw(&lists); |
| 1369 | gui_syncstatusbar_draw(&statusbars, true); |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1370 | list_do_action(CONTEXT_STD, HZ, |
| 1371 | &lists, &action, LIST_WRAP_UNLESS_HELD); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1372 | switch (action) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1373 | { |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1374 | case ACTION_STD_MENU: |
| 1375 | radio_add_preset(); |
| 1376 | break; |
| 1377 | case ACTION_STD_CANCEL: |
| 1378 | result = 1; |
| 1379 | break; |
| 1380 | case ACTION_STD_OK: |
| 1381 | curr_preset = gui_synclist_get_sel_pos(&lists); |
| 1382 | curr_freq = presets[curr_preset].frequency; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1383 | next_station(0); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1384 | remember_frequency(); |
| 1385 | result = 1; |
| 1386 | break; |
| 1387 | case ACTION_F3: |
| 1388 | case ACTION_STD_CONTEXT: |
| 1389 | selected_preset = gui_synclist_get_sel_pos(&lists); |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 1390 | do_menu(&handle_radio_preset_menu, NULL, NULL, false); |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1391 | gui_synclist_speak_item(&lists); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1392 | break; |
| 1393 | default: |
| 1394 | if(default_event_handler(action) == SYS_USB_CONNECTED) |
| 1395 | result = 2; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1396 | } |
| 1397 | } |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1398 | return result - 1; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1399 | } |
| 1400 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1401 | void toggle_mono_mode(bool mono) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1402 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1403 | tuner_set(RADIO_FORCE_MONO, mono); |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1404 | } |
| 1405 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1406 | void set_radio_region(int region) |
Linus Nielsen Feltzing | 8448ba8 | 2004-07-05 14:30:17 +0000 | [diff] [blame] | 1407 | { |
Michael Sevakis | 680afaf | 2007-07-14 13:41:59 +0000 | [diff] [blame] | 1408 | #ifdef HAVE_RADIO_REGION |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1409 | tuner_set(RADIO_REGION, region); |
Michael Sevakis | 680afaf | 2007-07-14 13:41:59 +0000 | [diff] [blame] | 1410 | #endif |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1411 | next_station(0); |
Dominik Riebeling | a22d995 | 2006-10-12 13:59:44 +0000 | [diff] [blame] | 1412 | remember_frequency(); |
Michael Sevakis | 680afaf | 2007-07-14 13:41:59 +0000 | [diff] [blame] | 1413 | (void)region; |
Dominik Riebeling | e66b2ec | 2006-10-05 12:40:13 +0000 | [diff] [blame] | 1414 | } |
| 1415 | |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1416 | MENUITEM_SETTING(set_region, &global_settings.fm_region, NULL); |
| 1417 | MENUITEM_SETTING(force_mono, &global_settings.fm_force_mono, NULL); |
| 1418 | |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1419 | #ifndef FM_MODE |
Bertrik Sikken | 1942590 | 2008-05-03 21:33:00 +0000 | [diff] [blame] | 1420 | static char* get_mode_text(int selected_item, void * data, char *buffer) |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1421 | { |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1422 | (void)selected_item; |
| 1423 | (void)data; |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 1424 | snprintf(buffer, MAX_PATH, "%s %s", str(LANG_MODE), |
| 1425 | radio_mode ? str(LANG_PRESET) : |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1426 | str(LANG_RADIO_SCAN_MODE)); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1427 | return buffer; |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1428 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1429 | static int toggle_radio_mode(void) |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1430 | { |
| 1431 | radio_mode = (radio_mode == RADIO_SCAN_MODE) ? |
| 1432 | RADIO_PRESET_MODE : RADIO_SCAN_MODE; |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1433 | return 0; |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1434 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1435 | MENUITEM_FUNCTION_DYNTEXT(radio_mode_item, 0, |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1436 | toggle_radio_mode, NULL, |
Stéphane Doyon | 5acf091 | 2007-10-09 03:48:56 +0000 | [diff] [blame] | 1437 | get_mode_text, NULL, NULL, NULL, Icon_NOICON); |
Jens Arnold | 2a31407 | 2005-11-29 15:10:07 +0000 | [diff] [blame] | 1438 | #endif |
| 1439 | |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1440 | static int scan_presets(void *viewports) |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1441 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1442 | bool do_scan = true; |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1443 | int i; |
| 1444 | struct viewport *vp = (struct viewport *)viewports; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1445 | |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1446 | FOR_NB_SCREENS(i) |
| 1447 | screens[i].set_viewport(vp?&vp[i]:NULL); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1448 | if(num_presets > 0) /* Do that to avoid 2 questions. */ |
Nils Wallménius | 5b76936 | 2007-08-06 13:08:36 +0000 | [diff] [blame] | 1449 | do_scan = yesno_pop(ID2P(LANG_FM_CLEAR_PRESETS)); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1450 | |
| 1451 | if(do_scan) |
| 1452 | { |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1453 | const struct fm_region_data * const fmr = |
| 1454 | &fm_region_data[global_settings.fm_region]; |
| 1455 | |
Peter D'Hoye | d3f1070 | 2007-06-04 21:38:23 +0000 | [diff] [blame] | 1456 | char buf[MAX_FMPRESET_LEN + 1]; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1457 | |
| 1458 | curr_freq = fmr->freq_min; |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 1459 | num_presets = 0; |
Hristo Kovachev | f709ad7 | 2006-04-03 10:06:39 +0000 | [diff] [blame] | 1460 | memset(presets, 0, sizeof(presets)); |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1461 | tuner_set(RADIO_MUTE, 1); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1462 | |
| 1463 | while(curr_freq <= fmr->freq_max) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1464 | { |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1465 | int freq, frac; |
Jonathan Gordon | 568e18e | 2006-12-26 22:01:27 +0000 | [diff] [blame] | 1466 | if (num_presets >= MAX_PRESETS || action_userabort(TIMEOUT_NOBLOCK)) |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 1467 | break; |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1468 | |
Dominik Riebeling | e66b2ec | 2006-10-05 12:40:13 +0000 | [diff] [blame] | 1469 | freq = curr_freq / 10000; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1470 | frac = freq % 100; |
| 1471 | freq /= 100; |
| 1472 | |
| 1473 | snprintf(buf, MAX_FMPRESET_LEN, str(LANG_FM_SCANNING), freq, frac); |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 1474 | gui_syncsplash(0, buf); |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1475 | |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1476 | if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq)) |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1477 | { |
| 1478 | /* add preset */ |
Stéphane Doyon | d65f9f1 | 2007-11-07 02:14:28 +0000 | [diff] [blame] | 1479 | presets[num_presets].name[0] = '\0'; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1480 | presets[num_presets].frequency = curr_freq; |
| 1481 | num_presets++; |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 1482 | } |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1483 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1484 | curr_freq += fmr->freq_step; |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 1485 | } |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1486 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1487 | if (radio_status == FMRADIO_PLAYING) |
Michael Sevakis | 7d759f6 | 2007-07-14 11:20:31 +0000 | [diff] [blame] | 1488 | tuner_set(RADIO_MUTE, 0); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1489 | |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1490 | presets_changed = true; |
| 1491 | |
| 1492 | FOR_NB_SCREENS(i) |
| 1493 | { |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1494 | screens[i].clear_viewport(); |
| 1495 | screens[i].update_viewport(); |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1496 | } |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1497 | |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1498 | if(num_presets > 0) |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1499 | { |
Anton Oleynikov | 0afd971 | 2005-11-19 14:54:41 +0000 | [diff] [blame] | 1500 | curr_freq = presets[0].frequency; |
Anton Oleynikov | c94557e | 2005-11-19 19:23:44 +0000 | [diff] [blame] | 1501 | radio_mode = RADIO_PRESET_MODE; |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1502 | presets_loaded = true; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1503 | next_station(0); |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1504 | } |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1505 | else |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1506 | { |
| 1507 | /* Wrap it to beginning or we'll be past end of band */ |
Hristo Kovachev | 009853f | 2006-04-02 12:23:08 +0000 | [diff] [blame] | 1508 | presets_loaded = false; |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1509 | next_station(1); |
| 1510 | } |
Anton Oleynikov | d79f3a1 | 2005-11-16 23:36:35 +0000 | [diff] [blame] | 1511 | } |
| 1512 | return true; |
| 1513 | } |
| 1514 | |
Jörg Hohensohn | c100a42 | 2004-10-19 22:50:34 +0000 | [diff] [blame] | 1515 | |
Michael Sevakis | 69b98bd | 2006-10-10 13:42:22 +0000 | [diff] [blame] | 1516 | #ifdef HAVE_RECORDING |
| 1517 | |
Michael Sevakis | 8f659ae | 2007-05-20 20:26:36 +0000 | [diff] [blame] | 1518 | #if defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC |
Michael Sevakis | 69b98bd | 2006-10-10 13:42:22 +0000 | [diff] [blame] | 1519 | #define FM_RECORDING_SCREEN |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1520 | static int fm_recording_screen(void) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1521 | { |
| 1522 | bool ret; |
| 1523 | |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1524 | /* switch recording source to FMRADIO for the duration */ |
| 1525 | int rec_source = global_settings.rec_source; |
| 1526 | global_settings.rec_source = AUDIO_SRC_FMRADIO; |
| 1527 | |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1528 | ret = recording_screen(true); |
| 1529 | |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1530 | /* safe to reset as changing sources is prohibited here */ |
| 1531 | global_settings.rec_source = rec_source; |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1532 | |
| 1533 | return ret; |
| 1534 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1535 | |
Michael Sevakis | 8f659ae | 2007-05-20 20:26:36 +0000 | [diff] [blame] | 1536 | #endif /* defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC */ |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1537 | |
Michael Sevakis | 8f659ae | 2007-05-20 20:26:36 +0000 | [diff] [blame] | 1538 | #if defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC |
Michael Sevakis | 69b98bd | 2006-10-10 13:42:22 +0000 | [diff] [blame] | 1539 | #define FM_RECORDING_SETTINGS |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1540 | static int fm_recording_settings(void) |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1541 | { |
| 1542 | bool ret = recording_menu(true); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1543 | |
Michael Sevakis | 9d56f2d | 2006-09-17 18:52:31 +0000 | [diff] [blame] | 1544 | #if CONFIG_CODEC != SWCODEC |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1545 | if (!ret) |
| 1546 | { |
Michael Sevakis | 0f5cb94 | 2006-11-06 18:07:30 +0000 | [diff] [blame] | 1547 | struct audio_recording_options rec_options; |
| 1548 | rec_init_recording_options(&rec_options); |
| 1549 | rec_options.rec_source = AUDIO_SRC_LINEIN; |
| 1550 | rec_set_recording_options(&rec_options); |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1551 | } |
Michael Sevakis | 9d56f2d | 2006-09-17 18:52:31 +0000 | [diff] [blame] | 1552 | #endif |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1553 | |
| 1554 | return ret; |
| 1555 | } |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1556 | |
Michael Sevakis | 8f659ae | 2007-05-20 20:26:36 +0000 | [diff] [blame] | 1557 | #endif /* defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC */ |
Michael Sevakis | 69b98bd | 2006-10-10 13:42:22 +0000 | [diff] [blame] | 1558 | #endif /* HAVE_RECORDING */ |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1559 | |
| 1560 | #ifdef FM_RECORDING_SCREEN |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 1561 | MENUITEM_FUNCTION(recscreen_item, 0, ID2P(LANG_RECORDING), |
Peter D'Hoye | e50cba9 | 2007-06-25 21:19:45 +0000 | [diff] [blame] | 1562 | fm_recording_screen, NULL, NULL, Icon_Recording); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1563 | #endif |
| 1564 | #ifdef FM_RECORDING_SETTINGS |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1565 | MENUITEM_FUNCTION(recsettings_item, 0, ID2P(LANG_RECORDING_SETTINGS), |
Peter D'Hoye | e50cba9 | 2007-06-25 21:19:45 +0000 | [diff] [blame] | 1566 | fm_recording_settings, NULL, NULL, Icon_Recording); |
Michael Sevakis | a2ee6a6 | 2007-03-16 14:40:40 +0000 | [diff] [blame] | 1567 | #endif |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1568 | #ifndef FM_PRESET |
Nils Wallménius | b311367 | 2007-08-05 19:19:39 +0000 | [diff] [blame] | 1569 | MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1570 | handle_radio_presets, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1571 | #endif |
| 1572 | #ifndef FM_PRESET_ADD |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1573 | MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1574 | radio_add_preset, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1575 | #endif |
Michael Sevakis | 4fc717a | 2006-08-28 22:38:41 +0000 | [diff] [blame] | 1576 | |
| 1577 | |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1578 | MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1579 | load_preset_list, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1580 | MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1581 | save_preset_list, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | daf6694 | 2007-03-17 12:33:34 +0000 | [diff] [blame] | 1582 | MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1583 | clear_preset_list, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | 0501fb0 | 2008-05-29 11:13:46 +0000 | [diff] [blame] | 1584 | MENUITEM_FUNCTION(scan_presets_item, MENU_FUNC_USEPARAM, |
| 1585 | ID2P(LANG_FM_SCAN_PRESETS), |
Jonathan Gordon | e54d8e1 | 2007-03-18 07:03:43 +0000 | [diff] [blame] | 1586 | scan_presets, NULL, NULL, Icon_NOICON); |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1587 | |
Peter D'Hoye | 9337efd | 2007-07-03 18:31:13 +0000 | [diff] [blame] | 1588 | MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL, |
Jonathan Gordon | 02a8717 | 2007-03-03 13:52:14 +0000 | [diff] [blame] | 1589 | Icon_Radio_screen, |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1590 | #ifndef FM_PRESET |
| 1591 | &radio_presets_item, |
| 1592 | #endif |
| 1593 | #ifndef FM_PRESET_ADD |
| 1594 | &radio_addpreset_item, |
| 1595 | #endif |
| 1596 | &presetload_item, &presetsave_item, &presetclear_item, |
| 1597 | &force_mono, |
| 1598 | #ifndef FM_MODE |
| 1599 | &radio_mode_item, |
| 1600 | #endif |
| 1601 | &set_region, &sound_settings, |
| 1602 | #ifdef FM_RECORDING_SCREEN |
Jonathan Gordon | 4721def | 2007-02-27 09:22:56 +0000 | [diff] [blame] | 1603 | &recscreen_item, |
Jonathan Gordon | 2816dc9 | 2007-02-27 09:06:30 +0000 | [diff] [blame] | 1604 | #endif |
| 1605 | #ifdef FM_RECORDING_SETTINGS |
| 1606 | &recsettings_item, |
| 1607 | #endif |
| 1608 | &scan_presets_item); |
Jörg Hohensohn | c100a42 | 2004-10-19 22:50:34 +0000 | [diff] [blame] | 1609 | /* main menu of the radio screen */ |
Jens Arnold | 2597a13 | 2006-12-25 14:01:47 +0000 | [diff] [blame] | 1610 | static bool radio_menu(void) |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1611 | { |
Jonathan Gordon | 5ca1539 | 2008-03-26 03:35:24 +0000 | [diff] [blame] | 1612 | return do_menu(&radio_settings_menu, NULL, NULL, false) == MENU_ATTACHED_USB; |
Linus Nielsen Feltzing | c5dacdc | 2003-05-04 02:23:18 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Linus Nielsen Feltzing | 331c7d9 | 2003-05-03 02:40:09 +0000 | [diff] [blame] | 1615 | #endif |