OSDN Git Service

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