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:
Sun Apr 12 16:26:28 2015 +0000
Revision:
3:99f4c06f86a0
Parent:
1:365082270f1a
Child:
4:5368e5b2f312
Tidy RDS text code

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