📄 radio.c
字号:
#include "..\bu2624\bu2624.h"
#include "..\bu1923\bu1923.h"
#include "..\main.h"
#include <iom163.h>
#include "..\io.h"
#include <eeprom.h>
extern NV_SETTINGS gps;
extern unsigned int freq;
extern unsigned char g_ui_tmp_msg_cnt;
extern unsigned char is_autosearching;
extern unsigned char search_ok;
extern unsigned char search_dir;
extern unsigned char autosrch_step;
extern unsigned char station_no;
extern unsigned char *err_msg;
extern unsigned int radio_count;
extern unsigned char radio_is_muted;
extern unsigned char is_stereo;
extern unsigned int info;
unsigned char store_bit;
#ifdef SGJM_RDS
extern unsigned char rds_display_type;
extern unsigned char rds_dis_string[65];
extern unsigned char pty_is_searching;
extern unsigned char rds_status;
extern RDS_DATA_STRUCT rds_data;
//#define pty_dis_type rds_dis_string[0]
//#define pty_search_type rds_dis_string[1]
//#define pty_search_delay rds_dis_string[2]
#endif
extern unsigned char Mchvol;
extern unsigned char amfm_flag,station_no,display_type;
extern unsigned char uicc_code,last_key;
void save_fre(void)
{
if(amfm_flag)
{
EEPROM_WRITE((int)&(gps.ps_amfre),freq);
}
else
{
EEPROM_WRITE((int)&(gps.ps_fmfre),freq);
}
}
unsigned char find_station_no(void)
{
unsigned char i;
unsigned int val;
if(amfm_flag)
{
for(i=0;i<MAX_AM_STATION;i++)
{
EEPROM_READ((int)&gps.ps_am_station[i],val);
if(val == freq)
return i;
};
return 255;
}
else
{
for(i=0;i<MAX_FM_STATION;i++)
{
EEPROM_READ((int)&gps.ps_fm_station[i],val);
if(val==freq)
return i;
};
return 255;
}
}
void radio_action(void)
{
unsigned char i;
switch(uicc_code)
{
case UICC_EJECT:
display_type = DISPLAY_VERSION;
g_ui_tmp_msg_cnt = 20;
break;
#ifdef SGJM_RDS
case RD_DISPLAY:
if(amfm_flag) break;
#ifdef RDS_SW
if(get_rds_sw()) break;
#endif
if(uicc_code == last_key)
{
rds_status = 0;
rds_display_type = (rds_display_type + 1)%5;
for(i=0;i<65;i++)
rds_dis_string[i] = ' ';
if(rds_display_type == DIS_PS_NAME)
{
rds_init();
open_rds();
}
else if(rds_display_type == DIS_FREQUENCY)
close_rds();
};
switch(rds_display_type)
{
case DIS_PS_NAME:
err_msg = "PS NAME";
break;
case DIS_PTY:
pty_is_searching = 0;
err_msg = " PTY";
break;
case DIS_RT:
err_msg = " RT";
break;
case DIS_CT:
err_msg = " CT";
break;
case DIS_FREQUENCY:
err_msg = " FREQ";
break;
}
display_type = ERROR_MSG;
g_ui_tmp_msg_cnt = 10;
// rds_msg_detect_cnt = 25;
// printf("begin rds key\n");
break;
case RD_SEARCH:
if(amfm_flag) break;
#ifdef RDS_SW
if(get_rds_sw()) break;
#endif
//judge the first pressed pty search
if(pty_is_searching==0)
{
pty_is_searching = 1;
//g_ui_tmp_msg_cnt = 15;
if(rds_display_type!=DIS_FREQUENCY)
{
if(rds_data.syc_flag)
{
pty_search_type = (unsigned char)((rds_data.B_word>>5)&0x001f);
if((pty_search_type!=PTY_ALARM)&&(pty_search_type>PTY_OTHER_M))
{
pty_search_type = PTY_NONE;
};
}
else
pty_search_type = PTY_NONE;
}
else
{
rds_init();
open_rds();
pty_search_type = PTY_NONE;
};
rds_display_type = DIS_PTY;
display_type = rds_display_type;
}
// else if(pty_is_searching==2) //the 3rd
// {
// pty_is_searching = 0;
// is_autosearching = 0;
// }
else if(pty_is_searching == 1) //the 2rd
{
pty_is_searching = 2;
search_ok = 0;
search_dir = 1;
is_autosearching = 1;
autosrch_step = AUTOSRCH_STEP5;
g_ui_tmp_msg_cnt = 0;
pty_search_delay = 30;
};
break;
#endif
case RD_AUTO_SEARCH_F:
//case RD_FP_SEARCH_F:
#ifdef SGJM_RDS
//if(pty_is_searching) break;
#endif
display_type = DIS_FREQUENCY;
g_ui_tmp_msg_cnt = 0;
search_ok = 0;
search_dir = 1;
autosrch_step = AUTOSRCH_STEP5;
is_autosearching = 1;
break;
case RD_AUTO_SEARCH_R:
#ifdef SGJM_RDS
//if(pty_is_searching) break;
#endif
display_type = DIS_FREQUENCY;
search_ok = 0;
search_dir = 0;
autosrch_step = AUTOSRCH_STEP5;
is_autosearching = 1;;
g_ui_tmp_msg_cnt = 0;
//turnauto_serach
break;
case RD_FMAM:
is_autosearching = 0;
radio_is_muted = 1;
mute_radio();
#ifdef SGJM_RDS
close_rds();
rds_display_type = 0;
#endif
if(amfm_flag)
{
amfm_flag = 0;
}
else
{
amfm_flag = 1;
};
EEPROMwrite((int)&(gps.ps_amfm_flag),amfm_flag);
init_radio();
break;
case RD_UP:
if(display_type == RADIO_STORE)
{
if(amfm_flag)
radio_count = radio_count%MAX_AM_STATION;
else
radio_count = radio_count%MAX_FM_STATION;
radio_count = radio_count+1;
g_ui_tmp_msg_cnt = 30;
break;
}
#ifdef SGJM_RDS
if(pty_is_searching == 1)
{
if(pty_search_type == PTY_ALARM)
pty_search_type = PTY_NONE;
else if(pty_search_type == PTY_OTHER_M)
pty_search_type = PTY_ALARM;
else
pty_search_type++;
}
#endif
break;
case RD_DOWN:
if(display_type == RADIO_STORE)
{
if(radio_count >0)
radio_count = radio_count-1;
else
{
if(amfm_flag)
radio_count = MAX_AM_STATION;
else
radio_count = MAX_FM_STATION;
};
g_ui_tmp_msg_cnt = 30;
break;
}
#ifdef SGJM_RDS
if(pty_is_searching == 1)
{
if(pty_search_type == PTY_ALARM)
pty_search_type = PTY_OTHER_M;
else if(pty_search_type == PTY_NONE)
pty_search_type = PTY_ALARM;
else
pty_search_type--;
}
#endif
break;
case RD_STEP_B:
search_dir = 0;
tuner_handsearch();
save_fre();
break;
case RD_STEP_F:
//is_autosearching = 0;
search_dir = 1;
tuner_handsearch();
save_fre();
break;
case RD_STOP:
if(
#ifdef SGJM_RDS
pty_is_searching
||
#endif
is_autosearching)
{
#ifdef SGJM_RDS
pty_is_searching = 0;
#endif
radio_is_muted = 1;
mute_radio();
is_autosearching = 0;
switch_fmam();
delay_ms(500);
radio_is_muted = 0;
mute_radio();
//display_type = rds_display_type;
g_ui_tmp_msg_cnt = 2;
};
break;
case RD_AUDIO:
if(!amfm_flag)
{
if(is_stereo)
is_stereo = 0;
else
is_stereo = 1;
switch_audio_channel();
};
break;
case RD_SKIPB:
is_autosearching = 0;
g_ui_tmp_msg_cnt = 10;
if(amfm_flag)
{
if( station_no == 0 )
station_no = MAX_AM_STATION-1;
else
station_no--;
EEPROMwrite((int)&(gps.ps_am_no),station_no);//ps_update_radio(PS_UPDATE_AM_NO);
EEPROM_READ((int)&gps.ps_am_station[station_no],freq);
}
else
{
if( station_no == 0 )
station_no = MAX_FM_STATION-1;
else
station_no--;
EEPROMwrite((int)&(gps.ps_fm_no),station_no);
EEPROM_READ((int)&gps.ps_fm_station[station_no],freq);
};
save_fre();
init_radio();
display_type = DIS_FREQUENCY;
break;
case RD_SKIPF:
//if(is_search_all_station||is_autosearching) brea
is_autosearching = 0;
g_ui_tmp_msg_cnt = 10;
if(amfm_flag)
{
station_no=(station_no+1)%MAX_AM_STATION;
EEPROMwrite((int)&(gps.ps_am_no),station_no);
EEPROM_READ((int)&gps.ps_am_station[station_no],freq);
}
else
{
station_no=(station_no+1)%MAX_FM_STATION;
EEPROMwrite((int)&(gps.ps_fm_no),station_no);
EEPROM_READ((int)&gps.ps_fm_station[station_no],freq);
}
save_fre();
init_radio();
display_type = DIS_FREQUENCY;
break;
case RD_STORE:
if(is_autosearching) break;
if(display_type != RADIO_STORE)
{
// flashtime = 0;
display_type = RADIO_STORE;
radio_count = station_no+2;
if(amfm_flag)
{
if(radio_count>MAX_AM_STATION)
radio_count = 1;
}
else
{
if(radio_count>MAX_FM_STATION)
radio_count = 1;
}
g_ui_tmp_msg_cnt = 20;
//store_bit = 0;
}
else
{
if(radio_count!=0)
{
station_no=radio_count-1;
if(amfm_flag)
{
EEPROM_WRITE((int)&gps.ps_am_station[station_no],freq);
EEPROMwrite((int)&gps.ps_am_no,station_no);
}
else
{
EEPROM_WRITE((int)&gps.ps_fm_station[station_no],freq);
EEPROMwrite((int)&gps.ps_fm_no,station_no);
}
};
g_ui_tmp_msg_cnt=1;
}
break;
case RD_9:
case RD_8:
case RD_7:
case RD_6:
case RD_5:
case RD_4:
case RD_3:
case RD_2:
case RD_1:
case RD_0:
g_ui_tmp_msg_cnt = 20 ; //30s
if((display_type != DISPLAY_DIGIT)&&(display_type!=RADIO_STORE)) //first
{
display_type = DISPLAY_DIGIT;
radio_count = 0;
};
if(radio_count >= 6000) break;
radio_count *= 10;
radio_count += (uicc_code-RD_0);
if(display_type == RADIO_STORE)
{
if(amfm_flag)
{
if(radio_count > MAX_AM_STATION)
radio_count = radio_count / 10;
}
else
{
if(radio_count > MAX_FM_STATION)
radio_count = radio_count / 10;
}
}
break;
case RD_CLEAR:
if(display_type==RADIO_STORE)
radio_count = 0;
else
radio_count /= 10;
g_ui_tmp_msg_cnt = 20;
break;
case RD_ENTER:
//is_autosearching = 0;
if(display_type != DISPLAY_DIGIT) break;
if((radio_count>=AMreq_MIN)&&(radio_count<=AMreq_MAX))
{
amfm_flag = 1;
freq = radio_count;
station_no = find_station_no();
if(station_no!=255)
{
EEPROMwrite((int)&(gps.ps_am_no),station_no);
};
#ifdef SGJM_RDS
close_rds();
rds_display_type = 0;
#endif
radio_is_muted = 1;
mute_radio();
delay_ms(500);
switch_fmam();
delay_ms(500);
radio_is_muted =0;
mute_radio();
save_fre();
EEPROMwrite((int)&(gps.ps_amfm_flag),amfm_flag);
}
else if((radio_count>=FMreq_MIN)&&(radio_count<=FMreq_MAX))
{
amfm_flag = 0;
freq = radio_count;
station_no = find_station_no();
if(station_no!=255)
{
EEPROMwrite((int)&(gps.ps_fm_no),station_no);
};
radio_is_muted = 1;
mute_radio();
delay_ms(500);
switch_fmam();
delay_ms(500);
radio_is_muted = 0;
mute_radio();
save_fre();
EEPROMwrite((int)&(gps.ps_amfm_flag),amfm_flag);
}
else
{
if(radio_count!=0)
{
radio_count--;
if(amfm_flag)
{
if(radio_count < MAX_AM_STATION)
{
station_no = radio_count;
EEPROMwrite((int)&(gps.ps_am_no),station_no);
EEPROM_READ((int)&gps.ps_am_station[station_no],freq);
save_fre();
init_radio();
}
/*else
{
display_type = RADIO_ERR_MENU;
g_ui_tmp_msg_cnt = 20;
};*/
}
else
{
if(radio_count < MAX_FM_STATION)
{
station_no = radio_count;
EEPROMwrite((int)&(gps.ps_fm_no),station_no);
EEPROM_READ((int)&gps.ps_fm_station[station_no],freq);
save_fre();
init_radio();
}
/*else
{
radio_menu_id = RADIO_ERR_MENU;
g_ui_tmp_msg_cnt = 20;
};*/
}
}
}
g_ui_tmp_msg_cnt = 1;
break;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -