OSDN Git Service

[SCHEMATIC] Modify SW/MW/LW Preamp, insert galbanic-isolator replace of common-mode...
[openi2cradio/OpenI2CRadio.git] / menu.c
1 /*
2  * OpenI2CRADIO
3  * Menu sub-routines.
4  * Copyright (C) 2013-06-21 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
35 void toggle_amfm(void)
36 {
37     unsigned int freq;
38     if(setup.fm != 0){
39         setup.fm = 0;
40         setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
41   //      akc6955_set_amband(amband);
42         freq = setup.amfreq_bank[setup.amband];
43     } else {
44         setup.fm = 0xff;
45         setup.amfreq_bank[setup.amband] = setup.amfreq;
46 //        akc6955_set_fmband(fmband);
47         freq = setup.fmfreq_bank[setup.fmband];
48     }
49     akc6955_chg_fm(setup.fm, freq);
50     idle_time_ms(500);
51 //    akc6955_set_freq(freq);
52 }
53
54
55
56 void set_stereomode(void)
57 {
58     __bitops_t mode;
59     mode.byte = 0x00;
60     if(setup.stereo == 0x00){
61             mode.b0 = 1; // Force mono
62     } else if(setup.stereo < 0x80){
63             mode.b1 = 1; // Force stereo
64     }
65     akc6955_set_stereomode(mode.byte);
66 }
67
68 void set_stereo(void)
69 {
70     
71     if(setup.stereo == 0xff) {// Force Mono
72         setup.stereo = 0x00;
73     } else if(setup.stereo == 0x00) { //Mono->Stereo
74         setup.stereo = 0x7f;
75     } else { // Default, Stereo->auto
76         setup.stereo = 0xff;
77     }
78     set_stereomode();
79 }
80
81 void setfreq_direct(void)
82 {
83     unsigned long val;
84     _CLS();
85 //    _LOCATE(0,0);
86     printstr("Set Freq:");
87     _LOCATE_0_1();
88     if(setup.fm != 0){
89         // FM
90         printstr("FM ");
91         val = setup.fmfreq;
92         val = read_numeric(val, 5, 7, 1);
93         if((val & 0x80000000) != 0) return;
94         setup.fmfreq = val;
95     } else {
96         // FM
97         printstr("AM ");
98         val = setup.amfreq;
99         val = read_numeric(val, 5, 7, 1);
100         if((val & 0x80000000) != 0) return;
101         setup.amfreq = val;
102     }
103     akc6955_set_freq(val);
104 }
105
106 void setband_direct(void)
107 {
108     unsigned long band;
109     unsigned char band2;
110     unsigned int freq;
111     unsigned char mode3k;
112
113     _CLS();
114 //    _LOCATE(0,0);
115     if(setup.fm != 0){
116         printstr("Set Band:FM#");
117         band2 = setup.fmband & 7;
118         if(band2 == AKC6955_BAND_FMUSER) {
119             userband.fm_usrbands[setup.fm_userbandnum].freq = setup.fmfreq;
120         }
121         setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
122         band2 = pollkey_numeric(band2);
123         band2 &= 7;
124         if(band2 == AKC6955_BAND_FMUSER) {
125             call_userband(setup.fm_userbandnum);
126             freq = userband.fm_usrbands[setup.fm_userbandnum].freq;
127         } else {
128             freq = setup.fmfreq_bank[band2];
129         }
130         setup.fmband = band2;
131         akc6955_set_fmband(band2);
132         setup.fmfreq = freq;
133     } else {
134         printstr("Set Band:AM#");
135         band = setup.amband & 0x1f;
136         setup.amfreq_bank[band] = setup.amfreq;
137         if(band == AKC6955_BAND_AMUSER) {
138             userband.am_usrbands[setup.am_userbandnum].freq = setup.amfreq;
139         }
140         band = read_numeric(band, 2, 7, 1);
141         if((band & 0x80000000) != 0) return;
142         band &= 0x1f;
143         setup.amband = band;
144         freq = setup.amfreq_bank[setup.amband];
145         switch(band) {
146          case AKC6955_BAND_LW:
147          case AKC6955_BAND_MW2:
148            mode3k = 0xff;
149            break;
150          case AKC6955_BAND_AMUSER:
151             call_userband(setup.am_userbandnum);
152             mode3k = userband.am_usrbands[setup.am_userbandnum].mode3k;
153             freq = userband.am_usrbands[setup.am_userbandnum].freq;
154             break;
155          default:
156             mode3k = 0x00;
157            break;
158         }
159         akc6955_mode3k(mode3k);
160         akc6955_set_amband(band);
161         setup.amfreq = freq;
162         setup.am_mode3k = mode3k;
163     }
164     akc6955_do_tune();
165     akc6955_set_freq(freq);
166 }
167
168 void menu_poweroff(void)
169 {
170     unsigned char c;
171     c = printhelp_2lines("Poweroff", "A=Yes");
172     if(c == charcode_a) {
173         shutdown(1);
174     }
175 }
176
177 void menu_setfmresolution(void)
178 {
179    unsigned char c;
180     if(setup.fm != 0){
181        _CLS();
182 //       _LOCATE(0,0);
183         c = akc6955_get_scanrate_fm();
184         printstr("FM pitch:");
185         _PUTCHAR('0' + c);
186         printstr("->");
187         c = pollkey_numeric(c);
188         setup.fm_tunepitch = c & 3;
189         akc6955_set_scanrate_fm(c);
190         _CLS();
191 //        _LOCATE(0,0);
192     }
193 }
194
195 void setup_akc6955(void)
196 {
197     akc6955_writecmd(AKC6955_POWER, 0xc0);  // You musto *not* mute, set b2 to '0".
198     akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
199     if(setup.fm == 0) {
200         akc6955_set_amband(setup.amband);
201         if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
202         setup.amfreq = setup.amfreq_bank[setup.amband];
203         akc6955_chg_fm(0, setup.amfreq); // Set to AM
204         akc6955_set_freq(setup.amfreq);
205     } else {
206         akc6955_set_fmband(setup.fmband);
207         if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
208         setup.fmfreq = setup.fmfreq_bank[setup.fmband];
209         akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
210         akc6955_set_freq(setup.fmfreq);
211     }// Dummy, TBS (954KHz)
212     akc6955_set_power(0xff); // Power ON
213     akc6955_setvolume(36); // Temporally
214     akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
215     akc6955_set_thresh_amcnr(setup.threshold_amcnr);
216     akc6955_set_thresh_width(setup.threshold_width);
217     akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
218     akc6955_setvolumemode(0);
219     akc6955_set_lowboost(setup.lowboost);
220     akc6955_set_scanrate_fm(setup.fm_tunepitch);
221     set_stereomode();
222 }
223
224 /*
225  * Main Menu : initial-screen -> 'F'.
226  */
227 void main_menu(void)
228 {
229     unsigned char c;
230     unsigned char d;
231     unsigned int val;
232     unsigned int freq;
233
234     printhelp_2lines("Menu:F=HELP", "B=CANCEL");
235     c = pollkey_single(); // 1012ms
236     switch(c) {
237         case charcode_1:
238             // Band
239             setband_direct();
240             break;
241         case charcode_3:
242             // Band
243             setfreq_direct();
244             break;
245         case charcode_4:
246             on_call_userfreq();
247             break;
248             // Scan
249         case charcode_5:
250             break;
251         case charcode_6:
252             on_set_userfreq();
253             break;
254             // Scan
255         case charcode_7:
256             menu_poweroff();
257             break;
258         case charcode_8:
259             // Set volume
260             set_volume();
261             break;
262         case charcode_9:
263             freq = akc6955_get_freq();
264             akc6955_set_freq(freq);
265             break;
266         case charcode_0:
267             // Setup Menu
268             setup_menu();
269             break;
270         case charcode_a:
271             toggle_amfm();
272             break;
273         case charcode_c:
274             set_userband();
275             break;
276         case charcode_d:
277             input_userband();
278             break;
279         case charcode_e:
280             menu_setfmresolution();
281             break;
282         case charcode_f:
283             mainmenu_help();
284             // HELP
285             break;
286         default:
287             break;
288         }
289        _CLS();
290        _LOCATE_0_0();
291 }
292