*/
#include "menu.h"
+#include "menu_memoryfreq.h"
+#include "power.h"
+#include "commondef.h"
+#include "backlight.h"
void toggle_amfm(void)
{
- if(fm != 0){
- fm = 0;
-// akc6955_chg_fm(fm);
-// akc6955_set_amband(amband);
-// akc6955_set_freq(amfreq);
+ unsigned int freq;
+ if(setup.fm != 0){
+ setup.fm = 0;
+ setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
+ // akc6955_set_amband(amband);
+ freq = setup.amfreq_bank[setup.amband];
} else {
- fm = 0xff;
-// akc6955_chg_fm(fm);
+ setup.fm = 0xff;
+ setup.amfreq_bank[setup.amband] = setup.amfreq;
// akc6955_set_fmband(fmband);
-// akc6955_set_freq(fmfreq);
+ freq = setup.fmfreq_bank[setup.fmband];
}
+ akc6955_chg_fm(setup.fm, freq);
+ idle_time_ms(500);
+// akc6955_set_freq(freq);
}
-void set_volume(void)
+
+
+void set_stereomode(void)
{
+ __bitops_t mode;
+ mode.byte = 0x00;
+ if(setup.stereo == 0x00){
+ mode.b0 = 1; // Force mono
+ } else if(setup.stereo < 0x80){
+ mode.b1 = 1; // Force stereo
+ }
+ akc6955_set_stereomode(mode.byte);
}
-void scan_start(void)
+void set_stereo(void)
+{
+
+ if(setup.stereo == 0xff) {// Force Mono
+ setup.stereo = 0x00;
+ } else if(setup.stereo == 0x00) { //Mono->Stereo
+ setup.stereo = 0x7f;
+ } else { // Default, Stereo->auto
+ setup.stereo = 0xff;
+ }
+ set_stereomode();
+}
+
+
+void set_volume(void)
{
- unsigned char input_flag;
unsigned char c;
+ unsigned char d;
+ unsigned char fact;
+ unsigned char dispf = 0xff;
+ _CLS();
do {
- if(scanflag == 0){
- // New Scan
- _CLS();
- printstr("Scan A=ABORT");
- _LOCATE(0,1);
- printstr("U=6, D=4");
- do {
- input_flag = readkey_compare();
- idle(0xff80);
- } while(input_flag == 0);
- c = pop_keyinfifo();
- if(c == charcode_6){
- akc6955_do_scan(0xff);
- } else if(c == charcode_4){
- akc6955_do_scan(0);
+ if(dispf != 0) {
+ _LOCATE(0,0);
+ d = akc6955_getvolumemode();
+ if(d == 0){
+ _PUTCHAR('D');
} else {
- break;
+ _PUTCHAR('K');
}
- scanflag = 0xff;
+ printstr(" Vol:");
+ print_numeric_nosupress(setup.volume, 2);
+ printstr(" F:Exit");
+ _LOCATE(0,1);
+ printstr("Pre:");
+ _PUTCHAR('0' + (setup.prevolume & 3));
+ _LOCATE(16-4, 1);
+ if(setup.lowboost == 0x00){
+ printstr(" ");
+ } else {
+ printstr("LOW");
+ }
+ _HOME();
+ }
+ c = pollkey_single_timeout(41, 1); // 943ms
+ backlight_reset(c);
+ dispf = backlight_dec(dispf);
+
+ switch(c) {
+ case charcode_6:
+ setup.volume++;
+ if(setup.volume > 63) setup.volume = 63;
+ akc6955_setvolume(setup.volume);
+ break;
+ case charcode_4:
+ setup.volume--;
+ if(setup.volume < 23) setup.volume = 23;
+ akc6955_setvolume(setup.volume);
+ break;
+ case charcode_f:
+ _CLS();
+ return;
+ case charcode_a:
+ fact = 0xff;
+ if(d != 0){
+ fact = 0x00;
+ }
+ akc6955_setvolumemode(fact);
+ akc6955_setvolume(setup.volume);
+ break;
+ case charcode_b:
+ setup.prevolume++;
+ if(setup.prevolume > 3) setup.prevolume = 0;
+ akc6955_set_prevolume(setup.prevolume);
+ akc6955_setvolume(setup.volume);
+ break;
+ case charcode_d:
+ fact = 0x00;
+ if(setup.lowboost == 0x00){
+ fact = 0xff;
+ }
+ setup.lowboost = fact;
+ akc6955_set_lowboost(setup.lowboost);
+ akc6955_setvolume(setup.volume);
+ break;
+ default:
+ break;
+ }
+ if(setup.volume < 24){
+ set_examp_mute(1);
} else {
- do {
- input_flag = readkey_compare();
- idle(0xff80);
- } while(input_flag == 0);
- c = pop_keyinfifo();
+ set_examp_mute(0);
+ }
+ idle_time_ms(9); // Pad.
+ } while(1);
+}
- if(c == charcode_a){
- akc6955_abort_scan();
- break;
- } else if(c == charcode_4){
- akc6955_abort_scan();
- akc6955_do_scan(0);
- continue;
- } else if(c == charcode_6){
- akc6955_abort_scan();
- akc6955_do_scan(0xff);
- continue;
+
+void scan_start(void)
+{
+ unsigned char c;
+ unsigned char cc;
+ unsigned char n;
+ _CLS();
+ scanflag = 0;
+ do {
+ do {
+ c = pollkey_single_timeout(20, 0) ; // 23*20 = 460ms
+ if(chk_powerbutton() != 0) shutdown(1);
+ update_status();
+ cc = ' ';
+ if((akc6955_chk_donescan() == 0) && (scanflag != 0)){
+ cc = '>';
}
- if(akc6955_chk_donescan() != 0) break;
- }
- idle(0xff00);
+ _PUTCHAR(cc);
+ printstr("Scan A/4/6/F");
+ print_freq(1);
+ _HOME();
+ } while(c == charcode_null);
+ // New Scan
+ switch(c){
+ case charcode_6:
+ scanflag = 0xff;
+ akc6955_do_scan(0xff);
+ break;
+ case charcode_4:
+ scanflag = 0xff;
+ akc6955_do_scan(0);
+ break;
+ case charcode_a:
+ akc6955_abort_scan();
+ goto _l0;
+ break;
+ case charcode_f:
+ goto _l0;
+ break;
+ default:
+ break;
+ }
} while(1);
- scanflag=0;
+_l0:
_CLS();
- update_status();
- update_display();
}
void setfreq_direct(void)
{
unsigned int val;
_CLS();
- if(fm != 0){
+ _LOCATE(0,0);
+ printstr("Set Freq:");
+ _LOCATE(0,1);
+ if(setup.fm != 0){
// FM
- _LOCATE(0,0);
- printstr("Set Freq:FM");
- val = fmfreq;
+ printstr("FM ");
+ val = setup.fmfreq;
val = read_numeric(val, 5, 7, 1);
- fmfreq = val;
- //akc6955_set_freq(val);
+ setup.fmfreq = val;
} else {
// FM
- _LOCATE(0,0);
- printstr("Set Freq:AM");
- val = amfreq;
+ printstr("AM ");
+ val = setup.amfreq;
val = read_numeric(val, 5, 7, 1);
- amfreq = val;
- //akc6955_set_freq(val);
+ setup.amfreq = val;
}
+ akc6955_set_freq(val);
}
void setband_direct(void)
{
unsigned int band;
+ unsigned int freq;
_CLS();
_LOCATE(0,0);
- if(fm != 0){
- printstr("Set Band:FM");
- band = fmband & 7;
- band = read_numeric(band, 2, 7, 1);
- akc6955_set_fmband(band);
- akc6955_do_tune();
- idle(0xff00);
+ if(setup.fm != 0){
+ printstr("Set Band:FM#");
+ band = setup.fmband & 7;
+ setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
+ setup.fmband = read_numeric(band, 2, 7, 1);
+ setup.fmfreq = setup.fmfreq_bank[setup.fmband];
+ akc6955_set_fmband(setup.fmband);
+ freq = setup.fmfreq;
} else {
- printstr("Set Band:AM");
- band = amband & 0x1f;
- band = read_numeric(band, 2, 7, 1);
- akc6955_set_amband(band);
- akc6955_do_tune();
+ printstr("Set Band:AM#");
+ band = setup.amband & 0x1f;
+ setup.amfreq_bank[setup.amband] = setup.amfreq;
+ setup.amband = read_numeric(band, 2, 7, 1);
+ setup.amfreq = setup.amfreq_bank[setup.amband];
+ switch(band) {
+ case AKC6955_BAND_LW:
+ case AKC6955_BAND_MW2:
+ setup.am_mode3k = 0xff;
+ break;
+ case AKC6955_BAND_MW1:
+ case AKC6955_BAND_MW3:
+ case AKC6955_BAND_MW4:
+ setup.am_mode3k = 0x00;
+ break;
+ default:
+ break;
+ }
+
+ akc6955_set_amband(setup.amband);
+ freq = setup.amfreq;
}
- idle(0xff00);
- update_status();
- update_display();
+ akc6955_do_tune();
+ akc6955_set_freq(freq);
}
void call_userband(unsigned char num)
{
unsigned int freq;
unsigned int ch;
+ unsigned char start;
+ unsigned char end;
+ unsigned char mode3k;
+ unsigned char freq2;
+ _userband_t *p;
+
if(num >= USER_BAND_NUM) return;
- if(fm != 0){
- freq = fm_usrbands[num].freq;
- ch = ((freq - 3000) / 25) * 10;
- akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
- fm_usrbands[num].mode3k);
- } else {
- unsigned int p = 5;
- if(am_usrbands[num].mode3k != 0) p = 3;
- freq = am_usrbands[num].freq;
- ch = freq / p;
- akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
- am_usrbands[num].mode3k);
+
+ p = &(setup.am_usrbands[num]);
+ if(setup.fm != 0){
+ p = &(setup.fm_usrbands[num]);
}
- if(fm != 0) {
- fmband = AKC6955_BAND_AMUSER;
+ freq = p->freq;
+ start = p->start;
+ end = p->stop;
+ mode3k = p->mode3k;
+ if(setup.fm != 0) {
+ ch = ((freq - 3000) / 5) * 2;
+ setup.fmband = AKC6955_BAND_FMUSER;
} else {
- amband = AKC6955_BAND_AMUSER;
+ unsigned int q = 5;
+ if(mode3k != 0) q = 3;
+ ch = freq / q;
+ setup.amband = AKC6955_BAND_AMUSER;
+ }
+
+ if(start > end) {
+ unsigned char tmp;
+ tmp = start;
+ start = end;
+ end = tmp;
+ }
+
+ freq2 = ch / 32;
+ if(freq2 > end) {
+ ch = end * 32;
}
- idle(0xff00);
- update_status();
- update_display();
+ if(freq2 < start){
+ ch = start * 32;
+ }
+ akc6955_set_userband(start, end, ch, mode3k);
}
void set_userband(void)
{
unsigned int from,to;
unsigned char c;
- unsigned char p;
+ unsigned char pp;
unsigned char mode3k;
- unsigned int input_flag;
char cc;
_CLS();
_LOCATE(0,0);
printstr("User ch:");
- do {
- input_flag = readkey_compare();
- idle(0xff80);
- } while(input_flag == 0);
- c = pop_keyinfifo();
+ c = pollkey_single();
if(c > charcode_0) return;
if(c < charcode_1) return;
c = c - charcode_1 + 1;
}
if(c >= USER_BAND_NUM) return;
- if(fm != 0){
- from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
- to = fm_usrbands[c].stop * 80 + 3000;
+
+ if(setup.fm != 0){
+ from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
+ to = setup.fm_usrbands[c].stop * 80 + 3000;
_CLS();
_LOCATE(0,0);
- printstr("FM #");
+ _LOCATE(0,0);
+ printstr("FM#");
print_numeric_nosupress(c, 1);
+ _LOCATE(0,1);
printstr(" From:");
from = read_numeric(from, 5, 7, 1);
- _CLS();
- _LOCATE(0,0);
- printstr("FM #");
- print_numeric_nosupress(c, 1);
- printstr(" To:");
+ _LOCATE(0,1);
+ printstr(" To: ");
to = read_numeric(to, 5, 7, 1);
- fm_usrbands[c].start = (from - 3000) / 80;
- fm_usrbands[c].stop = (to - 3000) / 80;
- fm_usrbands[c].freq = from * 80 + 3000;
- fm_userbandnum = c;
+ setup.fm_usrbands[c].start = (from - 3000) / 80;
+ setup.fm_usrbands[c].stop = (to - 3000) / 80;
+ setup.fm_usrbands[c].freq = from * 80 + 3000;
+ setup.fm_userbandnum = c;
} else {
- mode3k = am_usrbands[c].mode3k;
- p = 96; // 3*32
- if(mode3k == 0) p = 160; // 5*32
- from = am_usrbands[c].start * p;
- to = am_usrbands[c].stop * p;
+ mode3k = setup.am_usrbands[c].mode3k;
+ pp = 96; // 3*32
+ if(mode3k == 0) pp = 160; // 5*32
+ from = setup.am_usrbands[c].start * pp;
+ to = setup.am_usrbands[c].stop * pp;
_CLS();
_LOCATE(0,0);
- printstr("AM #");
+ printstr("AM#");
print_numeric_nosupress(c, 1);
printstr(" Step:");
_LOCATE(0,1);
printstr("0=3k 1=5k");
- do {
- input_flag = readkey_compare();
- idle(0xff80);
- } while(input_flag == 0);
- cc = pop_keyinfifo();
-
+ cc = pollkey_single();
if(cc == charcode_0){
- p = 96;
+ pp = 96;
mode3k = 0xff;
} else if(cc = charcode_1) {
- p = 160;
+ pp = 160;
mode3k = 0;
}
_CLS();
_LOCATE(0,0);
- printstr("AM #");
+ printstr("AM#");
print_numeric_nosupress(c, 1);
+ _LOCATE(0,1);
printstr(" From:");
from = read_numeric(from, 5, 7, 1);
- _CLS();
- _LOCATE(0,0);
- printstr("AM #");
- print_numeric_nosupress(c, 1);
- printstr(" To:");
+ _LOCATE(0,1);
+ printstr(" To: ");
to = read_numeric(to, 5, 7, 1);
- am_usrbands[c].start = from / p;
- am_usrbands[c].stop = to / p;
- am_usrbands[c].mode3k = mode3k;
- am_usrbands[c].freq = from * p;
- am_userbandnum = c;
+ setup.am_usrbands[c].start = from / pp;
+ setup.am_usrbands[c].stop = to / pp;
+ setup.am_usrbands[c].mode3k = mode3k;
+ setup.am_usrbands[c].freq = from * pp;
+ setup.am_userbandnum = c;
}
call_userband(c);
+ _CLS();
}
void input_userband(void)
{
unsigned char c;
- unsigned char input_flag;
do{
- _CLS();
- _LOCATE(0,0);
- printstr("User Band");
- _LOCATE(0,1);
- printstr(" #");
- do {
- input_flag = readkey_compare();
- idle(0xff80);
- } while(input_flag == 0);
- c = pop_keyinfifo();
+ c = printhelp_2lines("User Band", " #");
- if((c >= charcode_a) && (c <= charcode_f)){
- break;
- }
- if(c == charcode_0) {
- _PUTCHAR('0');
- if(fm != 0){
- fm_userbandnum = 0;
- } else {
- am_userbandnum = 0;
- }
- call_userband(0);
- } else {
- c = c - charcode_1 + 1;
- if(c < USER_BAND_NUM) {
- _PUTCHAR(c + '0');
- if(fm != 0){
- fm_userbandnum = c;
+
+ if((c >= charcode_a) && (c <= charcode_f)){
+ break;
+ }
+ if(c == charcode_0) {
+ _PUTCHAR('0');
+ if(setup.fm != 0){
+ setup.fm_userbandnum = 0;
+ } else {
+ setup.am_userbandnum = 0;
+ }
+ call_userband(0);
+ } else {
+ c = c - charcode_1 + 1;
+ if(c < USER_BAND_NUM) {
+ _PUTCHAR(c + '0');
+ if(setup.fm != 0){
+ setup.fm_userbandnum = c;
} else {
- am_userbandnum = c;
+ setup.am_userbandnum = c;
}
call_userband(c);
}
- }
- idle(0xff00);
+ }
+ idle(setup.ui_idlecount);
} while(1);
_CLS();
}
+
+void menu_poweroff(void)
+{
+ unsigned char c;
+ c = printhelp_2lines("Poweroff", "A=Yes");
+ if(c == charcode_a) {
+ shutdown(1);
+ }
+}
+
+void setup_akc6955(void)
+{
+ akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
+ akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
+ if(setup.fm == 0) {
+ akc6955_set_amband(setup.amband);
+ if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
+ setup.amfreq = setup.amfreq_bank[setup.amband];
+ akc6955_chg_fm(0, setup.amfreq); // Set to AM
+ akc6955_set_freq(setup.amfreq);
+ } else {
+ akc6955_set_fmband(setup.fmband);
+ if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
+ setup.fmfreq = setup.fmfreq_bank[setup.fmband];
+ akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
+ akc6955_set_freq(setup.fmfreq);
+ }// Dummy, TBS (954KHz)
+ akc6955_set_power(0xff); // Power ON
+ akc6955_setvolume(36); // Temporally
+ akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
+ akc6955_set_thresh_amcnr(setup.threshold_amcnr);
+ akc6955_set_thresh_width(setup.threshold_width);
+ akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
+ akc6955_setvolumemode(0);
+ akc6955_set_lowboost(setup.lowboost);
+ set_stereomode();
+}
+
+void menu_save(void)
+{
+ unsigned char c;
+ c = printhelp_2lines("Save settings", "A=Yes");
+ if(c == charcode_a) {
+ save_eeprom();
+ }
+}
+
+void menu_load(void)
+{
+ unsigned char c;
+ c = printhelp_2lines("Load settings", "A=Yes B=Init");
+ if(c == charcode_a) {
+ c = load_eeprom();
+ if( c != 0xff) {
+ _CLS();
+ _LOCATE(0,0);
+ c = printhelp_2lines("X) Load Error", "A=Fix");
+ setdefault();
+ if(c == charcode_a){
+ save_eeprom();
+ }
+ }
+ setup_akc6955();
+ } else if(c == charcode_b){
+ setdefault();
+ setup_akc6955();
+ }
+}
+
+void setup_menu(void)
+{
+ unsigned char c;
+ unsigned int val;
+
+ c = printhelp_2lines("Setup F=HELP", "5=Return");
+ switch(c){
+ case charcode_3:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("BL Level:");
+ val = read_numeric(setup.backlight_level, 3, 0,1);
+ if(val > 255) val = 255;
+ if(val < 10) val = 15;
+ setup.backlight_level = (unsigned char)val;
+ break;
+ case charcode_4:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("FM Bandwidth:");
+ akc6955_get_fmbandwidth(val);
+ val = read_numeric(val, 1, 0, 1) & 3;
+ setup.fmbandwidth = (unsigned char)val;
+ akc6955_set_fmbandwidth(setup.fmbandwidth);
+ break;
+ case charcode_5:
+ break;
+ case charcode_7:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("FM-CNR threshold:");
+ val = setup.threshold_fmcnr;
+ val = read_numeric(val, 1, 0, 1);
+ akc6955_set_thresh_fmcnr((unsigned char)val);
+ break;
+ case charcode_8:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("AM-CNR threshold:");
+ val = setup.threshold_amcnr;
+ val = read_numeric(val, 1, 0, 1);
+ akc6955_set_thresh_amcnr((unsigned char)val);
+ break;
+ case charcode_9:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("Stereo threshold:");
+ val = setup.threshold_fmstereo;
+ val = read_numeric(val, 1, 0, 1);
+ akc6955_set_thresh_fmstereo((unsigned char)val);
+ break;
+ case charcode_0:
+ menu_poweroff();
+ break;
+ case charcode_a:
+ menu_load();
+ break;
+ case charcode_c:
+ menu_save();
+ break;
+ case charcode_d:
+ setdefault();
+ break;
+ case charcode_e:
+ _CLS();
+ _LOCATE(0,0);
+ printstr("BL Long:");
+ val = read_numeric(setup.backlight_long, 3, 0,1);
+ if(val > 999) val = 999;
+ setup.backlight_long = val;
+ break;
+ case charcode_f:
+ setup_help();
+ break;
+ default:
+ break;
+ }
+}
/*
* Main Menu : initial-screen -> 'F'.
*/
void main_menu(void)
{
unsigned char c;
- unsigned char p;
- unsigned char n;
- unsigned int input_flag;
- _CLS();
- _HOME();
- _LOCATE(0,0);
- printstr("Menu:F=HELP");
- _LOCATE(0,1);
- printstr("B=CANCEL");
- do {
- n = pollkeys(pollkeybuf, 60, 1);
- } while(n == 0);
- p = 0;
- c = pollkeybuf[0];
- if(c == charcode_f){
- // HELP
- } else if(c == charcode_b){
- // Cancel
- } else if(c == charcode_1){
- // Reserve
- } else if(c == charcode_2){
+ unsigned int val;
+
+ printhelp_2lines("Menu:F=HELP", "B=CANCEL");
+ c = pollkey_single(); // 1012ms
+ if(c == charcode_1){
// Band
-// setband_direct();
+ setband_direct();
} else if(c == charcode_3){
// Band
setfreq_direct();
- } else if(c == charcode_a){
- // fm
- toggle_amfm();
- } else if(c == charcode_5){
+ }else if(c == charcode_4){
+ on_call_userfreq();
+ // Scan
+ }else if(c == charcode_5){
+ // scan_start();
+ // Scan
+ }else if(c == charcode_6){
+ on_set_userfreq();
// Scan
- } else if(c == charcode_6){
- // Set gain
} else if(c == charcode_7){
- // Set volume
+ menu_poweroff();
} else if(c == charcode_8){
- // Set sensitivity
+ // Set volume
+ set_volume();
} else if(c == charcode_9){
+ _CLS();
+ _LOCATE(0,0);
+ printstr("Sig width:");
+ val = setup.threshold_width;
+ val = read_numeric(val, 1, 0, 1);
+ akc6955_set_thresh_width((unsigned char)val);
// Set NF
} else if(c == charcode_0){
// Setup Menu
- } else if(c == charcode_d){
- // Call userband
- // input_userband();
+ setup_menu();
+ } else if(c == charcode_a){
+ toggle_amfm();
} else if(c == charcode_c){
// Set userband
- // set_userband();
- } else if(c == charcode_e){
- // Reserve
+ set_userband();
+ } else if(c == charcode_d){
+ // Call userband
+ input_userband();
+ } else if (c == charcode_f){
+ mainmenu_help();
+ // HELP
}
_CLS();
_LOCATE(0,0);