OSDN Git Service

[Build] Prepare to build with Microchip's XC8.
[openi2cradio/OpenI2CRadio.git] / ui_updown.c
1 /*
2  * OpenI2CRADIO
3  * Up-down UI routine.
4  * Copyright (C) 2013-06-10 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 <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #if defined(__SDCC)
34 #include <sdcc-lib.h>
35 #include <pic18fregs.h> /* ONLY FOR PIC18x */
36 #include <delay.h>
37 #else
38 #include <xc.h>
39 #endif
40 #include <signal.h>
41
42 #include "iodef.h"
43 #include "idle.h"
44 #include "i2c_io.h"
45 #include "akc6955.h"
46 #include "lcd_acm1602.h"
47 #include "ui.h"
48 #include "eeprom.h"
49 #include "ioports.h"
50 #include "menu.h"
51 #include "power.h"
52 #include "adc_int.h"
53
54 void setfreq_updown(unsigned char ctlword)
55 {
56     switch(ctlword){
57         case charcode_8: // Change band
58                 if(fm == 0){
59                     amfreq_bank[amband] = amfreq;
60                     if(amband >= AKC6955_BAND_MW4) {
61                         amband = 0;
62                     } else {
63                         amband++;
64                     }
65                     amfreq = amfreq_bank[amband];
66                 akc6955_set_amband(amband);
67                 akc6955_set_freq(amfreq);
68                 idle_time_62_5ms(); // 62.5ms
69                 amband = akc6955_get_amband();
70                 amfreq = akc6955_get_freq();
71             } else {
72                     fmfreq_bank[fmband] = fmfreq;
73                     if(fmband >= AKC6955_BAND_FMUSER) {
74                         fmband = 0;
75                     } else {
76                         fmband++;
77                     }
78                     fmfreq = fmfreq_bank[fmband];
79                     akc6955_set_fmband(fmband);
80                     idle_time_62_5ms(); // 62.5ms
81                     akc6955_set_freq(fmfreq);
82                     fmband = akc6955_get_fmband();
83                     fmfreq = akc6955_get_freq();
84             }
85             break;
86         case charcode_2: // Change band
87                 if(fm == 0){
88                     amfreq_bank[amband] = amfreq;
89                     if(amband == 0) {
90                         amband = AKC6955_BAND_MW4;
91                     } else if(amband > AKC6955_BAND_MW4) {
92                         amband = AKC6955_BAND_MW4;
93                     } else {
94                         amband--;
95                     }
96                     amfreq = amfreq_bank[amband];
97                 akc6955_set_amband(amband);
98                 akc6955_set_freq(amfreq);
99                     idle_time_62_5ms(); // 62.5ms
100                 amband = akc6955_get_amband();
101                 amfreq = akc6955_get_freq();
102             } else {
103                     fmfreq_bank[fmband] = fmfreq;
104                     if(fmband == 0) {
105                        fmband = AKC6955_BAND_FMUSER;
106                     } else if(fmband > AKC6955_BAND_FMUSER) {
107                         fmband = AKC6955_BAND_FMUSER;
108                     } else {
109                         fmband--;
110                     }
111                     fmfreq = fmfreq_bank[fmband];
112                     akc6955_set_fmband(fmband);
113                     idle_time_62_5ms(); // 62.5ms
114                     akc6955_set_freq(fmfreq);
115                     fmband = akc6955_get_fmband();
116                     fmfreq = akc6955_get_freq();
117             }
118             break;
119         case charcode_4: // Down Freq;
120             if(fm != 0){
121                 fmfreq = akc6955_down_freq(25); // DOWN 250KHz
122             } else {
123                  amfreq = akc6955_down_freq(30); // DOWN 30KHz
124             }
125             break;
126         case charcode_6: // Down Freq;
127             if(fm != 0){
128     //            fmfreq += 10;
129                 fmfreq = akc6955_up_freq(25); // UP 250KHz
130             } else {
131     //            amfreq += 10;
132                 amfreq = akc6955_up_freq(30); // UP 30KHz
133             }
134             break;
135         case charcode_9: // Down Fast;
136             if(fm != 0){
137       //          fmfreq += 50;
138                 fmfreq = akc6955_up_freq(50); // DOWN 500KHz
139             } else {
140       //          amfreq += 50;
141                 amfreq = akc6955_up_freq(100); // DOWN 100KHz
142             }
143             break;
144         case charcode_7: // Down Fast;
145             if(fm != 0){
146 //                fmfreq -= 50;
147                 fmfreq = akc6955_down_freq(50); // UP 500KHz
148             } else {
149 //                amfreq -= 50;
150                 amfreq = akc6955_down_freq(100); // UP 10KHz
151             }
152             break;
153         case charcode_1: // Down Slow;
154             if(fm != 0){
155   //              fmfreq -= 3;
156                 fmfreq = akc6955_down_freq(3); // DOWN 30KHz
157             } else {
158   //              amfreq -= 3;
159                 if(amband == AKC6955_BAND_MW2) {
160                     amfreq = akc6955_down_freq(9);
161                 } else if(amband == AKC6955_BAND_MW3) {
162                     amfreq = akc6955_down_freq(10);
163                 } else if(am_mode3k == 0x00) {
164                     amfreq = akc6955_down_freq(3); // DOWN 50KHz
165                 } else {
166                     amfreq = akc6955_down_freq(5); // DOWN 50KHz
167                 }
168             }
169             break;
170         case charcode_3: // Down Slow;
171             if(fm != 0){
172 //                fmfreq += 3;
173                 fmfreq = akc6955_up_freq(3); // UP 30KHz
174             } else {
175 //                amfreq += 3;
176                 if(amband == AKC6955_BAND_MW2){
177                     amfreq = akc6955_up_freq(9);
178                 } else if(amband == AKC6955_BAND_MW3) {
179                     amfreq = akc6955_up_freq(10);
180                 } else if(am_mode3k == 0x00) {
181                     amfreq = akc6955_up_freq(3); // DOWN 50KHz
182                 } else {
183                     amfreq = akc6955_up_freq(5); // DOWN 50KHz
184                 }
185             }
186             break;
187         case charcode_0: // Step
188             if(fm == 0){
189                 if(am_mode3k == 0) {
190                     am_mode3k = 0xff;
191                 } else {
192                     am_mode3k = 0;
193                 }
194                 amfreq = akc6955_mode3k(am_mode3k);
195             }
196             break;
197         case charcode_a: // Toggle FM
198             toggle_amfm();
199             break;
200         case charcode_b:
201             set_volume();
202             break;
203         case charcode_c:
204             // Scan
205             scan_start();
206             break;
207         case charcode_d:
208             // FM Narrow/Wide
209             set_stereo();
210             break;
211         case charcode_e: // Backlight ON/OFF
212             if(backlight_counter > 0) {
213                backlight_counter = 0;
214             } else {
215                backlight_counter = backlight_long;
216             }
217             break;
218         case charcode_5:
219             main_menu();
220             break;
221         case charcode_f:
222             updown_help();
223             _CLS();
224             _LOCATE(0,0);
225             break;
226         default:
227             break;
228     }
229 }