OSDN Git Service

[UI][HELP] Fix version string.
[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
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 char freq2;
44     _userband_t *p;
45
46     if(num >= USER_BAND_NUM) return;
47
48     p = &(setup.am_usrbands[num]);
49     if(setup.fm != 0){
50         p = &(setup.fm_usrbands[num]);
51     }
52     freq = p->freq;
53     start = p->start;
54     end = p->stop;
55     mode3k = p->mode3k;
56     if(setup.fm != 0) {
57         ch = ((freq - 3000) / 5) * 2;
58         setup.fmband = AKC6955_BAND_FMUSER;
59     } else {
60         unsigned int q = 5;
61         if(mode3k != 0) q = 3;
62         ch = freq / q;
63         setup.amband = AKC6955_BAND_AMUSER;
64     }
65
66     if(start > end) {
67         unsigned char tmp;
68         tmp = start;
69         start = end;
70         end = tmp;
71     }
72
73     freq2 = ch / 32;
74     if(freq2 > end) {
75         ch = end * 32;
76     }
77     if(freq2 < start){
78         ch = start * 32;
79     }
80     akc6955_set_userband(start, end, ch, mode3k);
81 }
82
83 void set_userband(void)
84 {
85     unsigned long from,to;
86     unsigned char c;
87     unsigned char pp;
88     unsigned char mode3k;
89     char cc;
90
91     _CLS();
92     _LOCATE(0,0);
93     printstr("User ch:");
94     c = pollkey_single();
95
96     if(c > charcode_0) return;
97     if(c < charcode_1) return;
98     if(c == charcode_0) {
99         c = 0;
100     } else {
101         c = c - charcode_1 + 1;
102     }
103     if(c >= USER_BAND_NUM) return;
104
105     if(setup.fm != 0){
106         from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
107         to = setup.fm_usrbands[c].stop * 80 + 3000;
108         _CLS();
109         _LOCATE(0,0);
110         printstr("FM#");
111         print_numeric_nosupress(c, 1);
112         _LOCATE(0,1);
113         printstr(" From:");
114         from = read_numeric(from, 5, 7, 1);
115         if(from >= 0x80000000) goto _l0;
116         _LOCATE(0,1);
117         printstr(" To:  ");
118         to = read_numeric(to, 5, 7, 1);
119         if(to >= 0x80000000) goto _l0;
120         setup.fm_usrbands[c].start = (from - 3000) / 80;
121         setup.fm_usrbands[c].stop = (to - 3000) / 80;
122         setup.fm_usrbands[c].freq = from;
123         setup.fm_userbandnum = c;
124     } else {
125         mode3k = setup.am_usrbands[c].mode3k;
126         pp = 96; // 3*32
127         if(mode3k == 0) pp = 160; // 5*32
128         from = setup.am_usrbands[c].start * pp;
129         to = setup.am_usrbands[c].stop * pp;
130         _CLS();
131         _LOCATE(0,0);
132         printstr("AM#");
133         print_numeric_nosupress(c, 1);
134         printstr(" Step:");
135         _LOCATE(0,1);
136         printstr("0=3k 1=5k");
137         cc = pollkey_single();
138         if(cc == charcode_0){
139             pp = 96;
140             mode3k = 0xff;
141         } else if(cc = charcode_1) {
142             pp = 160;
143             mode3k = 0;
144         }
145         _CLS();
146         _LOCATE(0,0);
147         printstr("AM#");
148         print_numeric_nosupress(c, 1);
149         _LOCATE(0,1);
150         printstr(" From:");
151         from = read_numeric(from, 5, 7, 1);
152         if(from >= 0x80000000) goto _l0;
153         _LOCATE(0,1);
154         printstr(" To:  ");
155         to = read_numeric(to, 5, 7, 1);
156         if(to >= 0x80000000) goto _l0;
157         setup.am_usrbands[c].start = from / pp;
158         setup.am_usrbands[c].stop = to  / pp;
159         setup.am_usrbands[c].mode3k = mode3k;
160         setup.am_usrbands[c].freq = from;
161         setup.am_userbandnum = c;
162     }
163     call_userband(c);
164 _l0:
165     _CLS();
166 }
167
168 void input_userband(void)
169 {
170     unsigned char c;
171     do{
172     c = printhelp_2lines("User Band", "   #");
173     if((c >= charcode_a) && (c <= charcode_f)){
174         break;
175     }
176     if(c == charcode_0) {
177         _PUTCHAR('0');
178         if(setup.fm != 0){
179            setup.fm_userbandnum = 0;
180         } else {
181            setup.am_userbandnum = 0;
182         }
183         call_userband(0);
184     } else {
185         c = c - charcode_1 + 1;
186         if(c < USER_BAND_NUM) {
187             _PUTCHAR(c + '0');
188             if(setup.fm != 0){
189                setup.fm_userbandnum = c;
190             } else {
191                 setup.am_userbandnum = c;
192             }
193             call_userband(c);
194         }
195     }
196     idle(setup.ui_idlecount);
197     } while(1);
198     _CLS();
199 }
200