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
87 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); // 943ms
115 dispf = backlight_dec(dispf);
120 if(setup.volume > 63) setup.volume = 63;
121 akc6955_setvolume(setup.volume);
125 if(setup.volume < 23) setup.volume = 23;
126 akc6955_setvolume(setup.volume);
136 akc6955_setvolumemode(fact);
137 akc6955_setvolume(setup.volume);
141 if(setup.prevolume > 3) setup.prevolume = 0;
142 akc6955_set_prevolume(setup.prevolume);
143 akc6955_setvolume(setup.volume);
147 if(setup.lowboost == 0x00){
150 setup.lowboost = fact;
151 akc6955_set_lowboost(setup.lowboost);
152 akc6955_setvolume(setup.volume);
157 if(setup.volume < 24){
162 idle_time_ms(9); // Pad.
167 void scan_start(void)
176 c = pollkey_single_timeout(20, 0) ; // 23*20 = 460ms
179 if((akc6955_chk_donescan() == 0) && (scanflag != 0)){
183 printstr("Scan A/4/6/F");
186 } while(c == charcode_null);
191 akc6955_do_scan(0xff);
198 akc6955_abort_scan();
212 void setfreq_direct(void)
217 printstr("Set Freq:");
223 val = read_numeric(val, 5, 7, 1);
229 val = read_numeric(val, 5, 7, 1);
232 akc6955_set_freq(val);
235 void setband_direct(void)
242 printstr("Set Band:FM#");
243 band = setup.fmband & 7;
244 setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
245 setup.fmband = read_numeric(band, 2, 7, 1);
246 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
247 akc6955_set_fmband(setup.fmband);
250 printstr("Set Band:AM#");
251 band = setup.amband & 0x1f;
252 setup.amfreq_bank[setup.amband] = setup.amfreq;
253 setup.amband = read_numeric(band, 2, 7, 1);
254 setup.amfreq = setup.amfreq_bank[setup.amband];
255 akc6955_set_amband(setup.amband);
259 akc6955_set_freq(freq);
262 void call_userband(unsigned char num)
268 unsigned char mode3k;
272 if(num >= USER_BAND_NUM) return;
274 p = &(setup.am_usrbands[num]);
276 p = &(setup.fm_usrbands[num]);
283 ch = ((freq - 3000) / 5) * 2;
284 setup.fmband = AKC6955_BAND_FMUSER;
287 if(mode3k != 0) q = 3;
289 setup.amband = AKC6955_BAND_AMUSER;
306 akc6955_set_userband(start, end, ch, mode3k);
309 void set_userband(void)
311 unsigned int from,to;
314 unsigned char mode3k;
319 printstr("User ch:");
320 c = pollkey_single();
322 if(c > charcode_0) return;
323 if(c < charcode_1) return;
324 if(c == charcode_0) {
327 c = c - charcode_1 + 1;
329 if(c >= USER_BAND_NUM) return;
332 from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
333 to = setup.fm_usrbands[c].stop * 80 + 3000;
338 print_numeric_nosupress(c, 1);
341 from = read_numeric(from, 5, 7, 1);
344 to = read_numeric(to, 5, 7, 1);
345 setup.fm_usrbands[c].start = (from - 3000) / 80;
346 setup.fm_usrbands[c].stop = (to - 3000) / 80;
347 setup.fm_usrbands[c].freq = from * 80 + 3000;
348 setup.fm_userbandnum = c;
350 mode3k = setup.am_usrbands[c].mode3k;
352 if(mode3k == 0) pp = 160; // 5*32
353 from = setup.am_usrbands[c].start * pp;
354 to = setup.am_usrbands[c].stop * pp;
358 print_numeric_nosupress(c, 1);
361 printstr("0=3k 1=5k");
362 cc = pollkey_single();
363 if(cc == charcode_0){
366 } else if(cc = charcode_1) {
373 print_numeric_nosupress(c, 1);
376 from = read_numeric(from, 5, 7, 1);
379 to = read_numeric(to, 5, 7, 1);
380 setup.am_usrbands[c].start = from / pp;
381 setup.am_usrbands[c].stop = to / pp;
382 setup.am_usrbands[c].mode3k = mode3k;
383 setup.am_usrbands[c].freq = from * pp;
384 setup.am_userbandnum = c;
390 void input_userband(void)
394 c = printhelp_2lines("User Band", " #");
397 if((c >= charcode_a) && (c <= charcode_f)){
400 if(c == charcode_0) {
403 setup.fm_userbandnum = 0;
405 setup.am_userbandnum = 0;
409 c = c - charcode_1 + 1;
410 if(c < USER_BAND_NUM) {
413 setup.fm_userbandnum = c;
415 setup.am_userbandnum = c;
420 idle(setup.ui_idlecount);
426 void menu_poweroff(void)
429 c = printhelp_2lines("Poweroff", "A=Yes");
430 if(c == charcode_a) {
435 void setup_akc6955(void)
437 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
438 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
440 akc6955_set_amband(setup.amband);
441 if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
442 setup.amfreq = setup.amfreq_bank[setup.amband];
443 akc6955_chg_fm(0, setup.amfreq); // Set to AM
444 akc6955_set_freq(setup.amfreq);
446 akc6955_set_fmband(setup.fmband);
447 if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
448 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
449 akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
450 akc6955_set_freq(setup.fmfreq);
451 }// Dummy, TBS (954KHz)
452 akc6955_set_power(0xff); // Power ON
453 akc6955_setvolume(36); // Temporally
454 akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
455 akc6955_set_thresh_amcnr(setup.threshold_amcnr);
456 akc6955_set_thresh_width(setup.threshold_width);
457 akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
458 akc6955_setvolumemode(0);
459 akc6955_set_lowboost(setup.lowboost);
466 c = printhelp_2lines("Save settings", "A=Yes");
467 if(c == charcode_a) {
475 c = printhelp_2lines("Load settings", "A=Yes B=Init");
476 if(c == charcode_a) {
481 c = printhelp_2lines("X) Load Error", "A=Fix");
488 } else if(c == charcode_b){
494 void setup_menu(void)
499 c = printhelp_2lines("Setup F=HELP", "5=Return");
504 printstr("BL Level:");
505 val = read_numeric(setup.backlight_level, 3, 0,1);
506 if(val > 255) val = 255;
507 if(val < 10) val = 15;
508 setup.backlight_level = (unsigned char)val;
513 printstr("FM Bandwidth:");
514 akc6955_get_fmbandwidth(val);
515 val = read_numeric(val, 1, 0, 1) & 3;
516 setup.fmbandwidth = (unsigned char)val;
517 akc6955_set_fmbandwidth(setup.fmbandwidth);
524 printstr("FM-CNR threshold:");
525 val = setup.threshold_fmcnr;
526 val = read_numeric(val, 1, 0, 1);
527 akc6955_set_thresh_fmcnr((unsigned char)val);
532 printstr("AM-CNR threshold:");
533 val = setup.threshold_amcnr;
534 val = read_numeric(val, 1, 0, 1);
535 akc6955_set_thresh_amcnr((unsigned char)val);
540 printstr("Stereo threshold:");
541 val = setup.threshold_fmstereo;
542 val = read_numeric(val, 1, 0, 1);
543 akc6955_set_thresh_fmstereo((unsigned char)val);
560 printstr("BL Long:");
561 val = read_numeric(setup.backlight_long, 3, 0,1);
562 if(val > 999) val = 999;
563 setup.backlight_long = val;
573 * Main Menu : initial-screen -> 'F'.
580 printhelp_2lines("Menu:F=HELP", "B=CANCEL");
581 c = pollkey_single(); // 1012ms
585 } else if(c == charcode_3){
588 }else if(c == charcode_4){
591 }else if(c == charcode_5){
594 }else if(c == charcode_6){
597 } else if(c == charcode_7){
599 } else if(c == charcode_8){
602 } else if(c == charcode_9){
605 printstr("Sig width:");
606 val = setup.threshold_width;
607 val = read_numeric(val, 1, 0, 1);
608 akc6955_set_thresh_width((unsigned char)val);
610 } else if(c == charcode_0){
613 } else if(c == charcode_a){
615 } else if(c == charcode_c){
618 } else if(c == charcode_d){
621 } else if (c == charcode_f){