OSDN Git Service

[Schematic] Add another type: Using plain AKC6955.
[openi2cradio/OpenI2CRadio.git] / menu_userband.c
index 15bf293..06f7dc4 100644 (file)
@@ -31,7 +31,7 @@
 #include "power.h"
 #include "commondef.h"
 #include "backlight.h"
-
+#include "eeprom_util.h"
 
 void call_userband(unsigned char num)
 {
@@ -40,43 +40,33 @@ void call_userband(unsigned char num)
     unsigned char start;
     unsigned char end;
     unsigned char mode3k;
-    unsigned char freq2;
+    unsigned int q;
     _userband_t *p;
 
     if(num >= USER_BAND_NUM) return;
 
-    p = &(setup.am_usrbands[num]);
     if(setup.fm != 0){
-        p = &(setup.fm_usrbands[num]);
-    }
-    freq = p->freq;
-    start = p->start;
-    end = p->stop;
-    mode3k = p->mode3k;
-    if(setup.fm != 0) {
+        p = &(userband.fm_usrbands[num]);
+        freq = p->freq;
+        mode3k = 0;
         ch = ((freq - 3000) / 5) * 2;
         setup.fmband = AKC6955_BAND_FMUSER;
+        setup.fmfreq = freq;
     } else {
-        unsigned int q = 5;
+        p = &(userband.am_usrbands[num]);
+        freq = p->freq;
+        mode3k = p->mode3k;
+        q = 5;
         if(mode3k != 0) q = 3;
         ch = freq / q;
         setup.amband = AKC6955_BAND_AMUSER;
+        setup.amfreq = freq;
+        setup.am_mode3k = mode3k;
     }
+    start = p->start;
+    end = p->stop;
 
-    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);
 }
 
@@ -86,73 +76,113 @@ void set_userband(void)
     unsigned char c;
     unsigned char pp;
     unsigned char mode3k;
-    char cc;
+    unsigned int freq;
+    unsigned int _from, _to, tmp;
+    unsigned char cc;
+    unsigned char fm = setup.fm;
 
     _CLS();
-    _LOCATE(0,0);
+//    _LOCATE(0,0);
     c = 0;
     printstr("User ch:");
     c = pollkey_numeric(c);
-    if(c >= USER_BAND_NUM) return;
+    if(c >= USER_BAND_NUM) goto _l0;
 
-    if(setup.fm != 0){
-        from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
-        to = setup.fm_usrbands[c].stop * 80 + 3000;
+    if(fm != 0){
+        from = userband.fm_usrbands[c].start * 80 + 3000; // 32*25/10
+        to = userband.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);
-        if((from & 0x80000000) != 0) goto _l0;
-        _LOCATE(0,1);
-        printstr(" To:  ");
-        to = read_numeric(to, 5, 7, 1);
-        if((to & 0x80000000) != 0) goto _l0;
-        setup.fm_usrbands[c].start = (from - 3000) / 80;
-        setup.fm_usrbands[c].stop = (to - 3000) / 80;
-        setup.fm_usrbands[c].freq = from;
-        setup.fm_userbandnum = c;
     } else {
-        mode3k = setup.am_usrbands[c].mode3k;
+        mode3k = userband.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;
+        from = userband.am_usrbands[c].start * pp;
+        to = userband.am_usrbands[c].stop * pp;
         _CLS();
-        _LOCATE(0,0);
+//        _LOCATE(0,0);
         printstr("AM#");
         print_numeric_nosupress(c, 1);
         printstr(" Step:");
-        _LOCATE(0,1);
+        if(mode3k == 0){
+            printstr("5K->");
+        } else {
+            printstr("3K->");
+        }
+        _LOCATE_0_1();
         printstr("0=3k 1=5k");
         cc = pollkey_single();
         if(cc == charcode_0){
             pp = 96;
             mode3k = 0xff;
-        } else if(cc = charcode_1) {
+        } else if(cc == charcode_1) {
             pp = 160;
             mode3k = 0;
+        } else {
+            goto _l0;
         }
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM#");
-        print_numeric_nosupress(c, 1);
-        _LOCATE(0,1);
-        printstr(" From:");
-        from = read_numeric(from, 5, 7, 1);
-        if((from & 0x80000000) != 0) goto _l0;
-        _LOCATE(0,1);
-        printstr(" To:  ");
-        to = read_numeric(to, 5, 7, 1);
-        if((to & 0x80000000) != 0) goto _l0;
-        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;
+        _LOCATE(10,0);
+        if(mode3k == 0){
+            printstr("5K  ");
+        } else {
+            printstr("3K  ");
+        }
+    }
+
+    _LOCATE_0_1();
+    printstr("From:");
+    from = read_numeric(from, 5, 7, 1);
+    if((from & 0xffff0000) != 0) goto _l0;
+    _LOCATE_0_1();
+    printstr("To:  ");
+    to = read_numeric(to, 5, 7, 1);
+    if((to & 0xffff0000) != 0) goto _l0;
+
+    _from = (unsigned int)from;
+    _to = (unsigned int)to;
+    if(_from > _to){
+         tmp = _to;
+         _to = _from;
+         _from = tmp;
+    }
+    freq = (_to - _from) / 2 + _from;
+
+    _CLS();
+    if(fm != 0){
+        printstr("FM");
+    } else {
+        printstr("AM");
+    }
+    _PUTCHAR('#');
+    _PUTCHAR('0' + c);
+    printstr(" A=OK");
+    _LOCATE_0_1();
+    print_numeric_nosupress(_from, 5);
+    printstr("->");
+    print_numeric_nosupress(_to, 5);
+    cc = pollkey_single();
+    if(cc != charcode_a) goto _l0;
+    if(fm != 0)
+    {
+        if((_from <= 3000) || (_from >= 28000)) goto _l0;
+        if((_to <= 3000) || (_to >= 28000)) goto _l0;
+        userband.fm_usrbands[c].start = (_from - 3000) / 80;
+        userband.fm_usrbands[c].stop = (_to - 3000) / 80 + 1;
+        userband.fm_usrbands[c].freq = freq;
+        userband.fm_usrbands[c].mode3k = 0;
+        setup.fm_userbandnum = c;
+    } else {
+        if((_from <100) || (_from >= 28000)) goto _l0;
+        if((_to < 100) || (_to >= 28000)) goto _l0;
+        userband.am_usrbands[c].start = _from / pp;
+        userband.am_usrbands[c].stop = _to  / pp + 1;
+        userband.am_usrbands[c].mode3k = mode3k;
+        userband.am_usrbands[c].freq = freq;
         setup.am_userbandnum = c;
     }
+    save_userbands();
     call_userband(c);
 _l0:
     _CLS();
@@ -161,33 +191,66 @@ _l0:
 void input_userband(void)
 {
     unsigned char c;
-    do{
-    c = printhelp_2lines("User Band", "   #");
-    if((c >= charcode_a) && (c <= charcode_f)){
-        break;
-    }
-    if(c == charcode_0) {
-        _PUTCHAR('0');
-        if(setup.fm != 0){
-           setup.fm_userbandnum = 0;
+    int d;
+        c = printhelp_2lines("User Band", "   #");
+        if((c > charcode_a) && (c <= charcode_f)){
+            goto _l0;
+         }
+        if(c == charcode_a){
+            d = load_userbands();
+            if(d < 0) format_userbands();
+
         } else {
-           setup.am_userbandnum = 0;
-        }
-        call_userband(0);
-    } else {
-        c = c - charcode_1 + 1;
-        if(c < USER_BAND_NUM) {
-            _PUTCHAR(c + '0');
+            if(c == charcode_0) {
+              c = 0;
+           }
+            _PUTCHAR('0' + c);
             if(setup.fm != 0){
-               setup.fm_userbandnum = c;
+                setup.fm_userbandnum = c;
             } else {
                 setup.am_userbandnum = c;
             }
             call_userband(c);
         }
-    }
-    idle(setup.ui_idlecount);
-    } while(1);
+_l0:
     _CLS();
 }
 
+void list_userband(void)
+{
+    unsigned char i;
+    unsigned char q;
+    unsigned char c;
+
+    for(i = 0; i < USER_BAND_NUM; i ++){
+        _CLS();
+        printstr("FM#");
+        _PUTCHAR('0' + i);
+        _LOCATE_0_1();
+        print_numeric_nosupress(userband.fm_usrbands[i].start * 80 + 3000, 5);
+        printstr(" to ");
+        print_numeric_nosupress(userband.fm_usrbands[i].stop * 80 + 3000, 5);
+        c = pollkey_single();
+        if(c == charcode_a) {
+            return;
+        }
+    }
+    for(i = 0; i < USER_BAND_NUM; i ++){
+        _CLS();
+        printstr("AM#");
+        _PUTCHAR('0' + i);
+        _LOCATE_0_1();
+        if(userband.am_usrbands[i].mode3k != 0){
+            q = 3 * 32;
+        } else {
+            q = 5 * 32;
+        }
+        print_numeric_nosupress(userband.am_usrbands[i].start * q, 5);
+        printstr(" to ");
+        print_numeric_nosupress(userband.am_usrbands[i].stop *  q, 5);
+        c = pollkey_single();
+        if(c == charcode_a) {
+            return;
+        }
+    }
+}
\ No newline at end of file