4 * Copyright (C) 2013-06-21 K.Ohta <whatisthis.sowhat ai gmail.com>
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.
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,
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.
30 #include "menu_memoryfreq.h"
32 #include "commondef.h"
33 #include "backlight.h"
35 void toggle_amfm(void)
40 setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
41 // akc6955_set_amband(amband);
42 freq = setup.amfreq_bank[setup.amband];
45 setup.amfreq_bank[setup.amband] = setup.amfreq;
46 // akc6955_set_fmband(fmband);
47 freq = setup.fmfreq_bank[setup.fmband];
49 akc6955_chg_fm(setup.fm, freq);
51 // akc6955_set_freq(freq);
56 void set_stereomode(void)
60 if(setup.stereo == 0x00){
61 mode.b0 = 1; // Force mono
62 } else if(setup.stereo < 0x80){
63 mode.b1 = 1; // Force stereo
65 akc6955_set_stereomode(mode.byte);
71 if(setup.stereo == 0xff) {// Force Mono
73 } else if(setup.stereo == 0x00) { //Mono->Stereo
75 } else { // Default, Stereo->auto
86 unsigned char dispf = 0xff;
93 d = akc6955_getvolumemode();
100 print_numeric_nosupress(setup.volume, 2);
104 _PUTCHAR('0' + (setup.prevolume & 3));
106 if(setup.lowboost == 0x00){
113 c = pollkey_single_timeout(41, 1); // 506ms
115 dispf = backlight_dec(dispf);
119 if(setup.volume > 63) setup.volume = 63;
123 if(setup.volume < 23) setup.volume = 23;
133 akc6955_setvolumemode(fact);
137 if(setup.prevolume > 3) setup.prevolume = 0;
138 akc6955_set_prevolume(setup.prevolume);
142 if(setup.lowboost == 0x00){
145 setup.lowboost = fact;
146 akc6955_set_lowboost(setup.lowboost);
151 if(setup.volume < 24){
156 akc6955_setvolume(setup.volume);
157 idle_time_ms(9); // Adjust to 1S
162 void scan_start(void)
170 c = pollkey_single_timeout(20, 0) ; // 23*20 = 460ms
173 if((akc6955_chk_donescan() == 0) && (scanflag != 0)){
177 printstr("Scan A/4/6/F");
180 } while(c == charcode_null);
184 akc6955_do_scan(0xff);
191 akc6955_abort_scan();
205 void setfreq_direct(void)
210 printstr("Set Freq:");
216 val = read_numeric(val, 5, 7, 1);
222 val = read_numeric(val, 5, 7, 1);
225 akc6955_set_freq(val);
228 void setband_direct(void)
235 printstr("Set Band:FM#");
236 band = setup.fmband & 7;
237 setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
238 setup.fmband = read_numeric(band, 2, 7, 1);
239 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
240 akc6955_set_fmband(setup.fmband);
243 printstr("Set Band:AM#");
244 band = setup.amband & 0x1f;
245 setup.amfreq_bank[setup.amband] = setup.amfreq;
246 setup.amband = read_numeric(band, 2, 7, 1);
247 setup.amfreq = setup.amfreq_bank[setup.amband];
248 akc6955_set_amband(setup.amband);
252 akc6955_set_freq(freq);
255 void call_userband(unsigned char num)
261 unsigned char mode3k;
265 if(num >= USER_BAND_NUM) return;
267 p = &(setup.am_usrbands[num]);
269 p = &(setup.fm_usrbands[num]);
276 ch = ((freq - 3000) / 5) * 2;
277 setup.fmband = AKC6955_BAND_FMUSER;
280 if(mode3k != 0) q = 3;
282 setup.amband = AKC6955_BAND_AMUSER;
299 akc6955_set_userband(start, end, ch, mode3k);
302 void set_userband(void)
304 unsigned int from,to;
307 unsigned char mode3k;
312 printstr("User ch:");
313 c = pollkey_single();
315 if(c > charcode_0) return;
316 if(c < charcode_1) return;
317 if(c == charcode_0) {
320 c = c - charcode_1 + 1;
322 if(c >= USER_BAND_NUM) return;
325 from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
326 to = setup.fm_usrbands[c].stop * 80 + 3000;
330 print_numeric_nosupress(c, 1);
333 from = read_numeric(from, 5, 7, 1);
336 to = read_numeric(to, 5, 7, 1);
337 setup.fm_usrbands[c].start = (from - 3000) / 80;
338 setup.fm_usrbands[c].stop = (to - 3000) / 80;
339 setup.fm_usrbands[c].freq = from * 80 + 3000;
340 setup.fm_userbandnum = c;
342 mode3k = setup.am_usrbands[c].mode3k;
344 if(mode3k == 0) pp = 160; // 5*32
345 from = setup.am_usrbands[c].start * pp;
346 to = setup.am_usrbands[c].stop * pp;
350 print_numeric_nosupress(c, 1);
353 printstr("0=3k 1=5k");
354 cc = pollkey_single();
355 if(cc == charcode_0){
358 } else if(cc = charcode_1) {
365 print_numeric_nosupress(c, 1);
368 from = read_numeric(from, 5, 7, 1);
371 to = read_numeric(to, 5, 7, 1);
372 setup.am_usrbands[c].start = from / pp;
373 setup.am_usrbands[c].stop = to / pp;
374 setup.am_usrbands[c].mode3k = mode3k;
375 setup.am_usrbands[c].freq = from * pp;
376 setup.am_userbandnum = c;
382 void input_userband(void)
386 c = printhelp_2lines("User Band", " #");
387 if((c >= charcode_a) && (c <= charcode_f)){
390 if(c == charcode_0) {
393 setup.fm_userbandnum = 0;
395 setup.am_userbandnum = 0;
399 c = c - charcode_1 + 1;
400 if(c < USER_BAND_NUM) {
403 setup.fm_userbandnum = c;
405 setup.am_userbandnum = c;
410 idle(setup.ui_idlecount);
416 void menu_poweroff(void)
419 c = printhelp_2lines("Poweroff", "A=Yes");
420 if(c == charcode_a) {
425 void setup_akc6955(void)
427 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
428 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
430 akc6955_set_amband(setup.amband);
431 if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
432 setup.amfreq = setup.amfreq_bank[setup.amband];
433 akc6955_chg_fm(0, setup.amfreq); // Set to AM
434 akc6955_set_freq(setup.amfreq);
436 akc6955_set_fmband(setup.fmband);
437 if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
438 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
439 akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
440 akc6955_set_freq(setup.fmfreq);
441 }// Dummy, TBS (954KHz)
442 akc6955_set_power(0xff); // Power ON
443 akc6955_setvolume(36); // Temporally
444 akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
445 akc6955_set_thresh_amcnr(setup.threshold_amcnr);
446 akc6955_set_thresh_width(setup.threshold_width);
447 akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
448 akc6955_setvolumemode(0);
449 akc6955_set_lowboost(setup.lowboost);
456 c = printhelp_2lines("Save settings", "A=Yes");
457 if(c == charcode_a) {
465 c = printhelp_2lines("Load settings", "A=Yes B=Init");
466 if(c == charcode_a) {
471 c = printhelp_2lines("X) Load Error", "A=Fix");
478 } else if(c == charcode_b){
484 void setup_menu(void)
489 c = printhelp_2lines("Setup F=HELP", "5=Return");
494 printstr("BL Level:");
495 val = read_numeric(setup.backlight_level, 3, 0,1);
496 if(val > 255) val = 255;
497 if(val < 10) val = 15;
498 setup.backlight_level = (unsigned char)val;
501 printstr("FM Bandwidth:");
502 akc6955_get_fmbandwidth(val);
503 val = read_numeric(val, 1, 0, 1) & 3;
504 setup.fmbandwidth = (unsigned char)val;
505 akc6955_set_fmbandwidth(setup.fmbandwidth);
510 printstr("FM-CNR threshold:");
511 val = setup.threshold_fmcnr;
512 val = read_numeric(val, 1, 0, 1);
513 akc6955_set_thresh_fmcnr((unsigned char)val);
516 printstr("AM-CNR threshold:");
517 val = setup.threshold_amcnr;
518 val = read_numeric(val, 1, 0, 1);
519 akc6955_set_thresh_amcnr((unsigned char)val);
522 printstr("Stereo threshold:");
523 val = setup.threshold_fmstereo;
524 val = read_numeric(val, 1, 0, 1);
525 akc6955_set_thresh_fmstereo((unsigned char)val);
540 printstr("BL Long:");
541 val = read_numeric(setup.backlight_long, 3, 0,1);
542 if(val > 999) val = 999;
543 setup.backlight_long = val;
555 * Main Menu : initial-screen -> 'F'.
562 c = printhelp_2lines("Menu: F=HELP", "B=CANCEL");
566 } else if(c == charcode_3){
569 }else if(c == charcode_4){
572 }else if(c == charcode_5){
575 }else if(c == charcode_6){
578 } else if(c == charcode_7){
580 } else if(c == charcode_8){
583 } else if(c == charcode_9){
586 printstr("Sig width:");
587 val = setup.threshold_width;
588 val = read_numeric(val, 1, 0, 1);
589 akc6955_set_thresh_width((unsigned char)val);
591 } else if(c == charcode_0){
594 } else if(c == charcode_a){
596 } else if(c == charcode_c){
599 } else if(c == charcode_d){
602 } else if (c == charcode_f){