OSDN Git Service

[v1.0][Doc] v1.0(.0) Release.
[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     _CLS();
112     //_LOCATE(0,0);
113     if(setup.fm != 0){
114        printstr("Set Band:FM#");
115        band2 = setup.fmband & 7;
116        setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
117        band2 = pollkey_numeric(band2);
118        setup.fmband = band2 & 7;
119        if(setup.fmband == AKC6955_BAND_FMUSER) {
120           setup.fmfreq = setup.fm_usrbands[setup.fm_userbandnum].freq;
121        } else {
122           setup.fmfreq = setup.fmfreq_bank[setup.fmband];
123        }
124        akc6955_set_fmband(setup.fmband);
125        freq = setup.fmfreq;
126     } else {
127         printstr("Set Band:AM#");
128         band = setup.amband & 0x1f;
129         setup.amfreq_bank[setup.amband] = setup.amfreq;
130         band = read_numeric(band, 2, 7, 1);
131         if((band & 0x80000000) != 0) return;
132         setup.amband = band & 0x1f;
133         switch(setup.amband) {
134          case AKC6955_BAND_LW:
135          case AKC6955_BAND_MW2:
136            setup.am_mode3k = 0xff;
137            break;
138          case AKC6955_BAND_AMUSER:
139            setup.am_mode3k = setup.am_usrbands[setup.am_userbandnum].mode3k;
140            break;
141          default:
142            setup.am_mode3k = 0;
143            break;
144         }
145         if(setup.amband == AKC6955_BAND_AMUSER) {
146            setup.amfreq = setup.am_usrbands[setup.am_userbandnum].freq;
147         } else {
148            setup.amfreq = setup.amfreq_bank[setup.amband];
149         }
150        
151         akc6955_set_amband(setup.amband);
152         akc6955_mode3k(setup.am_mode3k);
153         freq = setup.amfreq;
154     }
155     akc6955_do_tune();
156     akc6955_set_freq(freq);
157 }
158
159 void menu_poweroff(void)
160 {
161     unsigned char c;
162     c = printhelp_2lines("Poweroff", "A=Yes");
163     if(c == charcode_a) {
164         shutdown(1);
165     }
166 }
167
168 void menu_setfmresolution(void)
169 {
170    unsigned char c;
171     if(setup.fm != 0){
172        _CLS();
173        //_LOCATE(0,0);
174         c = akc6955_get_scanrate_fm();
175         printstr("FM pitch:");
176         c = pollkey_numeric(c);
177         setup.fm_tunepitch = c & 3;
178         akc6955_set_scanrate_fm(c);
179         _CLS();
180         //_LOCATE(0,0);
181     }
182 }
183
184         
185
186
187 void setup_akc6955(void)
188 {
189     akc6955_writecmd(AKC6955_POWER, 0xc0);  // You musto *not* mute, set b2 to '0".
190     akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
191     if(setup.fm == 0) {
192         akc6955_set_amband(setup.amband);
193         if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
194         setup.amfreq = setup.amfreq_bank[setup.amband];
195         akc6955_chg_fm(0, setup.amfreq); // Set to AM
196         akc6955_set_freq(setup.amfreq);
197     } else {
198         akc6955_set_fmband(setup.fmband);
199         if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
200         setup.fmfreq = setup.fmfreq_bank[setup.fmband];
201         akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
202         akc6955_set_freq(setup.fmfreq);
203     }// Dummy, TBS (954KHz)
204     akc6955_set_power(0xff); // Power ON
205     akc6955_setvolume(36); // Temporally
206     akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
207     akc6955_set_thresh_amcnr(setup.threshold_amcnr);
208     akc6955_set_thresh_width(setup.threshold_width);
209     akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
210     akc6955_setvolumemode(0);
211     akc6955_set_lowboost(setup.lowboost);
212     akc6955_set_scanrate_fm(setup.fm_tunepitch & 3);
213     set_stereomode();
214 }
215
216 /*
217  * Main Menu : initial-screen -> 'F'.
218  */
219 void main_menu(void)
220 {
221     unsigned char c;
222     unsigned char d;
223     unsigned int val;
224     unsigned int freq;
225
226     printhelp_2lines("Menu:F=HELP", "B=CANCEL");
227     c = pollkey_single(); // 1012ms
228     switch(c) {
229         case charcode_1:
230             // Band
231             setband_direct();
232             break;
233         case charcode_3:
234             // Band
235             setfreq_direct();
236             break;
237         case charcode_4:
238             on_call_userfreq();
239             break;
240             // Scan
241         case charcode_5:
242             break;
243         case charcode_6:
244             on_set_userfreq();
245             break;
246             // Scan
247         case charcode_7:
248             menu_poweroff();
249             break;
250         case charcode_8:
251             // Set volume
252             set_volume();
253             break;
254         case charcode_9:
255             freq = akc6955_get_freq();
256             akc6955_set_freq(freq);
257             break;
258         case charcode_0:
259             // Setup Menu
260             setup_menu();
261             break;
262         case charcode_a:
263             toggle_amfm();
264             break;
265         case charcode_c:
266             set_userband();
267             break;
268         case charcode_d:
269             input_userband();
270             break;
271         case charcode_e:
272             menu_setfmresolution();
273             break;
274      case charcode_f:
275             mainmenu_help();
276             // HELP
277             break;
278         default:
279             break;
280         }
281        _CLS();
282        //_LOCATE(0,0);
283 }
284