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"
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
92 d = akc6955_getvolumemode();
99 print_numeric_nosupress(setup.volume, 2);
103 _PUTCHAR('0' + (setup.prevolume & 3));
105 if(setup.lowboost == 0x00){
111 // c = pollkeys(pollkeybuf, 5, 1);
113 c = pollkey_single_timeout(22, 1); // 506ms
117 if(setup.volume > 63) setup.volume = 63;
121 if(setup.volume < 23) setup.volume = 23;
131 akc6955_setvolumemode(fact);
135 if(setup.prevolume > 3) setup.prevolume = 0;
136 akc6955_set_prevolume(setup.prevolume);
140 if(setup.lowboost == 0x00){
143 setup.lowboost = fact;
144 akc6955_set_lowboost(setup.lowboost);
149 if(setup.volume < 24){
154 akc6955_setvolume(setup.volume);
160 void scan_start(void)
169 c = pollkey_single_timeout(20, 0) ; // 23*20 = 460ms
170 // n = pollkeys(pollkeybuf, 19, 1);
175 if((akc6955_chk_donescan() == 0) && (scanflag != 0)){
179 printstr("Scan A/4/6/F");
182 } while(c == charcode_null);
183 // c = pollkeybuf[0];
188 akc6955_do_scan(0xff);
195 akc6955_abort_scan();
209 void setfreq_direct(void)
214 printstr("Set Freq:");
220 val = read_numeric(val, 5, 7, 1);
226 val = read_numeric(val, 5, 7, 1);
229 akc6955_set_freq(val);
232 void setband_direct(void)
239 printstr("Set Band:FM#");
240 band = setup.fmband & 7;
241 setup.fmfreq_bank[setup.fmband] = setup.fmfreq;
242 setup.fmband = read_numeric(band, 2, 7, 1);
243 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
244 akc6955_set_fmband(setup.fmband);
247 printstr("Set Band:AM#");
248 band = setup.amband & 0x1f;
249 setup.amfreq_bank[setup.amband] = setup.amfreq;
250 setup.amband = read_numeric(band, 2, 7, 1);
251 setup.amfreq = setup.amfreq_bank[setup.amband];
252 akc6955_set_amband(setup.amband);
256 akc6955_set_freq(freq);
259 void call_userband(unsigned char num)
265 unsigned char mode3k;
269 if(num >= USER_BAND_NUM) return;
271 p = &(setup.am_usrbands[num]);
273 p = &(setup.fm_usrbands[num]);
280 ch = ((freq - 3000) / 5) * 2;
281 setup.fmband = AKC6955_BAND_FMUSER;
284 if(mode3k != 0) q = 3;
286 setup.amband = AKC6955_BAND_AMUSER;
303 akc6955_set_userband(start, end, ch, mode3k);
306 void set_userband(void)
308 unsigned int from,to;
311 unsigned char mode3k;
316 printstr("User ch:");
317 c = pollkey_single();
319 if(c > charcode_0) return;
320 if(c < charcode_1) return;
321 if(c == charcode_0) {
324 c = c - charcode_1 + 1;
326 if(c >= USER_BAND_NUM) return;
329 from = setup.fm_usrbands[c].start * 80 + 3000; // 32*25/10
330 to = setup.fm_usrbands[c].stop * 80 + 3000;
335 print_numeric_nosupress(c, 1);
338 from = read_numeric(from, 5, 7, 1);
341 to = read_numeric(to, 5, 7, 1);
342 setup.fm_usrbands[c].start = (from - 3000) / 80;
343 setup.fm_usrbands[c].stop = (to - 3000) / 80;
344 setup.fm_usrbands[c].freq = from * 80 + 3000;
345 setup.fm_userbandnum = c;
347 mode3k = setup.am_usrbands[c].mode3k;
349 if(mode3k == 0) pp = 160; // 5*32
350 from = setup.am_usrbands[c].start * pp;
351 to = setup.am_usrbands[c].stop * pp;
355 print_numeric_nosupress(c, 1);
358 printstr("0=3k 1=5k");
359 cc = pollkey_single();
360 if(cc == charcode_0){
363 } else if(cc = charcode_1) {
370 print_numeric_nosupress(c, 1);
373 from = read_numeric(from, 5, 7, 1);
376 to = read_numeric(to, 5, 7, 1);
377 setup.am_usrbands[c].start = from / pp;
378 setup.am_usrbands[c].stop = to / pp;
379 setup.am_usrbands[c].mode3k = mode3k;
380 setup.am_usrbands[c].freq = from * pp;
381 setup.am_userbandnum = c;
387 void input_userband(void)
393 printstr("User Band");
396 c = pollkey_single();
398 if((c >= charcode_a) && (c <= charcode_f)){
401 if(c == charcode_0) {
404 setup.fm_userbandnum = 0;
406 setup.am_userbandnum = 0;
410 c = c - charcode_1 + 1;
411 if(c < USER_BAND_NUM) {
414 setup.fm_userbandnum = c;
416 setup.am_userbandnum = c;
421 idle(setup.ui_idlecount);
427 void menu_poweroff(void)
430 c = printhelp_2lines("Poweroff", "A=Yes");
431 if(c == charcode_a) {
436 void setup_akc6955(void)
438 akc6955_writecmd(AKC6955_POWER, 0xc0); // You musto *not* mute, set b2 to '0".
439 akc6955_writecmd(AKC6955_VOLUME, 0xc0); // You must select to radio(b1 = '0).
441 akc6955_set_amband(setup.amband);
442 if(setup.amband == AKC6955_BAND_AMUSER) call_userband(setup.am_userbandnum);
443 setup.amfreq = setup.amfreq_bank[setup.amband];
444 akc6955_chg_fm(0, setup.amfreq); // Set to AM
445 akc6955_set_freq(setup.amfreq);
447 akc6955_set_fmband(setup.fmband);
448 if(setup.fmband == AKC6955_BAND_FMUSER) call_userband(setup.fm_userbandnum);
449 setup.fmfreq = setup.fmfreq_bank[setup.fmband];
450 akc6955_chg_fm(0xff, setup.fmfreq); // Set to AM
451 akc6955_set_freq(setup.fmfreq);
452 }// Dummy, TBS (954KHz)
453 akc6955_set_power(0xff); // Power ON
454 akc6955_setvolume(36); // Temporally
455 akc6955_set_thresh_fmcnr(setup.threshold_fmcnr);
456 akc6955_set_thresh_amcnr(setup.threshold_amcnr);
457 akc6955_set_thresh_width(setup.threshold_width);
458 akc6955_set_thresh_fmstereo(setup.threshold_fmstereo);
459 akc6955_setvolumemode(0);
460 akc6955_set_lowboost(setup.lowboost);
467 c = printhelp_2lines("Save settings", "A=Yes");
468 if(c == charcode_a) {
476 c = printhelp_2lines("Load settings", "A=Yes B=Init");
477 if(c == charcode_a) {
482 c = printhelp_2lines("X) Load Error", "A=Fix");
489 } else if(c == charcode_b){
495 void setup_menu(void)
500 c = printhelp_2lines("Setup F=HELP", "5=Return");
505 printstr("BL Level:");
506 val = read_numeric(setup.backlight_level, 3, 0,1);
507 if(val > 255) val = 255;
508 if(val < 10) val = 15;
509 setup.backlight_level = (unsigned char)val;
514 printstr("FM Bandwidth:");
515 akc6955_get_fmbandwidth(val);
516 val = read_numeric(val, 1, 0, 1) & 3;
517 setup.fmbandwidth = (unsigned char)val;
518 akc6955_set_fmbandwidth(setup.fmbandwidth);
525 printstr("FM-CNR threshold:");
526 val = setup.threshold_fmcnr;
527 val = read_numeric(val, 1, 0, 1);
528 akc6955_set_thresh_fmcnr((unsigned char)val);
533 printstr("AM-CNR threshold:");
534 val = setup.threshold_amcnr;
535 val = read_numeric(val, 1, 0, 1);
536 akc6955_set_thresh_amcnr((unsigned char)val);
541 printstr("Stereo threshold:");
542 val = setup.threshold_fmstereo;
543 val = read_numeric(val, 1, 0, 1);
544 akc6955_set_thresh_fmstereo((unsigned char)val);
561 printstr("BL Long:");
562 val = read_numeric(setup.backlight_long, 3, 0,1);
563 if(val > 999) val = 999;
564 setup.backlight_long = val;
574 * Main Menu : initial-screen -> 'F'.
584 printstr("Menu:F=HELP");
586 printstr("B=CANCEL");
587 c = pollkey_single(); // 1012ms
591 } else if(c == charcode_3){
594 }else if(c == charcode_4){
597 }else if(c == charcode_5){
600 }else if(c == charcode_6){
603 } else if(c == charcode_7){
605 } else if(c == charcode_8){
608 } else if(c == charcode_9){
611 printstr("Sig width:");
612 val = setup.threshold_width;
613 val = read_numeric(val, 1, 0, 1);
614 akc6955_set_thresh_width((unsigned char)val);
616 } else if(c == charcode_0){
619 } else if(c == charcode_a){
621 } else if(c == charcode_c){
624 } else if(c == charcode_d){
627 } else if (c == charcode_f){