OSDN Git Service

[USERBAND] Fix correct? tuning process.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 15:26:59 +0000 (00:26 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Sun, 7 Jul 2013 15:26:59 +0000 (00:26 +0900)
akc6955.c
menu.c
ui_updown.c

index 76952ed..6dc7a00 100644 (file)
--- a/akc6955.c
+++ b/akc6955.c
@@ -350,20 +350,31 @@ void akc6955_set_freq(unsigned int freq)
     __bitops_t f;
     __bitops_t mode3k;
     unsigned char band;
+    unsigned int start, stop;
 
     f.byte = akc6955_readcmd(AKC6955_POWER);
     if(f.b6) { // FM
         akc6955_get_fmband(band);
 //        band &= 7;
-        if(freq <  fmbands[band].start) freq = fmbands[band].start;
-        if(freq >= fmbands[band].end)   freq = fmbands[band].end - 1;
+        if(band == AKC6955_BAND_FMUSER){
+            start = fm_usrbands[fm_userbandnum].start * 32;
+            stop = fm_usrbands[fm_userbandnum].stop * 32;
+        } else {
+            start = fmbands[band].start;
+            stop = fmbands[band].end;
+        }
         ch = freq - 3000;
         ch = (ch * 4) / 10;
     } else {
         akc6955_get_amband(band);
 //        if(band >= AKC6955_BAND_AMEND) band = AKC6955_BAND_AMEND - 1;
-        if(freq <  ambands[band].start) freq = ambands[band].start;
-        if(freq >= ambands[band].end)   freq = ambands[band].end - 1;
+        if(band == AKC6955_BAND_AMUSER){
+            start = am_usrbands[am_userbandnum].start * 32;
+            stop = am_usrbands[am_userbandnum].stop * 32;
+        } else {
+            start = ambands[band].start;
+            stop = ambands[band].end;
+        }
         mode3k.byte = akc6955_readcmd(AKC6955_CNR_AM);
         if(band == AKC6955_BAND_MW2) {
             ch = (freq / 9) * 3; // See datasheet.
@@ -375,6 +386,8 @@ void akc6955_set_freq(unsigned int freq)
             ch = freq / 5;
         }
     }
+    if(freq <  start) freq = start;
+    if(freq >= stop)   freq = stop - 1;
     akc6955_set_tune(mode3k.b7, ch);
 }
 
diff --git a/menu.c b/menu.c
index 13257cb..2e7dfe0 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -104,6 +104,7 @@ void set_stereomode(void)
 
 void set_stereo(void)
 {
+    
     if(stereo == 0xff) {// Force Mono
         stereo = 0x00;
     } else if(stereo == 0x00) { //Mono->Stereo
@@ -157,6 +158,7 @@ void set_volume(void)
                  if(volume < 23) volume = 23;
                  break;
              case charcode_f:
+                 _CLS();
                  return;
              case charcode_a:
                  fact = 0xff;
@@ -220,7 +222,7 @@ void scan_start(void)
        } else {
            if((scanflag != 0) && (akc6955_chk_donescan() != 0)) {
                 scanflag = 0;
-                _LOCATE(0,0);
+                _HOME();
                 printstr("Scan F/A/4/6");
                 update_status();
                 print_freq(1);
@@ -262,15 +264,21 @@ void setband_direct(void)
     if(fm != 0){
         printstr("Set Band:FM#");
         band = fmband & 7;
+        fmfreq_bank[fmband] = amfreq;
         fmband = read_numeric(band, 2, 7, 1);
         akc6955_set_fmband(fmband);
         akc6955_do_tune();
+        fmfreq = fmfreq_bank[fmband];
+        akc6955_set_freq(fmfreq);
     } else {
         printstr("Set Band:AM#");
         band = amband & 0x1f;
+        amfreq_bank[amband] = amfreq;
         amband = read_numeric(band, 2, 7, 1);
+        amfreq = amfreq_bank[amband];
         akc6955_set_amband(amband);
         akc6955_do_tune();
+        akc6955_set_freq(amfreq);
     }
 }
 
@@ -278,22 +286,45 @@ void call_userband(unsigned char num)
 {
     unsigned int freq;
     unsigned int ch;
+    unsigned char start;
+    unsigned char end;
+    unsigned char mode3k;
+    unsigned char freq2;
+
     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);
-        fmband = AKC6955_BAND_AMUSER;
+        ch = ((freq - 3000) / 5) * 2;
+        start = fm_usrbands[num].start;
+        end = fm_usrbands[num].stop;
+        mode3k = fm_usrbands[num].mode3k;
+        fmband = AKC6955_BAND_FMUSER;
     } 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);
+        start = am_usrbands[num].start;
+        end = am_usrbands[num].stop;
+        mode3k = am_usrbands[num].mode3k;
         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;
+    }
+    if(freq2 < start){
+        ch = start * 32;
+    }
+    akc6955_set_userband(start, end, ch, mode3k);
 }
 
 void set_userband(void)
@@ -322,12 +353,14 @@ void set_userband(void)
         to = fm_usrbands[c].stop * 80 + 3000;
         _CLS();
         _LOCATE(0,0);
+        _LOCATE(0,0);
         printstr("FM#");
         print_numeric_nosupress(c, 1);
+        _LOCATE(0,1);
         printstr(" From:");
         from = read_numeric(from, 5, 7, 1);
-        _LOCATE(6,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;
@@ -358,10 +391,11 @@ void set_userband(void)
         _LOCATE(0,0);
         printstr("AM#");
         print_numeric_nosupress(c, 1);
+        _LOCATE(0,1);
         printstr(" From:");
         from = read_numeric(from, 5, 7, 1);
-        _LOCATE(6, 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;
@@ -370,6 +404,7 @@ void set_userband(void)
         am_userbandnum = c;
     }
     call_userband(c);
+    _CLS();
 }
 
 void input_userband(void)
index 6e7cfdb..b447f2e 100644 (file)
@@ -80,25 +80,39 @@ static void setband_updown(unsigned char updown)
     unsigned char band;
     if(fm == 0){  // MW
         band = amband + 1;
+        if(amband == AKC6955_BAND_AMUSER){
+            am_usrbands[am_userbandnum].freq = amfreq;
+        }
         amfreq_bank[amband] = amfreq;
         if(updown == 0) { // down
             if(band <= 1) {
-                band = AKC6955_BAND_AMEND + 1;
+                band = AKC6955_BAND_AMEND - 1;
             }
             band -= 2;
         }
         amband = band;
+        if(amband == AKC6955_BAND_AMUSER){
+//            amfreq = am_usrbands[am_userbandnum].freq;
+            call_userband(am_userbandnum);
+        }
         setfreq_updown_amsub();
     } else { // FM
+        if(fmband == AKC6955_BAND_FMUSER){
+            fm_usrbands[fm_userbandnum].freq = fmfreq;
+        }
         band = fmband + 1;
         fmfreq_bank[fmband] = fmfreq;
         if(updown == 0) { // down
             if(band <= 1) {
-                band = AKC6955_BAND_FMEND + 1;
+                band = AKC6955_BAND_FMEND - 1;
             }
             band -= 2;
         }
         fmband = band;
+        if(fmband == AKC6955_BAND_FMUSER){
+   //         fmfreq = fm_usrbands[fm_userbandnum].freq;
+            call_userband(fm_userbandnum);
+        }
         setfreq_updown_fmsub();
     }
 }