OSDN Git Service

[UI][HELP] Update help of setup.
[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 #include "backlight.h"
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 long 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     if(val >= 0x80000000) return;
108     call_freqbank(val);
109 }
110
111 void on_set_userfreq(void)
112 {
113     unsigned long val = USER_MEMORY_NUM * USER_MEMORY_BANKS;
114     unsigned char n;
115     unsigned char c;
116     _CLS();
117     _LOCATE(0,0);
118     printstr("Set Mem: 000-");
119     print_numeric_nosupress(val - 1, 3);
120     val = read_numeric(val, 3, 4, 1);
121     if(val >= 0x80000000) return;
122     _HOME();
123     _LOCATE(0,0);
124     printstr("OK? A=OK       ");
125     c = pollkey_single();
126     if(c != charcode_a) return;
127     set_freqbank(val);
128 //    save_eeprom();
129 }
130
131 void on_updown_userfreq(void)
132 {
133     unsigned int _freq;
134     unsigned char _fm;
135     unsigned char _band;
136     unsigned char _userband;
137     unsigned char c;
138     unsigned char dispf = 0xff;
139
140     _fm = setup.fm;
141     _freq = setup.amfreq;
142     _userband = setup.am_userbandnum;
143     _band = setup.amband;
144     if(_fm){
145         _userband = setup.fm_userbandnum;
146         _band = setup.fmband;
147         _freq = setup.fmfreq;
148     }
149
150     _CLS();
151     do {
152        if(dispf != 0)  {
153             _LOCATE(0,0);
154             printstr("CH:");
155             print_numeric_nosupress(setup.memorynum, 3);
156             printstr(" HELP=F");
157             update_status();
158             print_freq(1);
159             _HOME();
160        }
161        c = pollkey_single_timeout(41, 1); // 23*41 = 943ms
162        backlight_reset(c);
163        dispf = backlight_dec(dispf);
164
165        switch(c) {
166            case charcode_7: // UP 1CH
167                 setup.memorynum++;
168                 if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
169                 call_freqbank(setup.memorynum);
170                 break;
171            case charcode_1: // Down 1CH
172                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
173                setup.memorynum--;
174                call_freqbank(setup.memorynum);
175                break;
176            case charcode_9: // Up CH FAST
177                setup.memorynum += 100;
178                if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
179                     setup.memorynum = setup.memorynum % 100;
180                }
181                call_freqbank(setup.memorynum);
182                break;
183            case charcode_3: // Down CH FAST
184                if(setup.memorynum < 100) {
185                     setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
186                } else {
187                     setup.memorynum -= 100;
188                }
189                call_freqbank(setup.memorynum);
190                break;
191            case charcode_8: // Up CH MID
192                setup.memorynum += USER_MEMORY_NUM;
193                if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
194                     setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
195                }
196                call_freqbank(setup.memorynum);
197                break;
198            case charcode_2: // Down CH MID
199                if(setup.memorynum < USER_MEMORY_NUM) {
200                     setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
201                } else {
202                     setup.memorynum -= USER_MEMORY_NUM;
203                }
204                call_freqbank(setup.memorynum);
205                break;
206             case charcode_5: // Recall
207                call_freqbank(setup.memorynum);
208                break;
209             case charcode_d: // Reset
210                if(_fm) { // AM
211                     setup.fmband = _band;
212                     setup.fm_userbandnum = _userband;
213                     setup.fmfreq = _freq;
214                } else {
215                     setup.amband = _band;
216                     setup.am_userbandnum = _userband;
217                     setup.amfreq = _freq;
218                }
219                akc6955_chg_fm(_fm, _freq);
220                break;
221            case charcode_4:
222                on_call_userfreq();
223                break;
224            case charcode_6:
225                on_set_userfreq();
226                break;
227            case charcode_a:
228                 goto _l0;
229                 break;
230            case charcode_f:
231                userfreq_help();
232                _CLS();
233                break;
234            case charcode_e: // Set Light
235            default:
236                break;
237            }
238             idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.
239     } while(1);
240 _l0:
241     _CLS();
242
243 }