OSDN Git Service

[Build] Split menu-related routines to menu.c.
authorK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 21 Jun 2013 07:26:54 +0000 (16:26 +0900)
committerK.Ohta <whatisthis.sowhat@gmail.com>
Fri, 21 Jun 2013 07:26:54 +0000 (16:26 +0900)
[UI] fix read_numeric().

main.c
menu.c [new file with mode: 0644]
menu.h [new file with mode: 0644]
nbproject/Makefile-default.mk
nbproject/Makefile-genesis.properties
nbproject/configurations.xml
ui.c
ui.h

diff --git a/main.c b/main.c
index 7aa681e..03bcb7d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -43,7 +43,7 @@
 #include "ui.h"
 #include "eeprom.h"
 #include "ioports.h"
-
+#include "menu.h"
 /*
  * Config words.
  */
@@ -121,13 +121,6 @@ unsigned char fm;
 unsigned char am_mode3k;
 unsigned char am_userbandnum;
 unsigned char fm_userbandnum;
-typedef struct {
-    unsigned char mode3k; // mode3k if am
-    unsigned char start;
-    unsigned char stop;
-    unsigned int freq;
-} _userband_t;
-#define USER_BAND_NUM 4
 _userband_t am_usrbands[USER_BAND_NUM];
 _userband_t fm_usrbands[USER_BAND_NUM];
 
@@ -300,24 +293,10 @@ unsigned char load_eeprom(void)
 }
 
 
-void toggle_amfm(void)
-{
-    if(fm != 0){
-        fm = 0;
-//        akc6955_chg_fm(fm);
-//        akc6955_set_amband(amband);
-//        akc6955_set_freq(amfreq);
-    } else {
-        fm = 0xff;
-//        akc6955_chg_fm(fm);
-//        akc6955_set_fmband(fmband);
-//        akc6955_set_freq(fmfreq);
-    }
-}
 
-static void update_status(void)
+void update_status(void)
 {
-#ifndef _LCD_DEBUG
+#if 0
         recv_signal = akc6955_read_level();
         if(fm != 0){
             fmfreq = akc6955_get_freq();
@@ -329,10 +308,6 @@ static void update_status(void)
 }
 
 
-void set_volume(void)
-{
-}
-
 void update_display(void)
 {
 //    _HOME();
@@ -396,358 +371,6 @@ void update_display(void)
     _HOME();
 }
 
-void scan_start()
-{
-    unsigned char input_flag;
-    unsigned char c;
-
-    do {
-        if(scanflag == 0){
-        // New Scan
-            _CLS();
-            printstr("Scan A=ABORT");
-            _LOCATE(0,1);
-            printstr("U=6, D=4");
-            do {
-                input_flag = readkey_compare();
-                idle(0xff80);
-            } while(input_flag == 0);
-            c = pop_keyinfifo();
-            if(c == charcode_6){
-                    akc6955_do_scan(0xff);
-            } else if(c == charcode_4){
-                    akc6955_do_scan(0);
-            } else {
-                break;
-            }
-            scanflag = 0xff;
-        } else {
-            do {
-                input_flag = readkey_compare();
-                idle(0xff80);
-            } while(input_flag == 0);
-            c = pop_keyinfifo();
-
-            if(c == charcode_a){
-                akc6955_abort_scan();
-                break;
-            } else if(c == charcode_4){
-                akc6955_abort_scan();
-                akc6955_do_scan(0);
-                continue;
-            } else if(c == charcode_6){
-                akc6955_abort_scan();
-                akc6955_do_scan(0xff);
-                continue;
-            }
-            if(akc6955_chk_donescan() != 0) break;
-        }
-        idle(0xff00);
-    } while(1);
-    scanflag=0;
-    _CLS();
-    update_status();
-    update_display();
-}
-
-void setfreq_direct(void)
-{
-    unsigned int val;
-    _CLS();
-    if(fm != 0){
-        // FM
-        _LOCATE(0,0);
-        printstr("Set Freq:FM");
-        val = fmfreq;
-        val = read_numeric(val, 5, 7, 1);
-        fmfreq = val;
-        akc6955_set_freq(val);
-    } else {
-        // FM
-        _LOCATE(0,0);
-        printstr("Set Freq:AM");
-        val = amfreq;
-        val = read_numeric(val, 5, 7, 1);
-        amfreq = val;
-        akc6955_set_freq(val);
-    }
-    idle(0xff00);
-    update_status();
-    update_display();
-}
-
-void setband_direct(void)
-{
-    unsigned int band;
-    _CLS();
-    _LOCATE(0,0);
-    if(fm != 0){
-        printstr("Set Band:FM");
-        band = fmband & 7;
-        band = read_numeric(band, 2, 7, 1);
-        akc6955_set_fmband(band);
-        akc6955_do_tune();
-        idle(0xff00);
-    } else {
-        printstr("Set Band:AM");
-        band = amband & 0x1f;
-        band = read_numeric(band, 2, 7, 1);
-        akc6955_set_amband(band);
-        akc6955_do_tune();
-    }
-    idle(0xff00);
-    update_status();
-    update_display();
-}
-
-void call_userband(unsigned char num)
-{
-    unsigned int freq;
-    unsigned int ch;
-    if(num >= USER_BAND_NUM) return;
-    if(fm != 0){
-        freq = fm_usrbands[num].freq;
-        ch = ((freq - 3000) / 25) * 10;
-        akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
-                            fm_usrbands[num].mode3k);
-    } else {
-        unsigned int p = 5;
-        if(am_usrbands[num].mode3k != 0) p = 3;
-        freq = am_usrbands[num].freq;
-        ch = freq / p;
-        akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
-                            am_usrbands[num].mode3k);
-    }
-    if(fm != 0) {
-        fmband = AKC6955_BAND_AMUSER;
-    } else {
-        amband = AKC6955_BAND_AMUSER;
-    }
-    idle(0xff00);
-    update_status();
-    update_display();
-}
-
-void set_userband(void)
-{
-    unsigned int from,to;
-    unsigned char c;
-    unsigned char p;
-    unsigned char mode3k;
-    unsigned int input_flag;
-    char cc;
-
-    _CLS();
-    _LOCATE(0,0);
-    printstr("User ch:");
-    do {
-        input_flag = readkey_compare();
-        idle(0xff80);
-    } while(input_flag == 0);
-    c = pop_keyinfifo();
-
-    if(c > charcode_0) return;
-    if(c < charcode_1) return;
-    if(c == charcode_0) {
-        c = 0;
-    } else {
-        c = c - charcode_1 + 1;
-    }
-    if(c >= USER_BAND_NUM) return;
-    if(fm != 0){
-        from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
-        to = fm_usrbands[c].stop * 80 + 3000;
-        _CLS();
-        _LOCATE(0,0);
-        printstr("FM #");
-        print_numeric_nosupress(c, 1);
-        printstr(" From:");
-        from = read_numeric(from, 5, 7, 1);
-        _CLS();
-        _LOCATE(0,0);
-        printstr("FM #");
-        print_numeric_nosupress(c, 1);
-        printstr(" To:");
-        to = read_numeric(to, 5, 7, 1);
-        fm_usrbands[c].start = (from - 3000) / 80;
-        fm_usrbands[c].stop = (to - 3000) / 80;
-        fm_usrbands[c].freq = from * 80 + 3000;
-        fm_userbandnum = c;
-    } else {
-        mode3k = am_usrbands[c].mode3k;
-        p = 96; // 3*32
-        if(mode3k == 0) p = 160; // 5*32
-        from = am_usrbands[c].start * p; 
-        to = am_usrbands[c].stop * p;
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM #");
-        print_numeric_nosupress(c, 1);
-        printstr(" Step:");
-        _LOCATE(0,1);
-        printstr("0=3k 1=5k");
-        do {
-            input_flag = readkey_compare();
-            idle(0xff80);
-        } while(input_flag == 0);
-        cc = pop_keyinfifo();
-
-        if(cc == charcode_0){
-            p = 96;
-            mode3k = 0xff;
-        } else if(cc = charcode_1) {
-            p = 160;
-            mode3k = 0;
-        }
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM #");
-        print_numeric_nosupress(c, 1);
-        printstr(" From:");
-        from = read_numeric(from, 5, 7, 1);
-        _CLS();
-        _LOCATE(0,0);
-        printstr("AM #");
-        print_numeric_nosupress(c, 1);
-        printstr(" To:");
-        to = read_numeric(to, 5, 7, 1);
-        am_usrbands[c].start = from / p;
-        am_usrbands[c].stop = to  / p;
-        am_usrbands[c].mode3k = mode3k;
-        am_usrbands[c].freq = from * p;
-        am_userbandnum = c;
-    }
-    call_userband(c);
-}
-
-void input_userband(void)
-{
-    unsigned char c;
-    unsigned char input_flag;
-    do{
-    _CLS();
-    _LOCATE(0,0);
-    printstr("User Band");
-    _LOCATE(0,1);
-    printstr("   #");
-    do {
-        input_flag = readkey_compare();
-        idle(0xff80);
-    } while(input_flag == 0);
-    c = pop_keyinfifo();
-
-    if((c >= charcode_a) && (c <= charcode_f)){
-        break;
-    }
-    if(c == charcode_0) {
-        _PUTCHAR('0');
-        if(fm != 0){
-           fm_userbandnum = 0;
-        } else {
-           am_userbandnum = 0;
-        }
-        call_userband(0);
-    } else {
-        c = c - charcode_1 + 1;
-        if(c < USER_BAND_NUM) {
-            _PUTCHAR(c + '0');
-            if(fm != 0){
-               fm_userbandnum = c;
-            } else {
-                am_userbandnum = c;
-            }
-            call_userband(c);
-        }
-    }
-    idle(0xff00);
-    } while(1);
-    _CLS();
-}
-
-
-void main_menu(void)
-{
-    unsigned char c;
-    unsigned int input_flag;
-    _CLS();
-    _LOCATE(0,0);
-    printstr("Menu:F=HELP");
-    _LOCATE(1,0);
-    printstr("A=CANCEL");
-    do{
-        do {
-            input_flag = readkey_compare();
-            idle(0xff80);
-        } while(input_flag == 0);
-
-        c = pop_keyinfifo();
-        if((c < charcode_1) || ( c > charcode_0)) {
-            idle(0xff00);
-            continue; // Error
-        }
-        if(c == charcode_f){
-            // HELP
-        } else if(c == charcode_a){
-            // Cancel
-            break;
-        } else if(c == charcode_1){
-            // AM
-            fm = 0;
-            akc6955_chg_fm(fm);
-            akc6955_set_amband(amband);
-            akc6955_set_freq(amfreq);
-            break;
-        } else if(c == charcode_2){
-            // Band
-            setband_direct();
-            break;
-        } else if(c == charcode_3){
-            // Band
-            setfreq_direct();
-            break;
-        } else if(c == charcode_4){
-            // fm
-            fm = 0xff;
-            akc6955_chg_fm(fm);
-            akc6955_set_fmband(fmband);
-            akc6955_set_freq(fmfreq);
-            break;
-        } else if(c == charcode_5){
-            // Scan
-            break;
-        } else if(c == charcode_6){
-            // Set gain
-            break;
-        } else if(c == charcode_7){
-            // Set volume
-            break;
-        } else if(c == charcode_8){
-            // Set sensitivity
-            break;
-        } else if(c == charcode_9){
-            // Set NF
-            break;
-        } else if(c == charcode_0){
-            // Setup Menu
-            break;
-        } else if(c == charcode_b){
-            // Call userband
-            input_userband();
-            break;
-        } else if(c == charcode_c){
-            // Set userband
-            set_userband();
-            break;
-        } else if(c == charcode_d){
-            // Reserve
-            break;
-        } else if(c == charcode_e){
-            // Reserve
-            break;
-        }
-        idle(0xff00);
-    } while(1);
-}
 
 void setfreq_updown(unsigned char ctlword)
 {
@@ -807,35 +430,42 @@ void setfreq_updown(unsigned char ctlword)
     //            fmfreq = akc6955_up_freq(10); // UP 100KHz
             } else {
                 amfreq += 10;
-
     //            amfreq = akc6955_up_freq(10); // UP 10KHz
             }
             break;
-        case charcode_7: // Down Fast;
+        case charcode_9: // Down Fast;
             if(fm != 0){
+                fmfreq += 50;
       //          fmfreq = akc6955_down_freq(50); // DOWN 500KHz
             } else {
+                amfreq += 50;
       //          amfreq = akc6955_down_freq(50); // DOWN 50KHz
             }
             break;
-        case charcode_9: // Down Fast;
+        case charcode_7: // Down Fast;
             if(fm != 0){
+                fmfreq -= 50;
         //        fmfreq = akc6955_up_freq(50); // UP 100KHz
             } else {
+                amfreq -= 50;
         //        amfreq = akc6955_up_freq(50); // UP 10KHz
             }
             break;
         case charcode_1: // Down Slow;
             if(fm != 0){
+                fmfreq -= 3;
         //        fmfreq = akc6955_down_freq(5); // DOWN 50KHz
             } else {
+                amfreq -= 3;
           //      amfreq = akc6955_down_freq(5); // DOWN 50KHz
             }
             break;
         case charcode_3: // Down Slow;
             if(fm != 0){
+                fmfreq += 3;
         //        fmfreq = akc6955_up_freq(5); // UP 50KHz
             } else {
+                amfreq += 3;
         //        amfreq = akc6955_up_freq(5); // UP 5KHz
             }
             break;
@@ -869,7 +499,7 @@ void setfreq_updown(unsigned char ctlword)
            }
             break;
         case charcode_f:
-            //main_menu();
+            main_menu();
             break;
         default:
             break;
diff --git a/menu.c b/menu.c
new file mode 100644 (file)
index 0000000..58bcca8
--- /dev/null
+++ b/menu.c
@@ -0,0 +1,374 @@
+/*
+ * OpenI2CRADIO
+ * Menu sub-routines.
+ * Copyright (C) 2013-06-21 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#include "menu.h"
+
+void toggle_amfm(void)
+{
+    if(fm != 0){
+        fm = 0;
+//        akc6955_chg_fm(fm);
+//        akc6955_set_amband(amband);
+//        akc6955_set_freq(amfreq);
+    } else {
+        fm = 0xff;
+//        akc6955_chg_fm(fm);
+//        akc6955_set_fmband(fmband);
+//        akc6955_set_freq(fmfreq);
+    }
+}
+
+void set_volume(void)
+{
+}
+
+void scan_start(void)
+{
+    unsigned char input_flag;
+    unsigned char c;
+
+    do {
+        if(scanflag == 0){
+        // New Scan
+            _CLS();
+            printstr("Scan A=ABORT");
+            _LOCATE(0,1);
+            printstr("U=6, D=4");
+            do {
+                input_flag = readkey_compare();
+                idle(0xff80);
+            } while(input_flag == 0);
+            c = pop_keyinfifo();
+            if(c == charcode_6){
+                    akc6955_do_scan(0xff);
+            } else if(c == charcode_4){
+                    akc6955_do_scan(0);
+            } else {
+                break;
+            }
+            scanflag = 0xff;
+        } else {
+            do {
+                input_flag = readkey_compare();
+                idle(0xff80);
+            } while(input_flag == 0);
+            c = pop_keyinfifo();
+
+            if(c == charcode_a){
+                akc6955_abort_scan();
+                break;
+            } else if(c == charcode_4){
+                akc6955_abort_scan();
+                akc6955_do_scan(0);
+                continue;
+            } else if(c == charcode_6){
+                akc6955_abort_scan();
+                akc6955_do_scan(0xff);
+                continue;
+            }
+            if(akc6955_chk_donescan() != 0) break;
+        }
+        idle(0xff00);
+    } while(1);
+    scanflag=0;
+    _CLS();
+    update_status();
+    update_display();
+}
+
+void setfreq_direct(void)
+{
+    unsigned int val;
+    _CLS();
+    if(fm != 0){
+        // FM
+        _LOCATE(0,0);
+        printstr("Set Freq:FM");
+        val = fmfreq;
+        val = read_numeric(val, 5, 7, 1);
+        fmfreq = val;
+        //akc6955_set_freq(val);
+    } else {
+        // FM
+        _LOCATE(0,0);
+        printstr("Set Freq:AM");
+        val = amfreq;
+        val = read_numeric(val, 5, 7, 1);
+        amfreq = val;
+        //akc6955_set_freq(val);
+    }
+}
+
+void setband_direct(void)
+{
+    unsigned int band;
+    _CLS();
+    _LOCATE(0,0);
+    if(fm != 0){
+        printstr("Set Band:FM");
+        band = fmband & 7;
+        band = read_numeric(band, 2, 7, 1);
+        akc6955_set_fmband(band);
+        akc6955_do_tune();
+        idle(0xff00);
+    } else {
+        printstr("Set Band:AM");
+        band = amband & 0x1f;
+        band = read_numeric(band, 2, 7, 1);
+        akc6955_set_amband(band);
+        akc6955_do_tune();
+    }
+    idle(0xff00);
+    update_status();
+    update_display();
+}
+
+void call_userband(unsigned char num)
+{
+    unsigned int freq;
+    unsigned int ch;
+    if(num >= USER_BAND_NUM) return;
+    if(fm != 0){
+        freq = fm_usrbands[num].freq;
+        ch = ((freq - 3000) / 25) * 10;
+        akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch,
+                            fm_usrbands[num].mode3k);
+    } else {
+        unsigned int p = 5;
+        if(am_usrbands[num].mode3k != 0) p = 3;
+        freq = am_usrbands[num].freq;
+        ch = freq / p;
+        akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch,
+                            am_usrbands[num].mode3k);
+    }
+    if(fm != 0) {
+        fmband = AKC6955_BAND_AMUSER;
+    } else {
+        amband = AKC6955_BAND_AMUSER;
+    }
+    idle(0xff00);
+    update_status();
+    update_display();
+}
+
+void set_userband(void)
+{
+    unsigned int from,to;
+    unsigned char c;
+    unsigned char p;
+    unsigned char mode3k;
+    unsigned int input_flag;
+    char cc;
+
+    _CLS();
+    _LOCATE(0,0);
+    printstr("User ch:");
+    do {
+        input_flag = readkey_compare();
+        idle(0xff80);
+    } while(input_flag == 0);
+    c = pop_keyinfifo();
+
+    if(c > charcode_0) return;
+    if(c < charcode_1) return;
+    if(c == charcode_0) {
+        c = 0;
+    } else {
+        c = c - charcode_1 + 1;
+    }
+    if(c >= USER_BAND_NUM) return;
+    if(fm != 0){
+        from = fm_usrbands[c].start * 80 + 3000; // 32*25/10
+        to = fm_usrbands[c].stop * 80 + 3000;
+        _CLS();
+        _LOCATE(0,0);
+        printstr("FM #");
+        print_numeric_nosupress(c, 1);
+        printstr(" From:");
+        from = read_numeric(from, 5, 7, 1);
+        _CLS();
+        _LOCATE(0,0);
+        printstr("FM #");
+        print_numeric_nosupress(c, 1);
+        printstr(" To:");
+        to = read_numeric(to, 5, 7, 1);
+        fm_usrbands[c].start = (from - 3000) / 80;
+        fm_usrbands[c].stop = (to - 3000) / 80;
+        fm_usrbands[c].freq = from * 80 + 3000;
+        fm_userbandnum = c;
+    } else {
+        mode3k = am_usrbands[c].mode3k;
+        p = 96; // 3*32
+        if(mode3k == 0) p = 160; // 5*32
+        from = am_usrbands[c].start * p;
+        to = am_usrbands[c].stop * p;
+        _CLS();
+        _LOCATE(0,0);
+        printstr("AM #");
+        print_numeric_nosupress(c, 1);
+        printstr(" Step:");
+        _LOCATE(0,1);
+        printstr("0=3k 1=5k");
+        do {
+            input_flag = readkey_compare();
+            idle(0xff80);
+        } while(input_flag == 0);
+        cc = pop_keyinfifo();
+
+        if(cc == charcode_0){
+            p = 96;
+            mode3k = 0xff;
+        } else if(cc = charcode_1) {
+            p = 160;
+            mode3k = 0;
+        }
+        _CLS();
+        _LOCATE(0,0);
+        printstr("AM #");
+        print_numeric_nosupress(c, 1);
+        printstr(" From:");
+        from = read_numeric(from, 5, 7, 1);
+        _CLS();
+        _LOCATE(0,0);
+        printstr("AM #");
+        print_numeric_nosupress(c, 1);
+        printstr(" To:");
+        to = read_numeric(to, 5, 7, 1);
+        am_usrbands[c].start = from / p;
+        am_usrbands[c].stop = to  / p;
+        am_usrbands[c].mode3k = mode3k;
+        am_usrbands[c].freq = from * p;
+        am_userbandnum = c;
+    }
+    call_userband(c);
+}
+
+void input_userband(void)
+{
+    unsigned char c;
+    unsigned char input_flag;
+    do{
+    _CLS();
+    _LOCATE(0,0);
+    printstr("User Band");
+    _LOCATE(0,1);
+    printstr("   #");
+    do {
+        input_flag = readkey_compare();
+        idle(0xff80);
+    } while(input_flag == 0);
+    c = pop_keyinfifo();
+
+    if((c >= charcode_a) && (c <= charcode_f)){
+        break;
+    }
+    if(c == charcode_0) {
+        _PUTCHAR('0');
+        if(fm != 0){
+           fm_userbandnum = 0;
+        } else {
+           am_userbandnum = 0;
+        }
+        call_userband(0);
+    } else {
+        c = c - charcode_1 + 1;
+        if(c < USER_BAND_NUM) {
+            _PUTCHAR(c + '0');
+            if(fm != 0){
+               fm_userbandnum = c;
+            } else {
+                am_userbandnum = c;
+            }
+            call_userband(c);
+        }
+    }
+    idle(0xff00);
+    } while(1);
+    _CLS();
+}
+
+/*
+ * Main Menu : initial-screen -> 'F'.
+ */
+void main_menu(void)
+{
+    unsigned char c;
+    unsigned char p;
+    unsigned char n;
+    unsigned int input_flag;
+    _CLS();
+    _HOME();
+    _LOCATE(0,0);
+    printstr("Menu:F=HELP");
+    _LOCATE(0,1);
+    printstr("B=CANCEL");
+       do {
+           n = pollkeys(pollkeybuf, 60, 1);
+       } while(n == 0);
+       p = 0;
+       c = pollkeybuf[0];
+        if(c == charcode_f){
+            // HELP
+        } else if(c == charcode_b){
+            // Cancel
+        } else if(c == charcode_1){
+            // Reserve
+        } else if(c == charcode_2){
+            // Band
+//            setband_direct();
+        } else if(c == charcode_3){
+            // Band
+            setfreq_direct();
+        } else if(c == charcode_a){
+            // fm
+            toggle_amfm();
+        } else if(c == charcode_5){
+            // Scan
+        } else if(c == charcode_6){
+            // Set gain
+        } else if(c == charcode_7){
+            // Set volume
+        } else if(c == charcode_8){
+            // Set sensitivity
+        } else if(c == charcode_9){
+            // Set NF
+        } else if(c == charcode_0){
+            // Setup Menu
+        } else if(c == charcode_d){
+            // Call userband
+  //          input_userband();
+        } else if(c == charcode_c){
+            // Set userband
+    //        set_userband();
+        } else if(c == charcode_e){
+            // Reserve
+        }
+       _CLS();
+       _LOCATE(0,0);
+}
+
diff --git a/menu.h b/menu.h
new file mode 100644 (file)
index 0000000..5cf4a30
--- /dev/null
+++ b/menu.h
@@ -0,0 +1,115 @@
+/*
+ * OpenI2CRADIO
+ * Menu sub-routines.
+ * Copyright (C) 2013-06-21 K.Ohta <whatisthis.sowhat ai gmail.com>
+ * License: GPL2+LE
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2,
+ *  or (at your option) any later version.
+ *  This library / program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *  See the GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this library; see the file COPYING. If not, write to the
+ *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
+ *  MA 02110-1301, USA.
+ *
+ *  As a special exception, if you link this(includeed from sdcc) library
+ *  with other files, some of which are compiled with SDCC,
+ *  to produce an executable, this library does not by itself cause
+ *  the resulting executable to be covered by the GNU General Public License.
+ *  This exception does not however invalidate any other reasons why
+ *  the executable file might be covered by the GNU General Public License.
+ */
+
+#ifndef MENU_H
+#define        MENU_H
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sdcc-lib.h>
+#include <pic18fregs.h> /* ONLY FOR PIC18x */
+#include <delay.h>
+
+#include "iodef.h"
+#include "idle.h"
+#include "i2c_io.h"
+#include "akc6955.h"
+#include "lcd_acm1602.h"
+#include "ui.h"
+#include "eeprom.h"
+#include "ioports.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+#define USER_BAND_NUM 4
+    typedef struct {
+        unsigned char mode3k; // mode3k if am
+        unsigned char start;
+        unsigned char stop;
+        unsigned int freq;
+    } _userband_t;
+    /*
+     * main.c
+     */
+    extern unsigned int amfreq;
+    extern unsigned int fmfreq;
+    extern unsigned char amband;
+    extern unsigned char fmband;
+    extern unsigned char fm;
+    extern unsigned char am_mode3k;
+    extern unsigned char am_userbandnum;
+    extern unsigned char fm_userbandnum;
+    extern _userband_t am_usrbands[USER_BAND_NUM];
+    extern _userband_t fm_usrbands[USER_BAND_NUM];
+
+    extern unsigned char enter_mode;
+    extern unsigned char numeric_mode;
+    extern unsigned char menu_node;
+    extern int backlight_long;
+    extern unsigned char help_flag;
+    extern int help_line;
+    extern int help_section;
+    extern int ui_language;
+    extern unsigned int ui_idlecount;
+    extern unsigned char scanflag;
+
+    extern int recv_signal;
+    extern int backlight_counter;
+    extern unsigned char backlight_level;
+    extern unsigned char pollkeybuf[33];
+
+    extern void update_display(void);
+    extern void update_status(void);
+
+    /*
+     * menu.c
+     */
+    extern void main_menu(void);
+    extern void input_userband(void);
+    extern void set_userband(void);
+    extern void call_userband(unsigned char num);
+    extern void setband_direct(void);
+    extern void setfreq_direct(void);
+    extern void scan_start(void);
+    extern void set_volume(void);
+    extern void toggle_amfm(void);
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* MENU_H */
+
index cdc5838..3760737 100644 (file)
@@ -45,11 +45,11 @@ OBJECTDIR=build/${CND_CONF}/${IMAGE_TYPE}
 DISTDIR=dist/${CND_CONF}/${IMAGE_TYPE}
 
 # Object Files Quoted if spaced
-OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o
-POSSIBLE_DEPFILES=${OBJECTDIR}/ui.o.d ${OBJECTDIR}/i2c_io.o.d ${OBJECTDIR}/main.o.d ${OBJECTDIR}/idle.o.d ${OBJECTDIR}/lcd_acm1602.o.d ${OBJECTDIR}/akc6955.o.d ${OBJECTDIR}/eeprom.o.d ${OBJECTDIR}/ioports.o.d
+OBJECTFILES_QUOTED_IF_SPACED=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o
+POSSIBLE_DEPFILES=${OBJECTDIR}/ui.o.d ${OBJECTDIR}/i2c_io.o.d ${OBJECTDIR}/main.o.d ${OBJECTDIR}/idle.o.d ${OBJECTDIR}/lcd_acm1602.o.d ${OBJECTDIR}/akc6955.o.d ${OBJECTDIR}/eeprom.o.d ${OBJECTDIR}/ioports.o.d ${OBJECTDIR}/menu.o.d
 
 # Object Files
-OBJECTFILES=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o
+OBJECTFILES=${OBJECTDIR}/ui.o ${OBJECTDIR}/i2c_io.o ${OBJECTDIR}/main.o ${OBJECTDIR}/idle.o ${OBJECTDIR}/lcd_acm1602.o ${OBJECTDIR}/akc6955.o ${OBJECTDIR}/eeprom.o ${OBJECTDIR}/ioports.o ${OBJECTDIR}/menu.o
 
 
 CFLAGS=
@@ -111,6 +111,11 @@ ${OBJECTDIR}/ioports.o: ioports.c  nbproject/Makefile-${CND_CONF}.mk
        ${RM} ${OBJECTDIR}/ioports.o 
        ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small libio18f25k22.lib libc18f.lib -c -mpic16 -p18f45k20 ioports.c  -o${OBJECTDIR}/ioports.o
        
+${OBJECTDIR}/menu.o: menu.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/menu.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small libio18f25k22.lib libc18f.lib -c -mpic16 -p18f45k20 menu.c  -o${OBJECTDIR}/menu.o
+       
 else
 ${OBJECTDIR}/ui.o: ui.c  nbproject/Makefile-${CND_CONF}.mk
        ${MKDIR} ${OBJECTDIR} 
@@ -152,6 +157,11 @@ ${OBJECTDIR}/ioports.o: ioports.c  nbproject/Makefile-${CND_CONF}.mk
        ${RM} ${OBJECTDIR}/ioports.o 
        ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small libio18f25k22.lib libc18f.lib -c -mpic16 -p18f45k20 ioports.c  -o${OBJECTDIR}/ioports.o
        
+${OBJECTDIR}/menu.o: menu.c  nbproject/Makefile-${CND_CONF}.mk
+       ${MKDIR} ${OBJECTDIR} 
+       ${RM} ${OBJECTDIR}/menu.o 
+       ${MP_CC} --debug-ralloc --use-non-free -V --pstack-model=small libio18f25k22.lib libc18f.lib -c -mpic16 -p18f45k20 menu.c  -o${OBJECTDIR}/menu.o
+       
 endif
 
 # ------------------------------------------------------------------------------------
index 1a77a3a..aaa88a4 100644 (file)
@@ -1,5 +1,5 @@
 #
-#Fri Jun 21 07:28:22 JST 2013
+#Fri Jun 21 15:37:18 JST 2013
 default.languagetoolchain.dir=/usr/local/bin
 default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3
 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=8fe1589514540343a5279c082104bce0
index 063a882..53b40ab 100644 (file)
@@ -42,6 +42,8 @@
     <itemPath>eeprom.h</itemPath>
     <itemPath>ioports.c</itemPath>
     <itemPath>ioports.h</itemPath>
+    <itemPath>menu.c</itemPath>
+    <itemPath>menu.h</itemPath>
   </logicalFolder>
   <sourceRootList>
     <Elem>/usr/local/share/sdcc/lib/src/pic16/libc</Elem>
diff --git a/ui.c b/ui.c
index d0ac280..7d6cd97 100644 (file)
--- a/ui.c
+++ b/ui.c
@@ -51,6 +51,8 @@ const char charcodemap[] = {charcode_0,
                             charcode_a,
 };
 
+extern unsigned char pollkeybuf[32];
+
 keyin_defs keyin_old[2];
 keyin_defs keyin_now;
 char keyin_fifo[32];
@@ -220,31 +222,32 @@ void print_numeric_nosupress(unsigned int data, unsigned char digit)
 /*
  * Read Numeric(int)
  */
-unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c)
+unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned int c)
 {
-    unsigned int p = pos;
     unsigned int val;
-    if(p > 4) p = 4;
-    switch(p){
-        case 0:
-            val = (start / 10) * 10 + c;
-            break;
-        case 1:
-            val = (start / 100) * 100 + start % 10 + c * 10;
-            break;
-        case 2:
-            val = (start / 1000) * 1000 + start % 100 + c * 100;
-            break;
-        case 3:
-            val = (start / 10000) * 10000 + start % 1000 + c * 1000;
-            break;
-        case 4:
-            val = start % 10000 + c * 10000;
-            break;
-        default:
-            val = start;
-            break;
-      }
+    char i;
+    unsigned int fact, fact2;
+    unsigned char bcd[5];
+
+    if(pos > 4) pos = 4;
+    if((pos == 4) && (c > 6)) return 65535;
+    val = start;
+    // binary to BCD
+    fact = 10000;
+    for(i = 4; i >= 0; i--){
+        bcd[i] = val / fact;
+        val = val % fact;
+        fact = fact / 10;
+    }
+    // subst
+    bcd[pos] = c;
+    val = 0;
+    for(i = 3; i >= 0; i--){
+        val = val * 10;
+        val = val + bcd[i];
+    }
+    if((bcd[4] == 6) && (val > 5535)) return val;
+    val = val + bcd[4] * 10000;
     return val;
 }
 
@@ -252,47 +255,44 @@ unsigned int read_numeric(unsigned int initial, unsigned char digit,
         char startx, char starty)
 {
     unsigned char c;
-    unsigned char i;
+    unsigned char n;
+    char i;
     unsigned int val;
     unsigned char d;
     unsigned char input_flag;
 
-    d = digit;
-    if(d > 4) d = 4;
+    d = digit - 1;
     val = initial;
-    i = 0;
+    i = d;
     do {
         _LOCATE(startx, starty);
         print_numeric_nosupress(val, digit);
         
-        do {
-            input_flag = readkey_compare();
-            idle(0xff80);
-        } while(input_flag == 0);
-        c = pop_keyinfifo();
+       do {
+           n = pollkeys(pollkeybuf, 60, 0);
+       } while(n == 0);
+       c = pollkeybuf[0];
 
         if(c == charcode_0){
             val = subst_numeric(val, i, 0);
-            i++;
+            i--;
         } else if((c >= charcode_1) && (c <= charcode_9)) {
             val = subst_numeric(val, i, c - charcode_1 + 1);
+            i--;
         } else if(c == charcode_f) {
             // Enter
             break;
-        } else if(c == charcode_d) {
+        } else if(c == charcode_a) {
             // Del
-            if(i > 0) {
-                val = (val / 10) * 10;
-                i--;
-            }
+            val = val / 10;
+            if(i <= d) i++;
         } else if(c == charcode_b) {
             // cancel
             val = initial;
-            break;
+            i = d;
+//            break;
         }
-        print_numeric_nosupress(val, d);
-        idle(0xff00);
-    } while(i <= d);
+    } while(i >= 0);
     return val;
 }
 
diff --git a/ui.h b/ui.h
index f0183cd..3d2510c 100644 (file)
--- a/ui.h
+++ b/ui.h
@@ -65,7 +65,7 @@ extern void setsignal_tune(unsigned char flag);
 extern void set_backlight(unsigned char flag, unsigned int val);
 extern unsigned int read_numeric(unsigned int initial, unsigned char digit,
         char startx, char starty);
-extern unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c);
+extern unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned int c);
 extern void print_numeric_nosupress(unsigned int data, unsigned char digit);
 extern unsigned char readkey(void);
 extern unsigned char pollkeys(unsigned char *p, unsigned int limit, unsigned char repeat);