2003-05-03 02:40:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2003 Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdbool.h>
|
2007-03-16 14:40:40 +00:00
|
|
|
#include <stdlib.h>
|
2003-05-04 02:23:18 +00:00
|
|
|
#include "sprintf.h"
|
2003-05-03 02:40:09 +00:00
|
|
|
#include "mas.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "status.h"
|
2007-03-16 14:40:40 +00:00
|
|
|
#include "thread.h"
|
2003-05-03 02:40:09 +00:00
|
|
|
#include "mpeg.h"
|
2005-04-04 12:36:06 +00:00
|
|
|
#include "audio.h"
|
2004-01-05 22:46:54 +00:00
|
|
|
#include "mp3_playback.h"
|
2003-05-04 02:23:18 +00:00
|
|
|
#include "ctype.h"
|
|
|
|
#include "file.h"
|
|
|
|
#include "errno.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "radio.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "keyboard.h"
|
|
|
|
#include "screens.h"
|
2003-11-05 09:46:08 +00:00
|
|
|
#include "peakmeter.h"
|
|
|
|
#include "lang.h"
|
2003-11-06 00:47:47 +00:00
|
|
|
#include "font.h"
|
2003-11-20 00:33:43 +00:00
|
|
|
#include "sound_menu.h"
|
2007-10-02 21:04:10 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
2003-11-20 00:33:43 +00:00
|
|
|
#include "recording.h"
|
2007-10-02 21:04:10 +00:00
|
|
|
#endif
|
2004-03-19 22:15:53 +00:00
|
|
|
#include "talk.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
#include "tuner.h"
|
2004-10-17 08:53:18 +00:00
|
|
|
#include "power.h"
|
2005-04-01 14:09:41 +00:00
|
|
|
#include "sound.h"
|
2005-11-13 21:03:53 +00:00
|
|
|
#include "screen_access.h"
|
|
|
|
#include "statusbar.h"
|
|
|
|
#include "textarea.h"
|
|
|
|
#include "splash.h"
|
2005-11-19 14:54:41 +00:00
|
|
|
#include "yesno.h"
|
2005-11-20 01:02:14 +00:00
|
|
|
#include "buttonbar.h"
|
2005-11-19 19:23:44 +00:00
|
|
|
#include "power.h"
|
2006-04-02 12:23:08 +00:00
|
|
|
#include "tree.h"
|
|
|
|
#include "dir.h"
|
2006-09-22 12:18:58 +00:00
|
|
|
#include "action.h"
|
2007-02-27 09:06:30 +00:00
|
|
|
#include "list.h"
|
|
|
|
#include "menus/exported_menus.h"
|
2007-03-01 11:14:46 +00:00
|
|
|
#include "root_menu.h"
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2007-02-18 08:46:12 +00:00
|
|
|
#if CONFIG_TUNER
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2006-09-22 12:18:58 +00:00
|
|
|
#define FM_RECORD
|
|
|
|
#define FM_PRESET_ADD
|
|
|
|
#define FM_PRESET_ACTION
|
|
|
|
#define FM_PRESET
|
2006-09-23 11:05:13 +00:00
|
|
|
#define FM_MODE
|
2005-11-29 15:10:07 +00:00
|
|
|
|
2005-12-15 01:11:19 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2006-09-22 12:18:58 +00:00
|
|
|
#define FM_PRESET
|
2006-09-23 11:05:13 +00:00
|
|
|
#define FM_MODE
|
2006-09-23 12:22:01 +00:00
|
|
|
#define FM_NEXT_PRESET
|
|
|
|
#define FM_PREV_PRESET
|
2005-11-29 15:10:07 +00:00
|
|
|
|
2007-11-11 16:00:33 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define FM_PRESET
|
|
|
|
#define FM_MODE
|
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
|
2006-09-22 12:18:58 +00:00
|
|
|
#define FM_PRESET
|
2006-09-23 11:05:13 +00:00
|
|
|
#define FM_MODE
|
2007-03-16 14:40:40 +00:00
|
|
|
/* This should be removeable if the whole tuning thing is sorted out since
|
|
|
|
proper tuning quiets the screen almost entirely in that extreme measures
|
|
|
|
have to be taken to hear any interference. */
|
|
|
|
#define HAVE_NOISY_IDLE_MODE
|
2006-09-22 12:18:58 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define FM_RECORD_DBLPRE
|
|
|
|
#define FM_RECORD
|
2007-10-02 21:04:10 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || (CONFIG_KEYPAD == SANSA_C200_PAD)
|
2007-06-06 19:23:48 +00:00
|
|
|
#define FM_MENU
|
|
|
|
#define FM_PRESET
|
|
|
|
#define FM_STOP
|
|
|
|
#define FM_MODE
|
|
|
|
#define FM_EXIT
|
|
|
|
#define FM_PLAY
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
#define RADIO_SCAN_MODE 0
|
|
|
|
#define RADIO_PRESET_MODE 1
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
static int curr_preset = -1;
|
2004-07-12 13:28:44 +00:00
|
|
|
static int curr_freq;
|
2005-11-13 21:03:53 +00:00
|
|
|
static int radio_mode = RADIO_SCAN_MODE;
|
2007-03-29 01:55:47 +00:00
|
|
|
static int search_dir = 0;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
static int radio_status = FMRADIO_OFF;
|
|
|
|
static bool in_screen = false;
|
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
#define MAX_PRESETS 64
|
2006-04-02 12:23:08 +00:00
|
|
|
static bool presets_loaded = false, presets_changed = false;
|
2003-05-04 02:23:18 +00:00
|
|
|
static struct fmstation presets[MAX_PRESETS];
|
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
static char filepreset[MAX_PATH]; /* preset filename variable */
|
2003-05-04 22:58:12 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
static int num_presets = 0; /* The number of presets in the preset list */
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static void radio_save_presets(void);
|
2007-02-27 09:06:30 +00:00
|
|
|
static int handle_radio_presets(void);
|
2006-12-25 14:01:47 +00:00
|
|
|
static bool radio_menu(void);
|
2007-02-27 09:06:30 +00:00
|
|
|
static int radio_add_preset(void);
|
|
|
|
static int save_preset_list(void);
|
|
|
|
static int load_preset_list(void);
|
|
|
|
static int clear_preset_list(void);
|
2006-04-02 12:23:08 +00:00
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int scan_presets(void);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
/* Function to manipulate all yesno dialogues.
|
|
|
|
This function needs the output text as an argument. */
|
2008-04-26 09:30:24 +00:00
|
|
|
static bool yesno_pop(const char* text)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
|
|
|
int i;
|
2008-04-26 09:30:24 +00:00
|
|
|
const char *lines[]={text};
|
|
|
|
const struct text_message message={lines, 1};
|
2006-04-02 12:23:08 +00:00
|
|
|
bool ret = (gui_syncyesno_run(&message,NULL,NULL)== YESNO_YES);
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_textarea_clear(&screens[i]);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
void radio_init(void)
|
2003-05-09 00:14:59 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
tuner_init();
|
2004-11-22 06:34:14 +00:00
|
|
|
radio_stop();
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
2003-05-09 00:14:59 +00:00
|
|
|
|
2005-11-19 19:23:44 +00:00
|
|
|
int get_radio_status(void)
|
|
|
|
{
|
2007-02-08 10:36:49 +00:00
|
|
|
return radio_status;
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
bool in_radio_screen(void)
|
|
|
|
{
|
|
|
|
return in_screen;
|
|
|
|
}
|
|
|
|
|
2007-06-06 19:23:48 +00:00
|
|
|
/* TODO: Move some more of the control functionality to an HAL and clean up the
|
|
|
|
mess */
|
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
/* secret flag for starting paused - prevents unmute */
|
|
|
|
#define FMRADIO_START_PAUSED 0x8000
|
|
|
|
void radio_start(void)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
const struct fm_region_data *fmr;
|
2006-08-28 22:38:41 +00:00
|
|
|
bool start_paused;
|
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_PLAYING)
|
2006-08-28 22:38:41 +00:00
|
|
|
return;
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
fmr = &fm_region_data[global_settings.fm_region];
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
start_paused = radio_status & FMRADIO_START_PAUSED;
|
2006-08-28 22:38:41 +00:00
|
|
|
/* clear flag before any yielding */
|
2007-02-08 10:36:49 +00:00
|
|
|
radio_status &= ~FMRADIO_START_PAUSED;
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_OFF)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_power(true);
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-01-24 02:19:22 +00:00
|
|
|
curr_freq = global_status.last_frequency
|
2007-03-16 14:40:40 +00:00
|
|
|
* fmr->freq_step + fmr->freq_min;
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_SLEEP, 0); /* wake up the tuner */
|
2007-06-06 19:23:48 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_OFF)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
#ifdef HAVE_RADIO_REGION
|
|
|
|
tuner_set(RADIO_REGION, global_settings.fm_region);
|
2006-10-12 19:27:00 +00:00
|
|
|
#endif
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_FREQUENCY, curr_freq);
|
|
|
|
|
|
|
|
#ifdef HAVE_RADIO_MUTE_TIMEOUT
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
unsigned long mute_timeout = current_tick + HZ;
|
|
|
|
if (radio_status != FMRADIO_OFF)
|
|
|
|
{
|
|
|
|
/* paused */
|
|
|
|
mute_timeout += HZ;
|
|
|
|
}
|
|
|
|
|
|
|
|
while(!tuner_get(RADIO_STEREO) && !tuner_get(RADIO_TUNED))
|
|
|
|
{
|
|
|
|
if(TIME_AFTER(current_tick, mute_timeout))
|
|
|
|
break;
|
|
|
|
yield();
|
|
|
|
}
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
2007-07-14 11:20:31 +00:00
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
/* keep radio from sounding initially */
|
|
|
|
if(!start_paused)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 0);
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
radio_status = FMRADIO_PLAYING;
|
2006-08-28 22:38:41 +00:00
|
|
|
} /* radio_start */
|
|
|
|
|
|
|
|
void radio_pause(void)
|
|
|
|
{
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_PAUSED)
|
2006-08-28 22:38:41 +00:00
|
|
|
return;
|
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_OFF)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2007-02-08 10:36:49 +00:00
|
|
|
radio_status |= FMRADIO_START_PAUSED;
|
2006-08-28 22:38:41 +00:00
|
|
|
radio_start();
|
|
|
|
}
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 1);
|
|
|
|
tuner_set(RADIO_SLEEP, 1);
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
radio_status = FMRADIO_PAUSED;
|
2006-08-28 22:38:41 +00:00
|
|
|
} /* radio_pause */
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
void radio_stop(void)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_OFF)
|
2006-08-28 22:38:41 +00:00
|
|
|
return;
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 1);
|
|
|
|
tuner_set(RADIO_SLEEP, 1); /* low power mode, if available */
|
2007-02-08 10:36:49 +00:00
|
|
|
radio_status = FMRADIO_OFF;
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_power(false); /* status update, power off if avail. */
|
2006-08-28 22:38:41 +00:00
|
|
|
} /* radio_stop */
|
2003-05-09 00:14:59 +00:00
|
|
|
|
2003-12-19 01:24:02 +00:00
|
|
|
bool radio_hardware_present(void)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
return tuner_get(RADIO_PRESENT);
|
2003-12-19 01:24:02 +00:00
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
/* Keep freq on the grid for the current region */
|
|
|
|
static int snap_freq_to_grid(int freq)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
const struct fm_region_data * const fmr =
|
|
|
|
&fm_region_data[global_settings.fm_region];
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
/* Range clamp if out of range or just round to nearest */
|
|
|
|
if (freq < fmr->freq_min)
|
|
|
|
freq = fmr->freq_min;
|
|
|
|
else if (freq > fmr->freq_max)
|
|
|
|
freq = fmr->freq_max;
|
|
|
|
else
|
|
|
|
freq = (freq - fmr->freq_min + fmr->freq_step/2) /
|
|
|
|
fmr->freq_step * fmr->freq_step + fmr->freq_min;
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find a matching preset to freq */
|
2003-05-04 02:23:18 +00:00
|
|
|
static int find_preset(int freq)
|
|
|
|
{
|
|
|
|
int i;
|
2006-04-02 12:23:08 +00:00
|
|
|
if(num_presets < 1)
|
|
|
|
return -1;
|
2003-05-04 13:05:30 +00:00
|
|
|
for(i = 0;i < MAX_PRESETS;i++)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2003-05-04 13:05:30 +00:00
|
|
|
if(freq == presets[i].frequency)
|
|
|
|
return i;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
/* Return the first preset encountered in the search direction with
|
|
|
|
wraparound. */
|
|
|
|
static int find_closest_preset(int freq, int direction)
|
2005-11-13 21:03:53 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
int i;
|
2005-11-13 21:03:53 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if (direction == 0) /* direction == 0 isn't really used */
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_PRESETS; i++)
|
2005-11-13 21:03:53 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
int preset_frequency = presets[i].frequency;
|
|
|
|
|
|
|
|
if (preset_frequency == freq)
|
|
|
|
return i; /* Exact match = stop */
|
|
|
|
/* Stop when the preset frequency exeeds freq so that we can
|
|
|
|
pick the correct one based on direction */
|
|
|
|
if (preset_frequency > freq)
|
|
|
|
break;
|
2005-11-13 21:03:53 +00:00
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
/* wrap around depending on direction */
|
|
|
|
if (i == 0 || i >= num_presets - 1)
|
|
|
|
i = direction < 0 ? num_presets - 1 : 0;
|
|
|
|
else if (direction < 0)
|
|
|
|
i--; /* use previous */
|
|
|
|
|
|
|
|
return i;
|
2005-11-13 21:03:53 +00:00
|
|
|
}
|
|
|
|
|
2004-07-12 13:28:44 +00:00
|
|
|
static void remember_frequency(void)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
const struct fm_region_data * const fmr =
|
|
|
|
&fm_region_data[global_settings.fm_region];
|
2007-03-16 14:40:40 +00:00
|
|
|
global_status.last_frequency = (curr_freq - fmr->freq_min)
|
|
|
|
/ fmr->freq_step;
|
2007-01-24 02:19:22 +00:00
|
|
|
status_save();
|
2004-07-12 13:28:44 +00:00
|
|
|
}
|
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static void next_preset(int direction)
|
2005-11-13 21:03:53 +00:00
|
|
|
{
|
|
|
|
if (num_presets < 1)
|
|
|
|
return;
|
2006-04-02 12:23:08 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if (curr_preset == -1)
|
|
|
|
curr_preset = find_closest_preset(curr_freq, direction);
|
2005-11-13 21:03:53 +00:00
|
|
|
else
|
2007-03-16 14:40:40 +00:00
|
|
|
curr_preset = (curr_preset + direction + num_presets) % num_presets;
|
|
|
|
|
|
|
|
/* Must stay on the current grid for the region */
|
|
|
|
curr_freq = snap_freq_to_grid(presets[curr_preset].frequency);
|
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_FREQUENCY, curr_freq);
|
2005-11-13 21:03:53 +00:00
|
|
|
remember_frequency();
|
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
/* Step to the next or previous frequency */
|
|
|
|
static int step_freq(int freq, int direction)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
const struct fm_region_data * const fmr =
|
|
|
|
&fm_region_data[global_settings.fm_region];
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
freq += direction*fmr->freq_step;
|
|
|
|
|
|
|
|
/* Wrap first or snapping to grid will not let us on the band extremes */
|
|
|
|
if (freq > fmr->freq_max)
|
|
|
|
freq = direction > 0 ? fmr->freq_min : fmr->freq_max;
|
|
|
|
else if (freq < fmr->freq_min)
|
|
|
|
freq = direction < 0 ? fmr->freq_max : fmr->freq_min;
|
|
|
|
else
|
|
|
|
freq = snap_freq_to_grid(freq);
|
|
|
|
|
|
|
|
return freq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Step to the next or previous station */
|
|
|
|
static void next_station(int direction)
|
|
|
|
{
|
|
|
|
if (direction != 0 && radio_mode != RADIO_SCAN_MODE)
|
|
|
|
{
|
|
|
|
next_preset(direction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
curr_freq = step_freq(curr_freq, direction);
|
|
|
|
|
|
|
|
if (radio_status == FMRADIO_PLAYING)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 1);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_FREQUENCY, curr_freq);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
if (radio_status == FMRADIO_PLAYING)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 0);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
curr_preset = find_preset(curr_freq);
|
|
|
|
remember_frequency();
|
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
|
2007-03-29 01:55:47 +00:00
|
|
|
/* Ends an in-progress search */
|
|
|
|
static void end_search(void)
|
|
|
|
{
|
|
|
|
if (search_dir != 0 && radio_status == FMRADIO_PLAYING)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 0);
|
2007-03-29 01:55:47 +00:00
|
|
|
search_dir = 0;
|
|
|
|
}
|
|
|
|
|
2007-11-07 02:14:28 +00:00
|
|
|
/* Speak a frequency. */
|
|
|
|
static void talk_freq(int freq, bool enqueue)
|
|
|
|
{
|
|
|
|
freq /= 10000;
|
|
|
|
talk_number(freq / 100, enqueue);
|
|
|
|
talk_id(LANG_POINT, true);
|
|
|
|
talk_number(freq % 100 / 10, true);
|
|
|
|
if (freq % 10)
|
|
|
|
talk_number(freq % 10, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Speak a preset by number or by spelling its name, depending on settings. */
|
|
|
|
static void talk_preset(int preset, bool fallback, bool enqueue)
|
|
|
|
{
|
|
|
|
if (global_settings.talk_file == 1) /* number */
|
|
|
|
talk_number(preset + 1, enqueue);
|
|
|
|
else
|
|
|
|
{ /* spell */
|
|
|
|
if(presets[preset].name[0])
|
|
|
|
talk_spell(presets[preset].name, enqueue);
|
|
|
|
else if(fallback)
|
|
|
|
talk_freq(presets[preset].frequency, enqueue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-01 11:14:46 +00:00
|
|
|
int radio_screen(void)
|
2003-05-03 02:40:09 +00:00
|
|
|
{
|
2004-01-21 14:58:40 +00:00
|
|
|
char buf[MAX_PATH];
|
2003-05-03 02:40:09 +00:00
|
|
|
bool done = false;
|
2007-03-01 11:14:46 +00:00
|
|
|
int ret_val = GO_TO_ROOT;
|
2007-03-16 14:40:40 +00:00
|
|
|
int button;
|
|
|
|
int i;
|
|
|
|
bool stereo = false, last_stereo = false;
|
2005-11-13 21:03:53 +00:00
|
|
|
int fh;
|
2003-11-06 00:47:47 +00:00
|
|
|
int top_of_screen = 0;
|
2003-11-05 09:46:08 +00:00
|
|
|
bool update_screen = true;
|
2003-11-06 00:47:47 +00:00
|
|
|
bool screen_freeze = false;
|
2007-03-16 14:40:40 +00:00
|
|
|
bool keep_playing = false;
|
|
|
|
bool statusbar = global_settings.statusbar;
|
2007-11-07 02:14:28 +00:00
|
|
|
bool talk = false;
|
2007-03-16 14:40:40 +00:00
|
|
|
#ifdef FM_RECORD_DBLPRE
|
|
|
|
int lastbutton = BUTTON_NONE;
|
|
|
|
unsigned long rec_lastclick = 0;
|
|
|
|
#endif
|
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2003-11-20 00:33:43 +00:00
|
|
|
bool have_recorded = false;
|
2007-03-16 14:40:40 +00:00
|
|
|
int timeout = current_tick + HZ/10;
|
2005-08-13 17:35:02 +00:00
|
|
|
unsigned int seconds = 0;
|
2003-11-20 00:33:43 +00:00
|
|
|
unsigned int last_seconds = 0;
|
|
|
|
int hours, minutes;
|
2006-11-06 18:07:30 +00:00
|
|
|
struct audio_recording_options rec_options;
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2006-03-07 11:49:06 +00:00
|
|
|
int button_timeout = current_tick + (2*HZ);
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2005-11-20 01:02:14 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
struct gui_buttonbar buttonbar;
|
|
|
|
gui_buttonbar_init(&buttonbar);
|
|
|
|
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
|
|
|
|
#endif
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
/* change status to "in screen" */
|
2007-02-08 10:36:49 +00:00
|
|
|
in_screen = true;
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
/* always display status bar in radio screen for now */
|
2008-01-10 06:46:04 +00:00
|
|
|
global_status.statusbar_forced = statusbar?0:1;
|
2005-11-13 21:03:53 +00:00
|
|
|
global_settings.statusbar = true;
|
2006-04-02 12:23:08 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2005-11-13 21:03:53 +00:00
|
|
|
gui_textarea_clear(&screens[i]);
|
|
|
|
screen_set_xmargin(&screens[i],0);
|
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars,true);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
fh = font_get(FONT_UI)->height;
|
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
/* Adjust for font size, trying to center the information vertically */
|
|
|
|
if(fh < 10)
|
|
|
|
top_of_screen = 1;
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if(num_presets <= 0)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
|
|
|
memset(presets, 0, sizeof(presets));
|
|
|
|
radio_load_presets(global_settings.fmr_file);
|
|
|
|
}
|
|
|
|
|
2007-02-08 10:36:49 +00:00
|
|
|
if(radio_status == FMRADIO_OFF)
|
2006-08-28 22:38:41 +00:00
|
|
|
audio_stop();
|
2007-03-07 09:16:20 +00:00
|
|
|
#ifndef SIMULATOR
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2004-06-04 12:34:29 +00:00
|
|
|
if(rec_create_directory() > 0)
|
|
|
|
have_recorded = true;
|
2005-08-13 17:35:02 +00:00
|
|
|
|
2006-04-30 23:18:21 +00:00
|
|
|
audio_init_recording(talk_get_bufsize());
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-07-06 12:17:14 +00:00
|
|
|
sound_settings_apply();
|
2003-11-20 00:33:43 +00:00
|
|
|
/* Yes, we use the D/A for monitoring */
|
|
|
|
peak_meter_playback(true);
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
peak_meter_enabled = true;
|
2004-03-19 22:15:53 +00:00
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
rec_init_recording_options(&rec_options);
|
|
|
|
rec_options.rec_source = AUDIO_SRC_LINEIN;
|
|
|
|
rec_set_recording_options(&rec_options);
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
|
|
|
sound_default(SOUND_RIGHT_GAIN), AUDIO_GAIN_LINEIN);
|
2006-07-21 08:42:28 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
|
|
|
#endif /* ndef SIMULATOR */
|
2005-08-13 17:35:02 +00:00
|
|
|
|
2006-08-28 22:38:41 +00:00
|
|
|
/* turn on radio */
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-06-08 23:42:04 +00:00
|
|
|
audio_set_input_source(AUDIO_SRC_FMRADIO,
|
|
|
|
(radio_status == FMRADIO_PAUSED) ?
|
|
|
|
SRCF_FMRADIO_PAUSED : SRCF_FMRADIO_PLAYING);
|
2006-08-28 22:38:41 +00:00
|
|
|
#else
|
2007-02-08 10:36:49 +00:00
|
|
|
if (radio_status == FMRADIO_OFF)
|
2006-08-28 22:38:41 +00:00
|
|
|
radio_start();
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2004-07-12 13:28:44 +00:00
|
|
|
|
2007-08-06 13:08:36 +00:00
|
|
|
if(num_presets < 1 && yesno_pop(ID2P(LANG_FM_FIRST_AUTOSCAN)))
|
2006-04-02 12:23:08 +00:00
|
|
|
scan_presets();
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
2005-11-13 21:03:53 +00:00
|
|
|
if(curr_preset != -1)
|
|
|
|
radio_mode = RADIO_PRESET_MODE;
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2005-11-20 01:02:14 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
2006-08-28 22:38:41 +00:00
|
|
|
gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU),
|
2007-08-05 19:19:39 +00:00
|
|
|
str(LANG_PRESET), str(LANG_FM_BUTTONBAR_RECORD));
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-11-05 09:46:08 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2005-09-29 11:19:55 +00:00
|
|
|
cpu_idle_mode(true);
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
while(!done)
|
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
if(search_dir != 0)
|
2003-05-03 02:40:09 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
curr_freq = step_freq(curr_freq, search_dir);
|
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq))
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
curr_preset = find_preset(curr_freq);
|
2004-07-12 13:28:44 +00:00
|
|
|
remember_frequency();
|
2007-03-16 14:40:40 +00:00
|
|
|
end_search();
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
trigger_cpu_boost();
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
|
|
|
|
2007-11-20 03:44:25 +00:00
|
|
|
if (!update_screen)
|
|
|
|
{
|
|
|
|
cancel_cpu_boost();
|
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
|
|
|
/* TODO: Can we timeout at HZ when recording since peaks aren't
|
|
|
|
displayed? This should quiet recordings too. */
|
|
|
|
button = get_action(CONTEXT_FM,
|
|
|
|
update_screen ? TIMEOUT_NOBLOCK : HZ / PEAK_METER_FPS);
|
|
|
|
#else
|
|
|
|
button = get_action(CONTEXT_FM,
|
|
|
|
update_screen ? TIMEOUT_NOBLOCK : HZ);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2006-09-22 12:18:58 +00:00
|
|
|
if (button != ACTION_NONE)
|
2006-03-07 11:49:06 +00:00
|
|
|
{
|
|
|
|
cpu_idle_mode(false);
|
|
|
|
button_timeout = current_tick + (2*HZ);
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2003-05-03 02:40:09 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_STOP:
|
2006-08-28 22:38:41 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() == AUDIO_STATUS_RECORD)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_stop();
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
|
|
|
else
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
done = true;
|
2006-04-02 12:23:08 +00:00
|
|
|
if(presets_changed)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2006-08-28 22:38:41 +00:00
|
|
|
if(filepreset[0] == '\0')
|
2006-04-02 12:23:08 +00:00
|
|
|
save_preset_list();
|
|
|
|
else
|
|
|
|
radio_save_presets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Clear the preset list on exit. */
|
|
|
|
clear_preset_list();
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
|
|
|
update_screen = true;
|
|
|
|
break;
|
2003-05-09 00:14:59 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_RECORD
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_RECORD:
|
2005-09-05 19:17:23 +00:00
|
|
|
#ifdef FM_RECORD_DBLPRE
|
2006-09-22 12:18:58 +00:00
|
|
|
if (lastbutton != ACTION_FM_RECORD_DBLPRE)
|
2005-09-05 19:17:23 +00:00
|
|
|
{
|
|
|
|
rec_lastclick = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (current_tick - rec_lastclick > HZ/2)
|
|
|
|
{
|
|
|
|
rec_lastclick = current_tick;
|
|
|
|
break;
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* FM_RECORD_DBLPRE */
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() == AUDIO_STATUS_RECORD)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2007-08-25 15:53:54 +00:00
|
|
|
rec_command(RECORDING_CMD_START_NEWFILE);
|
2003-11-20 00:33:43 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-31 03:13:29 +00:00
|
|
|
have_recorded = true;
|
2007-08-25 15:53:54 +00:00
|
|
|
rec_command(RECORDING_CMD_START);
|
2003-11-20 00:33:43 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* SIMULATOR */
|
2003-11-20 00:33:43 +00:00
|
|
|
last_seconds = 0;
|
2003-05-09 00:14:59 +00:00
|
|
|
break;
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif /* #ifdef FM_RECORD */
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_EXIT:
|
2006-08-28 22:38:41 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() == AUDIO_STATUS_RECORD)
|
|
|
|
audio_stop();
|
2005-03-06 18:03:01 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +00:00
|
|
|
keep_playing = true;
|
2005-11-13 21:03:53 +00:00
|
|
|
done = true;
|
2007-03-01 11:14:46 +00:00
|
|
|
ret_val = GO_TO_ROOT;
|
2006-04-02 12:23:08 +00:00
|
|
|
if(presets_changed)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
if(yesno_pop(ID2P(LANG_FM_SAVE_CHANGES)))
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2006-08-28 22:38:41 +00:00
|
|
|
if(filepreset[0] == '\0')
|
2006-04-02 12:23:08 +00:00
|
|
|
save_preset_list();
|
|
|
|
else
|
|
|
|
radio_save_presets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear the preset list on exit. */
|
|
|
|
clear_preset_list();
|
2007-03-01 11:14:46 +00:00
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
2006-09-22 12:18:58 +00:00
|
|
|
|
|
|
|
case ACTION_STD_PREV:
|
|
|
|
case ACTION_STD_NEXT:
|
2007-03-16 14:40:40 +00:00
|
|
|
next_station(button == ACTION_STD_PREV ? -1 : 1);
|
|
|
|
end_search();
|
2003-11-06 00:47:47 +00:00
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_STD_PREVREPEAT:
|
2007-03-16 14:40:40 +00:00
|
|
|
case ACTION_STD_NEXTREPEAT:
|
|
|
|
{
|
|
|
|
int dir = search_dir;
|
|
|
|
search_dir = button == ACTION_STD_PREVREPEAT ? -1 : 1;
|
|
|
|
if (radio_mode != RADIO_SCAN_MODE)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
next_preset(search_dir);
|
|
|
|
end_search();
|
2006-04-02 12:23:08 +00:00
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = true;
|
2006-04-02 12:23:08 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
else if (dir == 0)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
/* Starting auto scan */
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 1);
|
2006-04-02 12:23:08 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
2007-03-16 14:40:40 +00:00
|
|
|
}
|
2006-09-22 12:18:58 +00:00
|
|
|
|
|
|
|
case ACTION_SETTINGS_INC:
|
|
|
|
case ACTION_SETTINGS_INCREPEAT:
|
2003-05-03 02:40:09 +00:00
|
|
|
global_settings.volume++;
|
2007-05-30 17:57:32 +00:00
|
|
|
setvol();
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_SETTINGS_DEC:
|
|
|
|
case ACTION_SETTINGS_DECREPEAT:
|
2003-05-03 02:40:09 +00:00
|
|
|
global_settings.volume--;
|
2007-05-30 17:57:32 +00:00
|
|
|
setvol();
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_PLAY:
|
2007-02-08 10:36:49 +00:00
|
|
|
if (radio_status == FMRADIO_PLAYING)
|
2006-08-28 22:38:41 +00:00
|
|
|
radio_pause();
|
2005-11-13 21:03:53 +00:00
|
|
|
else
|
2006-08-28 22:38:41 +00:00
|
|
|
radio_start();
|
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = false;
|
|
|
|
talk_shutup();
|
2005-11-13 21:03:53 +00:00
|
|
|
break;
|
2006-09-22 12:18:58 +00:00
|
|
|
|
|
|
|
case ACTION_FM_MENU:
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_menu();
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i){
|
2007-03-16 14:40:40 +00:00
|
|
|
struct screen *sc = &screens[i];
|
|
|
|
gui_textarea_clear(sc);
|
|
|
|
screen_set_xmargin(sc, 0);
|
2005-11-13 21:03:53 +00:00
|
|
|
}
|
2005-11-20 01:02:14 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_set(&buttonbar, str(LANG_BUTTONBAR_MENU),
|
2007-08-05 19:19:39 +00:00
|
|
|
str(LANG_PRESET),
|
2005-11-20 01:02:14 +00:00
|
|
|
str(LANG_FM_BUTTONBAR_RECORD));
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
break;
|
2006-09-22 12:18:58 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_PRESET
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_PRESET:
|
2006-04-02 12:23:08 +00:00
|
|
|
if(num_presets < 1)
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_FM_NO_PRESETS));
|
2005-11-16 23:36:35 +00:00
|
|
|
update_screen = true;
|
2006-04-02 12:23:08 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
struct screen *sc = &screens[i];
|
|
|
|
gui_textarea_clear(sc);
|
|
|
|
screen_set_xmargin(sc, 0);
|
|
|
|
gui_textarea_update(sc);
|
2006-04-02 12:23:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-16 23:36:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-07-05 14:30:17 +00:00
|
|
|
handle_radio_presets();
|
2006-04-02 12:23:08 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
struct screen *sc = &screens[i];
|
|
|
|
gui_textarea_clear(sc);
|
|
|
|
screen_set_xmargin(sc, 0);
|
|
|
|
gui_textarea_update(sc);
|
2005-11-13 21:03:53 +00:00
|
|
|
}
|
2005-11-20 01:02:14 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_set(&buttonbar,
|
|
|
|
str(LANG_BUTTONBAR_MENU),
|
2007-08-05 19:19:39 +00:00
|
|
|
str(LANG_PRESET),
|
2005-11-20 01:02:14 +00:00
|
|
|
str(LANG_FM_BUTTONBAR_RECORD));
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
break;
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* FM_PRESET */
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_FREEZE
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_FREEZE:
|
2003-11-06 00:47:47 +00:00
|
|
|
if(!screen_freeze)
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(HZ, str(LANG_FM_FREEZE));
|
2003-11-06 00:47:47 +00:00
|
|
|
screen_freeze = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
update_screen = true;
|
|
|
|
screen_freeze = false;
|
|
|
|
}
|
|
|
|
break;
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* FM_FREEZE */
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
case SYS_USB_CONNECTED:
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2003-11-20 00:33:43 +00:00
|
|
|
/* Only accept USB connection when not recording */
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() != AUDIO_STATUS_RECORD)
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2004-07-26 16:06:59 +00:00
|
|
|
default_event_handler(SYS_USB_CONNECTED);
|
2003-12-31 03:13:29 +00:00
|
|
|
screen_freeze = true; /* Cosmetic: makes sure the
|
|
|
|
radio screen doesn't redraw */
|
2003-11-20 00:33:43 +00:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
break;
|
2005-11-13 21:03:53 +00:00
|
|
|
|
|
|
|
#ifdef FM_MODE
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_MODE:
|
|
|
|
if(radio_mode == RADIO_SCAN_MODE)
|
2005-11-13 21:03:53 +00:00
|
|
|
{
|
2006-09-22 12:18:58 +00:00
|
|
|
/* Force scan mode if there are no presets. */
|
|
|
|
if(num_presets > 0)
|
|
|
|
radio_mode = RADIO_PRESET_MODE;
|
2005-11-13 21:03:53 +00:00
|
|
|
}
|
2006-09-22 12:18:58 +00:00
|
|
|
else
|
|
|
|
radio_mode = RADIO_SCAN_MODE;
|
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
cond_talk_ids_fq(radio_mode ?
|
|
|
|
LANG_PRESET : LANG_RADIO_SCAN_MODE);
|
|
|
|
talk = true;
|
2005-11-13 21:03:53 +00:00
|
|
|
break;
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* FM_MODE */
|
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
#ifdef FM_NEXT_PRESET
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_NEXT_PRESET:
|
2005-11-13 21:03:53 +00:00
|
|
|
next_preset(1);
|
2007-03-16 14:40:40 +00:00
|
|
|
end_search();
|
2005-11-13 21:03:53 +00:00
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = true;
|
2005-11-13 21:03:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
#ifdef FM_PREV_PRESET
|
2006-09-22 12:18:58 +00:00
|
|
|
case ACTION_FM_PREV_PRESET:
|
2005-11-13 21:03:53 +00:00
|
|
|
next_preset(-1);
|
2007-03-16 14:40:40 +00:00
|
|
|
end_search();
|
2005-11-13 21:03:53 +00:00
|
|
|
update_screen = true;
|
2007-11-07 02:14:28 +00:00
|
|
|
talk = true;
|
2005-11-13 21:03:53 +00:00
|
|
|
break;
|
|
|
|
#endif
|
2004-07-26 16:06:59 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
default_event_handler(button);
|
|
|
|
break;
|
2006-03-07 11:49:06 +00:00
|
|
|
} /*switch(button)*/
|
2003-11-05 09:46:08 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
#ifdef FM_RECORD_DBLPRE
|
2006-09-22 12:18:58 +00:00
|
|
|
if (button != ACTION_NONE)
|
2005-08-13 17:35:02 +00:00
|
|
|
lastbutton = button;
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2006-09-22 12:18:58 +00:00
|
|
|
|
2006-03-03 19:41:16 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2003-11-05 09:46:08 +00:00
|
|
|
peak_meter_peek();
|
2006-03-03 19:41:16 +00:00
|
|
|
#endif
|
2003-11-05 09:46:08 +00:00
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
if(!screen_freeze)
|
2005-11-13 21:03:53 +00:00
|
|
|
{
|
2003-12-31 03:13:29 +00:00
|
|
|
/* Only display the peak meter when not recording */
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:36:06 +00:00
|
|
|
if(!audio_status())
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2006-03-25 13:35:31 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
peak_meter_screen(&screens[i],0,
|
|
|
|
STATUSBAR_HEIGHT + fh*(top_of_screen + 4), fh);
|
|
|
|
screens[i].update_rect(0, STATUSBAR_HEIGHT + fh*(top_of_screen + 4),
|
|
|
|
screens[i].width, fh);
|
|
|
|
}
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
2005-08-29 20:07:17 +00:00
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
if(TIME_AFTER(current_tick, timeout))
|
2003-11-05 09:46:08 +00:00
|
|
|
{
|
2003-11-06 00:47:47 +00:00
|
|
|
timeout = current_tick + HZ;
|
2007-03-16 14:40:40 +00:00
|
|
|
#else /* SWCODEC */
|
|
|
|
{
|
|
|
|
#endif /* CONFIG_CODEC == SWCODEC */
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
/* keep "mono" from always being displayed when paused */
|
2007-02-08 10:36:49 +00:00
|
|
|
if (radio_status != FMRADIO_PAUSED)
|
2003-11-06 00:47:47 +00:00
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
stereo = tuner_get(RADIO_STEREO) &&
|
2006-08-28 22:38:41 +00:00
|
|
|
!global_settings.fm_force_mono;
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
if(stereo != last_stereo)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
|
|
|
update_screen = true;
|
2007-03-16 14:40:40 +00:00
|
|
|
last_stereo = stereo;
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
2003-11-06 00:47:47 +00:00
|
|
|
}
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
|
2005-11-12 04:00:56 +00:00
|
|
|
seconds = audio_recorded_time() / HZ;
|
2007-03-16 14:40:40 +00:00
|
|
|
if (update_screen || seconds > last_seconds)
|
2003-11-05 09:46:08 +00:00
|
|
|
{
|
2003-11-20 00:33:43 +00:00
|
|
|
last_seconds = seconds;
|
2007-03-16 14:40:40 +00:00
|
|
|
#else
|
|
|
|
if (update_screen)
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
int freq;
|
2005-11-29 15:10:07 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].setfont(FONT_UI);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
snprintf(buf, 128, curr_preset >= 0 ? "%d. %s" : " ",
|
|
|
|
curr_preset + 1, presets[curr_preset].name);
|
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen, buf);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2006-10-05 12:40:13 +00:00
|
|
|
freq = curr_freq / 10000;
|
|
|
|
snprintf(buf, 128, str(LANG_FM_STATION), freq / 100, freq % 100);
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen + 1, buf);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2005-11-13 21:03:53 +00:00
|
|
|
snprintf(buf, 128, stereo?str(LANG_CHANNEL_STEREO):
|
|
|
|
str(LANG_CHANNEL_MONO));
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen + 2, buf);
|
|
|
|
|
2007-08-05 19:19:39 +00:00
|
|
|
snprintf(buf, 128, "%s %s", str(LANG_MODE),
|
|
|
|
radio_mode ? str(LANG_PRESET) :
|
2005-11-29 15:10:07 +00:00
|
|
|
str(LANG_RADIO_SCAN_MODE));
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen + 3, buf);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2006-03-03 19:41:16 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() == AUDIO_STATUS_RECORD)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
hours = seconds / 3600;
|
|
|
|
minutes = (seconds - (hours * 3600)) / 60;
|
|
|
|
snprintf(buf, 32, "%s %02d:%02d:%02d",
|
|
|
|
str(LANG_RECORDING_TIME),
|
|
|
|
hours, minutes, seconds%60);
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen + 4, buf);
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
2003-12-31 03:13:29 +00:00
|
|
|
else
|
|
|
|
{
|
2006-11-06 18:07:30 +00:00
|
|
|
if(rec_options.rec_prerecord_time)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
|
|
|
snprintf(buf, 32, "%s %02d",
|
|
|
|
str(LANG_RECORD_PRERECORD), seconds%60);
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
screens[i].puts_scroll(0, top_of_screen + 4, buf);
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
2003-12-31 03:13:29 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
2005-11-20 01:02:14 +00:00
|
|
|
|
2005-11-20 01:35:20 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
2005-11-20 01:02:14 +00:00
|
|
|
gui_buttonbar_draw(&buttonbar);
|
|
|
|
#endif
|
2005-11-13 21:03:53 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_textarea_update(&screens[i]);
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
2004-12-26 18:36:48 +00:00
|
|
|
/* Only force the redraw if update_screen is true */
|
2005-11-13 21:03:53 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars,true);
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
update_screen = false;
|
|
|
|
|
2007-11-07 02:14:28 +00:00
|
|
|
if (global_settings.talk_file && talk
|
|
|
|
&& radio_status == FMRADIO_PAUSED)
|
|
|
|
{
|
|
|
|
talk = false;
|
|
|
|
bool enqueue = false;
|
|
|
|
if (radio_mode == RADIO_SCAN_MODE)
|
|
|
|
{
|
|
|
|
talk_freq(curr_freq, enqueue);
|
|
|
|
enqueue = true;
|
|
|
|
}
|
|
|
|
if (curr_preset >= 0)
|
|
|
|
talk_preset(curr_preset, radio_mode == RADIO_PRESET_MODE,
|
|
|
|
enqueue);
|
|
|
|
}
|
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() & AUDIO_STATUS_ERROR)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2006-03-07 11:49:06 +00:00
|
|
|
if (TIME_AFTER(current_tick, button_timeout))
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
|
|
|
cpu_idle_mode(true);
|
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2006-03-07 11:49:06 +00:00
|
|
|
} /*while(!done)*/
|
2003-05-03 15:39:40 +00:00
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() & AUDIO_STATUS_ERROR)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(0, str(LANG_DISK_FULL));
|
2005-11-13 21:03:53 +00:00
|
|
|
gui_syncstatusbar_draw(&statusbars,true);
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
gui_textarea_update(&screens[i]);
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_error_clear();
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
2006-09-22 12:18:58 +00:00
|
|
|
button = get_action(CONTEXT_FM, TIMEOUT_BLOCK);
|
2006-09-25 19:59:37 +00:00
|
|
|
if(button == ACTION_FM_STOP)
|
2003-11-20 00:33:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_init_playback();
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif /* CONFIG_CODEC != SWCODEC */
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2004-07-06 12:17:14 +00:00
|
|
|
sound_settings_apply();
|
2006-04-02 12:23:08 +00:00
|
|
|
#endif /* SIMULATOR */
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
if(keep_playing)
|
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
/* Catch FMRADIO_PLAYING status for the sim. */
|
2006-04-02 12:23:08 +00:00
|
|
|
#ifndef SIMULATOR
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2003-11-20 00:33:43 +00:00
|
|
|
/* Enable the Left and right A/D Converter */
|
2005-11-12 04:00:56 +00:00
|
|
|
audio_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
2006-08-28 22:38:41 +00:00
|
|
|
sound_default(SOUND_RIGHT_GAIN),
|
|
|
|
AUDIO_GAIN_LINEIN);
|
2003-11-20 00:33:43 +00:00
|
|
|
mas_codec_writereg(6, 0x4000);
|
2005-08-13 17:35:02 +00:00
|
|
|
#endif
|
2007-03-16 14:40:40 +00:00
|
|
|
end_search();
|
|
|
|
#endif /* SIMULATOR */
|
2004-10-19 08:20:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-08-29 21:15:27 +00:00
|
|
|
#if CONFIG_CODEC == SWCODEC
|
2007-06-08 23:42:04 +00:00
|
|
|
audio_set_input_source(AUDIO_SRC_PLAYBACK, SRCF_PLAYBACK);
|
2006-08-28 22:38:41 +00:00
|
|
|
#else
|
|
|
|
radio_stop();
|
2005-08-13 17:35:02 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
#ifndef HAVE_NOISY_IDLE_MODE
|
2005-09-29 11:19:55 +00:00
|
|
|
cpu_idle_mode(false);
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2005-11-13 21:03:53 +00:00
|
|
|
|
|
|
|
/* restore status bar settings */
|
|
|
|
global_settings.statusbar = statusbar;
|
2008-01-10 06:46:04 +00:00
|
|
|
global_status.statusbar_forced = 0;
|
2007-02-08 10:36:49 +00:00
|
|
|
in_screen = false;
|
2007-03-16 14:40:40 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2003-11-20 00:33:43 +00:00
|
|
|
return have_recorded;
|
2007-03-16 14:40:40 +00:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
} /* radio_screen */
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2006-12-25 14:01:47 +00:00
|
|
|
static void radio_save_presets(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int i;
|
2006-04-02 12:23:08 +00:00
|
|
|
|
2007-02-01 23:08:15 +00:00
|
|
|
fd = creat(filepreset);
|
2003-05-04 02:23:18 +00:00
|
|
|
if(fd >= 0)
|
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
for(i = 0;i < num_presets;i++)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2005-02-22 12:48:36 +00:00
|
|
|
fdprintf(fd, "%d:%s\n", presets[i].frequency, presets[i].name);
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
close(fd);
|
2006-04-02 12:23:08 +00:00
|
|
|
|
|
|
|
if(!strncasecmp(FMPRESET_PATH, filepreset, strlen(FMPRESET_PATH)))
|
|
|
|
set_file(filepreset, global_settings.fmr_file, MAX_FILENAME);
|
|
|
|
presets_changed = false;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_FM_PRESET_SAVE_FAILED));
|
2006-04-02 12:23:08 +00:00
|
|
|
}
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
void radio_load_presets(char *filename)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int rc;
|
|
|
|
char buf[128];
|
|
|
|
char *freq;
|
|
|
|
char *name;
|
|
|
|
bool done = false;
|
2004-07-05 14:30:17 +00:00
|
|
|
int f;
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
memset(presets, 0, sizeof(presets));
|
|
|
|
num_presets = 0;
|
|
|
|
|
|
|
|
/* No Preset in configuration. */
|
|
|
|
if(filename[0] == '\0')
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
2006-04-02 12:23:08 +00:00
|
|
|
filepreset[0] = '\0';
|
|
|
|
return;
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
/* Temporary preset, loaded until player shuts down. */
|
|
|
|
else if(filename[0] == '/')
|
|
|
|
strncpy(filepreset, filename, sizeof(filepreset));
|
|
|
|
/* Preset from default directory. */
|
|
|
|
else
|
2006-08-28 22:38:41 +00:00
|
|
|
snprintf(filepreset, sizeof(filepreset), "%s/%s.fmr",
|
2006-04-02 12:23:08 +00:00
|
|
|
FMPRESET_PATH, filename);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
fd = open(filepreset, O_RDONLY);
|
|
|
|
if(fd >= 0)
|
|
|
|
{
|
|
|
|
while(!done && num_presets < MAX_PRESETS)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2006-04-02 12:23:08 +00:00
|
|
|
rc = read_line(fd, buf, 128);
|
|
|
|
if(rc > 0)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2006-04-02 12:23:08 +00:00
|
|
|
if(settings_parseline(buf, &freq, &name))
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2006-04-02 12:23:08 +00:00
|
|
|
f = atoi(freq);
|
|
|
|
if(f) /* For backwards compatibility */
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
struct fmstation * const fms = &presets[num_presets];
|
|
|
|
fms->frequency = f;
|
|
|
|
strncpy(fms->name, name, MAX_FMPRESET_LEN);
|
|
|
|
fms->name[MAX_FMPRESET_LEN] = '\0';
|
2006-04-02 12:23:08 +00:00
|
|
|
num_presets++;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
else
|
|
|
|
done = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
close(fd);
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
else /* invalid file name? */
|
|
|
|
filepreset[0] = '\0';
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
presets_loaded = num_presets > 0;
|
2006-04-02 12:23:08 +00:00
|
|
|
presets_changed = false;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int radio_add_preset(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2007-05-05 12:06:35 +00:00
|
|
|
char buf[MAX_FMPRESET_LEN + 1];
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
if(num_presets < MAX_PRESETS)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2006-04-03 10:06:39 +00:00
|
|
|
memset(buf, 0, MAX_FMPRESET_LEN);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2006-04-03 10:06:39 +00:00
|
|
|
if (!kbd_input(buf, MAX_FMPRESET_LEN))
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
struct fmstation * const fms = &presets[num_presets];
|
|
|
|
buf[MAX_FMPRESET_LEN] = '\0';
|
|
|
|
strcpy(fms->name, buf);
|
|
|
|
fms->frequency = curr_freq;
|
2004-07-05 14:30:17 +00:00
|
|
|
num_presets++;
|
2006-04-02 12:23:08 +00:00
|
|
|
presets_changed = true;
|
2007-03-16 14:40:40 +00:00
|
|
|
presets_loaded = num_presets > 0;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_FM_NO_FREE_PRESETS));
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
/* needed to know which preset we are edit/delete-ing */
|
2007-03-16 14:40:40 +00:00
|
|
|
static int selected_preset = -1;
|
2007-02-27 09:06:30 +00:00
|
|
|
static int radio_edit_preset(void)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
2007-06-04 21:38:23 +00:00
|
|
|
char buf[MAX_FMPRESET_LEN + 1];
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if (num_presets > 0)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
struct fmstation * const fms = &presets[selected_preset];
|
|
|
|
|
|
|
|
strncpy(buf, fms->name, MAX_FMPRESET_LEN);
|
|
|
|
|
|
|
|
if (!kbd_input(buf, MAX_FMPRESET_LEN))
|
|
|
|
{
|
|
|
|
buf[MAX_FMPRESET_LEN] = '\0';
|
|
|
|
strcpy(fms->name, buf);
|
|
|
|
presets_changed = true;
|
|
|
|
}
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2007-03-18 07:57:36 +00:00
|
|
|
return 1;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int radio_delete_preset(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
if (num_presets > 0)
|
|
|
|
{
|
|
|
|
struct fmstation * const fms = &presets[selected_preset];
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if (selected_preset >= --num_presets)
|
|
|
|
selected_preset = num_presets - 1;
|
|
|
|
|
|
|
|
memmove(fms, fms + 1, (uintptr_t)(fms + num_presets) -
|
|
|
|
(uintptr_t)fms);
|
|
|
|
|
|
|
|
}
|
2007-02-27 09:06:30 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
/* Don't ask to save when all presets are deleted. */
|
2007-03-16 14:40:40 +00:00
|
|
|
presets_changed = num_presets > 0;
|
|
|
|
|
|
|
|
if (!presets_changed)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
|
|
|
/* The preset list will be cleared, switch to Scan Mode. */
|
|
|
|
radio_mode = RADIO_SCAN_MODE;
|
|
|
|
presets_loaded = false;
|
|
|
|
}
|
|
|
|
|
2007-03-18 07:57:36 +00:00
|
|
|
return 1;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int load_preset_list(void)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
|
|
|
return !rockbox_browse(FMPRESET_PATH, SHOW_FMR);
|
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int save_preset_list(void)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
if(num_presets > 0)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2006-04-25 00:14:21 +00:00
|
|
|
bool bad_file_name = true;
|
|
|
|
|
2008-04-16 19:51:43 +00:00
|
|
|
if(!dir_exists(FMPRESET_PATH)) /* Check if there is preset folder */
|
|
|
|
mkdir(FMPRESET_PATH);
|
|
|
|
|
2006-11-06 18:07:30 +00:00
|
|
|
create_numbered_filename(filepreset, FMPRESET_PATH, "preset",
|
|
|
|
".fmr", 2 IF_CNFN_NUM_(, NULL));
|
2006-04-25 00:14:21 +00:00
|
|
|
|
|
|
|
while(bad_file_name)
|
|
|
|
{
|
|
|
|
if(!kbd_input(filepreset, sizeof(filepreset)))
|
|
|
|
{
|
|
|
|
/* check the name: max MAX_FILENAME (20) chars */
|
|
|
|
char* p2;
|
|
|
|
char* p1;
|
|
|
|
int len;
|
|
|
|
p1 = strrchr(filepreset, '/');
|
|
|
|
p2 = p1;
|
|
|
|
while((p1) && (*p2) && (*p2 != '.'))
|
|
|
|
p2++;
|
|
|
|
len = (int)(p2-p1) - 1;
|
|
|
|
if((!p1) || (len > MAX_FILENAME) || (len == 0))
|
|
|
|
{
|
|
|
|
/* no slash, too long or too short */
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_INVALID_FILENAME));
|
2006-04-25 00:14:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* add correct extension (easier to always write)
|
|
|
|
at this point, p2 points to 0 or the extension dot */
|
|
|
|
*p2 = '\0';
|
|
|
|
strcat(filepreset,".fmr");
|
|
|
|
bad_file_name = false;
|
|
|
|
radio_save_presets();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* user aborted */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
}
|
|
|
|
else
|
2007-08-06 13:08:36 +00:00
|
|
|
gui_syncsplash(HZ, ID2P(LANG_FM_NO_PRESETS));
|
2006-04-02 12:23:08 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int clear_preset_list(void)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
|
|
|
/* Clear all the preset entries */
|
2007-03-16 14:40:40 +00:00
|
|
|
memset(presets, 0, sizeof (presets));
|
2006-04-02 12:23:08 +00:00
|
|
|
|
|
|
|
num_presets = 0;
|
|
|
|
presets_loaded = false;
|
|
|
|
/* The preset list will be cleared switch to Scan Mode. */
|
|
|
|
radio_mode = RADIO_SCAN_MODE;
|
|
|
|
|
|
|
|
presets_changed = false; /* Don't ask to save when clearing the list. */
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-03-18 07:57:36 +00:00
|
|
|
MENUITEM_FUNCTION(radio_edit_preset_item, MENU_FUNC_CHECK_RETVAL,
|
2007-03-17 12:33:34 +00:00
|
|
|
ID2P(LANG_FM_EDIT_PRESET),
|
2007-03-18 07:03:43 +00:00
|
|
|
radio_edit_preset, NULL, NULL, Icon_NOICON);
|
2007-03-18 07:57:36 +00:00
|
|
|
MENUITEM_FUNCTION(radio_delete_preset_item, MENU_FUNC_CHECK_RETVAL,
|
2007-03-17 12:33:34 +00:00
|
|
|
ID2P(LANG_FM_DELETE_PRESET),
|
2007-03-18 07:03:43 +00:00
|
|
|
radio_delete_preset, NULL, NULL, Icon_NOICON);
|
2007-02-27 09:16:47 +00:00
|
|
|
int radio_preset_callback(int action, const struct menu_item_ex *this_item)
|
|
|
|
{
|
|
|
|
if (action == ACTION_STD_OK)
|
2007-03-16 14:40:40 +00:00
|
|
|
action = ACTION_EXIT_AFTER_THIS_MENUITEM;
|
2007-02-27 09:16:47 +00:00
|
|
|
return action;
|
2007-03-16 14:40:40 +00:00
|
|
|
(void)this_item;
|
2007-02-27 09:16:47 +00:00
|
|
|
}
|
2007-08-05 19:19:39 +00:00
|
|
|
MAKE_MENU(handle_radio_preset_menu, ID2P(LANG_PRESET),
|
2007-03-03 13:52:14 +00:00
|
|
|
radio_preset_callback, Icon_NOICON, &radio_edit_preset_item,
|
2007-02-27 09:16:47 +00:00
|
|
|
&radio_delete_preset_item);
|
2007-02-27 09:06:30 +00:00
|
|
|
/* present a list of preset stations */
|
2008-04-09 15:25:17 +00:00
|
|
|
static char * presets_get_name(int selected_item, void *data,
|
|
|
|
char *buffer, size_t buffer_len)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
2007-02-27 09:06:30 +00:00
|
|
|
(void)data;
|
2007-11-07 02:14:28 +00:00
|
|
|
struct fmstation *p = &presets[selected_item];
|
|
|
|
if(p->name[0])
|
|
|
|
return p->name;
|
|
|
|
int freq = p->frequency / 10000;
|
|
|
|
int frac = freq % 100;
|
|
|
|
freq /= 100;
|
2008-04-09 15:25:17 +00:00
|
|
|
snprintf(buffer, buffer_len,
|
2007-11-07 02:14:28 +00:00
|
|
|
str(LANG_FM_DEFAULT_PRESET_NAME), freq, frac);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int presets_speak_name(int selected_item, void * data)
|
|
|
|
{
|
|
|
|
(void)data;
|
|
|
|
talk_preset(selected_item, true, false);
|
|
|
|
return 0;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int handle_radio_presets(void)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
2007-02-27 09:06:30 +00:00
|
|
|
struct gui_synclist lists;
|
|
|
|
int result = 0;
|
|
|
|
int action = ACTION_NONE;
|
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
struct gui_buttonbar buttonbar;
|
2005-11-13 21:03:53 +00:00
|
|
|
#endif
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
if(presets_loaded == false)
|
|
|
|
return result;
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
#ifdef HAS_BUTTONBAR
|
|
|
|
gui_buttonbar_init(&buttonbar);
|
|
|
|
gui_buttonbar_set_display(&buttonbar, &(screens[SCREEN_MAIN]) );
|
|
|
|
gui_buttonbar_set(&buttonbar, str(LANG_FM_BUTTONBAR_ADD),
|
2004-07-05 14:30:17 +00:00
|
|
|
str(LANG_FM_BUTTONBAR_EXIT),
|
|
|
|
str(LANG_FM_BUTTONBAR_ACTION));
|
2007-02-27 09:06:30 +00:00
|
|
|
gui_buttonbar_draw(&buttonbar);
|
|
|
|
#endif
|
2008-03-26 03:35:24 +00:00
|
|
|
gui_synclist_init(&lists, presets_get_name, NULL, false, 1, NULL);
|
2007-08-05 19:19:39 +00:00
|
|
|
gui_synclist_set_title(&lists, str(LANG_PRESET), NOICON);
|
2007-02-27 09:06:30 +00:00
|
|
|
gui_synclist_set_icon_callback(&lists, NULL);
|
2007-11-07 02:14:28 +00:00
|
|
|
if(global_settings.talk_file)
|
|
|
|
gui_synclist_set_voice_callback(&lists, presets_speak_name);
|
2007-02-27 09:06:30 +00:00
|
|
|
gui_synclist_set_nb_items(&lists, num_presets);
|
|
|
|
gui_synclist_select_item(&lists, curr_preset<0 ? 0 : curr_preset);
|
2007-11-07 02:14:28 +00:00
|
|
|
gui_synclist_speak_item(&lists);
|
2007-02-27 09:06:30 +00:00
|
|
|
|
|
|
|
while (result == 0)
|
|
|
|
{
|
|
|
|
gui_synclist_draw(&lists);
|
|
|
|
gui_syncstatusbar_draw(&statusbars, true);
|
2007-11-07 02:14:28 +00:00
|
|
|
list_do_action(CONTEXT_STD, HZ,
|
|
|
|
&lists, &action, LIST_WRAP_UNLESS_HELD);
|
2007-02-27 09:06:30 +00:00
|
|
|
switch (action)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2007-02-27 09:06:30 +00:00
|
|
|
case ACTION_STD_MENU:
|
|
|
|
radio_add_preset();
|
|
|
|
break;
|
|
|
|
case ACTION_STD_CANCEL:
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
case ACTION_STD_OK:
|
|
|
|
curr_preset = gui_synclist_get_sel_pos(&lists);
|
|
|
|
curr_freq = presets[curr_preset].frequency;
|
2007-03-16 14:40:40 +00:00
|
|
|
next_station(0);
|
2007-02-27 09:06:30 +00:00
|
|
|
remember_frequency();
|
|
|
|
result = 1;
|
|
|
|
break;
|
|
|
|
case ACTION_F3:
|
|
|
|
case ACTION_STD_CONTEXT:
|
|
|
|
selected_preset = gui_synclist_get_sel_pos(&lists);
|
2008-03-26 03:35:24 +00:00
|
|
|
do_menu(&handle_radio_preset_menu, NULL, NULL, false);
|
2007-11-07 02:14:28 +00:00
|
|
|
gui_synclist_speak_item(&lists);
|
2007-02-27 09:06:30 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if(default_event_handler(action) == SYS_USB_CONNECTED)
|
|
|
|
result = 2;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
2007-02-27 09:06:30 +00:00
|
|
|
return result - 1;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
void toggle_mono_mode(bool mono)
|
2006-10-05 12:40:13 +00:00
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_FORCE_MONO, mono);
|
2006-10-05 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
void set_radio_region(int region)
|
2006-10-05 12:40:13 +00:00
|
|
|
{
|
2007-07-14 13:41:59 +00:00
|
|
|
#ifdef HAVE_RADIO_REGION
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_REGION, region);
|
2007-07-14 13:41:59 +00:00
|
|
|
#endif
|
2007-03-16 14:40:40 +00:00
|
|
|
next_station(0);
|
2006-10-12 13:59:44 +00:00
|
|
|
remember_frequency();
|
2007-07-14 13:41:59 +00:00
|
|
|
(void)region;
|
2006-10-05 12:40:13 +00:00
|
|
|
}
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
MENUITEM_SETTING(set_region, &global_settings.fm_region, NULL);
|
|
|
|
MENUITEM_SETTING(force_mono, &global_settings.fm_force_mono, NULL);
|
2005-11-29 15:10:07 +00:00
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
#ifndef FM_MODE
|
|
|
|
char* get_mode_text(int selected_item, void * data, char *buffer)
|
2005-11-29 15:10:07 +00:00
|
|
|
{
|
2007-02-27 09:06:30 +00:00
|
|
|
(void)selected_item;
|
|
|
|
(void)data;
|
2007-08-05 19:19:39 +00:00
|
|
|
snprintf(buffer, MAX_PATH, "%s %s", str(LANG_MODE),
|
|
|
|
radio_mode ? str(LANG_PRESET) :
|
2005-11-29 15:10:07 +00:00
|
|
|
str(LANG_RADIO_SCAN_MODE));
|
2007-02-27 09:06:30 +00:00
|
|
|
return buffer;
|
2005-11-29 15:10:07 +00:00
|
|
|
}
|
2007-03-17 12:33:34 +00:00
|
|
|
static int toggle_radio_mode(void)
|
2005-11-29 15:10:07 +00:00
|
|
|
{
|
|
|
|
radio_mode = (radio_mode == RADIO_SCAN_MODE) ?
|
|
|
|
RADIO_PRESET_MODE : RADIO_SCAN_MODE;
|
2007-02-27 09:06:30 +00:00
|
|
|
return 0;
|
2005-11-29 15:10:07 +00:00
|
|
|
}
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION_DYNTEXT(radio_mode_item, 0,
|
2007-03-18 07:03:43 +00:00
|
|
|
toggle_radio_mode, NULL,
|
2007-10-09 03:48:56 +00:00
|
|
|
get_mode_text, NULL, NULL, NULL, Icon_NOICON);
|
2005-11-29 15:10:07 +00:00
|
|
|
#endif
|
|
|
|
|
2007-02-27 09:06:30 +00:00
|
|
|
static int scan_presets(void)
|
2005-11-16 23:36:35 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
bool do_scan = true;
|
2006-04-02 12:23:08 +00:00
|
|
|
|
|
|
|
if(num_presets > 0) /* Do that to avoid 2 questions. */
|
2007-08-06 13:08:36 +00:00
|
|
|
do_scan = yesno_pop(ID2P(LANG_FM_CLEAR_PRESETS));
|
2006-04-02 12:23:08 +00:00
|
|
|
|
|
|
|
if(do_scan)
|
|
|
|
{
|
2007-07-14 11:20:31 +00:00
|
|
|
const struct fm_region_data * const fmr =
|
|
|
|
&fm_region_data[global_settings.fm_region];
|
|
|
|
|
2007-06-04 21:38:23 +00:00
|
|
|
char buf[MAX_FMPRESET_LEN + 1];
|
2007-03-16 14:40:40 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
curr_freq = fmr->freq_min;
|
2005-11-19 14:54:41 +00:00
|
|
|
num_presets = 0;
|
2006-04-03 10:06:39 +00:00
|
|
|
memset(presets, 0, sizeof(presets));
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 1);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
while(curr_freq <= fmr->freq_max)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2007-03-16 14:40:40 +00:00
|
|
|
int freq, frac;
|
2006-12-26 22:01:27 +00:00
|
|
|
if (num_presets >= MAX_PRESETS || action_userabort(TIMEOUT_NOBLOCK))
|
2005-11-19 14:54:41 +00:00
|
|
|
break;
|
2005-11-16 23:36:35 +00:00
|
|
|
|
2006-10-05 12:40:13 +00:00
|
|
|
freq = curr_freq / 10000;
|
2007-03-16 14:40:40 +00:00
|
|
|
frac = freq % 100;
|
|
|
|
freq /= 100;
|
|
|
|
|
|
|
|
snprintf(buf, MAX_FMPRESET_LEN, str(LANG_FM_SCANNING), freq, frac);
|
2007-03-16 21:56:08 +00:00
|
|
|
gui_syncsplash(0, buf);
|
2005-11-19 14:54:41 +00:00
|
|
|
|
2007-07-14 11:20:31 +00:00
|
|
|
if(tuner_set(RADIO_SCAN_FREQUENCY, curr_freq))
|
2007-03-16 14:40:40 +00:00
|
|
|
{
|
|
|
|
/* add preset */
|
2007-11-07 02:14:28 +00:00
|
|
|
presets[num_presets].name[0] = '\0';
|
2007-03-16 14:40:40 +00:00
|
|
|
presets[num_presets].frequency = curr_freq;
|
|
|
|
num_presets++;
|
2005-11-19 14:54:41 +00:00
|
|
|
}
|
2005-11-16 23:36:35 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
curr_freq += fmr->freq_step;
|
2005-11-19 14:54:41 +00:00
|
|
|
}
|
2005-11-16 23:36:35 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if (radio_status == FMRADIO_PLAYING)
|
2007-07-14 11:20:31 +00:00
|
|
|
tuner_set(RADIO_MUTE, 0);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2006-04-02 12:23:08 +00:00
|
|
|
presets_changed = true;
|
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
gui_textarea_clear(&screens[i]);
|
|
|
|
screen_set_xmargin(&screens[i],0);
|
|
|
|
gui_textarea_update(&screens[i]);
|
|
|
|
}
|
2005-11-19 14:54:41 +00:00
|
|
|
|
2007-03-16 14:40:40 +00:00
|
|
|
if(num_presets > 0)
|
2006-04-02 12:23:08 +00:00
|
|
|
{
|
2005-11-19 14:54:41 +00:00
|
|
|
curr_freq = presets[0].frequency;
|
2005-11-19 19:23:44 +00:00
|
|
|
radio_mode = RADIO_PRESET_MODE;
|
2006-04-02 12:23:08 +00:00
|
|
|
presets_loaded = true;
|
2007-03-16 14:40:40 +00:00
|
|
|
next_station(0);
|
2005-11-16 23:36:35 +00:00
|
|
|
}
|
2006-04-02 12:23:08 +00:00
|
|
|
else
|
2007-03-16 14:40:40 +00:00
|
|
|
{
|
|
|
|
/* Wrap it to beginning or we'll be past end of band */
|
2006-04-02 12:23:08 +00:00
|
|
|
presets_loaded = false;
|
2007-03-16 14:40:40 +00:00
|
|
|
next_station(1);
|
|
|
|
}
|
2005-11-16 23:36:35 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
|
2006-10-10 13:42:22 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
|
2007-05-20 20:26:36 +00:00
|
|
|
#if defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC
|
2006-10-10 13:42:22 +00:00
|
|
|
#define FM_RECORDING_SCREEN
|
2007-02-27 09:06:30 +00:00
|
|
|
static int fm_recording_screen(void)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
|
|
|
bool ret;
|
|
|
|
|
|
|
|
/* switch recording source to FMRADIO for the duration */
|
|
|
|
int rec_source = global_settings.rec_source;
|
|
|
|
global_settings.rec_source = AUDIO_SRC_FMRADIO;
|
|
|
|
|
|
|
|
ret = recording_screen(true);
|
|
|
|
|
|
|
|
/* safe to reset as changing sources is prohibited here */
|
|
|
|
global_settings.rec_source = rec_source;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-03-17 12:33:34 +00:00
|
|
|
|
2007-05-20 20:26:36 +00:00
|
|
|
#endif /* defined(HAVE_FMRADIO_REC) && CONFIG_CODEC == SWCODEC */
|
2006-08-28 22:38:41 +00:00
|
|
|
|
2007-05-20 20:26:36 +00:00
|
|
|
#if defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC
|
2006-10-10 13:42:22 +00:00
|
|
|
#define FM_RECORDING_SETTINGS
|
2007-02-27 09:06:30 +00:00
|
|
|
static int fm_recording_settings(void)
|
2006-08-28 22:38:41 +00:00
|
|
|
{
|
|
|
|
bool ret = recording_menu(true);
|
2007-03-16 14:40:40 +00:00
|
|
|
|
2006-09-17 18:52:31 +00:00
|
|
|
#if CONFIG_CODEC != SWCODEC
|
2006-08-28 22:38:41 +00:00
|
|
|
if (!ret)
|
|
|
|
{
|
2006-11-06 18:07:30 +00:00
|
|
|
struct audio_recording_options rec_options;
|
|
|
|
rec_init_recording_options(&rec_options);
|
|
|
|
rec_options.rec_source = AUDIO_SRC_LINEIN;
|
|
|
|
rec_set_recording_options(&rec_options);
|
2006-08-28 22:38:41 +00:00
|
|
|
}
|
2006-09-17 18:52:31 +00:00
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2007-03-17 12:33:34 +00:00
|
|
|
|
2007-05-20 20:26:36 +00:00
|
|
|
#endif /* defined(HAVE_FMRADIO_REC) || CONFIG_CODEC != SWCODEC */
|
2006-10-10 13:42:22 +00:00
|
|
|
#endif /* HAVE_RECORDING */
|
2007-03-16 14:40:40 +00:00
|
|
|
|
|
|
|
#ifdef FM_RECORDING_SCREEN
|
2007-08-05 19:19:39 +00:00
|
|
|
MENUITEM_FUNCTION(recscreen_item, 0, ID2P(LANG_RECORDING),
|
2007-06-25 21:19:45 +00:00
|
|
|
fm_recording_screen, NULL, NULL, Icon_Recording);
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FM_RECORDING_SETTINGS
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(recsettings_item, 0, ID2P(LANG_RECORDING_SETTINGS),
|
2007-06-25 21:19:45 +00:00
|
|
|
fm_recording_settings, NULL, NULL, Icon_Recording);
|
2007-03-16 14:40:40 +00:00
|
|
|
#endif
|
2007-02-27 09:06:30 +00:00
|
|
|
#ifndef FM_PRESET
|
2007-08-05 19:19:39 +00:00
|
|
|
MENUITEM_FUNCTION(radio_presets_item, 0, ID2P(LANG_PRESET),
|
2007-03-18 07:03:43 +00:00
|
|
|
handle_radio_presets, NULL, NULL, Icon_NOICON);
|
2007-02-27 09:06:30 +00:00
|
|
|
#endif
|
|
|
|
#ifndef FM_PRESET_ADD
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(radio_addpreset_item, 0, ID2P(LANG_FM_ADD_PRESET),
|
2007-03-18 07:03:43 +00:00
|
|
|
radio_add_preset, NULL, NULL, Icon_NOICON);
|
2007-02-27 09:06:30 +00:00
|
|
|
#endif
|
2006-08-28 22:38:41 +00:00
|
|
|
|
|
|
|
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(presetload_item, 0, ID2P(LANG_FM_PRESET_LOAD),
|
2007-03-18 07:03:43 +00:00
|
|
|
load_preset_list, NULL, NULL, Icon_NOICON);
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(presetsave_item, 0, ID2P(LANG_FM_PRESET_SAVE),
|
2007-03-18 07:03:43 +00:00
|
|
|
save_preset_list, NULL, NULL, Icon_NOICON);
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR),
|
2007-03-18 07:03:43 +00:00
|
|
|
clear_preset_list, NULL, NULL, Icon_NOICON);
|
2007-03-17 12:33:34 +00:00
|
|
|
MENUITEM_FUNCTION(scan_presets_item, 0, ID2P(LANG_FM_SCAN_PRESETS),
|
2007-03-18 07:03:43 +00:00
|
|
|
scan_presets, NULL, NULL, Icon_NOICON);
|
2007-02-27 09:06:30 +00:00
|
|
|
|
2007-07-03 18:31:13 +00:00
|
|
|
MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL,
|
2007-03-03 13:52:14 +00:00
|
|
|
Icon_Radio_screen,
|
2005-09-22 18:36:02 +00:00
|
|
|
#ifndef FM_PRESET
|
2007-02-27 09:06:30 +00:00
|
|
|
&radio_presets_item,
|
2005-09-22 18:36:02 +00:00
|
|
|
#endif
|
|
|
|
#ifndef FM_PRESET_ADD
|
2007-02-27 09:06:30 +00:00
|
|
|
&radio_addpreset_item,
|
2005-08-13 17:35:02 +00:00
|
|
|
#endif
|
2007-02-27 09:06:30 +00:00
|
|
|
&presetload_item, &presetsave_item, &presetclear_item,
|
|
|
|
&force_mono,
|
2005-11-29 15:10:07 +00:00
|
|
|
#ifndef FM_MODE
|
2007-02-27 09:06:30 +00:00
|
|
|
&radio_mode_item,
|
2006-08-28 22:38:41 +00:00
|
|
|
#endif
|
2007-02-27 09:06:30 +00:00
|
|
|
&set_region, &sound_settings,
|
2006-10-10 13:42:22 +00:00
|
|
|
#ifdef FM_RECORDING_SCREEN
|
2007-02-27 09:22:56 +00:00
|
|
|
&recscreen_item,
|
2005-11-29 15:10:07 +00:00
|
|
|
#endif
|
2006-10-10 13:42:22 +00:00
|
|
|
#ifdef FM_RECORDING_SETTINGS
|
2007-02-27 09:06:30 +00:00
|
|
|
&recsettings_item,
|
2005-11-29 15:10:07 +00:00
|
|
|
#endif
|
2007-02-27 09:06:30 +00:00
|
|
|
&scan_presets_item);
|
|
|
|
/* main menu of the radio screen */
|
|
|
|
static bool radio_menu(void)
|
|
|
|
{
|
2008-03-26 03:35:24 +00:00
|
|
|
return do_menu(&radio_settings_menu, NULL, NULL, false) == MENU_ATTACHED_USB;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
#endif
|