⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 radio.c

📁 编译后直接运行的MP3播放器全部C语言源代码 一个包含FAT文件系统、系统引导 Boot、FLASH Driver等内容的
💻 C
📖 第 1 页 / 共 2 页
字号:
                break;        }        peak_meter_peek();        if(!screen_freeze)        {            lcd_setmargins(0, 8);                        /* Only display the peak meter when not recording */            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);            }                        if(TIME_AFTER(current_tick, timeout))            {                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;                }            }                        seconds = mpeg_recorded_time() / HZ;                        if(update_screen || seconds > last_seconds)            {                last_seconds = seconds;                                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);                if(mpeg_status() == MPEG_STATUS_RECORD)                {                    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);                }                else                {                    snprintf(buf, 32, "%s %02d",                             str(LANG_RECORD_PRERECORD), seconds%60);                    lcd_puts(0, top_of_screen + 3, buf);                }                                /* Only force the redraw if update_screen is true */                status_draw(update_screen);                                buttonbar_draw();                                lcd_update();                                update_screen = false;            }        }        if(mpeg_status() & MPEG_STATUS_ERROR)        {            done = true;        }    }        if(mpeg_status() & MPEG_STATUS_ERROR)    {        status_set_playmode(STATUS_STOP);        splash(0, true, str(LANG_DISK_FULL));        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);    fmradio_set_status(0);    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;}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;}void radio_save_presets(void){    int fd;    int i;        fd = creat(default_filename, O_WRONLY);    if(fd >= 0)    {        for(i = 0;i < MAX_PRESETS;i++)        {            fprintf(fd, "%d:%s\n", presets[i].frequency, presets[i].name);        }        close(fd);    }    else    {        splash(HZ*2, true, str(LANG_FM_PRESET_SAVE_FAILED));    }}void radio_load_presets(void){    int fd;    int rc;    char buf[128];    char *freq;    char *name;    bool done = false;    int i;    if(!presets_loaded)    {        memset(presets, 0, sizeof(presets));            fd = open(default_filename, O_RDONLY);        if(fd >= 0)        {            i = 0;            while(!done && i < MAX_PRESETS)            {                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);        }    }    presets_loaded = true;}bool radio_preset_select(void){    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;                /* 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 */            m = menu_init( menu, num_presets );            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;                radio_set_frequency(curr_freq);            }        }        else        {            splash(HZ*2, true, str(LANG_FM_NO_PRESETS));        }    }    return reload_dir;}static bool radio_add_preset(void){    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;            radio_save_presets();        }    }    else    {        splash(HZ*2, true, str(LANG_FM_NO_FREE_PRESETS));    }    return true;}bool radio_delete_preset(void){    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;                /* 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 */        m = menu_init( menu, num_presets );        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;            radio_save_presets();        }    }    return reload_dir;}static bool fm_recording_settings(void){    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;}bool radio_menu(void){    struct menu_items radio_menu_items[] = {        { 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 }    };    int m;    bool result;    m = menu_init( radio_menu_items,                   sizeof radio_menu_items / sizeof(struct menu_items) );    result = menu_run(m);    menu_exit(m);    return result;}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -