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

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "RDA5807M.h"
00003 #include "OLED32028P1T.h"
00004 
00005 #if defined(TARGET_Freescale)
00006     #include "FreescaleIAP.h"
00007     //RDA5807M radio(PTC9, PTC8); // sda - scl KL25
00008     RDA5807M radio(PTB4, PTB3); // sda - scl KL05
00009     //OLED32028P1T oled(PTE0, PTE1, PTD7);  // Oled Display tx, rx, rs KL25
00010     OLED32028P1T oled(PTB2, PTB1, PTA11);  // Oled Display tx, rx, rs KL05
00011 #else   
00012     //RDA5807M radio(p9, p10);      // sda - scl LPC1768
00013     RDA5807M radio(p28, p27);     // sda - scl LPC1768      
00014     //OLED32028P1T oled(p28, p27, p29);     // Oled Display tx, rx, rs
00015     OLED32028P1T oled(p13, p14, p26);     // Oled Display tx, rx, rs
00016     //RDA5807M radio(PC4, PC5);     // sda - scl EFM32
00017     //OLED32028P1T oled(PC0, PC1, PC2);     // Oled Display tx, rx, rs EFM32
00018 #endif
00019 
00020 Timer t1;
00021 
00022 int x,f,v,n,i,l,r,g,b,Fl,IRQ,xbuf,ybuf,pr,prgroup;
00023 int signal,lastsignal,volume,lastvol,lastmute,lastmono,lastbass,lastrds,laststereo,lastsynchro;
00024 int txtlen1,txtlen2;
00025 
00026 float lastfreq,pointer,lastpointer,Freq;
00027 float PresetFreq[11];
00028 
00029 char k;
00030 char tFQ[20],freq[8],vol[4],sig[4];
00031 char lastStationName[10];
00032 char RDStxt[70],RDStxt1[70],RDStxt2[70],lasttext1[70],lasttext2[70],lastCT[12];
00033 char PresetName[10][11] = {"Empty   A ", "Empty   A ", "Empty   A ", "Empty   A ", "Empty   A ", "Empty   B ", "Empty   B ", "Empty   B ", "Empty   B ", "Empty   B "};
00034 
00035 void radiomain(),initdisplay(),displayrefresh(),getrds(),savepresets(),loadpresets();
00036 void getkey(),flushbuffer(),Volume(),setfreq(),Power(),Preset(),Drawpresets(); 
00037  
00038 int main() { 
00039   
00040     oled.init();
00041     oled.clear();
00042     oled.setTextBackgroundType (TEXT_OPAQUE);
00043     oled.setFontSize(FONT5X7);oled.locate(2,20);
00044     oled.setFontColor(oled.toRGB(255,255,255));
00045     oled.enableTouch();oled.resetTouchArea();   
00046     radio.Reset();      // reset and power up radio chip    
00047     
00048     while(1){    
00049         initdisplay();
00050         loadpresets();
00051         if(PresetFreq[0]!=0){radio.Frequency(PresetFreq[0]);}
00052         radiomain();        
00053     }
00054 }
00055 
00056 void radiomain()
00057 {
00058     while(IRQ==0){
00059      
00060         getkey();   
00061         
00062     //oled.setFontSize(FONT5X7);oled.locate(20,0);  // include to calibrate touch screen buttons.
00063     //oled.printf("X %03d Y %03d  ",xbuf,ybuf);  
00064         
00065         if(radio.power){
00066             if(f){
00067                 t1.reset();t1.start();
00068                 setfreq();f=0;                
00069                 }
00070             radio.ProcessData();
00071             getrds();
00072             if(t1.read()>5){oled.drawTextGraphic(176,16,(FONT12X16),tFQ, 1, 1, oled.toRGB(0,200,200));t1.stop();}            
00073             displayrefresh();        
00074             wait_ms(10);
00075         }          
00076     }      
00077 }
00078 
00079 void displayrefresh()
00080 {   
00081     if (strcmp(lastStationName, radio.StationName) != 0){
00082         if(strlen(radio.StationName)<9){
00083             oled.drawTextGraphic(26,16,(FONT12X16),radio.StationName, 1, 1, oled.toRGB(0,200,200));
00084             strcpy(lastStationName,radio.StationName);
00085             }
00086         }    
00087     if(lastfreq != (radio.freq/1000) && (radio.freq/1000<108.10)){lastfreq = radio.freq/1000;
00088         sprintf(tFQ, "%3.2f ",radio.freq/1000);
00089         oled.drawTextGraphic(176,16,(FONT12X16),tFQ, 1, 1, oled.toRGB(0,200,200));       
00090         pointer = (lastfreq-87) *12;        
00091         oled.setPenSize(0);
00092         oled.drawRectangle(lastpointer+29,66,10,8,oled.toRGB(0,0,0));
00093         oled.drawRectangle(lastpointer+33,56,2,18,oled.toRGB(0,0,0));
00094         oled.drawRectangle(pointer+29,66,10,8,oled.toRGB(255,255,255));       
00095         oled.drawRectangle(pointer+33,56,2,18,oled.toRGB(255,0,0));
00096         oled.setPenSize(1);        
00097         lastpointer = pointer;
00098         lastsynchro=0;lastrds=!lastrds;       
00099         }
00100     if(laststereo != radio.stereo){
00101         if(radio.stereo){oled.drawTextGraphic(32,79,(FONT5X7),"Stereo", 1, 1, oled.toRGB(0,255,0));}
00102             else{oled.drawTextGraphic(32,79,(FONT5X7)," Mono ", 1, 1, oled.toRGB(255,0,0));}
00103         laststereo = radio.stereo;
00104         }        
00105     if(lastsignal != radio.signal){
00106         signal=radio.signal;
00107         if(radio.mute){signal=0;}
00108         sprintf(sig, "%d ",signal);
00109         oled.drawTextGraphic(124,79,(FONT5X7),sig, 1, 1, oled.toRGB(255,255,255));
00110         if(signal<10){r=255;g=0;b=0;}
00111         if(signal>9 && signal<24){r=255;g=255;b=0;}
00112         if(signal>15){r=0;g=255;b=0;}        
00113         oled.setPenSize(0);
00114         oled.drawRectangle(140,79,(lastsignal*2.4),6,oled.toRGB(0,0,0));
00115         oled.drawRectangle(140,79,(signal*2.4),6,oled.toRGB(r,g,b));
00116         oled.setPenSize(1);
00117         lastsignal=radio.signal;       
00118         }
00119     if(lastvol != radio.volume){
00120         volume=radio.volume;
00121         sprintf(vol," %d ", volume);
00122         oled.setPenSize(0);oled.setTextBackgroundType (TEXT_TRANSPARENT);    
00123         oled.drawRectangle(82,183,58,49,oled.toRGB(100,100,100));
00124         oled.drawTextGraphic(90,216,(FONT8X12),"Volume", 1, 1, oled.toRGB(255,255,255));  
00125         if(radio.volume<10){oled.drawTextGraphic(94,194,(FONT12X16),vol, 1, 1, oled.toRGB(255,255,255));} 
00126             else{oled.drawTextGraphic(88,194,(FONT12X16),vol, 1, 1, oled.toRGB(255,255,255));}    
00127         lastvol = volume;oled.setTextBackgroundType (TEXT_OPAQUE); 
00128         }
00129     if(lastmute != radio.mute){
00130         oled.setTextBackgroundType (TEXT_TRANSPARENT);
00131         if(radio.mute){oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Mute ");}
00132             else{oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Mute ");}
00133         oled.setTextBackgroundType (TEXT_OPAQUE);    
00134         lastmute=radio.mute;
00135         }
00136     if(lastmono != radio.mono){
00137         oled.setTextBackgroundType (TEXT_TRANSPARENT);
00138         if(radio.mono){oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,0,0)), 1, 1, " Mono ");}
00139             else{oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "Stereo");}
00140         oled.setTextBackgroundType (TEXT_OPAQUE);    
00141         lastmono=radio.mono;
00142         }      
00143     if(lastbass != radio.bass){
00144         oled.setTextBackgroundType (TEXT_TRANSPARENT);
00145         if(radio.bass){oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Bass ");}
00146             else{oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Bass ");}
00147         oled.setTextBackgroundType (TEXT_OPAQUE);    
00148         lastbass=radio.bass;
00149         }
00150     if(lastrds != radio.rds){
00151         oled.setTextBackgroundType (TEXT_TRANSPARENT);
00152         oled.setPenSize(0);oled.drawRectangle(0,95,320,18,oled.toRGB(0,0,0));oled.setPenSize(1);
00153         if(radio.rds){oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " RDS  ");}
00154             else{oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " RDS  ");lastsynchro=0;}            
00155         oled.setTextBackgroundType (TEXT_OPAQUE);    
00156         lastrds=radio.rds;
00157         }
00158     if(lastsynchro == 0 && radio.rdssynchro == 0x1000){
00159         oled.setTextBackgroundType (TEXT_TRANSPARENT);
00160         oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "RDS RT");
00161         oled.setTextBackgroundType (TEXT_OPAQUE);
00162         lastsynchro=1;        
00163         }                              
00164     if (strcmp(RDStxt1, lasttext1) != 0 || strcmp(RDStxt2, lasttext2) != 0){
00165         oled.setPenSize(0);oled.drawRectangle(0,95,320,18,oled.toRGB(0,0,0));oled.setPenSize(1);      
00166         if(strlen(RDStxt1)<41){oled.drawTextGraphic(20,96,(FONT5X7),RDStxt1, 1, 1, oled.toRGB(255,255,255));}
00167         memset(lasttext1, '\0', sizeof(lasttext1));strcpy(lasttext1, RDStxt1);           
00168         if(strlen(RDStxt2)<41){oled.drawTextGraphic(20,106,(FONT5X7),RDStxt2, 1, 1, oled.toRGB(255,255,255));}
00169         memset(lasttext2, '\0', sizeof(lasttext2));strcpy(lasttext2, RDStxt2);  
00170         }           
00171     if(strcmp(lastCT, radio.CTtime) !=0){    
00172         oled.drawTextGraphic(265,120,(FONT5X7),radio.CTtime, 1, 1, oled.toRGB(255,255,255));
00173         strcpy(lastCT,radio.CTtime);
00174         }  
00175 }       
00176 
00177 void getrds()
00178 {   
00179     if(strlen(radio.RDSText)>3){               
00180         memset(RDStxt1, '\0', sizeof(RDStxt1));
00181         memset(RDStxt2, '\0', sizeof(RDStxt2));
00182                                  
00183     // format into 2 lines of text seperated by first 'space' after 30 characters
00184         strcpy(RDStxt1,radio.RDSText);
00185         n=strlen(RDStxt1);    
00186         for ( i = 0; i < (n); i++ ){
00187             if (i>30 && (RDStxt1[i] == ' ') ){              
00188                 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';               
00189                 l=strlen(RDStxt1);
00190                 x=1;
00191                 break; // break if more than 30 characters with space 
00192                 }
00193             if(i>39){
00194                 RDStxt1 [strlen(RDStxt1) - (n-i)] = '\0';
00195                 l=strlen(RDStxt1);
00196                 x=1;
00197                 break; //break if more than 39 characters with no spaces
00198                 }
00199             }
00200         if(x==1){           
00201             strcpy (RDStxt2, radio.RDSText + l);
00202             while(RDStxt2[0]==' '){
00203                 strcpy (RDStxt2, (RDStxt2 + 1));
00204             }
00205             x=0;
00206         }
00207     }   
00208 }
00209 
00210 void initdisplay()
00211 {    
00212     oled.setPenSize(1);
00213     oled.drawTextGraphic(50,6,(FONT5X7),"Station                  Frequency", 1, 1, oled.toRGB(0,200,200));
00214     oled.drawTextGraphic(260,16,(FONT12X16),"MHz", 1, 1, oled.toRGB(0,200,200));    
00215     oled.drawTextGraphic(42,35,(FONT5X7),"88  90  92  94  96  98 100 102 104 106 108", 1, 1, oled.toRGB(255,255,0));
00216     oled.drawTextGraphic(78,79,(FONT5X7),"Signal:", 1, 1, oled.toRGB(255,255,255));
00217     oled.drawRectangle(26,55,268,20,oled.toRGB(255,255,255));
00218     oled.drawRectangle(26,75,268,14,oled.toRGB(255,255,255));        
00219     for (i = 46; i < (300); i=i+24 )
00220         {oled.drawLine(i,55,i,45,oled.toRGB(255,255,255));
00221          oled.drawLine(i-12,55,i-12,50,oled.toRGB(255,255,255));
00222         }
00223     oled.drawTextGraphic(10,120,(FONT5X7),"Direct Tune       Seek           Preset", 1, 1, oled.toRGB(0,128,128));                   
00224     oled.setTextBackgroundType (TEXT_TRANSPARENT);    
00225     oled.drawTextButton(1, 10, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, " 0 ");
00226     oled.drawTextButton(1, 56, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, ".");   
00227     oled.drawTextButton(1, 10, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "1");
00228     oled.drawTextButton(1, 33, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "2");
00229     oled.drawTextButton(1, 56, 184,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "3");
00230     oled.drawTextButton(1, 10, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "4");    
00231     oled.drawTextButton(1, 33, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "5");
00232     oled.drawTextButton(1, 56, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "6");
00233     oled.drawTextButton(1, 10, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "7");
00234     oled.drawTextButton(1, 33, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "8");
00235     oled.drawTextButton(1, 56, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "9");    
00236     oled.drawTextButton(1, 82, 132,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "   Up   ");
00237     oled.drawTextButton(1, 82, 158,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "  Down  ");    
00238     oled.drawTextButton(1, 146, 184,(oled.toRGB(100,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "+ ");
00239     oled.drawTextButton(1, 146, 210,(oled.toRGB(100,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "- ");    
00240     oled.drawTextButton(1, 260, 134,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " RDS  ");
00241     oled.drawTextButton(1, 260, 155,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(0,255,0)), 1, 1, "Stereo");
00242     oled.drawTextButton(1, 260, 176,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(128,128,128)), 1, 1, " Bass ");
00243     oled.drawTextButton(1, 260, 197,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " Mute ");
00244     oled.drawTextButton(1, 260, 218,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "Power ");
00245      
00246     oled.drawTextButton(1, 190, 132,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets  B"); 
00247     oled.drawTextButton(1, 190, 154,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[0]);
00248     oled.drawTextButton(1, 190, 171,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[1]);
00249     oled.drawTextButton(1, 190, 188,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[2]);
00250     oled.drawTextButton(1, 190, 205,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[3]);
00251     oled.drawTextButton(1, 190, 222,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[4]);   
00252     oled.setTextBackgroundType (TEXT_OPAQUE);   
00253 }
00254 
00255 void getkey()
00256 {
00257     flushbuffer();
00258     oled.getTouch(&xbuf,&ybuf);
00259     if(radio.power){
00260         if((xbuf>12 && xbuf<32) && (ybuf>188 && ybuf<210))  {k='1';f=1;}
00261         if((xbuf>34 && xbuf<52) && (ybuf>188 && ybuf<210))  {k='2';f=1;}
00262         if((xbuf>56 && xbuf<74) && (ybuf>188 && ybuf<210))  {k='3';f=1;}
00263         if((xbuf>12 && xbuf<32) && (ybuf>162 && ybuf<184))  {k='4';f=1;}
00264         if((xbuf>34 && xbuf<52) && (ybuf>162 && ybuf<184))  {k='5';f=1;}
00265         if((xbuf>56 && xbuf<74) && (ybuf>162 && ybuf<184))  {k='6';f=1;}
00266         if((xbuf>12 && xbuf<32) && (ybuf>138 && ybuf<160))  {k='7';f=1;}
00267         if((xbuf>34 && xbuf<52) && (ybuf>138 && ybuf<160))  {k='8';f=1;}
00268         if((xbuf>56 && xbuf<74) && (ybuf>138 && ybuf<160))  {k='9';f=1;}
00269         if((xbuf>12 && xbuf<54) && (ybuf>212 && ybuf<232))  {k='0';f=1;}
00270         if((xbuf>56 && xbuf<74) && (ybuf>212 && ybuf<232))  {k='.';f=1;}
00271         if((xbuf>248 && xbuf<296) && (ybuf>200 && ybuf<218)){radio.Mute();}
00272         if((xbuf>248 && xbuf<296) && (ybuf>182 && ybuf<198)){radio.BassBoost();}
00273         if((xbuf>248 && xbuf<296) && (ybuf>160 && ybuf<180)){radio.Mono();}
00274         if((xbuf>248 && xbuf<296) && (ybuf>140 && ybuf<158)){radio.RDS();}    
00275         if((xbuf>140 && xbuf<170) && (ybuf>188 && ybuf<208)){v=1;Volume();}
00276         if((xbuf>140 && xbuf<170) && (ybuf>212 && ybuf<230)){v=0;Volume();}
00277         if((xbuf>80 && xbuf<176) && (ybuf>138 && ybuf<160)){radio.SeekUp();}
00278         if((xbuf>80 && xbuf<176) && (ybuf>162 && ybuf<184)){radio.SeekDown();}
00279         
00280         if((xbuf>182 && xbuf<244) && (ybuf>136 && ybuf<156)){
00281             oled.setTextBackgroundType (TEXT_TRANSPARENT);
00282             if(prgroup==0){prgroup=5;oled.drawTextButton(1, 190, 132,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets  A");}
00283                 else{prgroup=0;oled.drawTextButton(1, 190, 132,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(255,255,255)), 1, 1, "Presets  B");}
00284             oled.setTextBackgroundType (TEXT_OPAQUE);
00285             Drawpresets(); 
00286             }
00287         if((xbuf>182 && xbuf<244) && (ybuf>160 && ybuf<172)){pr=0;Preset();}
00288         if((xbuf>182 && xbuf<244) && (ybuf>174 && ybuf<188)){pr=1;Preset();}
00289         if((xbuf>182 && xbuf<244) && (ybuf>190 && ybuf<204)){pr=2;Preset();}
00290         if((xbuf>182 && xbuf<244) && (ybuf>206 && ybuf<220)){pr=3;Preset();} 
00291         if((xbuf>182 && xbuf<244) && (ybuf>224 && ybuf<234)){pr=4;Preset();} 
00292     }
00293     if((xbuf>252 && xbuf<304) && (ybuf>220 && ybuf<236)){Power();}           
00294 }
00295 
00296 void Preset()
00297 {    
00298     if(PresetFreq[pr+prgroup]!=0 && PresetFreq[pr+prgroup]==radio.freq/1000){
00299         strcpy(PresetName[pr+prgroup],"Empty   ");
00300         if(prgroup){strcat(PresetName[pr+prgroup],"B ");}
00301             else{strcat(PresetName[pr+prgroup],"A ");}
00302         PresetFreq[pr+prgroup]=0;
00303         Drawpresets();
00304         savepresets();
00305         return;
00306         }    
00307     if(PresetFreq[pr+prgroup]==0){
00308         if(radio.signal>20 || radio.rdssynchro == 0x1000){
00309             strcpy(PresetName[pr+prgroup],radio.StationName);}
00310             else{
00311                 sprintf(tFQ, "%3.2f MHz",radio.freq/1000);
00312                 strcpy(PresetName[pr+prgroup],tFQ);
00313                 }
00314         while(strlen(PresetName[pr+prgroup])<10){
00315             strcat(PresetName[pr+prgroup]," ");            
00316             }                      
00317         PresetFreq[pr+prgroup]=radio.freq/1000;
00318         Drawpresets();
00319         savepresets();
00320         return;
00321         }    
00322     radio.Frequency(PresetFreq[pr+prgroup]);    
00323 }
00324 
00325 void savepresets()
00326 {
00327 #if defined(TARGET_Freescale)
00328     int address = flash_size() - SECTOR_SIZE;           //Write in last sector    
00329     erase_sector(address);    
00330     program_flash(address, (char*)&PresetFreq, 44);        //10 integers of 4 bytes each: 40 bytes length
00331     program_flash(address+44, (char*)&PresetName, 440);
00332 #endif    
00333 }
00334 
00335 void loadpresets()
00336 {    
00337 #if defined(TARGET_Freescale)
00338     int address = flash_size() - SECTOR_SIZE;    
00339     int *check = (int*)address;
00340     float *datafreq = (float*)address;   
00341     if (check[0] != -1){    
00342         for (i = 0; i<11; i++) {                  
00343             PresetFreq[i] = (datafreq[i]);            
00344             }            
00345         char *dataname = (char*)address+44;           
00346         memcpy (PresetName, dataname, 440);                
00347     }
00348     Drawpresets();
00349 #endif    
00350 }    
00351 
00352 void Drawpresets()
00353 {
00354     oled.setTextBackgroundType (TEXT_TRANSPARENT); 
00355     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]);}
00356         else{oled.drawTextButton(1, 190, 154,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[0+prgroup]);}    
00357     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]);}
00358         else{oled.drawTextButton(1, 190, 171,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[1+prgroup]);}       
00359     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]);}
00360         else{oled.drawTextButton(1, 190, 188,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[2+prgroup]);}   
00361     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]);}
00362         else{oled.drawTextButton(1, 190, 205,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[3+prgroup]);}   
00363     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]);}
00364         else{oled.drawTextButton(1, 190, 222,(oled.toRGB(0,100,100)),(FONT5X7),(oled.toRGB(128,128,128)), 1, 1, PresetName[4+prgroup]);}   
00365     oled.setTextBackgroundType (TEXT_OPAQUE); 
00366 }    
00367 
00368 void setfreq()
00369 {    
00370     Fl = strlen(freq); 
00371     if(Fl< 6){freq[Fl] = k;}    
00372     if (freq[0]!='1' && freq[0]!='8' && freq[0]!='9'){
00373         freq[0]='\0';}
00374     oled.setPenSize(0);oled.drawRectangle(176,16,80,14,oled.toRGB(0,0,0));oled.setPenSize(1);
00375     oled.drawTextGraphic(176,16,(FONT12X16),freq, 1, 1, oled.toRGB(0,200,200));
00376     if (freq[0]=='8' || freq[0]=='9'){Fl=5;}
00377         else{Fl=6;} 
00378     if(strlen(freq)==Fl){
00379         Freq = strtof (freq, NULL);
00380         if(Freq>86.99 && Freq<108.01){
00381             radio.Frequency(Freq);
00382             }
00383             else{lastfreq=0;}
00384         memset(freq, '\0', sizeof(freq));
00385     }       
00386 }    
00387 
00388 void Volume()
00389 {
00390     if(v){volume++;}
00391     if(!v){volume--;}    
00392     if(volume > 15){volume = 15;}
00393     if(volume < 0){volume = 0;}  
00394     radio.Volume(volume);    
00395 }
00396 
00397 void Power()
00398 {
00399     if(radio.power){      
00400         radio.RDS();
00401         radio.ProcessData();
00402         displayrefresh();
00403         radio.PowerOff();
00404         radio.ProcessData();
00405         displayrefresh();
00406     }    
00407     else{    
00408         radio.PowerOn();
00409         radio.RDS();
00410         radio.Frequency(lastfreq);
00411         radio.ProcessData();    
00412     }   
00413 }
00414 
00415 void flushbuffer()
00416 {
00417     while (xbuf!=0 && ybuf!=0){oled.getTouch(&xbuf,&ybuf);}
00418 }
00419             
00420 
00421           
00422     
00423     
00424     
00425     
00426     
00427 
00428  
00429