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>
|
2003-05-04 02:23:18 +00:00
|
|
|
#include "sprintf.h"
|
2003-05-03 02:40:09 +00:00
|
|
|
#include "lcd.h"
|
|
|
|
#include "mas.h"
|
|
|
|
#include "settings.h"
|
|
|
|
#include "button.h"
|
|
|
|
#include "fmradio.h"
|
|
|
|
#include "status.h"
|
|
|
|
#include "kernel.h"
|
|
|
|
#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 "atoi.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"
|
|
|
|
#include "recording.h"
|
2004-03-19 22:15:53 +00:00
|
|
|
#include "talk.h"
|
2004-10-15 21:41:46 +00:00
|
|
|
#include "tuner.h"
|
|
|
|
#include "hwcompat.h"
|
2004-10-17 08:53:18 +00:00
|
|
|
#include "power.h"
|
2005-04-01 14:09:41 +00:00
|
|
|
#include "sound.h"
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-09-28 22:13:26 +00:00
|
|
|
#ifdef CONFIG_TUNER
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2004-10-13 07:37:28 +00:00
|
|
|
#define FM_MENU BUTTON_F1
|
|
|
|
#define FM_PRESET BUTTON_F2
|
2004-10-10 17:12:43 +00:00
|
|
|
#define FM_RECORD BUTTON_F3
|
|
|
|
#define FM_FREEZE BUTTON_PLAY
|
|
|
|
#define FM_STOP BUTTON_OFF
|
|
|
|
#define FM_EXIT (BUTTON_ON | BUTTON_REL)
|
2004-10-19 09:09:27 +00:00
|
|
|
#define FM_PRESET_ADD BUTTON_F1
|
|
|
|
#define FM_PRESET_ACTION BUTTON_F3
|
2004-10-10 17:12:43 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD /* restricted keypad */
|
|
|
|
#define FM_MENU (BUTTON_MENU | BUTTON_REPEAT)
|
|
|
|
#define FM_RECORD (BUTTON_MENU | BUTTON_REL)
|
|
|
|
#define FM_STOP (BUTTON_OFF | BUTTON_REL)
|
|
|
|
#define FM_EXIT (BUTTON_OFF | BUTTON_REPEAT)
|
|
|
|
#endif
|
|
|
|
|
2003-11-05 09:46:08 +00:00
|
|
|
#define MAX_FREQ (108000000)
|
|
|
|
#define MIN_FREQ (87500000)
|
2003-05-03 02:40:09 +00:00
|
|
|
#define FREQ_STEP 100000
|
|
|
|
|
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;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
#define MAX_PRESETS 32
|
|
|
|
static bool presets_loaded = false;
|
|
|
|
static struct fmstation presets[MAX_PRESETS];
|
|
|
|
|
2004-08-03 19:22:56 +00:00
|
|
|
static const char default_filename[] = "/.rockbox/fm-presets-default.fmr";
|
2003-05-04 22:58:12 +00:00
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
static int preset_menu; /* The menu index of the preset list */
|
|
|
|
static struct menu_item preset_menu_items[MAX_PRESETS];
|
|
|
|
static int num_presets; /* The number of presets in the preset list */
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_load_presets(void);
|
2004-07-05 14:30:17 +00:00
|
|
|
bool handle_radio_presets(void);
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_menu(void);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2004-10-19 18:00:41 +00:00
|
|
|
#if CONFIG_TUNER == S1A0903X01 /* FM recorder */
|
2004-10-15 21:41:46 +00:00
|
|
|
#define radio_set samsung_set
|
|
|
|
#define radio_get samsung_get
|
2004-10-19 18:00:41 +00:00
|
|
|
#elif CONFIG_TUNER == TEA5767 /* Iriver */
|
2004-10-15 21:41:46 +00:00
|
|
|
#define radio_set philips_set
|
|
|
|
#define radio_get philips_get
|
2004-10-19 18:00:41 +00:00
|
|
|
#elif CONFIG_TUNER == (S1A0903X01 | TEA5767) /* OndioFM */
|
2004-10-15 21:41:46 +00:00
|
|
|
void (*radio_set)(int setting, int value);
|
|
|
|
int (*radio_get)(int setting);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void radio_init(void)
|
2003-05-09 00:14:59 +00:00
|
|
|
{
|
2004-10-15 21:41:46 +00:00
|
|
|
#if CONFIG_TUNER == (S1A0903X01 | TEA5767)
|
|
|
|
if (read_hw_mask() & TUNER_MODEL)
|
2004-07-05 14:30:17 +00:00
|
|
|
{
|
2004-10-15 21:41:46 +00:00
|
|
|
radio_set = philips_set;
|
|
|
|
radio_get = philips_get;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
2004-10-15 21:41:46 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
radio_set = samsung_set;
|
|
|
|
radio_get = samsung_get;
|
|
|
|
}
|
|
|
|
#endif
|
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
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
void radio_stop(void)
|
|
|
|
{
|
|
|
|
radio_set(RADIO_MUTE, 1);
|
2004-10-19 08:20:38 +00:00
|
|
|
radio_set(RADIO_SLEEP, 1); /* low power mode, if available */
|
|
|
|
radio_set_status(FMRADIO_OFF); /* status update, power off if avail. */
|
2003-05-09 00:14:59 +00:00
|
|
|
}
|
|
|
|
|
2003-12-19 01:24:02 +00:00
|
|
|
bool radio_hardware_present(void)
|
|
|
|
{
|
2004-10-17 17:49:30 +00:00
|
|
|
#ifdef HAVE_TUNER_PWR_CTRL
|
|
|
|
bool ret;
|
|
|
|
int fmstatus = radio_get_status(); /* get current state */
|
2004-10-19 08:20:38 +00:00
|
|
|
radio_set_status(FMRADIO_POWERED); /* power it up */
|
2004-10-17 17:49:30 +00:00
|
|
|
ret = radio_get(RADIO_PRESENT);
|
|
|
|
radio_set_status(fmstatus); /* restore previous state */
|
|
|
|
return ret;
|
|
|
|
#else
|
2004-10-15 21:41:46 +00:00
|
|
|
return radio_get(RADIO_PRESENT);
|
2004-10-17 17:49:30 +00:00
|
|
|
#endif
|
2003-12-19 01:24:02 +00:00
|
|
|
}
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
static int find_preset(int freq)
|
|
|
|
{
|
|
|
|
int i;
|
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;
|
|
|
|
}
|
|
|
|
|
2004-07-12 13:28:44 +00:00
|
|
|
static void remember_frequency(void)
|
|
|
|
{
|
|
|
|
global_settings.last_frequency = (curr_freq - MIN_FREQ) / FREQ_STEP;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
bool radio_screen(void)
|
|
|
|
{
|
2004-01-21 14:58:40 +00:00
|
|
|
char buf[MAX_PATH];
|
2003-05-03 02:40:09 +00:00
|
|
|
bool done = false;
|
|
|
|
int button;
|
|
|
|
int freq;
|
2004-10-19 08:20:38 +00:00
|
|
|
bool tuned;
|
2003-11-06 00:47:47 +00:00
|
|
|
bool stereo = false;
|
2003-05-03 02:40:09 +00:00
|
|
|
int search_dir = 0;
|
2003-05-04 13:05:30 +00:00
|
|
|
int fw, fh;
|
2004-07-02 07:43:49 +00:00
|
|
|
bool last_stereo_status = false;
|
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;
|
|
|
|
int timeout = current_tick + HZ/10;
|
2003-11-06 00:47:47 +00:00
|
|
|
bool screen_freeze = false;
|
2003-11-20 00:33:43 +00:00
|
|
|
bool have_recorded = false;
|
|
|
|
unsigned int seconds;
|
|
|
|
unsigned int last_seconds = 0;
|
|
|
|
int hours, minutes;
|
|
|
|
bool keep_playing = false;
|
2003-11-05 09:46:08 +00:00
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
lcd_clear_display();
|
|
|
|
lcd_setmargins(0, 8);
|
2003-11-05 09:46:08 +00:00
|
|
|
status_draw(true);
|
2004-10-17 08:53:18 +00:00
|
|
|
radio_set_status(FMRADIO_PLAYING);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
font_get(FONT_UI);
|
|
|
|
lcd_getstringsize("M", &fw, &fh);
|
|
|
|
|
|
|
|
/* Adjust for font size, trying to center the information vertically */
|
|
|
|
if(fh < 10)
|
|
|
|
top_of_screen = 1;
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_load_presets();
|
2003-05-10 23:58:20 +00:00
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2004-06-04 12:34:29 +00:00
|
|
|
if(rec_create_directory() > 0)
|
|
|
|
have_recorded = true;
|
|
|
|
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_stop();
|
2003-05-03 15:39:40 +00:00
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
mpeg_init_recording();
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-07-06 12:17:14 +00:00
|
|
|
sound_settings_apply();
|
2003-12-19 00:38:47 +00:00
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
/* Yes, we use the D/A for monitoring */
|
|
|
|
peak_meter_playback(true);
|
|
|
|
|
|
|
|
peak_meter_enabled = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-03-19 22:15:53 +00:00
|
|
|
if (global_settings.rec_prerecord_time)
|
|
|
|
talk_buffer_steal(); /* will use the mp3 buffer */
|
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
mpeg_set_recording_options(global_settings.rec_frequency,
|
|
|
|
global_settings.rec_quality,
|
2003-12-31 03:13:29 +00:00
|
|
|
1, /* Line In */
|
2003-11-20 00:33:43 +00:00
|
|
|
global_settings.rec_channels,
|
2003-12-31 03:13:29 +00:00
|
|
|
global_settings.rec_editable,
|
|
|
|
global_settings.rec_prerecord_time);
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
|
2005-04-01 13:41:03 +00:00
|
|
|
mpeg_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
|
|
|
sound_default(SOUND_RIGHT_GAIN), false);
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2004-07-12 13:28:44 +00:00
|
|
|
|
|
|
|
curr_freq = global_settings.last_frequency * FREQ_STEP + MIN_FREQ;
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2004-10-19 08:20:38 +00:00
|
|
|
radio_set(RADIO_SLEEP, 0); /* wake up the tuner */
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_FREQUENCY, curr_freq);
|
|
|
|
radio_set(RADIO_IF_MEASUREMENT, 0);
|
|
|
|
radio_set(RADIO_SENSITIVITY, 0);
|
|
|
|
radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
|
|
|
|
radio_set(RADIO_MUTE, 0);
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-11-05 09:46:08 +00:00
|
|
|
buttonbar_set(str(LANG_BUTTONBAR_MENU), str(LANG_FM_BUTTONBAR_PRESETS),
|
2003-11-20 00:33:43 +00:00
|
|
|
str(LANG_FM_BUTTONBAR_RECORD));
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-11-05 09:46:08 +00:00
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
while(!done)
|
|
|
|
{
|
|
|
|
if(search_dir)
|
|
|
|
{
|
|
|
|
curr_freq += search_dir * FREQ_STEP;
|
|
|
|
if(curr_freq < MIN_FREQ)
|
|
|
|
curr_freq = MAX_FREQ;
|
|
|
|
if(curr_freq > MAX_FREQ)
|
|
|
|
curr_freq = MIN_FREQ;
|
|
|
|
|
|
|
|
/* Tune in and delay */
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_FREQUENCY, curr_freq);
|
2003-11-05 09:46:08 +00:00
|
|
|
sleep(1);
|
2003-05-03 02:40:09 +00:00
|
|
|
|
|
|
|
/* Start IF measurement */
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_IF_MEASUREMENT, 1);
|
2003-11-05 09:46:08 +00:00
|
|
|
sleep(1);
|
2003-05-03 02:40:09 +00:00
|
|
|
|
|
|
|
/* Now check how close to the IF frequency we are */
|
2004-10-19 08:20:38 +00:00
|
|
|
tuned = radio_get(RADIO_TUNED);
|
2003-05-03 02:40:09 +00:00
|
|
|
|
2004-10-18 07:58:59 +00:00
|
|
|
/* Stop searching if the tuning is close */
|
2004-10-19 08:20:38 +00:00
|
|
|
if(tuned)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2003-05-03 02:40:09 +00:00
|
|
|
search_dir = 0;
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
2004-07-12 13:28:44 +00:00
|
|
|
remember_frequency();
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
2003-11-05 09:46:08 +00:00
|
|
|
|
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(search_dir)
|
|
|
|
button = button_get(false);
|
|
|
|
else
|
2003-11-05 09:46:08 +00:00
|
|
|
button = button_get_w_tmo(HZ / peak_meter_fps);
|
2003-05-03 02:40:09 +00:00
|
|
|
switch(button)
|
|
|
|
{
|
2004-10-10 17:12:43 +00:00
|
|
|
case FM_STOP:
|
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
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
update_screen = true;
|
|
|
|
break;
|
2003-05-09 00:14:59 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_RECORD
|
|
|
|
case FM_RECORD:
|
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
|
|
|
{
|
2004-01-21 14:58:40 +00:00
|
|
|
mpeg_new_file(rec_create_filename(buf));
|
2003-11-20 00:33:43 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-12-31 03:13:29 +00:00
|
|
|
have_recorded = true;
|
2004-03-19 22:15:53 +00:00
|
|
|
talk_buffer_steal(); /* we use the mp3 buffer */
|
2004-01-21 14:58:40 +00:00
|
|
|
mpeg_record(rec_create_filename(buf));
|
2003-11-20 00:33:43 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
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
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
case FM_EXIT:
|
2005-03-06 18:03:01 +00:00
|
|
|
#ifndef 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-05-03 02:40:09 +00:00
|
|
|
done = true;
|
2003-11-20 00:33:43 +00:00
|
|
|
keep_playing = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_LEFT:
|
2003-05-03 23:56:51 +00:00
|
|
|
curr_freq -= FREQ_STEP;
|
2003-05-03 02:40:09 +00:00
|
|
|
if(curr_freq < MIN_FREQ)
|
|
|
|
curr_freq = MIN_FREQ;
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_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();
|
2003-05-03 02:40:09 +00:00
|
|
|
search_dir = 0;
|
2003-11-06 00:47:47 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_RIGHT:
|
2003-05-03 23:56:51 +00:00
|
|
|
curr_freq += FREQ_STEP;
|
2003-05-03 02:40:09 +00:00
|
|
|
if(curr_freq > MAX_FREQ)
|
|
|
|
curr_freq = MAX_FREQ;
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_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();
|
2003-05-03 02:40:09 +00:00
|
|
|
search_dir = 0;
|
2003-11-06 00:47:47 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
|
|
|
search_dir = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
|
|
|
search_dir = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_UP:
|
|
|
|
case BUTTON_UP | BUTTON_REPEAT:
|
|
|
|
global_settings.volume++;
|
2005-04-01 13:41:03 +00:00
|
|
|
if(global_settings.volume > sound_max(SOUND_VOLUME))
|
|
|
|
global_settings.volume = sound_max(SOUND_VOLUME);
|
|
|
|
sound_set(SOUND_VOLUME, global_settings.volume);
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
settings_save();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
case BUTTON_DOWN | BUTTON_REPEAT:
|
|
|
|
global_settings.volume--;
|
2005-04-01 13:41:03 +00:00
|
|
|
if(global_settings.volume < sound_min(SOUND_VOLUME))
|
|
|
|
global_settings.volume = sound_min(SOUND_VOLUME);
|
|
|
|
sound_set(SOUND_VOLUME, global_settings.volume);
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
settings_save();
|
|
|
|
break;
|
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_MENU
|
|
|
|
case 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);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_setmargins(0, 8);
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-11-05 09:46:08 +00:00
|
|
|
buttonbar_set(str(LANG_BUTTONBAR_MENU),
|
|
|
|
str(LANG_FM_BUTTONBAR_PRESETS),
|
2003-11-20 00:33:43 +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;
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_PRESET
|
|
|
|
case FM_PRESET:
|
2004-07-05 14:30:17 +00:00
|
|
|
handle_radio_presets();
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_setmargins(0, 8);
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-11-05 09:46:08 +00:00
|
|
|
buttonbar_set(str(LANG_BUTTONBAR_MENU),
|
|
|
|
str(LANG_FM_BUTTONBAR_PRESETS),
|
2003-11-20 00:33:43 +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;
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#ifdef FM_FREEZE
|
|
|
|
case FM_FREEZE:
|
2003-11-06 00:47:47 +00:00
|
|
|
if(!screen_freeze)
|
|
|
|
{
|
2004-01-08 12:00:04 +00:00
|
|
|
splash(0, true, "Screen frozen");
|
2003-11-06 00:47:47 +00:00
|
|
|
lcd_update();
|
|
|
|
screen_freeze = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
update_screen = true;
|
|
|
|
screen_freeze = false;
|
|
|
|
}
|
|
|
|
break;
|
2004-09-10 13:19:41 +00:00
|
|
|
#endif
|
2003-05-04 02:23:18 +00:00
|
|
|
case SYS_USB_CONNECTED:
|
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)
|
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;
|
2004-07-26 16:06:59 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
default_event_handler(button);
|
|
|
|
break;
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
2003-11-05 09:46:08 +00:00
|
|
|
|
|
|
|
peak_meter_peek();
|
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
if(!screen_freeze)
|
2003-11-05 09:46:08 +00:00
|
|
|
{
|
2003-11-06 00:47:47 +00:00
|
|
|
lcd_setmargins(0, 8);
|
2003-12-31 03:13:29 +00:00
|
|
|
|
|
|
|
/* Only display the peak meter when not recording */
|
2005-04-04 12:36:06 +00:00
|
|
|
if(!audio_status())
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
lcd_clearrect(0, 8 + fh*(top_of_screen + 3), LCD_WIDTH, fh);
|
|
|
|
peak_meter_draw(0, 8 + fh*(top_of_screen + 3), LCD_WIDTH, fh);
|
|
|
|
lcd_update_rect(0, 8 + fh*(top_of_screen + 3), LCD_WIDTH, fh);
|
|
|
|
}
|
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;
|
|
|
|
|
2004-10-15 21:41:46 +00:00
|
|
|
stereo = radio_get(RADIO_STEREO) &&
|
2004-07-05 14:30:17 +00:00
|
|
|
!global_settings.fm_force_mono;
|
2003-11-06 00:47:47 +00:00
|
|
|
if(stereo != last_stereo_status)
|
|
|
|
{
|
|
|
|
update_screen = true;
|
|
|
|
last_stereo_status = stereo;
|
|
|
|
}
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2003-11-20 00:33:43 +00:00
|
|
|
seconds = mpeg_recorded_time() / HZ;
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +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;
|
|
|
|
|
2003-11-06 00:47:47 +00:00
|
|
|
lcd_setfont(FONT_UI);
|
|
|
|
|
|
|
|
if(curr_preset >= 0)
|
|
|
|
{
|
|
|
|
lcd_puts_scroll(0, top_of_screen,
|
|
|
|
presets[curr_preset].name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lcd_clearrect(0, 8 + top_of_screen*fh, LCD_WIDTH, fh);
|
|
|
|
}
|
|
|
|
|
|
|
|
freq = curr_freq / 100000;
|
|
|
|
snprintf(buf, 128, str(LANG_FM_STATION), freq / 10, freq % 10);
|
|
|
|
lcd_puts(0, top_of_screen + 1, buf);
|
|
|
|
|
|
|
|
snprintf(buf, 128,
|
|
|
|
stereo?str(LANG_CHANNEL_STEREO):
|
|
|
|
str(LANG_CHANNEL_MONO));
|
|
|
|
lcd_puts(0, top_of_screen + 2, buf);
|
2003-11-20 00:33:43 +00:00
|
|
|
|
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);
|
|
|
|
lcd_puts(0, top_of_screen + 3, buf);
|
|
|
|
}
|
2003-12-31 03:13:29 +00:00
|
|
|
else
|
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
if(global_settings.rec_prerecord_time)
|
|
|
|
{
|
|
|
|
snprintf(buf, 32, "%s %02d",
|
|
|
|
str(LANG_RECORD_PRERECORD), seconds%60);
|
|
|
|
lcd_puts(0, top_of_screen + 3, buf);
|
|
|
|
}
|
2003-12-31 03:13:29 +00:00
|
|
|
}
|
2003-11-06 00:47:47 +00:00
|
|
|
|
2004-10-10 17:12:43 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2003-11-06 00:47:47 +00:00
|
|
|
buttonbar_draw();
|
2004-10-10 17:12:43 +00:00
|
|
|
#endif
|
2003-11-06 00:47:47 +00:00
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
update_screen = false;
|
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 */
|
|
|
|
status_draw(update_screen);
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() & AUDIO_STATUS_ERROR)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
2003-05-03 15:39:40 +00:00
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2005-04-04 12:36:06 +00:00
|
|
|
if(audio_status() & AUDIO_STATUS_ERROR)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
2004-01-08 12:00:04 +00:00
|
|
|
splash(0, true, str(LANG_DISK_FULL));
|
2003-11-20 00:33:43 +00:00
|
|
|
status_draw(true);
|
|
|
|
lcd_update();
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_error_clear();
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
button = button_get(true);
|
|
|
|
if(button == (BUTTON_OFF | BUTTON_REL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-04-04 12:36:06 +00:00
|
|
|
audio_init_playback();
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2004-07-06 12:17:14 +00:00
|
|
|
sound_settings_apply();
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
if(keep_playing)
|
|
|
|
{
|
|
|
|
/* Enable the Left and right A/D Converter */
|
2005-04-01 13:41:03 +00:00
|
|
|
mpeg_set_recording_gain(sound_default(SOUND_LEFT_GAIN),
|
|
|
|
sound_default(SOUND_RIGHT_GAIN), false);
|
2003-11-20 00:33:43 +00:00
|
|
|
mas_codec_writereg(6, 0x4000);
|
2004-10-19 08:20:38 +00:00
|
|
|
radio_set_status(FMRADIO_POWERED); /* leave it powered */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
radio_stop();
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
2004-10-19 08:20:38 +00:00
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2003-11-20 00:33:43 +00:00
|
|
|
return have_recorded;
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_save_presets(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int i;
|
|
|
|
|
2003-05-04 22:58:12 +00:00
|
|
|
fd = creat(default_filename, O_WRONLY);
|
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);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-08 12:00:04 +00:00
|
|
|
splash(HZ*2, true, str(LANG_FM_PRESET_SAVE_FAILED));
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_load_presets(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int rc;
|
|
|
|
char buf[128];
|
|
|
|
char *freq;
|
|
|
|
char *name;
|
|
|
|
bool done = false;
|
|
|
|
int i;
|
2004-07-05 14:30:17 +00:00
|
|
|
int f;
|
2003-05-04 02:23:18 +00:00
|
|
|
|
|
|
|
if(!presets_loaded)
|
|
|
|
{
|
|
|
|
memset(presets, 0, sizeof(presets));
|
2004-07-05 14:30:17 +00:00
|
|
|
num_presets = 0;
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2003-05-04 22:58:12 +00:00
|
|
|
fd = open(default_filename, O_RDONLY);
|
2003-05-04 02:23:18 +00:00
|
|
|
if(fd >= 0)
|
|
|
|
{
|
|
|
|
i = 0;
|
2004-03-11 11:00:38 +00:00
|
|
|
while(!done && i < MAX_PRESETS)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
rc = read_line(fd, buf, 128);
|
|
|
|
if(rc > 0)
|
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
if(settings_parseline(buf, &freq, &name))
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
f = atoi(freq);
|
|
|
|
if(f) /* For backwards compatibility */
|
|
|
|
{
|
|
|
|
presets[num_presets].frequency = f;
|
|
|
|
strncpy(presets[num_presets].name, name, 27);
|
|
|
|
presets[num_presets].name[27] = 0;
|
|
|
|
num_presets++;
|
|
|
|
}
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
2003-05-04 13:05:30 +00:00
|
|
|
presets_loaded = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
static void rebuild_preset_menu(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
int i;
|
2004-07-05 14:30:17 +00:00
|
|
|
for(i = 0;i < num_presets;i++)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
preset_menu_items[i].desc = presets[i].name;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
static bool radio_add_preset(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
char buf[27];
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
if(num_presets < MAX_PRESETS)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
memset(buf, 0, 27);
|
|
|
|
|
|
|
|
if (!kbd_input(buf, 27))
|
|
|
|
{
|
|
|
|
buf[27] = 0;
|
2004-07-05 14:30:17 +00:00
|
|
|
strcpy(presets[num_presets].name, buf);
|
|
|
|
presets[num_presets].frequency = curr_freq;
|
|
|
|
menu_insert(preset_menu, -1,
|
2004-07-23 23:01:20 +00:00
|
|
|
presets[num_presets].name, 0);
|
2004-07-05 14:30:17 +00:00
|
|
|
/* We must still rebuild the menu table, since the
|
|
|
|
item name pointers must be updated */
|
|
|
|
rebuild_preset_menu();
|
|
|
|
num_presets++;
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_save_presets();
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2004-01-08 12:00:04 +00:00
|
|
|
splash(HZ*2, true, str(LANG_FM_NO_FREE_PRESETS));
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
/* button preprocessor for preset option submenu */
|
2004-07-05 14:30:17 +00:00
|
|
|
static int handle_radio_presets_menu_cb(int key, int m)
|
|
|
|
{
|
|
|
|
(void)m;
|
2004-10-19 18:00:41 +00:00
|
|
|
#ifdef FM_PRESET_ACTION
|
2004-07-05 14:30:17 +00:00
|
|
|
switch(key)
|
|
|
|
{
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ACTION:
|
2004-10-04 09:43:09 +00:00
|
|
|
key = MENU_EXIT; /* Fake an exit */
|
2004-07-05 14:30:17 +00:00
|
|
|
break;
|
2004-10-07 05:49:19 +00:00
|
|
|
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ACTION | BUTTON_REL:
|
|
|
|
/* Ignore the release events */
|
|
|
|
key = BUTTON_NONE;
|
|
|
|
break;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
2004-09-19 21:58:37 +00:00
|
|
|
#endif
|
2004-07-05 14:30:17 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool radio_edit_preset(void)
|
|
|
|
{
|
|
|
|
int pos = menu_cursor(preset_menu);
|
|
|
|
char buf[27];
|
|
|
|
|
|
|
|
strncpy(buf, menu_description(preset_menu, pos), 27);
|
|
|
|
|
|
|
|
if (!kbd_input(buf, 27))
|
|
|
|
{
|
|
|
|
buf[27] = 0;
|
|
|
|
strcpy(presets[pos].name, buf);
|
|
|
|
radio_save_presets();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_delete_preset(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
int pos = menu_cursor(preset_menu);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i = pos;i < num_presets;i++)
|
|
|
|
presets[i] = presets[i+1];
|
|
|
|
num_presets--;
|
|
|
|
|
|
|
|
menu_delete(preset_menu, pos);
|
|
|
|
/* We must still rebuild the menu table, since the
|
|
|
|
item name pointers must be updated */
|
|
|
|
rebuild_preset_menu();
|
|
|
|
radio_save_presets();
|
|
|
|
|
|
|
|
return true; /* Make the menu return immediately */
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
/* little menu on what to do with a preset entry */
|
2004-07-05 14:30:17 +00:00
|
|
|
bool handle_radio_presets_menu(void)
|
|
|
|
{
|
2004-08-03 20:52:31 +00:00
|
|
|
static const struct menu_item preset_menu_items[] = {
|
2004-07-23 23:31:58 +00:00
|
|
|
{ ID2P(LANG_FM_EDIT_PRESET), radio_edit_preset },
|
|
|
|
{ ID2P(LANG_FM_DELETE_PRESET), radio_delete_preset },
|
2004-07-05 14:30:17 +00:00
|
|
|
};
|
|
|
|
int m;
|
|
|
|
|
|
|
|
m = menu_init( preset_menu_items,
|
|
|
|
sizeof preset_menu_items / sizeof(struct menu_item),
|
|
|
|
handle_radio_presets_menu_cb,
|
|
|
|
NULL, NULL, str(LANG_FM_BUTTONBAR_EXIT));
|
|
|
|
menu_run(m);
|
|
|
|
menu_exit(m);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
/* button preprocessor for list of preset stations menu */
|
2004-07-05 14:30:17 +00:00
|
|
|
int handle_radio_presets_cb(int key, int m)
|
|
|
|
{
|
2004-09-19 21:58:37 +00:00
|
|
|
(void)m;
|
2004-07-05 14:30:17 +00:00
|
|
|
switch(key)
|
|
|
|
{
|
2004-10-19 18:00:41 +00:00
|
|
|
#ifdef FM_PRESET_ADD
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ADD:
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_add_preset();
|
|
|
|
menu_draw(m);
|
|
|
|
key = BUTTON_NONE;
|
|
|
|
break;
|
2004-10-19 18:00:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FM_PRESET
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET:
|
2004-07-05 14:30:17 +00:00
|
|
|
menu_draw(m);
|
2004-10-04 09:43:09 +00:00
|
|
|
key = MENU_EXIT; /* Fake an exit */
|
2004-07-05 14:30:17 +00:00
|
|
|
break;
|
2004-10-19 18:00:41 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FM_PRESET_ACTION
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ACTION:
|
2004-10-19 22:50:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2 | BUTTON_REPEAT:
|
|
|
|
#endif
|
|
|
|
case MENU_ENTER | BUTTON_REPEAT: /* long gives options */
|
2004-10-19 18:00:41 +00:00
|
|
|
{
|
|
|
|
bool ret;
|
2004-07-05 14:30:17 +00:00
|
|
|
ret = handle_radio_presets_menu();
|
|
|
|
menu_draw(m);
|
|
|
|
if(ret)
|
|
|
|
key = MENU_ATTACHED_USB;
|
|
|
|
else
|
|
|
|
key = BUTTON_NONE;
|
|
|
|
break;
|
2004-10-19 18:00:41 +00:00
|
|
|
}
|
2004-10-19 22:50:34 +00:00
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2 | BUTTON_REL:
|
2004-10-19 18:00:41 +00:00
|
|
|
#endif
|
2004-10-19 22:50:34 +00:00
|
|
|
case MENU_ENTER | BUTTON_REL:
|
|
|
|
key = MENU_ENTER; /* fake enter for short press */
|
|
|
|
break;
|
2004-10-19 09:09:27 +00:00
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2:
|
|
|
|
#endif
|
|
|
|
case MENU_ENTER: /* ignore down event */
|
2004-10-19 18:00:41 +00:00
|
|
|
/* Ignore the release events */
|
2004-10-19 22:50:34 +00:00
|
|
|
#ifdef FM_PRESET_ADD
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ADD | BUTTON_REL:
|
2004-10-19 22:50:34 +00:00
|
|
|
#endif
|
|
|
|
#ifdef FM_PRESET_ACTION
|
2004-10-19 09:09:27 +00:00
|
|
|
case FM_PRESET_ACTION | BUTTON_REL:
|
2004-10-19 22:50:34 +00:00
|
|
|
#endif
|
2004-10-19 09:09:27 +00:00
|
|
|
key = BUTTON_NONE;
|
|
|
|
break;
|
2004-07-05 14:30:17 +00:00
|
|
|
}
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
/* present a list of preset stations */
|
2004-07-05 14:30:17 +00:00
|
|
|
bool handle_radio_presets(void)
|
|
|
|
{
|
|
|
|
int result;
|
2003-05-04 02:23:18 +00:00
|
|
|
bool reload_dir = false;
|
|
|
|
|
|
|
|
if(presets_loaded)
|
|
|
|
{
|
2004-07-05 14:30:17 +00:00
|
|
|
rebuild_preset_menu();
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
/* DIY menu handling, since we want to exit after selection */
|
2004-07-05 14:30:17 +00:00
|
|
|
preset_menu = menu_init( preset_menu_items, num_presets,
|
|
|
|
handle_radio_presets_cb,
|
|
|
|
str(LANG_FM_BUTTONBAR_ADD),
|
|
|
|
str(LANG_FM_BUTTONBAR_EXIT),
|
|
|
|
str(LANG_FM_BUTTONBAR_ACTION));
|
2005-04-10 17:36:55 +00:00
|
|
|
if (curr_preset >= 0)
|
|
|
|
menu_set_cursor(preset_menu, curr_preset);
|
2004-07-05 14:30:17 +00:00
|
|
|
result = menu_show(preset_menu);
|
|
|
|
menu_exit(preset_menu);
|
2003-05-04 02:23:18 +00:00
|
|
|
if (result == MENU_SELECTED_EXIT)
|
|
|
|
return false;
|
|
|
|
else if (result == MENU_ATTACHED_USB)
|
|
|
|
reload_dir = true;
|
|
|
|
|
2004-07-05 14:30:17 +00:00
|
|
|
if (result >= 0) /* A preset was selected */
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2005-04-10 20:26:19 +00:00
|
|
|
curr_preset = menu_cursor(preset_menu);
|
|
|
|
curr_freq = presets[curr_preset].frequency;
|
2004-07-05 14:30:17 +00:00
|
|
|
radio_set(RADIO_FREQUENCY, curr_freq);
|
2004-07-12 13:28:44 +00:00
|
|
|
remember_frequency();
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
return reload_dir;
|
|
|
|
}
|
|
|
|
|
2004-07-02 07:43:49 +00:00
|
|
|
#ifndef SIMULATOR
|
2003-11-20 00:33:43 +00:00
|
|
|
static bool fm_recording_settings(void)
|
|
|
|
{
|
2003-12-31 03:13:29 +00:00
|
|
|
bool ret;
|
|
|
|
|
|
|
|
ret = recording_menu(true);
|
|
|
|
if(!ret)
|
|
|
|
{
|
2004-03-19 22:15:53 +00:00
|
|
|
if (global_settings.rec_prerecord_time)
|
|
|
|
talk_buffer_steal(); /* will use the mp3 buffer */
|
|
|
|
|
2003-12-31 03:13:29 +00:00
|
|
|
mpeg_set_recording_options(global_settings.rec_frequency,
|
|
|
|
global_settings.rec_quality,
|
|
|
|
1, /* Line In */
|
|
|
|
global_settings.rec_channels,
|
|
|
|
global_settings.rec_editable,
|
|
|
|
global_settings.rec_prerecord_time);
|
|
|
|
}
|
|
|
|
return ret;
|
2003-11-20 00:33:43 +00:00
|
|
|
}
|
2004-07-02 07:43:49 +00:00
|
|
|
#endif
|
2004-07-05 14:30:17 +00:00
|
|
|
|
|
|
|
char monomode_menu_string[32];
|
|
|
|
|
|
|
|
static void create_monomode_menu(void)
|
|
|
|
{
|
|
|
|
snprintf(monomode_menu_string, 32, "%s: %s", str(LANG_FM_MONO_MODE),
|
|
|
|
global_settings.fm_force_mono?
|
|
|
|
str(LANG_SET_BOOL_YES):str(LANG_SET_BOOL_NO));
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool toggle_mono_mode(void)
|
|
|
|
{
|
|
|
|
global_settings.fm_force_mono = !global_settings.fm_force_mono;
|
|
|
|
radio_set(RADIO_FORCE_MONO, global_settings.fm_force_mono);
|
|
|
|
settings_save();
|
|
|
|
create_monomode_menu();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
|
|
|
|
/* button preprocessor for the main menu */
|
|
|
|
int radio_menu_cb(int key, int m)
|
|
|
|
{
|
|
|
|
(void)m;
|
|
|
|
switch(key)
|
|
|
|
{
|
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2:
|
|
|
|
#endif
|
|
|
|
case MENU_ENTER:
|
|
|
|
key = BUTTON_NONE; /* eat the downpress, next menu reacts on release */
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef MENU_ENTER2
|
|
|
|
case MENU_ENTER2 | BUTTON_REL:
|
|
|
|
#endif
|
|
|
|
case MENU_ENTER | BUTTON_REL:
|
|
|
|
key = MENU_ENTER; /* fake downpress, next menu doesn't like release */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* main menu of the radio screen */
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_menu(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2004-10-19 18:00:41 +00:00
|
|
|
struct menu_item items[5];
|
2003-05-04 02:23:18 +00:00
|
|
|
int m;
|
|
|
|
bool result;
|
|
|
|
|
2004-10-19 22:50:34 +00:00
|
|
|
m = menu_init(items, 0, radio_menu_cb, NULL, NULL, NULL);
|
2004-07-05 14:30:17 +00:00
|
|
|
|
2004-10-19 08:20:38 +00:00
|
|
|
#if CONFIG_KEYPAD == ONDIO_PAD /* Ondio has no key for presets, put it in menu */
|
2004-10-19 18:00:41 +00:00
|
|
|
/* fixme: make real string table entries */
|
|
|
|
menu_insert(m, -1, ID2P(LANG_FM_BUTTONBAR_PRESETS), handle_radio_presets);
|
|
|
|
menu_insert(m, -1, ID2P(LANG_FM_BUTTONBAR_ADD), radio_add_preset);
|
2004-10-19 08:20:38 +00:00
|
|
|
#endif
|
2004-07-05 14:30:17 +00:00
|
|
|
create_monomode_menu();
|
2004-07-23 23:01:20 +00:00
|
|
|
menu_insert(m, -1, monomode_menu_string, toggle_mono_mode);
|
|
|
|
menu_insert(m, -1, ID2P(LANG_SOUND_SETTINGS), sound_menu);
|
2004-07-05 14:30:17 +00:00
|
|
|
#ifndef SIMULATOR
|
2004-07-23 23:01:20 +00:00
|
|
|
menu_insert(m, -1, ID2P(LANG_RECORDING_SETTINGS), fm_recording_settings);
|
2004-07-05 14:30:17 +00:00
|
|
|
#endif
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
result = menu_run(m);
|
|
|
|
menu_exit(m);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-05-03 02:40:09 +00:00
|
|
|
#endif
|