OSDN Git Service

[DOC][v1.0] Update documents for 1.0RC2.
[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;
41     unsigned int n = num;
42
43     if(num >= USER_MEMORY_NUM) return;
44
45
46     _fm = setup.memoryfreqs[n].fm;
47     _userband = setup.memoryfreqs[n].band;
48     _band = _userband & 0x1f;
49     _userband = _userband >> 5;
50     if(_fm) { // AM
51         setup.fmband = _band;
52         setup.fm_userbandnum = _userband;
53     } else {
54         setup.amband = _band;
55         setup.am_userbandnum = _userband;
56     }
57     setup.memorynum = num;
58     akc6955_chg_fm(_fm, setup.memoryfreqs[n].freq);
59 }
60
61
62 void set_freqbank(unsigned int num)
63 {
64     unsigned char _fm;
65     unsigned char _band;
66     unsigned char _userband;
67     unsigned int _freq;
68     unsigned int n = num;
69
70     if(num >= USER_MEMORY_NUM) return;
71
72
73     _fm = setup.fm;
74     _freq = setup.amfreq;
75     _userband = setup.am_userbandnum;
76     _band = setup.amband;
77     if(_fm){
78         _userband = setup.fm_userbandnum;
79         _band = setup.fmband;
80         _freq = setup.fmfreq;
81     }
82     setup.memoryfreqs[n].fm = _fm;
83     setup.memoryfreqs[n].band = (_userband << 5) | (_band & 0x1f);
84     setup.memoryfreqs[n].freq = _freq;
85
86     save_eeprom();
87 }
88
89
90 void on_call_userfreq(void)
91 {
92     unsigned long val = USER_MEMORY_NUM;
93     _CLS();
94     _LOCATE(0,0);
95     printstr("Mem: 00-");
96     print_numeric_nosupress(val - 1, 2);
97     val = read_numeric(val, 2, 4, 1);
98     if(val < 0x80000000) call_freqbank(val);
99 }
100
101 void on_set_userfreq(void)
102 {
103     unsigned long val = USER_MEMORY_NUM;
104     unsigned char n;
105     unsigned char c;
106     _CLS();
107     _LOCATE(0,0);
108     printstr("Set Mem: 00-");
109     print_numeric_nosupress(val - 1, 2);
110     val = read_numeric(val, 2, 4, 1);
111     _HOME();
112     if(val >= 0x80000000) return;
113     printstr("OK? A=OK       ");
114     c = pollkey_single();
115     if(c != charcode_a) return;
116     set_freqbank(val);
117 }
118
119 void on_updown_userfreq(void)
120 {
121     unsigned int _freq;
122     unsigned char _fm;
123     unsigned char _band;
124     unsigned char _userband;
125     unsigned char c;
126     unsigned char dispf = 0xff;
127
128     _fm = setup.fm;
129     _freq = setup.amfreq;
130     _userband = setup.am_userbandnum;
131     _band = setup.amband;
132     if(_fm){
133         _userband = setup.fm_userbandnum;
134         _band = setup.fmband;
135         _freq = setup.fmfreq;
136     }
137
138     _CLS();
139     do {
140         if(dispf != 0) {
141             _LOCATE(0,0);
142             printstr("CH:");
143             print_numeric_nosupress(setup.memorynum, 2);
144             printstr(" HELP = F");
145             update_status();
146             print_freq(1);
147             _HOME();
148         }
149         c = pollkey_single_timeout(41, 1); // About 1s
150         backlight_reset(c);
151         dispf = backlight_dec(dispf);
152        switch(c) {
153            case charcode_7: // UP 1CH
154                 setup.memorynum++;
155                 if(setup.memorynum >= USER_MEMORY_NUM) setup.memorynum = 0;
156                 call_freqbank(setup.memorynum);
157                 break;
158            case charcode_1: // Down 1CH
159                if(setup.memorynum == 0) setup.memorynum = USER_MEMORY_NUM;
160                setup.memorynum--;
161                call_freqbank(setup.memorynum);
162                break;
163             case charcode_5: // Recall
164                call_freqbank(setup.memorynum);
165                break;
166             case charcode_d: // Reset
167                if(_fm) { // AM
168                     setup.fmband = _band;
169                     setup.fm_userbandnum = _userband;
170                     setup.fmfreq = _freq;
171                } else {
172                     setup.amband = _band;
173                     setup.am_userbandnum = _userband;
174                     setup.amfreq = _freq;
175                }
176                akc6955_chg_fm(_fm, _freq);
177                break;
178            case charcode_4:
179                on_call_userfreq();
180                break;
181            case charcode_6:
182                on_set_userfreq();
183                break;
184            case charcode_a:
185                 goto _l0;
186                 break;
187            case charcode_f:
188                userfreq_help();
189                 _CLS();
190                break;
191            case charcode_e: // Set Light
192            default:
193                break;
194            }
195             idle_time_ms(9); // Pad 9ms, 1Loop = 1000ms.
196     } while(1);
197 _l0:
198     _CLS();
199
200 }