OSDN Git Service

[UI][USER_CH] Add slow-middle-fast changeing CHs.
[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 int num)
36 {
37     unsigned char _fm;
38     unsigned char _band;
39     unsigned char _userband;
40     unsigned int bank = num / USER_MEMORY_NUM;
41     unsigned int n = num % USER_MEMORY_NUM;
42
43     if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
44
45     if(bank != setup.pagenum){ // Swap memory
46 //        save_frequencies();
47         load_frequencies(bank, 0x00);
48     }
49
50     _fm = freqset.memoryfreqs[n].fm;
51     _userband = freqset.memoryfreqs[n].band;
52     _band = _userband & 0x1f;
53     _userband = _userband >> 5;
54     if(_fm) { // AM
55         setup.fmband = _band;
56         setup.fm_userbandnum = _userband;
57     } else {
58         setup.amband = _band;
59         setup.am_userbandnum = _userband;
60     }
61     setup.memorynum = num;
62     akc6955_chg_fm(_fm, freqset.memoryfreqs[n].freq);
63 }
64
65
66 void set_freqbank(unsigned int num)
67 {
68     unsigned char _fm;
69     unsigned char _band;
70     unsigned char _userband;
71     unsigned int _freq;
72     unsigned int bank = num / USER_MEMORY_NUM;
73     unsigned int n = num % USER_MEMORY_NUM;
74
75     if(num >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) return;
76
77      if(bank != setup.pagenum){ // Save now bank, and load using bank
78         save_frequencies();
79         load_frequencies(bank, 0x00);
80     }
81
82     _fm = setup.fm;
83     _freq = setup.amfreq;
84     _userband = setup.am_userbandnum;
85     _band = setup.amband;
86     if(_fm){
87         _userband = setup.fm_userbandnum;
88         _band = setup.fmband;
89         _freq = setup.fmfreq;
90     }
91     freqset.memoryfreqs[n].fm = _fm;
92     freqset.memoryfreqs[n].band = (_userband << 5) | (_band & 0x1f);
93     freqset.memoryfreqs[n].freq = _freq;
94
95     save_frequencies();
96 }
97
98
99 void on_call_userfreq(void)
100 {
101     unsigned int val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
102     _CLS();
103     _LOCATE(0,0);
104     printstr("Mem: 000-");
105     print_numeric_nosupress(val - 1, 3);
106     val = read_numeric(val, 3, 4, 1);
107     call_freqbank(val);
108 }
109
110 void on_set_userfreq(void)
111 {
112     unsigned int val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
113     unsigned char n;
114     unsigned char c;
115     _CLS();
116     _LOCATE(0,0);
117     printstr("Set Mem: 000-");
118     print_numeric_nosupress(val - 1, 3);
119     val = read_numeric(val, 3, 4, 1);
120     _HOME();
121     _LOCATE(0,0);
122     printstr("OK? A=OK       ");
123     do {
124            n = pollkeys(pollkeybuf, 19, 1);
125     } while(n == 0);
126     c = pollkeybuf[0];
127     if(c != charcode_a) return;
128     set_freqbank(val);
129 //    save_eeprom();
130 }
131
132 void on_updown_userfreq(void)
133 {
134     unsigned int _freq;
135     unsigned char _fm;
136     unsigned char _band;
137     unsigned char _userband;
138     unsigned char n;
139     unsigned char c;
140
141     _fm = setup.fm;
142     _freq = setup.amfreq;
143     _userband = setup.am_userbandnum;
144     _band = setup.amband;
145     if(_fm){
146         _userband = setup.fm_userbandnum;
147         _band = setup.fmband;
148         _freq = setup.fmfreq;
149     }
150
151     _CLS();
152     do {
153         _LOCATE(0,0);
154         printstr("CH:");
155         print_numeric_nosupress(setup.memorynum, 3);
156         printstr(" 8/2/A");
157         update_status();
158         print_freq(1);
159         _HOME();
160         c = pollkey_single_timeout(44, 1); // About 1s
161        switch(c) {
162            case charcode_7: // UP 1CH
163                 setup.memorynum++;
164                 if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
165                 call_freqbank(setup.memorynum);
166                 break;
167            case charcode_1: // Down 1CH
168                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
169                setup.memorynum--;
170                call_freqbank(setup.memorynum);
171                break;
172            case charcode_9: // Up CH FAST
173                setup.memorynum += 100;
174                if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
175                     setup.memorynum = setup.memorynum % 100;
176                }
177                call_freqbank(setup.memorynum);
178                break;
179            case charcode_3: // Down CH FAST
180                if(setup.memorynum < 100) {
181                     setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
182                } else {
183                     setup.memorynum -= 100;
184                }
185                call_freqbank(setup.memorynum);
186                break;
187            case charcode_8: // Up CH FAST
188                setup.memorynum += USER_MEMORY_NUM;
189                if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
190                     setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
191                }
192                call_freqbank(setup.memorynum);
193                break;
194            case charcode_2: // Down CH FAST
195                if(setup.memorynum < USER_MEMORY_NUM) {
196                     setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
197                } else {
198                     setup.memorynum -= USER_MEMORY_NUM;
199                }
200                call_freqbank(setup.memorynum);
201                break;
202             case charcode_5: // Reset
203                if(_fm) { // AM
204                     setup.fmband = _band;
205                     setup.fm_userbandnum = _userband;
206                     setup.fmfreq = _freq;
207                } else {
208                     setup.amband = _band;
209                     setup.am_userbandnum = _userband;
210                     setup.amfreq = _freq;
211                }
212                akc6955_chg_fm(_fm, _freq);
213                break;
214            case charcode_4:
215                on_call_userfreq();
216                break;
217            case charcode_6:
218                on_set_userfreq();
219                break;
220            case charcode_a:
221                 goto _l0;
222                 break;
223            default:
224                break;
225            }
226 //       _HOME();
227     } while(1);
228 _l0:
229     _CLS();
230
231 }