OSDN Git Service

07a4627a66ad7aec721ffbd61bd59bd423344317
[openi2cradio/OpenI2CRadio.git] / menu_memoryfreq.c
1 /*
2  * OpenI2CRADIO
3  * Menu sub-routines: Memory Freq.
4  * Copyright (C) 2013-08-14 K.Ohta <whatisthis.sowhat ai gmail.com>
5  * License: GPL2+LE
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2,
10  *  or (at your option) any later version.
11  *  This library / program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  *  See the GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this library; see the file COPYING. If not, write to the
18  *  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
19  *  MA 02110-1301, USA.
20  *
21  *  As a special exception, if you link this(includeed from sdcc) library
22  *  with other files, some of which are compiled with SDCC,
23  *  to produce an executable, this library does not by itself cause
24  *  the resulting executable to be covered by the GNU General Public License.
25  *  This exception does not however invalidate any other reasons why
26  *  the executable file might be covered by the GNU General Public License.
27  */
28
29 #include "menu.h"
30 #include "power.h"
31 #include "commondef.h"
32 #include "eeprom.h"
33
34
35 void call_freqbank(unsigned char num)
36 {
37     unsigned char _fm;
38     unsigned char _band;
39     unsigned char _userband;
40     if(num >= USER_MEMORY_NUM) return;
41
42     _fm = setup.memoryfreqs[num].fm;
43     _userband = setup.memoryfreqs[num].band;
44     _band = _userband & 0x1f;
45     _userband = _userband >> 5;
46     if(_fm) { // AM
47         setup.fmband = _band;
48         setup.fm_userbandnum = _userband;
49     } else {
50         setup.amband = _band;
51         setup.am_userbandnum = _userband;
52     }
53     akc6955_chg_fm(_fm, setup.memoryfreqs[num].freq);
54 }
55
56
57 void set_freqbank(unsigned char num)
58 {
59     unsigned char _fm;
60     unsigned char _band;
61     unsigned char _userband;
62     unsigned int _freq;
63
64     if(num >= USER_MEMORY_NUM) return;
65
66     _fm = setup.fm;
67     _freq = setup.amfreq;
68     _userband = setup.am_userbandnum;
69     _band = setup.amband;
70     if(_fm){
71         _userband = setup.fm_userbandnum;
72         _band = setup.fmband;
73         _freq = setup.fmfreq;
74     }
75     setup.memoryfreqs[num].fm = _fm;
76     setup.memoryfreqs[num].band = (_userband << 5) | (_band & 0x1f);
77     setup.memoryfreqs[num].freq = _freq;
78 }
79
80
81 void on_call_userfreq(void)
82 {
83     unsigned int val = USER_MEMORY_NUM;
84     _CLS();
85     _LOCATE(0,0);
86     printstr("Mem: 00-");
87     print_numeric_nosupress(USER_MEMORY_NUM - 1, 2);
88     val = read_numeric(val, 2, 4, 1);
89     call_freqbank(val);
90 }
91
92 void on_set_userfreq(void)
93 {
94     unsigned int val = USER_MEMORY_NUM;
95     unsigned char n;
96     unsigned char c;
97     _CLS();
98     _LOCATE(0,0);
99     printstr("Set Mem: 00-");
100     print_numeric_nosupress(USER_MEMORY_NUM - 1, 2);
101     val = read_numeric(val, 2, 4, 1);
102     _HOME();
103     _LOCATE(0,0);
104     printstr("OK? A=OK       ");
105     do {
106            n = pollkeys(pollkeybuf, 19, 1);
107     } while(n == 0);
108     c = pollkeybuf[0];
109     if(c != charcode_a) return;
110     set_freqbank(val);
111     save_eeprom();
112 }
113
114 void on_updown_userfreq(void)
115 {
116     unsigned int _freq;
117     unsigned char _fm;
118     unsigned char _band;
119     unsigned char _userband;
120     unsigned char n;
121     unsigned char c;
122
123     _fm = setup.fm;
124     _freq = setup.amfreq;
125     _userband = setup.am_userbandnum;
126     _band = setup.amband;
127     if(_fm){
128         _userband = setup.fm_userbandnum;
129         _band = setup.fmband;
130         _freq = setup.fmfreq;
131     }
132
133     _CLS();
134     do {
135         _LOCATE(0,0);
136         printstr("CH:");
137         print_numeric_nosupress(setup.memorynum, 2);
138         printstr(" 8/2/A");
139         update_status();
140         print_freq(1);
141         _HOME();
142         c = pollkey_single_timeout(44, 1); // About 1s
143        switch(c) {
144            case charcode_8: // UP CH
145                 setup.memorynum++;
146                 if(setup.memorynum >= USER_MEMORY_NUM) setup.memorynum = 0;
147                 call_freqbank(setup.memorynum);
148                 break;
149            case charcode_2: // Down CH
150                 if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM;
151                 setup.memorynum--;
152                 call_freqbank(setup.memorynum);
153                 break;
154             case charcode_d: // Reset
155                 if(_fm) { // AM
156                     setup.fmband = _band;
157                     setup.fm_userbandnum = _userband;
158                     setup.fmfreq = _freq;
159                 } else {
160                     setup.amband = _band;
161                     setup.am_userbandnum = _userband;
162                     setup.amfreq = _freq;
163                 }
164                 akc6955_chg_fm(_fm, _freq);
165                 break;
166            case charcode_5: // exit
167            case charcode_a:
168                 goto _l0;
169                 break;
170            default:
171                break;
172            }
173 //       _HOME();
174     } while(1);
175 _l0:
176     _CLS();
177
178 }