OSDN Git Service

[UART][v2.0] Enable to shell.Work temporally.
[openi2cradio/OpenI2CRadio.git] / menu_memoryfreq.c
index 0cadf42..8b2a6fd 100644 (file)
@@ -30,7 +30,8 @@
 #include "power.h"
 #include "commondef.h"
 #include "eeprom.h"
-
+#include "backlight.h"
+#include "rencoder.h"
 
 void call_freqbank(unsigned int num)
 {
@@ -98,46 +99,84 @@ void set_freqbank(unsigned int num)
 
 void on_call_userfreq(void)
 {
-    unsigned int val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
+    unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     _CLS();
-    _LOCATE(0,0);
+//    _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 * USER_MEMORY_BANKS;
+    unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
     unsigned char n;
     unsigned char c;
     _CLS();
-    _LOCATE(0,0);
+//    _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();
 }
 
+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)
 {
     unsigned int _freq;
     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;
@@ -150,56 +189,44 @@ void on_updown_userfreq(void)
 
     _CLS();
     do {
-        _LOCATE(0,0);
-        printstr("CH:");
-        print_numeric_nosupress(setup.memorynum, 3);
-        printstr(" 8/2/A");
-        update_status();
-        print_freq(1);
-        _HOME();
-        c = pollkey_single_timeout(44, 1); // About 1s
+       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_7: // UP 1CH
                 setup.memorynum++;
-                if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
-                call_freqbank(setup.memorynum);
+                changef = 0xff;
                 break;
            case charcode_1: // Down 1CH
-               if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
-               setup.memorynum--;
-               call_freqbank(setup.memorynum);
+                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;
-               if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
-                    setup.memorynum = setup.memorynum % 100;
-               }
-               call_freqbank(setup.memorynum);
                break;
            case charcode_3: // Down CH FAST
-               if(setup.memorynum < 100) {
-                    setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
-               } else {
-                    setup.memorynum -= 100;
-               }
-               call_freqbank(setup.memorynum);
+               changef = 0xff;
+               setup.memorynum = setup.memorynum + (USER_MEMORY_NUM * USER_MEMORY_BANKS) - 100;
                break;
-           case charcode_8: // Up CH FAST
+           case charcode_8: // Up CH MID
+               changef = 0xff;
                setup.memorynum += USER_MEMORY_NUM;
-               if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
-                    setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
-               }
-               call_freqbank(setup.memorynum);
                break;
-           case charcode_2: // Down CH FAST
-               if(setup.memorynum < USER_MEMORY_NUM) {
-                    setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
-               } else {
-                    setup.memorynum -= USER_MEMORY_NUM;
-               }
-               call_freqbank(setup.memorynum);
+           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_5: // Reset
+            case charcode_d: // Reset
                if(_fm) { // AM
                     setup.fmband = _band;
                     setup.fm_userbandnum = _userband;
@@ -220,10 +247,27 @@ void on_updown_userfreq(void)
            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();
+
+          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();