OSDN Git Service

[UI][USERBAND][SAVE] Save userbands to external eeprom.
[openi2cradio/OpenI2CRadio.git] / menu_userband.c
index c55d4cd..49fcb1a 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,49 +40,39 @@ 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 = &(userband.am_usrbands[num]);
     if(setup.fm != 0){
         p = &(userband.fm_usrbands[num]);
-    }
-    freq = p->freq;
-    start = p->start;
-    end = p->stop;
-    mode3k = p->mode3k;
-    if(setup.fm != 0) {
+        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);
 }
 
 void set_userband(void)
 {
-    unsigned long from,to;
+    unsigned long from,to, tmp;
     unsigned char c;
     unsigned char pp;
     unsigned char mode3k;
@@ -110,8 +100,13 @@ void set_userband(void)
         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;
+        userband.fm_usrbands[c].stop = (to - 3000) / 80 + 1;
         userband.fm_usrbands[c].freq = from;
         setup.fm_userbandnum = c;
     } else {
@@ -147,12 +142,18 @@ void set_userband(void)
         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.am_usrbands[c].start = from / pp;
-        userband.am_usrbands[c].stop = to  / pp;
+        userband.am_usrbands[c].stop = to  / pp + 1;
         userband.am_usrbands[c].mode3k = mode3k;
         userband.am_usrbands[c].freq = from;
         setup.am_userbandnum = c;
     }
+    save_userbands();
     call_userband(c);
 _l0:
     _CLS();
@@ -161,33 +162,26 @@ _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;
+    char 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');
+            c = c % 10;
+            _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();
 }