OSDN Git Service

[SCHEMATIC] Modify SW/MW/LW Preamp, insert galbanic-isolator replace of common-mode...
[openi2cradio/OpenI2CRadio.git] / menu_memoryfreq.c
index c1663dc..8b2a6fd 100644 (file)
 #include "power.h"
 #include "commondef.h"
 #include "eeprom.h"
+#include "backlight.h"
+#include "rencoder.h"
 
-
-void call_freqbank(unsigned char num)
+void call_freqbank(unsigned int num)
 {
     unsigned char _fm;
     unsigned char _band;
     unsigned char _userband;
-    if(num >= USER_MEMORY_NUM) return;
+    unsigned int bank = num / USER_MEMORY_NUM;
+    unsigned int n = num % USER_MEMORY_NUM;
+
+    if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
+
+    if(bank != setup.pagenum){ // Swap memory
+//        save_frequencies();
+        load_frequencies(bank, 0x00);
+    }
 
-    _fm = setup.memoryfreqs[num].fm;
-    _userband = setup.memoryfreqs[num].band;
+    _fm = freqset.memoryfreqs[n].fm;
+    _userband = freqset.memoryfreqs[n].band;
     _band = _userband & 0x1f;
     _userband = _userband >> 5;
     if(_fm) { // AM
@@ -50,18 +59,26 @@ void call_freqbank(unsigned char num)
         setup.amband = _band;
         setup.am_userbandnum = _userband;
     }
-    akc6955_chg_fm(_fm, setup.memoryfreqs[num].freq);
+    setup.memorynum = num;
+    akc6955_chg_fm(_fm, freqset.memoryfreqs[n].freq);
 }
 
 
-void set_freqbank(unsigned char num)
+void set_freqbank(unsigned int num)
 {
     unsigned char _fm;
     unsigned char _band;
     unsigned char _userband;
     unsigned int _freq;
+    unsigned int bank = num / USER_MEMORY_NUM;
+    unsigned int n = num % USER_MEMORY_NUM;
+
+    if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
 
-    if(num >= USER_MEMORY_NUM) return;
+     if(bank != setup.pagenum){ // Save now bank, and load using bank
+        save_frequencies();
+        load_frequencies(bank, 0x00);
+    }
 
     _fm = setup.fm;
     _freq = setup.amfreq;
@@ -72,43 +89,79 @@ void set_freqbank(unsigned char num)
         _band = setup.fmband;
         _freq = setup.fmfreq;
     }
-    setup.memoryfreqs[num].fm = _fm;
-    setup.memoryfreqs[num].band = (_userband << 5) | (_band & 0x1f);
-    setup.memoryfreqs[num].freq = _freq;
+    freqset.memoryfreqs[n].fm = _fm;
+    freqset.memoryfreqs[n].band = (_userband << 5) | (_band & 0x1f);
+    freqset.memoryfreqs[n].freq = _freq;
+
+    save_frequencies();
 }
 
 
 void on_call_userfreq(void)
 {
-    unsigned int val = USER_MEMORY_NUM;
+    unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     _CLS();
-    _LOCATE(0,0);
-    printstr("Mem: 00-");
-    print_numeric_nosupress(USER_MEMORY_NUM - 1, 2);
-    val = read_numeric(val, 2, 4, 1);
+//    _LOCATE(0,0);
+    printstr("Mem: 000-");
+    print_numeric_nosupress(val - 1, 3);
+    val = read_numeric(val, 3, 4, 1);
+    if(val >= 0x80000000) return;
     call_freqbank(val);
 }
 
 void on_set_userfreq(void)
 {
-    unsigned int val = USER_MEMORY_NUM;
+    unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     unsigned char n;
     unsigned char c;
     _CLS();
-    _LOCATE(0,0);
-    printstr("Set Mem: 00-");
-    print_numeric_nosupress(USER_MEMORY_NUM - 1, 2);
-    val = read_numeric(val, 2, 4, 1);
+//    _LOCATE(0,0);
+    printstr("Set Mem: 000-");
+    print_numeric_nosupress(val - 1, 3);
+    val = read_numeric(val, 3, 4, 1);
+    if(val >= 0x80000000) return;
     _HOME();
-    _LOCATE(0,0);
-    printstr("OK? A=OK       ");
-    do {
-           n = pollkeys(pollkeybuf, 19, 1);
-    } while(n == 0);
-    c = pollkeybuf[0];
+//    _LOCATE(0,0);
+    printstr("OK? A=OK        ");
+    c = pollkey_single();
     if(c != charcode_a) return;
     set_freqbank(val);
-    save_eeprom();
+//    save_eeprom();
+}
+
+static void disp_updown_lcd(void)
+{
+      //         _LOCATE(0,0);
+       printstr("CH:");
+       print_numeric_nosupress(setup.memorynum, 3);
+       printstr(" HELP=F");
+       update_status();
+       print_freq(1);
+       _HOME();
+
+}
+
+static unsigned char renc_updown_userfreq(unsigned char dispf)
+{
+    unsigned int count;
+    count = renc_count;
+
+    if((renc_dir == RENC_NONE) || (count == 0)) return dispf;
+    if(renc_dir == RENC_RIGHT) {
+        setup.memorynum += count;
+    } else if(renc_dir == RENC_LEFT) {
+        setup.memorynum = (setup.memorynum +
+                USER_MEMORY_NUM * USER_MEMORY_BANKS) - count;
+    } else {
+        return dispf;
+    }
+    setup.memorynum = setup.memorynum  % (USER_MEMORY_NUM * USER_MEMORY_BANKS);
+    rencoder_start();
+    call_freqbank(setup.memorynum);
+    backlight_reset(charcode_f);
+    dispf = backlight_dec(0x00);
+    disp_updown_lcd();
+    return dispf;
 }
 
 void on_updown_userfreq(void)
@@ -117,9 +170,13 @@ void on_updown_userfreq(void)
     unsigned char _fm;
     unsigned char _band;
     unsigned char _userband;
-    unsigned char n;
     unsigned char c;
-
+    unsigned char dispf = 0xff;
+    unsigned int _ui_idle = setup.ui_idlecount / 23;
+    unsigned char _ui_pad = setup.ui_idlecount % 23;
+    unsigned char changef = 0x00;
+    
+    if(_ui_idle == 0) _ui_idle = 1;
     _fm = setup.fm;
     _freq = setup.amfreq;
     _userband = setup.am_userbandnum;
@@ -131,54 +188,86 @@ void on_updown_userfreq(void)
     }
 
     _CLS();
-    _LOCATE(0,0);
-    printstr("CH: ");
-    print_numeric_nosupress(setup.memorynum, 2);
-    update_status();
-    print_freq(1);
-    _HOME();
     do {
-       do {
-           n = pollkeys(pollkeybuf, 19, 1);
-       } while(n == 0);
-       c = pollkeybuf[0];
+       dispf = renc_updown_userfreq(dispf);
+       if(dispf != 0)  {
+           disp_updown_lcd();
+       }
+       c = pollkey_single_timeout(_ui_idle, 1); // 23*41 = 943ms
+       backlight_reset(c);
+       dispf = backlight_dec(dispf);
+
+
        switch(c) {
-           case charcode_8: // UP CH
+           case charcode_7: // UP 1CH
                 setup.memorynum++;
-                if(setup.memorynum >= USER_MEMORY_NUM) setup.memorynum = 0;
-                call_freqbank(setup.memorynum);
-                break;
-           case charcode_2: // Down CH
-                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM;
-                setup.memorynum--;
-                call_freqbank(setup.memorynum);
+                changef = 0xff;
                 break;
+           case charcode_1: // Down 1CH
+                changef = 0xff;
+               setup.memorynum = setup.memorynum + (USER_MEMORY_NUM * USER_MEMORY_BANKS) - 1;
+               break;
+           case charcode_9: // Up CH FAST
+                changef = 0xff;
+               setup.memorynum += 100;
+               break;
+           case charcode_3: // Down CH FAST
+               changef = 0xff;
+               setup.memorynum = setup.memorynum + (USER_MEMORY_NUM * USER_MEMORY_BANKS) - 100;
+               break;
+           case charcode_8: // Up CH MID
+               changef = 0xff;
+               setup.memorynum += USER_MEMORY_NUM;
+               break;
+           case charcode_2: // Down CH MID
+               changef = 0xff;
+               setup.memorynum = setup.memorynum + (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM;
+               break;
+            case charcode_5: // Recall
+               changef = 0xff;
+               break;
             case charcode_d: // Reset
-                if(_fm) { // AM
+               if(_fm) { // AM
                     setup.fmband = _band;
                     setup.fm_userbandnum = _userband;
                     setup.fmfreq = _freq;
-                } else {
+               } else {
                     setup.amband = _band;
                     setup.am_userbandnum = _userband;
                     setup.amfreq = _freq;
-                }
-                akc6955_chg_fm(_fm, _freq);
-                break;
-           case charcode_5: // exit
+               }
+               akc6955_chg_fm(_fm, _freq);
+               break;
+           case charcode_4:
+               on_call_userfreq();
+               break;
+           case charcode_6:
+               on_set_userfreq();
+               break;
            case charcode_a:
                 goto _l0;
                 break;
+           case charcode_f:
+               userfreq_help();
+               _CLS();
+               break;
+           case charcode_e: // Set Light
+               if(dispf == 0x00){
+                   dispf = 0xff;
+               } else {
+                   dispf = 0x00;
+               }
+               break;
            default:
                break;
            }
-//        _HOME();
-        _LOCATE(0,0);
-       printstr("CH: ");
-       print_numeric_nosupress(setup.memorynum, 2);
-       update_status();
-       print_freq(1);
-       _HOME();
+
+          setup.memorynum = setup.memorynum % (USER_MEMORY_NUM * USER_MEMORY_BANKS);
+           if(changef != 0) {
+                call_freqbank(setup.memorynum);
+           }
+           if(_ui_pad != 0) idle_time_ms(_ui_pad); // Pad 9ms, 1Loop = 1000ms.
+           changef = 0;
     } while(1);
 _l0:
     _CLS();