OSDN Git Service

[SCHEMATIC] Modify SW/MW/LW Preamp, insert galbanic-isolator replace of common-mode...
[openi2cradio/OpenI2CRadio.git] / menu_userband.c
1 /*
2  * OpenI2CRADIO
3  * Menu sub-routines / USER BAND.
4  * Copyright (C) 2013-09-11 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 "menu_memoryfreq.h"
31 #include "power.h"
32 #include "commondef.h"
33 #include "backlight.h"
34 #include "eeprom_util.h"
35
36 void call_userband(unsigned char num)
37 {
38     unsigned int freq;
39     unsigned int ch;
40     unsigned char start;
41     unsigned char end;
42     unsigned char mode3k;
43     unsigned int q;
44     _userband_t *p;
45
46     if(num >= USER_BAND_NUM) return;
47
48     if(setup.fm != 0){
49         p = &(userband.fm_usrbands[num]);
50         freq = p->freq;
51         mode3k = 0;
52         ch = ((freq - 3000) / 5) * 2;
53         setup.fmband = AKC6955_BAND_FMUSER;
54         setup.fmfreq = freq;
55     } else {
56         p = &(userband.am_usrbands[num]);
57         freq = p->freq;
58         mode3k = p->mode3k;
59         q = 5;
60         if(mode3k != 0) q = 3;
61         ch = freq / q;
62         setup.amband = AKC6955_BAND_AMUSER;
63         setup.amfreq = freq;
64         setup.am_mode3k = mode3k;
65     }
66     start = p->start;
67     end = p->stop;
68
69
70     akc6955_set_userband(start, end, ch, mode3k);
71 }
72
73 void set_userband(void)
74 {
75     unsigned long from,to;
76     unsigned char c;
77     unsigned char pp;
78     unsigned char mode3k;
79     unsigned int freq;
80     unsigned int _from, _to, tmp;
81     unsigned char cc;
82     unsigned char fm = setup.fm;
83
84     _CLS();
85 //    _LOCATE(0,0);
86     c = 0;
87     printstr("User ch:");
88     c = pollkey_numeric(c);
89     if(c >= USER_BAND_NUM) goto _l0;
90
91     if(fm != 0){
92         from = userband.fm_usrbands[c].start * 80 + 3000; // 32*25/10
93         to = userband.fm_usrbands[c].stop * 80 + 3000;
94         _CLS();
95    //     _LOCATE(0,0);
96         printstr("FM#");
97         print_numeric_nosupress(c, 1);
98     } else {
99         mode3k = userband.am_usrbands[c].mode3k;
100         pp = 96; // 3*32
101         if(mode3k == 0) pp = 160; // 5*32
102         from = userband.am_usrbands[c].start * pp;
103         to = userband.am_usrbands[c].stop * pp;
104         _CLS();
105 //        _LOCATE(0,0);
106         printstr("AM#");
107         print_numeric_nosupress(c, 1);
108         printstr(" Step:");
109         if(mode3k == 0){
110             printstr("5K->");
111         } else {
112             printstr("3K->");
113         }
114         _LOCATE_0_1();
115         printstr("0=3k 1=5k");
116         cc = pollkey_single();
117         if(cc == charcode_0){
118             pp = 96;
119             mode3k = 0xff;
120         } else if(cc == charcode_1) {
121             pp = 160;
122             mode3k = 0;
123         } else {
124             goto _l0;
125         }
126         _LOCATE(10,0);
127         if(mode3k == 0){
128             printstr("5K  ");
129         } else {
130             printstr("3K  ");
131         }
132     }
133
134     _LOCATE_0_1();
135     printstr("From:");
136     from = read_numeric(from, 5, 7, 1);
137     if((from & 0xffff0000) != 0) goto _l0;
138     _LOCATE_0_1();
139     printstr("To:  ");
140     to = read_numeric(to, 5, 7, 1);
141     if((to & 0xffff0000) != 0) goto _l0;
142
143     _from = (unsigned int)from;
144     _to = (unsigned int)to;
145     if(_from > _to){
146          tmp = _to;
147          _to = _from;
148          _from = tmp;
149     }
150     freq = (_to - _from) / 2 + _from;
151
152     _CLS();
153     if(fm != 0){
154         printstr("FM");
155     } else {
156         printstr("AM");
157     }
158     _PUTCHAR('#');
159     _PUTCHAR('0' + c);
160     printstr(" A=OK");
161     _LOCATE_0_1();
162     print_numeric_nosupress(_from, 5);
163     printstr("->");
164     print_numeric_nosupress(_to, 5);
165     cc = pollkey_single();
166     if(cc != charcode_a) goto _l0;
167     if(fm != 0)
168     {
169         if((_from <= 3000) || (_from >= 28000)) goto _l0;
170         if((_to <= 3000) || (_to >= 28000)) goto _l0;
171         userband.fm_usrbands[c].start = (_from - 3000) / 80;
172         userband.fm_usrbands[c].stop = (_to - 3000) / 80 + 1;
173         userband.fm_usrbands[c].freq = freq;
174         userband.fm_usrbands[c].mode3k = 0;
175         setup.fm_userbandnum = c;
176     } else {
177         if((_from <100) || (_from >= 28000)) goto _l0;
178         if((_to < 100) || (_to >= 28000)) goto _l0;
179         userband.am_usrbands[c].start = _from / pp;
180         userband.am_usrbands[c].stop = _to  / pp + 1;
181         userband.am_usrbands[c].mode3k = mode3k;
182         userband.am_usrbands[c].freq = freq;
183         setup.am_userbandnum = c;
184     }
185     save_userbands();
186     call_userband(c);
187 _l0:
188     _CLS();
189 }
190
191 void input_userband(void)
192 {
193     unsigned char c;
194     int d;
195         c = printhelp_2lines("User Band", "   #");
196         if((c > charcode_a) && (c <= charcode_f)){
197             goto _l0;
198          }
199         if(c == charcode_a){
200             d = load_userbands();
201             if(d < 0) format_userbands();
202
203         } else {
204             if(c == charcode_0) {
205                c = 0;
206             }
207             _PUTCHAR('0' + c);
208             if(setup.fm != 0){
209                 setup.fm_userbandnum = c;
210             } else {
211                 setup.am_userbandnum = c;
212             }
213             call_userband(c);
214         }
215 _l0:
216     _CLS();
217 }
218
219 void list_userband(void)
220 {
221     unsigned char i;
222     unsigned char q;
223     unsigned char c;
224
225     for(i = 0; i < USER_BAND_NUM; i ++){
226         _CLS();
227         printstr("FM#");
228         _PUTCHAR('0' + i);
229         _LOCATE_0_1();
230         print_numeric_nosupress(userband.fm_usrbands[i].start * 80 + 3000, 5);
231         printstr(" to ");
232         print_numeric_nosupress(userband.fm_usrbands[i].stop * 80 + 3000, 5);
233         c = pollkey_single();
234         if(c == charcode_a) {
235             return;
236         }
237     }
238     for(i = 0; i < USER_BAND_NUM; i ++){
239         _CLS();
240         printstr("AM#");
241         _PUTCHAR('0' + i);
242         _LOCATE_0_1();
243         if(userband.am_usrbands[i].mode3k != 0){
244             q = 3 * 32;
245         } else {
246             q = 5 * 32;
247         }
248         print_numeric_nosupress(userband.am_usrbands[i].start * q, 5);
249         printstr(" to ");
250         print_numeric_nosupress(userband.am_usrbands[i].stop *  q, 5);
251         c = pollkey_single();
252         if(c == charcode_a) {
253             return;
254         }
255     }
256 }