From 80ea0aa72067fc86c296ab284c734e1e45e363af Mon Sep 17 00:00:00 2001 From: "K.Ohta" Date: Thu, 13 Jun 2013 13:53:25 +0900 Subject: [PATCH] [UI] Add userband functions. --- akc6955.c | 15 ++ akc6955.h | 3 +- main.c | 283 +++++++++++++++++++++++++++++++++- nbproject/Makefile-genesis.properties | 2 +- ui.c | 91 +++++++++++ ui.h | 8 +- 6 files changed, 394 insertions(+), 8 deletions(-) diff --git a/akc6955.c b/akc6955.c index b8f2f35..24d738f 100644 --- a/akc6955.c +++ b/akc6955.c @@ -138,6 +138,7 @@ unsigned char akc6955_tune(void) } } + unsigned int akc6955_mode3k(unsigned char flag) { unsigned char b; @@ -268,6 +269,20 @@ void akc6955_set_freq(unsigned int freq) akc6955_set_tune(mode3k, ch); } +void akc6955_set_userband(unsigned char start, unsigned char stop, unsigned int ch, unsigned char mode3k) +{ + unsigned char fm; + fm = akc6955_readcmd(AKC6955_POWER) & 0x40; + akc6955_writecmd(AKC6955_UCH_ST, start); + akc6955_writecmd(AKC6955_UCH_EN, stop); + if(fm == 0){ + akc6955_set_amband(AKC6955_BAND_AMUSER); + } else { + akc6955_set_fmband(AKC6955_BAND_FMUSER); + } + akc6955_set_tune(mode3k, ch); +} + unsigned char akc6955_get_cnr(void) { diff --git a/akc6955.h b/akc6955.h index 5ab2436..5b55b85 100644 --- a/akc6955.h +++ b/akc6955.h @@ -43,7 +43,7 @@ extern "C" { #define AKC6955_CH_HI 2 #define AKC6955_CH_LO 3 #define AKC6955_UCH_ST 4 -#define AKC6955_UCS_EN 5 +#define AKC6955_UCH_EN 5 #define AKC6955_VOLUME 6 #define AKC6955_STEREO 7 #define AKC6955_THRESH 8 @@ -155,6 +155,7 @@ extern unsigned char akc6955_chk_donescan(void); extern unsigned int akc6955_get_freq(void); extern void akc6955_set_freq(unsigned int freq); extern unsigned char akc6955_get_cnr(void); +extern void akc6955_set_userband(unsigned char start, unsigned char stop, unsigned int ch, unsigned char mode3k); extern int akc6955_read_level(void); extern unsigned int akc6955_up_freq(unsigned int step); diff --git a/main.c b/main.c index b514fef..5f6bf63 100644 --- a/main.c +++ b/main.c @@ -106,12 +106,14 @@ unsigned char am_mode3k; unsigned char am_userbandnum; unsigned char fm_userbandnum; typedef struct { + unsigned char mode3k; // mode3k if am unsigned char start; unsigned char stop; + unsigned int freq; } _userband_t; - -_userband_t am_usrbands[4]; -_userband_t fm_usrbands[4]; +#define USER_BAND_NUM 4 +_userband_t am_usrbands[USER_BAND_NUM]; +_userband_t fm_usrbands[USER_BAND_NUM]; unsigned char enter_mode; unsigned char numeric_mode; @@ -200,8 +202,279 @@ void update_display(void) } +void setfreq_direct(void) +{ + unsigned int val; + _CLS(); + if(fm != 0){ + // FM + _LOCATE(0,0); + printstr("Set Freq:FM"); + val = fmfreq; + val = read_numeric(val, 5, 7, 1); + fmfreq = val; + akc6955_set_freq(val); + idle(0xff00); + fmfreq = akc6955_get_freq(); + } else { + // FM + _LOCATE(0,0); + printstr("Set Freq:AM"); + val = amfreq; + val = read_numeric(val, 5, 7, 1); + amfreq = val; + akc6955_set_freq(val); + idle(0xff00); + amfreq = akc6955_get_freq(); + } +} + +void setband_direct(void) +{ + unsigned int band; + _CLS(); + _LOCATE(0,0); + if(fm != 0){ + printstr("Set Band:FM"); + band = fmband & 7; + band = read_numeric(band, 2, 7, 1); + akc6955_set_fmband(band); + akc6955_do_tune(); + idle(0xff00); + fmfreq = akc6955_get_freq(); + } else { + printstr("Set Band:AM"); + band = amband & 0x1f; + band = read_numeric(band, 2, 7, 1); + akc6955_set_amband(band); + akc6955_do_tune(); + idle(0xff00); + amfreq = akc6955_get_freq(); + } +} + +void call_userband(unsigned char num) +{ + unsigned int freq; + unsigned int ch; + if(num >= USER_BAND_NUM) return; + if(fm != 0){ + freq = fm_usrbands[num].freq; + ch = ((freq - 3000) / 25) * 10; + akc6955_set_userband(fm_usrbands[num].start, fm_usrbands[num].stop, ch, + fm_usrbands[num].mode3k); + } else { + unsigned int p = 5; + if(am_usrbands[num].mode3k != 0) p = 3; + freq = am_usrbands[num].freq; + ch = freq / p; + akc6955_set_userband(am_usrbands[num].start, am_usrbands[num].stop, ch, + am_usrbands[num].mode3k); + } +} + +void set_userband(void) +{ + unsigned int from,to; + unsigned char c; + unsigned char p; + unsigned char mode3k; + char cc; + + _CLS(); + _LOCATE(0,0); + printstr("User ch:"); + c = pop_keyinfifo(); + if(c > charcode_0) return; + if(c < charcode_1) return; + if(c == charcode_0) { + c = 0; + } else { + c = c - charcode_1 + 1; + } + if(c >= USER_BAND_NUM) return; + if(fm != 0){ + from = fm_usrbands[c].start * 80 + 3000; // 32*25/10 + to = fm_usrbands[c].stop * 80 + 3000; + _CLS(); + _LOCATE(0,0); + printstr("FM #"); + print_numeric_nosupress(c, 1); + printstr(" From:"); + from = read_numeric(from, 5, 7, 1); + _CLS(); + _LOCATE(0,0); + printstr("FM #"); + print_numeric_nosupress(c, 1); + printstr(" To:"); + to = read_numeric(to, 5, 7, 1); + fm_usrbands[c].start = (from - 3000) / 80; + fm_usrbands[c].stop = (to - 3000) / 80; + fm_usrbands[c].freq = from * 80 + 3000; + fm_userbandnum = c; + } else { + mode3k = am_usrbands[c].mode3k; + p = 96; // 3*32 + if(mode3k == 0) p = 160; // 5*32 + from = am_usrbands[c].start * p; + to = am_usrbands[c].stop * p; + _CLS(); + _LOCATE(0,0); + printstr("AM #"); + print_numeric_nosupress(c, 1); + printstr(" Step:"); + _LOCATE(0,1); + printstr("0=3k 1=5k"); + cc = pop_keyinfifo(); + if(cc == charcode_0){ + p = 96; + mode3k = 0xff; + } else if(cc = charcode_1) { + p = 160; + mode3k = 0; + } + _CLS(); + _LOCATE(0,0); + printstr("AM #"); + print_numeric_nosupress(c, 1); + printstr(" From:"); + from = read_numeric(from, 5, 7, 1); + _CLS(); + _LOCATE(0,0); + printstr("AM #"); + print_numeric_nosupress(c, 1); + printstr(" To:"); + to = read_numeric(to, 5, 7, 1); + am_usrbands[c].start = from / p; + am_usrbands[c].stop = to / p; + am_usrbands[c].mode3k = mode3k; + am_usrbands[c].freq = from * p; + am_userbandnum = c; + } + call_userband(c); +} + +void input_userband(void) +{ + unsigned char c; + do{ + _CLS(); + _LOCATE(0,0); + printstr("User Band"); + _LOCATE(0,1); + printstr(" #"); + c = pop_keyinfifo(); + if((c >= charcode_a) && (c <= charcode_f)){ + break; + } + if(c == charcode_0) { + _PUTCHAR('0'); + if(fm != 0){ + fm_userbandnum = 0; + } else { + am_userbandnum = 0; + } + call_userband(0); + } else { + c = c - charcode_1 + 1; + if(c < USER_BAND_NUM) { + _PUTCHAR(c + '0'); + if(fm != 0){ + fm_userbandnum = c; + } else { + am_userbandnum = c; + } + call_userband(c); + } + } + idle(0xff00); + } while(1); + _CLS(); +} + + +void main_menu(void) +{ + unsigned char c; + + _CLS(); + _LOCATE(0,0); + printstr("Menu:F=HELP"); + _LOCATE(1,0); + printstr("A=CANCEL"); + do{ + c = pop_keyinfifo(); + if((c < charcode_1) || ( c >charcode_s3)) { + idle(0xff00); + continue; // Error + } + if(c == charcode_f){ + // HELP + } else if(c == charcode_a){ + // Cancel + break; + } else if(c == charcode_1){ + // AM + fm = 0; + akc6955_chg_fm(fm); + akc6955_set_amband(amband); + akc6955_set_freq(amfreq); + break; + } else if(c == charcode_2){ + // Band + setband_direct(); + break; + } else if(c == charcode_3){ + // Band + setfreq_direct(); + break; + } else if(c == charcode_4){ + // fm + fm = 0xff; + akc6955_chg_fm(fm); + akc6955_set_fmband(fmband); + akc6955_set_freq(fmfreq); + break; + } else if(c == charcode_5){ + // Scan + break; + } else if(c == charcode_6){ + // Set gain + break; + } else if(c == charcode_7){ + // Set volume + break; + } else if(c == charcode_8){ + // Set sensitivity + break; + } else if(c == charcode_9){ + // Set NF + break; + } else if(c == charcode_0){ + // Setup Menu + break; + } else if(c == charcode_b){ + // Call userband + input_userband(); + break; + } else if(c == charcode_c){ + // Set userband + set_userband(); + break; + } else if(c == charcode_d){ + // Reserve + break; + } else if(c == charcode_e){ + // Reserve + break; + } + idle(0xff00); + } while(1); +} + void setfreq_updown(unsigned char ctlword) { + unsigned char c; #ifndef _LCD_DEBUG switch(ctlword){ case charcode_8: // Change band @@ -300,7 +573,7 @@ void setfreq_updown(unsigned char ctlword) toggle_amfm(); break; case charcode_b: - // Menu / cancel + // Userband break; case charcode_c: break; @@ -311,7 +584,7 @@ void setfreq_updown(unsigned char ctlword) backlight_counter = backlight_long; break; case charcode_f: - // Toggle Numeric/Padkey(NO Numeric is not entered) + main_menu(); break; default: break; diff --git a/nbproject/Makefile-genesis.properties b/nbproject/Makefile-genesis.properties index 3547e54..7ee4ebd 100644 --- a/nbproject/Makefile-genesis.properties +++ b/nbproject/Makefile-genesis.properties @@ -1,5 +1,5 @@ # -#Thu Jun 13 02:58:22 JST 2013 +#Thu Jun 13 11:23:50 JST 2013 default.languagetoolchain.dir=/usr/local/bin default.br-unifei-rmaalmeida-toolchainSDCC-SDCCtoolchain.md5=b67cce1ad75b450308d7806e430931b3 com-microchip-mplab-nbide-embedded-makeproject-MakeProject.md5=8fe1589514540343a5279c082104bce0 diff --git a/ui.c b/ui.c index 3e6d695..1134cd3 100644 --- a/ui.c +++ b/ui.c @@ -26,6 +26,7 @@ */ #include "ui.h" +#include "idle.h" keyin_defs keyin_old[2]; keyin_defs keyin_now; @@ -249,6 +250,96 @@ void printstr(char *s) } while(p < 255); } +void print_numeric_nosupress(unsigned int data, unsigned char digit) +{ + unsigned char i; + unsigned char c; + int ref = 10; + int div = 1; + + if(digit == 0) return; + if(digit >= 5) digit = 5; + _CURSOR_LEFT(); + for(i = 0; i < digit; i++){ + c = (data % ref) / div + '0'; + _PUTCHAR(c); + ref *= 10; + } + _CURSOR_RIGHT(); +} +/* + * Read Numeric(int) + */ +unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c) +{ + unsigned int p = pos; + unsigned int val; + if(p > 4) p = 4; + switch(p){ + case 0: + val = (start / 10) * 10 + c; + break; + case 1: + val = (start / 100) * 100 + start % 10 + c * 10; + break; + case 2: + val = (start / 1000) * 1000 + start % 100 + c * 100; + break; + case 3: + val = (start / 10000) * 10000 + start % 1000 + c * 1000; + break; + case 4: + val = start % 10000 + c * 10000; + break; + default: + val = start; + break; + } + return val; +} + +unsigned int read_numeric(unsigned int initial, unsigned char digit, + char startx, char starty) +{ + unsigned char c; + unsigned char i; + unsigned int val; + unsigned char d; + + d = digit; + if(d > 4) d = 4; + val = initial; + i = 0; + do { + _LOCATE(startx, starty); + print_numeric_nosupress(val, digit); + c = pop_keyinfifo(); + if(c == charcode_0){ + val = subst_numeric(val, i, 0); + i++; + } else if((c >= charcode_1) && (c <= charcode_9)) { + val = subst_numeric(val, i, c - charcode_1 + 1); + } else if(c == charcode_f) { + // Enter + break; + } else if(c == charcode_d) { + // Del + if(i > 0) { + val = (val / 10) * 10; + i--; + } + } else if(c == charcode_b) { + // cancel + val = initial; + break; + } + print_numeric_nosupress(val, d); + idle(0xff00); + } while(i <= d); + return val; +} + + /* * Set signal tune status led assigned to RC0. diff --git a/ui.h b/ui.h index 500fdea..525e8e2 100644 --- a/ui.h +++ b/ui.h @@ -49,6 +49,9 @@ extern char keyin_counter; #define _PUTCHAR(c) acm1602_putchar(0xa0, c) #define _CURSOR_LEFT() acm1602_cursordir(0xa0, 0x00) #define _CURSOR_RIGHT() acm1602_cursordir(0xa0, 0xff) +#define _CLS() acm1602_cls(0xa0); +#define _HOME() acm1602_home(0xa0); + extern void keyin_init(void); extern void keyin_ioinit(void); @@ -61,7 +64,10 @@ extern void printstr(char *s); extern void print_numeric(int i, unsigned char supressf); extern void setsignal_tune(unsigned char flag); extern void set_backlight(unsigned char flag, unsigned int val); - +extern unsigned int read_numeric(unsigned int initial, unsigned char digit, + char startx, char starty); +extern unsigned int subst_numeric(unsigned int start, unsigned char pos, unsigned char c); +extern void print_numeric_nosupress(unsigned int data, unsigned char digit); #ifdef __cplusplus } -- 2.11.0