OSDN Git Service

[UI][MENU] Change "'5'->'9'" to reload.
[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     c = 0;
94     printstr("User ch:");
95     c = pollkey_numeric(c);
96     if(c >= USER_BAND_NUM) return;
97
98     if(setup.fm != 0){
99         from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
100         to = setup.fm_usrbands[c].stop * 80 + 3000;
101         _CLS();
102         _LOCATE(0,0);
103         printstr("FM#");
104         print_numeric_nosupress(c, 1);
105         _LOCATE(0,1);
106         printstr(" From:");
107         from = read_numeric(from, 5, 7, 1);
108         if((from & 0x80000000) != 0) goto _l0;
109         _LOCATE(0,1);
110         printstr(" To:  ");
111         to = read_numeric(to, 5, 7, 1);
112         if((to & 0x80000000) != 0) goto _l0;
113         setup.fm_usrbands[c].start = (from - 3000) / 80;
114         setup.fm_usrbands[c].stop = (to - 3000) / 80;
115         setup.fm_usrbands[c].freq = from;
116         setup.fm_userbandnum = c;
117     } else {
118         mode3k = setup.am_usrbands[c].mode3k;
119         pp = 96; // 3*32
120         if(mode3k == 0) pp = 160; // 5*32
121         from = setup.am_usrbands[c].start * pp;
122         to = setup.am_usrbands[c].stop * pp;
123         _CLS();
124         _LOCATE(0,0);
125         printstr("AM#");
126         print_numeric_nosupress(c, 1);
127         printstr(" Step:");
128         _LOCATE(0,1);
129         printstr("0=3k 1=5k");
130         cc = pollkey_single();
131         if(cc == charcode_0){
132             pp = 96;
133             mode3k = 0xff;
134         } else if(cc = charcode_1) {
135             pp = 160;
136             mode3k = 0;
137         }
138         _CLS();
139         _LOCATE(0,0);
140         printstr("AM#");
141         print_numeric_nosupress(c, 1);
142         _LOCATE(0,1);
143         printstr(" From:");
144         from = read_numeric(from, 5, 7, 1);
145         if((from & 0x80000000) != 0) goto _l0;
146         _LOCATE(0,1);
147         printstr(" To:  ");
148         to = read_numeric(to, 5, 7, 1);
149         if((to & 0x80000000) != 0) goto _l0;
150         setup.am_usrbands[c].start = from / pp;
151         setup.am_usrbands[c].stop = to  / pp;
152         setup.am_usrbands[c].mode3k = mode3k;
153         setup.am_usrbands[c].freq = from;
154         setup.am_userbandnum = c;
155     }
156     call_userband(c);
157 _l0:
158     _CLS();
159 }
160
161 void input_userband(void)
162 {
163     unsigned char c;
164     do{
165     c = printhelp_2lines("User Band", "   #");
166     if((c >= charcode_a) && (c <= charcode_f)){
167         break;
168     }
169     if(c == charcode_0) {
170         _PUTCHAR('0');
171         if(setup.fm != 0){
172            setup.fm_userbandnum = 0;
173         } else {
174            setup.am_userbandnum = 0;
175         }
176         call_userband(0);
177     } else {
178         c = c - charcode_1 + 1;
179         if(c < USER_BAND_NUM) {
180             _PUTCHAR(c + '0');
181             if(setup.fm != 0){
182                setup.fm_userbandnum = c;
183             } else {
184                 setup.am_userbandnum = c;
185             }
186             call_userband(c);
187         }
188     }
189     idle(setup.ui_idlecount);
190     } while(1);
191     _CLS();
192 }
193