OSDN Git Service

[UI] Split ui-depend routines from main.c.
[openi2cradio/OpenI2CRadio.git] / ui_display.c
1 /*
2  * OpenI2CRADIO
3  * UI->LCD->Display status.
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 #include <sdcc-lib.h>
34 #include <pic18fregs.h> /* ONLY FOR PIC18x */
35 #include <signal.h>
36 #include <delay.h>
37
38 #include "commondef.h"
39 #include "iodef.h"
40 #include "idle.h"
41 #include "i2c_io.h"
42 #include "akc6955.h"
43 #include "lcd_acm1602.h"
44 #include "ui.h"
45 #include "eeprom.h"
46 #include "ioports.h"
47 #include "menu.h"
48 #include "power.h"
49 #include "adc_int.h"
50
51
52 void print_freq(unsigned char y)
53 {
54     int freq;
55     int freq_lo;
56     int freq_hi;
57     _LOCATE(0,y);
58     if(fm != 0){ // FM
59         if(fmband < AKC6955_BAND_TV1) {
60             printstr("FM");
61             _PUTCHAR('1' + (fmband & 7));
62             printstr("  ");
63         } else if(fmband < AKC6955_BAND_FMUSER){
64             printstr("TV");
65             _PUTCHAR('1' + fmband - AKC6955_BAND_TV1);
66             printstr("  ");
67         } else { // USER
68             printstr("FMU");
69             _PUTCHAR('0' + fm_userbandnum);
70             _PUTCHAR(' ');
71         }
72     } else { // AM
73         if(amband == AKC6955_BAND_LW) {
74             printstr("LW");
75         } else if(amband <AKC6955_BAND_SW1) { //MW
76             printstr("MW");
77             _PUTCHAR('1' + amband - AKC6955_BAND_MW1);
78             printstr("  ");
79         } else if(amband <AKC6955_BAND_SW10) { //MW
80             printstr("SW");
81             _PUTCHAR('1' + amband - AKC6955_BAND_SW1);
82             printstr("  ");
83         } else if(amband < AKC6955_BAND_AMUSER) { //MW
84             printstr("SW1");
85             _PUTCHAR('0' + amband - AKC6955_BAND_SW10);
86             _PUTCHAR(' ');
87         } else if(amband == AKC6955_BAND_MW4){
88             printstr("MW4  ");
89         } else {
90             printstr("AMU");
91             _PUTCHAR('0' + am_userbandnum);
92             _PUTCHAR(' ');
93         }
94      }
95 //     _LOCATE(15-5 ,1);
96      _LOCATE(16-3-6, y);
97      if(fm != 0){
98          if(stereoflag != 0){
99              printstr("ST");
100          } else {
101              printstr("  ");
102          }
103          freq = fmfreq + diffstat / 100;
104          freq_lo = freq % 100;
105          freq_hi = freq / 100;
106          print_numeric_nosupress(freq_hi, 3);
107          _PUTCHAR('.');
108          print_numeric_nosupress(freq_lo, 2);
109      } else {
110          freq = amfreq + diffstat / 10;
111          printstr("   ");
112          print_numeric_nosupress(freq, 5);
113      }
114      // Signal
115      _LOCATE(16-3, y);
116      if(fm != 0){
117          printstr("MHz");
118      } else {
119          printstr("KHz");
120      }
121 }
122
123 void update_display(void)
124 {
125
126     unsigned int vol;
127     int lv;
128 //    _HOME();
129     _LOCATE(0,0);
130     printstr("S");
131     if(recv_signal < 0){
132         _PUTCHAR('-');
133         lv = - recv_signal;
134         print_numeric_nosupress(lv / 20, 1);
135     } else {
136         lv = recv_signal;
137         print_numeric_nosupress(lv / 20, 1); // MAX=123
138         _PUTCHAR(' ');
139     }
140     if(fm == 0){
141         set_amlamp(1);
142         set_fmlamp(0);
143     } else {
144         set_amlamp(0);
145         set_fmlamp(1);
146     }
147      // vol = volume * 1.5 + prevolume * 3.5[dB]
148      if(volume > 24) {
149          vol = volume - 24;
150          vol = (vol * 3 + prevolume * 7) / 2;
151          printstr("V:");
152          print_numeric_nosupress(vol,2);
153      } else {
154          printstr("MUTE");
155      }
156
157      _LOCATE(16-5,0);
158      print_numeric_nosupress(battlevel / 100, 1);
159      _PUTCHAR('.');
160      print_numeric_nosupress(battlevel % 100, 2);
161      _PUTCHAR('V');
162      print_freq(1);
163 //    _PUTCHAR(' ');
164     _HOME();
165 }