OSDN Git Service

[UI][LCD][DISP] Save _LOCATE() calling and change _LOCATE(0,0), _LOCATE(0,1) to _LOCA...
[openi2cradio/OpenI2CRadio.git] / menu_userband.c
index ebc2438..d6a99d9 100644 (file)
@@ -72,43 +72,29 @@ void call_userband(unsigned char num)
 
 void set_userband(void)
 {
-    unsigned long from,to, tmp;
+    unsigned long from,to;
     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){
+    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;
-        if(from > to){
-            tmp = to;
-            to = from;
-            from = tmp;
-        }
-        userband.fm_usrbands[c].start = (from - 3000) / 80;
-        userband.fm_usrbands[c].stop = (to - 3000) / 80 + 1;
-        userband.fm_usrbands[c].freq = from;
-        setup.fm_userbandnum = c;
     } else {
         mode3k = userband.am_usrbands[c].mode3k;
         pp = 96; // 3*32
@@ -116,41 +102,84 @@ void set_userband(void)
         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;
-        if(from > to){
-            tmp = to;
-            to = from;
-            from = tmp;
+        _LOCATE(10,0);
+        if(mode3k == 0){
+            printstr("5K  ");
+        } else {
+            printstr("3K  ");
         }
-        userband.am_usrbands[c].start = from / pp;
-        userband.am_usrbands[c].stop = to  / pp + 1;
+    }
+
+    _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 = from;
+        userband.am_usrbands[c].freq = freq;
         setup.am_userbandnum = c;
     }
     save_userbands();
@@ -187,3 +216,41 @@ _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