OSDN Git Service

[I2C][EEPROM] Set I2CEEPROM_ADDR in i2c_eeprom.h as ROM's ADDR.
[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 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 c;
139     unsigned char dispf = 0xff;
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        if(dispf != 0)  {
154             _LOCATE(0,0);
155             printstr("CH:");
156             print_numeric_nosupress(setup.memorynum, 3);
157             printstr(" 8/2/A");
158             update_status();
159             print_freq(1);
160             _HOME();
161        }
162        c = pollkey_single_timeout(41, 1); // 23*41 = 943ms
163        backlight_reset(c);
164        dispf = backlight_dec(dispf);
165
166        switch(c) {
167            case charcode_7: // UP 1CH
168                 setup.memorynum++;
169                 if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) setup.memorynum = 0;
170                 call_freqbank(setup.memorynum);
171                 break;
172            case charcode_1: // Down 1CH
173                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM * USER_MEMORY_BANKS;
174                setup.memorynum--;
175                call_freqbank(setup.memorynum);
176                break;
177            case charcode_9: // Up CH FAST
178                setup.memorynum += 100;
179                if(setup.memorynum > (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
180                     setup.memorynum = setup.memorynum % 100;
181                }
182                call_freqbank(setup.memorynum);
183                break;
184            case charcode_3: // Down CH FAST
185                if(setup.memorynum < 100) {
186                     setup.memorynum = (((USER_MEMORY_NUM * USER_MEMORY_BANKS) / 100 - 1) * 100) + (setup.memorynum % 100);
187                } else {
188                     setup.memorynum -= 100;
189                }
190                call_freqbank(setup.memorynum);
191                break;
192            case charcode_8: // Up CH MID
193                setup.memorynum += USER_MEMORY_NUM;
194                if(setup.memorynum >= (USER_MEMORY_NUM * USER_MEMORY_BANKS)) {
195                     setup.memorynum = setup.memorynum - USER_MEMORY_NUM * USER_MEMORY_BANKS;
196                }
197                call_freqbank(setup.memorynum);
198                break;
199            case charcode_2: // Down CH MID
200                if(setup.memorynum < USER_MEMORY_NUM) {
201                     setup.memorynum = (USER_MEMORY_NUM * USER_MEMORY_BANKS) - USER_MEMORY_NUM + setup.memorynum;
202                } else {
203                     setup.memorynum -= USER_MEMORY_NUM;
204                }
205                call_freqbank(setup.memorynum);
206                break;
207             case charcode_5: // Recall
208                call_freqbank(setup.memorynum);
209                break;
210             case charcode_d: // Reset
211                if(_fm) { // AM
212                     setup.fmband = _band;
213                     setup.fm_userbandnum = _userband;
214                     setup.fmfreq = _freq;
215                } else {
216                     setup.amband = _band;
217                     setup.am_userbandnum = _userband;
218                     setup.amfreq = _freq;
219                }
220                akc6955_chg_fm(_fm, _freq);
221                break;
222            case charcode_4:
223                on_call_userfreq();
224                break;
225            case charcode_6:
226                on_set_userfreq();
227                break;
228            case charcode_a:
229                 goto _l0;
230                 break;
231            case charcode_e: // Set Light
232            default:
233                break;
234            }
235             idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.
236     } while(1);
237 _l0:
238     _CLS();
239
240 }