RDA5807M FM RDS radio program using 4DSystems 32028 Oled touch screen display. Search and direct frequency selection, RDS text, 10 preset memories

Dependencies:   4Dsystems_uOLED-32028-P1T RDA5807M FreescaleIAP mbed-src

/media/uploads/star297/fm_radio.jpg

Committer:
star297
Date:
Sat Apr 11 22:53:48 2015 +0000
Revision:
1:365082270f1a
Parent:
0:879245ce9cdb
Child:
3:99f4c06f86a0
Version 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:879245ce9cdb 1 #include "mbed.h"
star297 0:879245ce9cdb 2 #include "RDA5807M.h"
star297 0:879245ce9cdb 3 #include "OLED32028P1T.h"
star297 1:365082270f1a 4
star297 1:365082270f1a 5 RDA5807M radio(p9, p10); // sda - scl
star297 1:365082270f1a 6
star297 1:365082270f1a 7 OLED32028P1T oled(p28, p27, p26); // Oled Display tx, rx, rs
star297 1:365082270f1a 8
star297 1:365082270f1a 9 DigitalOut led(LED1);
star297 0:879245ce9cdb 10
star297 1:365082270f1a 11 Timer t1;
star297 1:365082270f1a 12
star297 1:365082270f1a 13 int f,v,n,i,l,r,g,b,Fl,IRQ,xbuf,ybuf,pr,prgroup;
star297 1:365082270f1a 14 int signal,lastsignal,volume,lastvol,lastmute,lastmono,lastbass,lastrds,laststereo,rdstextgood;
star297 0:879245ce9cdb 15
star297 1:365082270f1a 16 float lastfreq,pointer,lastpointer,Freq;
star297 0:879245ce9cdb 17
star297 1:365082270f1a 18 char k;
star297 1:365082270f1a 19 char sig[4];
star297 1:365082270f1a 20 char tFQ[20],freq[8],vol[4];
star297 1:365082270f1a 21 char station[10],lastStationName[10];
star297 1:365082270f1a 22 char text1[50],lasttext1[50];
star297 1:365082270f1a 23 char text2[50],lasttext2[50];
star297 1:365082270f1a 24 char PresetName[10][12] = {"Empty A ", "Empty A ", "Empty A ", "Empty A ", "Empty A ", "Empty B ", "Empty B ", "Empty B ", "Empty B ", "Empty B "};
star297 0:879245ce9cdb 25
star297 1:365082270f1a 26 float PresetFreq[10];
star297 1:365082270f1a 27
star297 1:365082270f1a 28 void radiomain(),initdisplay(),displayrefresh(),getrds();
star297 1:365082270f1a 29 void getkey(),flushbuffer(),Volume(),setfreq(),Power(),Preset(),Drawpresets();
star297 1:365082270f1a 30
star297 1:365082270f1a 31 int main() {
star297 0:879245ce9cdb 32 oled.init();
star297 0:879245ce9cdb 33 oled.clear();
star297 0:879245ce9cdb 34 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 35 oled.setFontSize(FONT5X7);oled.locate(2,20);
star297 0:879245ce9cdb 36 oled.setFontColor(oled.toRGB(255,255,255));
star297 1:365082270f1a 37 oled.enableTouch();oled.resetTouchArea();
star297 1:365082270f1a 38
star297 1:365082270f1a 39 radio.Reset(); // reset and power up radio chip
star297 0:879245ce9cdb 40
star297 1:365082270f1a 41 while(1){
star297 1:365082270f1a 42 initdisplay();
star297 1:365082270f1a 43 radiomain();
star297 1:365082270f1a 44 }
star297 1:365082270f1a 45 }
star297 1:365082270f1a 46
star297 1:365082270f1a 47
star297 1:365082270f1a 48 void radiomain()
star297 1:365082270f1a 49 {
star297 1:365082270f1a 50 while(IRQ==0){
star297 1:365082270f1a 51
star297 1:365082270f1a 52 getkey();
star297 0:879245ce9cdb 53
star297 1:365082270f1a 54 //oled.setFontSize(FONT5X7);oled.locate(20,0);
star297 1:365082270f1a 55 //oled.printf("X %03d Y %03d ",xbuf,ybuf);
star297 0:879245ce9cdb 56
star297 1:365082270f1a 57 if(radio.power){
star297 1:365082270f1a 58 if(f){setfreq();f=0;}
star297 1:365082270f1a 59 radio.processData();
star297 1:365082270f1a 60 getrds();
star297 1:365082270f1a 61 displayrefresh();
star297 1:365082270f1a 62 wait_ms(10);
star297 1:365082270f1a 63 led=!led;
star297 1:365082270f1a 64 }
star297 1:365082270f1a 65 }
star297 1:365082270f1a 66 }
star297 1:365082270f1a 67
star297 1:365082270f1a 68 void displayrefresh()
star297 1:365082270f1a 69 {
star297 1:365082270f1a 70 if (strcmp(lastStationName, radio.StationName) != 0){
star297 1:365082270f1a 71 oled.drawTextGraphic(26,16,(FONT12X16),radio.StationName, 1, 1, oled.toRGB(0,200,200));
star297 1:365082270f1a 72 strcpy(lastStationName,radio.StationName);
star297 1:365082270f1a 73 }
star297 1:365082270f1a 74 if(lastfreq != radio.freq/1000){lastfreq = radio.freq/1000;
star297 1:365082270f1a 75 sprintf(tFQ, "%3.2f ",radio.freq/1000);
star297 1:365082270f1a 76 oled.drawTextGraphic(176,16,(FONT12X16),tFQ, 1, 1, oled.toRGB(0,200,200));
star297 1:365082270f1a 77 pointer = (lastfreq-87) *12;
star297 1:365082270f1a 78 oled.setPenSize(0);
star297 1:365082270f1a 79 oled.drawRectangle(lastpointer+29,66,10,8,oled.toRGB(0,0,0));
star297 1:365082270f1a 80 oled.drawRectangle(lastpointer+33,56,2,18,oled.toRGB(0,0,0));
star297 1:365082270f1a 81 oled.drawRectangle(pointer+29,66,10,8,oled.toRGB(255,255,255));
star297 1:365082270f1a 82 oled.drawRectangle(pointer+33,56,2,18,oled.toRGB(255,0,0));
star297 1:365082270f1a 83 lastpointer = pointer;
star297 1:365082270f1a 84 rdstextgood=0;lastrds=!lastrds;
star297 1:365082270f1a 85 oled.setPenSize(1);
star297 1:365082270f1a 86 }
star297 1:365082270f1a 87 if(laststereo != radio.stereo){
star297 1:365082270f1a 88 if(radio.stereo){oled.drawTextGraphic(32,79,(FONT5X7),"Stereo", 1, 1, oled.toRGB(0,255,0));}
star297 1:365082270f1a 89 else{oled.drawTextGraphic(32,79,(FONT5X7)," Mono ", 1, 1, oled.toRGB(255,0,0));}
star297 1:365082270f1a 90 laststereo = radio.stereo;
star297 1:365082270f1a 91 }
star297 1:365082270f1a 92 if(lastsignal != radio.signal){
star297 1:365082270f1a 93 signal=radio.signal;
star297 1:365082270f1a 94 if(radio.mute){signal=0;}
star297 1:365082270f1a 95 sprintf(sig, "%d ",signal);
star297 1:365082270f1a 96 oled.drawTextGraphic(124,79,(FONT5X7),sig, 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 97 if(signal<20){r=255;g=0;b=0;}
star297 1:365082270f1a 98 if(signal>19 && signal<24){r=255;g=255;b=0;}
star297 1:365082270f1a 99 if(signal>23){r=0;g=255;b=0;}
star297 1:365082270f1a 100 oled.setPenSize(0);
star297 1:365082270f1a 101 oled.drawRectangle(140,79,(lastsignal*2.4),6,oled.toRGB(0,0,0));
star297 1:365082270f1a 102 oled.drawRectangle(140,79,(signal*2.4),6,oled.toRGB(r,g,b));
star297 1:365082270f1a 103 oled.setPenSize(1);
star297 1:365082270f1a 104 lastsignal=radio.signal;
star297 1:365082270f1a 105 }
star297 1:365082270f1a 106 if(lastvol != radio.volume){
star297 1:365082270f1a 107 volume=radio.volume;
star297 1:365082270f1a 108 sprintf(vol," %d ", volume);
star297 1:365082270f1a 109 if(radio.volume<10){oled.drawTextGraphic(94,196,(FONT12X16),vol, 1, 1, oled.toRGB(255,255,255));}
star297 1:365082270f1a 110 else{oled.drawTextGraphic(88,196,(FONT12X16),vol, 1, 1, oled.toRGB(255,255,255));}
star297 1:365082270f1a 111 lastvol = volume;
star297 1:365082270f1a 112 }
star297 1:365082270f1a 113 if(lastmute != radio.mute){
star297 1:365082270f1a 114 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 115 if(radio.mute){oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Mute ");}
star297 1:365082270f1a 116 else{oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Mute ");}
star297 1:365082270f1a 117 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 118 lastmute=radio.mute;
star297 1:365082270f1a 119 }
star297 1:365082270f1a 120 if(lastmono != radio.mono){
star297 1:365082270f1a 121 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 122 if(radio.mono){oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,0,0)), 1, 1, " Mono ");}
star297 1:365082270f1a 123 else{oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "Stereo");}
star297 1:365082270f1a 124 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 125 lastmono=radio.mono;
star297 1:365082270f1a 126 }
star297 1:365082270f1a 127 if(lastbass != radio.bass){
star297 1:365082270f1a 128 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 129 if(radio.bass){oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Bass ");}
star297 1:365082270f1a 130 else{oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Bass ");}
star297 1:365082270f1a 131 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 132 lastbass=radio.bass;
star297 1:365082270f1a 133 }
star297 1:365082270f1a 134 if(lastrds != radio.rds){
star297 1:365082270f1a 135 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 136 oled.setPenSize(0);oled.drawRectangle(30,96,280,18,oled.toRGB(0,0,0));oled.setPenSize(1);
star297 1:365082270f1a 137 if(radio.rds){
star297 1:365082270f1a 138 if(rdstextgood){oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "RDS RT");}
star297 1:365082270f1a 139 else{oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " RDS ");}
star297 1:365082270f1a 140 }
star297 1:365082270f1a 141 else{oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " RDS ");rdstextgood=0;}
star297 1:365082270f1a 142 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 143 lastrds=radio.rds;
star297 1:365082270f1a 144 }
star297 1:365082270f1a 145 if (strcmp(text1, lasttext1) != 0){
star297 1:365082270f1a 146 oled.setPenSize(0);oled.drawRectangle(30,96,280,8,oled.toRGB(0,0,0));oled.setPenSize(1);
star297 1:365082270f1a 147 oled.drawTextGraphic(30,96,(FONT5X7),text1, 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 148 strcpy(lasttext1, text1);}
star297 1:365082270f1a 149 if (strcmp(text2, lasttext2) != 0){
star297 1:365082270f1a 150 oled.setPenSize(0);oled.drawRectangle(30,106,280,8,oled.toRGB(0,0,0));oled.setPenSize(1);
star297 1:365082270f1a 151 oled.drawTextGraphic(30,106,(FONT5X7),text2, 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 152 strcpy(lasttext2, text2);}
star297 1:365082270f1a 153 }
star297 1:365082270f1a 154
star297 1:365082270f1a 155 void getrds()
star297 1:365082270f1a 156 {
star297 1:365082270f1a 157 if(strlen(radio.RDSText)==64 && signal>23){
star297 1:365082270f1a 158 //oled.drawTextGraphic(10,200,(FONT5X7),radio._RDSText, 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 159 memset(text1, '\0', sizeof(text1));
star297 1:365082270f1a 160 memset(text2, '\0', sizeof(text2));
star297 1:365082270f1a 161 memset(lasttext1, '\0', sizeof(lasttext1));
star297 1:365082270f1a 162 memset(lasttext2, '\0', sizeof(lasttext2));
star297 1:365082270f1a 163 if(!rdstextgood){rdstextgood=1;lastrds=!lastrds;}
star297 1:365082270f1a 164 strcpy (text1, radio.RDSText);
star297 1:365082270f1a 165
star297 1:365082270f1a 166 for ( i = 0; i < (64); i++ )
star297 1:365082270f1a 167 if (i>30 && (text1[i] == ' ') ){
star297 1:365082270f1a 168 text1 [strlen(text1) - (64-i)] = '\0';
star297 1:365082270f1a 169 l=strlen(text1);
star297 1:365082270f1a 170 i=64;
star297 1:365082270f1a 171 }
star297 1:365082270f1a 172 strcpy (text2, radio.RDSText + l);
star297 1:365082270f1a 173 while(text2[0]==' '){
star297 1:365082270f1a 174 strcpy (text2, (text2 + 1));
star297 1:365082270f1a 175 }
star297 1:365082270f1a 176 strcat (text1,"\0");
star297 1:365082270f1a 177 strcat (text2,"\0");
star297 1:365082270f1a 178 memset(radio.RDSText, '\0', sizeof(radio.RDSText));
star297 0:879245ce9cdb 179 }
star297 0:879245ce9cdb 180 }
star297 0:879245ce9cdb 181
star297 1:365082270f1a 182 void initdisplay()
star297 1:365082270f1a 183 {
star297 1:365082270f1a 184 oled.setPenSize(1);
star297 1:365082270f1a 185 oled.drawTextGraphic(50,6,(FONT5X7),"Station Frequency", 1, 1, oled.toRGB(0,200,200));
star297 1:365082270f1a 186 oled.drawTextGraphic(260,16,(FONT12X16),"MHz", 1, 1, oled.toRGB(0,200,200));
star297 1:365082270f1a 187 oled.drawTextGraphic(42,35,(FONT5X7),"88 90 92 94 96 98 100 102 104 106 108", 1, 1, oled.toRGB(255,255,0));
star297 1:365082270f1a 188 oled.drawTextGraphic(78,79,(FONT5X7),"Signal:", 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 189 oled.drawRectangle(26,55,268,20,oled.toRGB(255,255,255));
star297 1:365082270f1a 190 oled.drawRectangle(26,75,268,14,oled.toRGB(255,255,255));
star297 1:365082270f1a 191 for (i = 46; i < (300); i=i+24 )
star297 1:365082270f1a 192 {oled.drawLine(i,55,i,45,oled.toRGB(255,255,255));
star297 1:365082270f1a 193 oled.drawLine(i-12,55,i-12,50,oled.toRGB(255,255,255));
star297 1:365082270f1a 194 }
star297 1:365082270f1a 195 oled.drawTextGraphic(90,220,(FONT8X12),"Volume", 1, 1, oled.toRGB(255,255,255));
star297 1:365082270f1a 196 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 197 oled.drawTextButton(1, 10, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, " 0 ");
star297 1:365082270f1a 198 oled.drawTextButton(1, 56, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, ".");
star297 1:365082270f1a 199 oled.drawTextButton(1, 10, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "1");
star297 1:365082270f1a 200 oled.drawTextButton(1, 33, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "2");
star297 1:365082270f1a 201 oled.drawTextButton(1, 56, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "3");
star297 1:365082270f1a 202 oled.drawTextButton(1, 10, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "4");
star297 1:365082270f1a 203 oled.drawTextButton(1, 33, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "5");
star297 1:365082270f1a 204 oled.drawTextButton(1, 56, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "6");
star297 1:365082270f1a 205 oled.drawTextButton(1, 10, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "7");
star297 1:365082270f1a 206 oled.drawTextButton(1, 33, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "8");
star297 1:365082270f1a 207 oled.drawTextButton(1, 56, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "9");
star297 1:365082270f1a 208 oled.drawTextButton(1, 86, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, " Up ");
star297 1:365082270f1a 209 oled.drawTextButton(1, 86, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, " Down ");
star297 1:365082270f1a 210 oled.drawTextButton(1, 146, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "+");
star297 1:365082270f1a 211 oled.drawTextButton(1, 146, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "-");
star297 1:365082270f1a 212 oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " RDS ");
star297 1:365082270f1a 213 oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "Stereo");
star297 1:365082270f1a 214 oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Bass ");
star297 1:365082270f1a 215 oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Mute ");
star297 1:365082270f1a 216 oled.drawTextButton(1, 260, 218,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "Power ");
star297 1:365082270f1a 217
star297 1:365082270f1a 218 oled.drawTextButton(1, 190, 134,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets A");
star297 1:365082270f1a 219 oled.drawTextButton(1, 190, 154,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[0]);
star297 1:365082270f1a 220 oled.drawTextButton(1, 190, 171,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[1]);
star297 1:365082270f1a 221 oled.drawTextButton(1, 190, 188,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[2]);
star297 1:365082270f1a 222 oled.drawTextButton(1, 190, 205,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[3]);
star297 1:365082270f1a 223 oled.drawTextButton(1, 190, 222,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[4]);
star297 1:365082270f1a 224 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 225 }
star297 1:365082270f1a 226
star297 1:365082270f1a 227 void getkey()
star297 1:365082270f1a 228 {
star297 1:365082270f1a 229 flushbuffer();
star297 1:365082270f1a 230 oled.getTouch(&xbuf,&ybuf);
star297 1:365082270f1a 231 if(radio.power){
star297 1:365082270f1a 232 if((xbuf>16 && xbuf<34) && (ybuf>180 && ybuf<202)) {k='1';f=1;}
star297 1:365082270f1a 233 if((xbuf>38 && xbuf<54) && (ybuf>180 && ybuf<202)) {k='2';f=1;}
star297 1:365082270f1a 234 if((xbuf>58 && xbuf<78) && (ybuf>180 && ybuf<202)) {k='3';f=1;}
star297 1:365082270f1a 235 if((xbuf>16 && xbuf<34) && (ybuf>158 && ybuf<178)) {k='4';f=1;}
star297 1:365082270f1a 236 if((xbuf>38 && xbuf<54) && (ybuf>158 && ybuf<178)) {k='5';f=1;}
star297 1:365082270f1a 237 if((xbuf>58 && xbuf<78) && (ybuf>158 && ybuf<178)){k='6';f=1;}
star297 1:365082270f1a 238 if((xbuf>16 && xbuf<34) && (ybuf>135 && ybuf<154)) {k='7';f=1;}
star297 1:365082270f1a 239 if((xbuf>38 && xbuf<54) && (ybuf>135 && ybuf<154)){k='8';f=1;}
star297 1:365082270f1a 240 if((xbuf>58 && xbuf<78) && (ybuf>135 && ybuf<154)){k='9';f=1;}
star297 1:365082270f1a 241 if((xbuf>16 && xbuf<56) && (ybuf>205 && ybuf<225)) {k='0';f=1;}
star297 1:365082270f1a 242 if((xbuf>60 && xbuf<78) && (ybuf>205 && ybuf<225)) {k='.';f=1;}
star297 1:365082270f1a 243 if((xbuf>248 && xbuf<298) && (ybuf>194 && ybuf<210)){radio.Mute();}
star297 1:365082270f1a 244 if((xbuf>248 && xbuf<298) && (ybuf>176 && ybuf<192)){radio.BassBoost();}
star297 1:365082270f1a 245 if((xbuf>248 && xbuf<298) && (ybuf>158 && ybuf<174)){radio.Mono();}
star297 1:365082270f1a 246 if((xbuf>248 && xbuf<298) && (ybuf>138 && ybuf<156)){radio.RDS();}
star297 1:365082270f1a 247 if((xbuf>140 && xbuf<160) && (ybuf>180 && ybuf<202)){v=1;Volume();}
star297 1:365082270f1a 248 if((xbuf>140 && xbuf<160) && (ybuf>204 && ybuf<226)){v=0;Volume();}
star297 1:365082270f1a 249 if((xbuf>86 && xbuf<160) && (ybuf>135 && ybuf<155)){radio.SeekUp();}
star297 1:365082270f1a 250 if((xbuf>86 && xbuf<160) && (ybuf>157 && ybuf<179)){radio.SeekDown();}
star297 1:365082270f1a 251
star297 1:365082270f1a 252 if((xbuf>182 && xbuf<244) && (ybuf>137 && ybuf<150)){
star297 1:365082270f1a 253 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 254 if(prgroup==0){prgroup=5;oled.drawTextButton(1, 190, 134,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets A");}
star297 1:365082270f1a 255 else{prgroup=0;oled.drawTextButton(1, 190, 134,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets B");}
star297 1:365082270f1a 256 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 257 Drawpresets();
star297 1:365082270f1a 258 }
star297 1:365082270f1a 259 if((xbuf>182 && xbuf<244) && (ybuf>154 && ybuf<166)){pr=0;Preset();}
star297 1:365082270f1a 260 if((xbuf>182 && xbuf<244) && (ybuf>170 && ybuf<180)){pr=1;Preset();}
star297 1:365082270f1a 261 if((xbuf>182 && xbuf<244) && (ybuf>184 && ybuf<196)){pr=2;Preset();}
star297 1:365082270f1a 262 if((xbuf>182 && xbuf<244) && (ybuf>198 && ybuf<210)){pr=3;Preset();}
star297 1:365082270f1a 263 if((xbuf>182 && xbuf<244) && (ybuf>212 && ybuf<225)){pr=4;Preset();}
star297 1:365082270f1a 264 }
star297 1:365082270f1a 265 if((xbuf>248 && xbuf<298) && (ybuf>212 && ybuf<228)){Power();}
star297 1:365082270f1a 266 }
star297 1:365082270f1a 267
star297 1:365082270f1a 268 void Preset()
star297 1:365082270f1a 269 {
star297 1:365082270f1a 270
star297 1:365082270f1a 271 if(PresetFreq[pr+prgroup]!=0 && PresetFreq[pr+prgroup]==radio.freq/1000){
star297 1:365082270f1a 272 strcpy(PresetName[pr+prgroup],"Empty ");
star297 1:365082270f1a 273 if(prgroup){strcat(PresetName[pr+prgroup],"B ");}
star297 1:365082270f1a 274 else{strcat(PresetName[pr+prgroup],"A ");}
star297 1:365082270f1a 275 PresetFreq[pr+prgroup]=0;
star297 1:365082270f1a 276 Drawpresets();
star297 1:365082270f1a 277 return;
star297 1:365082270f1a 278 }
star297 1:365082270f1a 279
star297 1:365082270f1a 280 if(PresetFreq[pr+prgroup]==0){
star297 1:365082270f1a 281 if(radio.signal>25){
star297 1:365082270f1a 282 strcpy(PresetName[pr+prgroup],radio.StationName);}
star297 1:365082270f1a 283 else{
star297 1:365082270f1a 284 sprintf(tFQ, "%3.2f MHz",radio.freq/1000);
star297 1:365082270f1a 285 strcpy(PresetName[pr+prgroup],tFQ);
star297 1:365082270f1a 286 }
star297 1:365082270f1a 287 while(strlen(PresetName[pr+prgroup])<10){
star297 1:365082270f1a 288 strcat(PresetName[pr+prgroup]," ");
star297 1:365082270f1a 289 }
star297 1:365082270f1a 290 PresetFreq[pr+prgroup]=radio.freq/1000;
star297 1:365082270f1a 291 Drawpresets();
star297 1:365082270f1a 292 return;
star297 1:365082270f1a 293 }
star297 1:365082270f1a 294
star297 1:365082270f1a 295 radio.Frequency(PresetFreq[pr+prgroup]);
star297 1:365082270f1a 296 }
star297 1:365082270f1a 297
star297 1:365082270f1a 298 void Drawpresets()
star297 1:365082270f1a 299 {
star297 1:365082270f1a 300 oled.setTextBackgroundType (TEXT_TRANSPARENT);
star297 1:365082270f1a 301 if(PresetFreq[0+prgroup]!=0){oled.drawTextButton(1, 190, 154,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(0,255,255)), 1, 1, PresetName[0+prgroup]);}
star297 1:365082270f1a 302 else{oled.drawTextButton(1, 190, 154,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[0+prgroup]);}
star297 1:365082270f1a 303 if(PresetFreq[1+prgroup]!=0){oled.drawTextButton(1, 190, 171,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(0,255,255)), 1, 1, PresetName[1+prgroup]);}
star297 1:365082270f1a 304 else{oled.drawTextButton(1, 190, 171,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[1+prgroup]);}
star297 1:365082270f1a 305 if(PresetFreq[2+prgroup]!=0){oled.drawTextButton(1, 190, 188,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(0,255,255)), 1, 1, PresetName[2+prgroup]);}
star297 1:365082270f1a 306 else{oled.drawTextButton(1, 190, 188,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[2+prgroup]);}
star297 1:365082270f1a 307 if(PresetFreq[3+prgroup]!=0){oled.drawTextButton(1, 190, 205,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(0,255,255)), 1, 1, PresetName[3+prgroup]);}
star297 1:365082270f1a 308 else{oled.drawTextButton(1, 190, 205,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[3+prgroup]);}
star297 1:365082270f1a 309 if(PresetFreq[4+prgroup]!=0){oled.drawTextButton(1, 190, 222,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(0,255,255)), 1, 1, PresetName[4+prgroup]);}
star297 1:365082270f1a 310 else{oled.drawTextButton(1, 190, 222,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[4+prgroup]);}
star297 1:365082270f1a 311 oled.setTextBackgroundType (TEXT_OPAQUE);
star297 1:365082270f1a 312 }
star297 1:365082270f1a 313
star297 1:365082270f1a 314 void setfreq()
star297 1:365082270f1a 315 {
star297 1:365082270f1a 316 oled.setPenSize(0);oled.drawRectangle(176,16,80,14,oled.toRGB(0,0,0));oled.setPenSize(1);
star297 1:365082270f1a 317 Fl = strlen(freq);
star297 1:365082270f1a 318 if(Fl< 6){freq[Fl] = k;}
star297 1:365082270f1a 319 if (freq[0]!='1' && freq[0]!='8' && freq[0]!='9'){
star297 1:365082270f1a 320 freq[0]='\0';}
star297 1:365082270f1a 321 oled.drawTextGraphic(176,16,(FONT12X16),freq, 1, 1, oled.toRGB(0,200,200));
star297 1:365082270f1a 322 if (freq[0]=='8' || freq[0]=='9'){Fl=5;}
star297 1:365082270f1a 323 else{Fl=6;}
star297 1:365082270f1a 324 if(strlen(freq)==Fl){
star297 1:365082270f1a 325 Freq = strtof (freq, NULL);
star297 1:365082270f1a 326 radio.Frequency(Freq);
star297 1:365082270f1a 327 memset(freq, '\0', sizeof(freq));
star297 1:365082270f1a 328 }
star297 1:365082270f1a 329 }
star297 1:365082270f1a 330
star297 1:365082270f1a 331 void Volume()
star297 1:365082270f1a 332 {
star297 1:365082270f1a 333 if(v){volume++;}
star297 1:365082270f1a 334 if(!v){volume--;}
star297 1:365082270f1a 335 if(volume > 15){volume = 15;}
star297 1:365082270f1a 336 if(volume < 0){volume = 0;}
star297 1:365082270f1a 337 radio.Volume(volume);
star297 1:365082270f1a 338 }
star297 1:365082270f1a 339
star297 1:365082270f1a 340 void Power()
star297 1:365082270f1a 341 {
star297 1:365082270f1a 342 if(radio.power){
star297 1:365082270f1a 343 radio.RDS();
star297 1:365082270f1a 344 radio.processData();
star297 1:365082270f1a 345 displayrefresh();
star297 1:365082270f1a 346 rdstextgood=0;
star297 1:365082270f1a 347 radio.PowerOff();
star297 1:365082270f1a 348 radio.processData();
star297 1:365082270f1a 349 displayrefresh();
star297 1:365082270f1a 350 led=0;
star297 1:365082270f1a 351 }
star297 1:365082270f1a 352 else{
star297 1:365082270f1a 353 radio.PowerOn();
star297 1:365082270f1a 354 radio.RDS();
star297 1:365082270f1a 355 radio.Frequency(lastfreq);
star297 1:365082270f1a 356 radio.processData();
star297 1:365082270f1a 357 }
star297 1:365082270f1a 358 }
star297 1:365082270f1a 359
star297 1:365082270f1a 360 void flushbuffer()
star297 1:365082270f1a 361 {
star297 1:365082270f1a 362 while (xbuf!=0 && ybuf!=0){oled.getTouch(&xbuf,&ybuf);}
star297 1:365082270f1a 363 }
star297 1:365082270f1a 364
star297 1:365082270f1a 365
star297 1:365082270f1a 366
star297 1:365082270f1a 367
star297 1:365082270f1a 368
star297 1:365082270f1a 369
star297 1:365082270f1a 370
star297 1:365082270f1a 371
star297 1:365082270f1a 372
star297 1:365082270f1a 373