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"
|
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"
|
2003-05-03 02:40:09 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_FMRADIO
|
|
|
|
|
2003-11-05 09:46:08 +00:00
|
|
|
#define MAX_FREQ (108000000)
|
|
|
|
#define MIN_FREQ (87500000)
|
2003-05-03 23:56:51 +00:00
|
|
|
#define PLL_FREQ_STEP 10000
|
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;
|
2003-05-03 02:40:09 +00:00
|
|
|
static int curr_freq = 99400000;
|
|
|
|
static int pll_cnt;
|
|
|
|
|
2003-05-04 02:23:18 +00:00
|
|
|
#define MAX_PRESETS 32
|
|
|
|
static bool presets_loaded = false;
|
|
|
|
static struct fmstation presets[MAX_PRESETS];
|
|
|
|
|
2003-05-04 22:58:12 +00:00
|
|
|
static char default_filename[] = "/.rockbox/fm-presets-default.fmr";
|
|
|
|
|
2004-02-04 09:53:22 +00:00
|
|
|
int debug_fm_detection;
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_load_presets(void);
|
|
|
|
bool radio_preset_select(void);
|
|
|
|
bool radio_menu(void);
|
2003-05-04 02:23:18 +00:00
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_stop(void)
|
|
|
|
{
|
|
|
|
/* Mute the FM radio */
|
|
|
|
fmradio_set(1, 0x100003);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-12-19 01:24:02 +00:00
|
|
|
bool radio_hardware_present(void)
|
|
|
|
{
|
|
|
|
int val;
|
|
|
|
|
|
|
|
fmradio_set(2, 0x140885); /* 5kHz, 7.2MHz crystal, test mode 1 */
|
|
|
|
val = fmradio_read(0);
|
2004-02-04 09:53:22 +00:00
|
|
|
debug_fm_detection = val;
|
2003-12-19 01:24:02 +00:00
|
|
|
if(val == 0x140885)
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
void radio_set_frequency(int freq)
|
2003-05-03 02:40:09 +00:00
|
|
|
{
|
|
|
|
/* We add the standard Intermediate Frequency 10.7MHz before calculating
|
|
|
|
** the divisor
|
|
|
|
** The reference frequency is set to 50kHz, and the VCO output is prescaled
|
|
|
|
** by 2.
|
|
|
|
*/
|
|
|
|
|
2003-05-03 23:56:51 +00:00
|
|
|
pll_cnt = (freq + 10700000) / (PLL_FREQ_STEP/2) / 2;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
|
|
|
/* 0x100000 == FM mode
|
|
|
|
** 0x000002 == Microprocessor controlled Mute
|
|
|
|
*/
|
|
|
|
fmradio_set(1, 0x100002 | pll_cnt << 3);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
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 val;
|
|
|
|
int freq;
|
|
|
|
int i_freq;
|
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;
|
2003-11-06 00:47:47 +00:00
|
|
|
int last_stereo_status = false;
|
|
|
|
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);
|
2003-05-03 15:39:40 +00:00
|
|
|
fmradio_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
|
|
|
|
|
|
|
mpeg_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
|
|
|
|
2003-12-19 00:38:47 +00:00
|
|
|
mpeg_sound_channel_config(global_settings.channel_config);
|
|
|
|
mpeg_sound_set(SOUND_BASS, global_settings.bass);
|
|
|
|
mpeg_sound_set(SOUND_TREBLE, global_settings.treble);
|
|
|
|
mpeg_sound_set(SOUND_BALANCE, global_settings.balance);
|
2003-11-20 00:33:43 +00:00
|
|
|
mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
|
2003-12-19 00:38:47 +00:00
|
|
|
mpeg_sound_set(SOUND_LOUDNESS, global_settings.loudness);
|
|
|
|
mpeg_sound_set(SOUND_SUPERBASS, global_settings.bass_boost);
|
|
|
|
mpeg_sound_set(SOUND_AVC, global_settings.avc);
|
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
status_set_playmode(STATUS_STOP);
|
|
|
|
|
|
|
|
/* Yes, we use the D/A for monitoring */
|
|
|
|
peak_meter_playback(true);
|
|
|
|
|
|
|
|
peak_meter_enabled = true;
|
2003-05-03 02:40:09 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN),
|
|
|
|
mpeg_sound_default(SOUND_RIGHT_GAIN), false);
|
|
|
|
|
2003-05-03 23:56:51 +00:00
|
|
|
fmradio_set(2, 0x140884); /* 5kHz, 7.2MHz crystal */
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_set_frequency(curr_freq);
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
2003-11-06 00:47:47 +00:00
|
|
|
|
|
|
|
/* We use the A/D pseudo peak */
|
|
|
|
peak_meter_playback(false);
|
|
|
|
peak_meter_enabled = true;
|
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));
|
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 */
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_set_frequency(curr_freq);
|
2003-11-05 09:46:08 +00:00
|
|
|
sleep(1);
|
2003-05-03 02:40:09 +00:00
|
|
|
|
|
|
|
/* Start IF measurement */
|
|
|
|
fmradio_set(1, 0x100006 | pll_cnt << 3);
|
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 */
|
|
|
|
val = fmradio_read(3);
|
|
|
|
i_freq = (val & 0x7ffff) / 80;
|
|
|
|
|
|
|
|
/* Stop searching if the IF frequency is close to 10.7MHz */
|
|
|
|
if(i_freq > 1065 && i_freq < 1075)
|
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);
|
|
|
|
}
|
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)
|
|
|
|
{
|
2003-05-04 02:23:18 +00:00
|
|
|
case BUTTON_OFF:
|
2003-12-31 03:13:29 +00:00
|
|
|
if(mpeg_status() == MPEG_STATUS_RECORD)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
mpeg_stop();
|
|
|
|
status_set_playmode(STATUS_STOP);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
radio_stop();
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
update_screen = true;
|
|
|
|
break;
|
2003-05-09 00:14:59 +00:00
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
case BUTTON_F3:
|
2003-12-31 03:13:29 +00:00
|
|
|
if(mpeg_status() == MPEG_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-01-21 14:58:40 +00:00
|
|
|
mpeg_record(rec_create_filename(buf));
|
2003-12-31 03:13:29 +00:00
|
|
|
status_set_playmode(STATUS_RECORD);
|
2003-11-20 00:33:43 +00:00
|
|
|
update_screen = true;
|
|
|
|
}
|
|
|
|
last_seconds = 0;
|
2003-05-09 00:14:59 +00:00
|
|
|
break;
|
2003-11-20 00:33:43 +00:00
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
case BUTTON_ON | BUTTON_REL:
|
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;
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_set_frequency(curr_freq);
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
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;
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_set_frequency(curr_freq);
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
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++;
|
|
|
|
if(global_settings.volume > mpeg_sound_max(SOUND_VOLUME))
|
|
|
|
global_settings.volume = mpeg_sound_max(SOUND_VOLUME);
|
|
|
|
mpeg_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--;
|
|
|
|
if(global_settings.volume < mpeg_sound_min(SOUND_VOLUME))
|
|
|
|
global_settings.volume = mpeg_sound_min(SOUND_VOLUME);
|
|
|
|
mpeg_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;
|
|
|
|
|
2003-05-04 02:27:42 +00:00
|
|
|
case BUTTON_F1:
|
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);
|
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));
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
break;
|
|
|
|
|
2003-05-04 02:27:42 +00:00
|
|
|
case BUTTON_F2:
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_preset_select();
|
2003-05-04 02:23:18 +00:00
|
|
|
curr_preset = find_preset(curr_freq);
|
|
|
|
lcd_clear_display();
|
|
|
|
lcd_setmargins(0, 8);
|
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));
|
2003-11-05 09:46:08 +00:00
|
|
|
update_screen = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
break;
|
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
case BUTTON_PLAY:
|
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;
|
|
|
|
|
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 */
|
2003-12-31 03:13:29 +00:00
|
|
|
if(mpeg_status() != MPEG_STATUS_RECORD)
|
2003-11-20 00:33:43 +00:00
|
|
|
{
|
|
|
|
usb_screen();
|
|
|
|
fmradio_set_status(0);
|
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;
|
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 */
|
2003-11-20 00:33:43 +00:00
|
|
|
if(!mpeg_status())
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
|
|
|
val = fmradio_read(3);
|
|
|
|
stereo = (val & 0x100000)?true:false;
|
|
|
|
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
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
seconds = mpeg_recorded_time() / HZ;
|
|
|
|
|
|
|
|
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
|
|
|
|
2003-12-31 03:13:29 +00:00
|
|
|
if(mpeg_status() == MPEG_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
|
|
|
|
{
|
|
|
|
snprintf(buf, 32, "%s %02d",
|
|
|
|
str(LANG_RECORD_PRERECORD), seconds%60);
|
|
|
|
lcd_puts(0, top_of_screen + 3, buf);
|
|
|
|
}
|
2003-11-06 00:47:47 +00:00
|
|
|
|
|
|
|
/* Only force the redraw if update_screen is true */
|
|
|
|
status_draw(update_screen);
|
|
|
|
|
|
|
|
buttonbar_draw();
|
|
|
|
|
|
|
|
lcd_update();
|
|
|
|
|
|
|
|
update_screen = false;
|
2003-11-05 09:46:08 +00:00
|
|
|
}
|
|
|
|
}
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
if(mpeg_status() & MPEG_STATUS_ERROR)
|
|
|
|
{
|
|
|
|
done = true;
|
|
|
|
}
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
2003-05-03 15:39:40 +00:00
|
|
|
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
if(mpeg_status() & MPEG_STATUS_ERROR)
|
|
|
|
{
|
|
|
|
status_set_playmode(STATUS_STOP);
|
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();
|
|
|
|
mpeg_error_clear();
|
|
|
|
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
button = button_get(true);
|
|
|
|
if(button == (BUTTON_OFF | BUTTON_REL))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mpeg_init_playback();
|
|
|
|
|
|
|
|
mpeg_sound_channel_config(global_settings.channel_config);
|
|
|
|
mpeg_sound_set(SOUND_BASS, global_settings.bass);
|
|
|
|
mpeg_sound_set(SOUND_TREBLE, global_settings.treble);
|
|
|
|
mpeg_sound_set(SOUND_BALANCE, global_settings.balance);
|
|
|
|
mpeg_sound_set(SOUND_VOLUME, global_settings.volume);
|
|
|
|
mpeg_sound_set(SOUND_LOUDNESS, global_settings.loudness);
|
|
|
|
mpeg_sound_set(SOUND_SUPERBASS, global_settings.bass_boost);
|
|
|
|
mpeg_sound_set(SOUND_AVC, global_settings.avc);
|
|
|
|
|
2003-05-03 15:39:40 +00:00
|
|
|
fmradio_set_status(0);
|
2003-11-20 00:33:43 +00:00
|
|
|
|
|
|
|
if(keep_playing)
|
|
|
|
{
|
|
|
|
/* Enable the Left and right A/D Converter */
|
|
|
|
mpeg_set_recording_gain(mpeg_sound_default(SOUND_LEFT_GAIN),
|
|
|
|
mpeg_sound_default(SOUND_RIGHT_GAIN), false);
|
|
|
|
mas_codec_writereg(6, 0x4000);
|
|
|
|
}
|
|
|
|
return have_recorded;
|
2003-05-03 02:40:09 +00:00
|
|
|
}
|
2003-05-04 02:23:18 +00:00
|
|
|
|
|
|
|
static bool parseline(char* line, char** freq, char** name)
|
|
|
|
{
|
|
|
|
char* ptr;
|
|
|
|
|
|
|
|
while ( isspace(*line) )
|
|
|
|
line++;
|
|
|
|
|
|
|
|
if ( *line == '#' )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
ptr = strchr(line, ':');
|
|
|
|
if ( !ptr )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*freq = line;
|
|
|
|
*ptr = 0;
|
|
|
|
ptr++;
|
|
|
|
while (isspace(*ptr))
|
|
|
|
ptr++;
|
|
|
|
*name = ptr;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
for(i = 0;i < MAX_PRESETS;i++)
|
|
|
|
{
|
|
|
|
fprintf(fd, "%d:%s\n", presets[i].frequency, presets[i].name);
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
|
|
|
|
if(!presets_loaded)
|
|
|
|
{
|
|
|
|
memset(presets, 0, sizeof(presets));
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if(parseline(buf, &freq, &name))
|
|
|
|
{
|
|
|
|
presets[i].frequency = atoi(freq);
|
|
|
|
strncpy(presets[i].name, name, 27);
|
|
|
|
presets[i].name[27] = 0;
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
2003-05-04 13:05:30 +00:00
|
|
|
presets_loaded = true;
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_preset_select(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
struct menu_items menu[MAX_PRESETS];
|
|
|
|
int m, result;
|
|
|
|
int i;
|
|
|
|
bool reload_dir = false;
|
|
|
|
int num_presets;
|
|
|
|
|
|
|
|
if(presets_loaded)
|
|
|
|
{
|
|
|
|
num_presets = 0;
|
|
|
|
|
|
|
|
for(i = 0;i < MAX_PRESETS;i++)
|
|
|
|
{
|
|
|
|
if(presets[i].frequency)
|
|
|
|
{
|
|
|
|
menu[num_presets].desc = presets[i].name;
|
2004-03-14 21:33:53 +00:00
|
|
|
menu[num_presets].voice_id = -1;
|
2003-05-04 02:23:18 +00:00
|
|
|
/* We use the function pointer entry for the preset
|
|
|
|
entry index */
|
|
|
|
menu[num_presets++].function = (void *)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(num_presets)
|
|
|
|
{
|
|
|
|
/* DIY menu handling, since we want to exit after selection */
|
2004-03-12 10:20:33 +00:00
|
|
|
m = menu_init( menu, num_presets, NULL );
|
2003-05-04 02:23:18 +00:00
|
|
|
result = menu_show(m);
|
|
|
|
menu_exit(m);
|
|
|
|
if (result == MENU_SELECTED_EXIT)
|
|
|
|
return false;
|
|
|
|
else if (result == MENU_ATTACHED_USB)
|
|
|
|
reload_dir = true;
|
|
|
|
|
|
|
|
if (result >= 0)
|
|
|
|
{
|
|
|
|
i = (int)menu[result].function;
|
|
|
|
curr_freq = presets[i].frequency;
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_set_frequency(curr_freq);
|
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_PRESETS));
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reload_dir;
|
|
|
|
}
|
|
|
|
|
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];
|
|
|
|
int i = find_preset(0);
|
|
|
|
|
|
|
|
if(i >= 0)
|
|
|
|
{
|
|
|
|
memset(buf, 0, 27);
|
|
|
|
|
|
|
|
if (!kbd_input(buf, 27))
|
|
|
|
{
|
|
|
|
buf[27] = 0;
|
|
|
|
strcpy(presets[i].name, buf);
|
|
|
|
presets[i].frequency = curr_freq;
|
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;
|
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_delete_preset(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
|
|
|
struct menu_items menu[MAX_PRESETS];
|
|
|
|
int m, result;
|
|
|
|
int i;
|
|
|
|
bool reload_dir = false;
|
|
|
|
int num_presets;
|
|
|
|
|
|
|
|
if(presets_loaded)
|
|
|
|
{
|
|
|
|
num_presets = 0;
|
|
|
|
|
|
|
|
for(i = 0;i < MAX_PRESETS;i++)
|
|
|
|
{
|
|
|
|
if(presets[i].frequency)
|
|
|
|
{
|
|
|
|
menu[num_presets].desc = presets[i].name;
|
2004-03-14 21:33:53 +00:00
|
|
|
menu[num_presets].voice_id = -1;
|
2003-05-04 02:23:18 +00:00
|
|
|
/* We use the function pointer entry for the preset
|
|
|
|
entry index */
|
|
|
|
menu[num_presets++].function = (void *)i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DIY menu handling, since we want to exit after selection */
|
2004-03-12 10:20:33 +00:00
|
|
|
m = menu_init( menu, num_presets, NULL );
|
2003-05-04 02:23:18 +00:00
|
|
|
result = menu_show(m);
|
|
|
|
menu_exit(m);
|
|
|
|
if (result == MENU_SELECTED_EXIT)
|
|
|
|
return false;
|
|
|
|
else if (result == MENU_ATTACHED_USB)
|
|
|
|
reload_dir = true;
|
|
|
|
|
|
|
|
if (result >= 0)
|
|
|
|
{
|
|
|
|
i = (int)menu[result].function;
|
|
|
|
presets[i].frequency = 0;
|
2003-05-09 00:14:59 +00:00
|
|
|
radio_save_presets();
|
2003-05-04 02:23:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reload_dir;
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
bool radio_menu(void)
|
2003-05-04 02:23:18 +00:00
|
|
|
{
|
2003-11-05 09:46:08 +00:00
|
|
|
struct menu_items radio_menu_items[] = {
|
2004-03-14 21:33:53 +00:00
|
|
|
{ STR(LANG_FM_SAVE_PRESET), radio_add_preset },
|
|
|
|
{ STR(LANG_FM_DELETE_PRESET), radio_delete_preset },
|
|
|
|
{ STR(LANG_SOUND_SETTINGS), sound_menu },
|
|
|
|
{ STR(LANG_RECORDING_SETTINGS), fm_recording_settings }
|
2003-11-05 09:46:08 +00:00
|
|
|
};
|
2003-05-04 02:23:18 +00:00
|
|
|
int m;
|
|
|
|
bool result;
|
|
|
|
|
2003-05-09 00:14:59 +00:00
|
|
|
m = menu_init( radio_menu_items,
|
2004-03-12 10:20:33 +00:00
|
|
|
sizeof radio_menu_items / sizeof(struct menu_items), NULL );
|
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
|