Guido Ottaviani / Mbed 2 deprecated LeonardoMbos

Dependencies:   mbos Watchdog TextLCD mbed ConfigFile

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Task3Lcd.cpp Source File

Task3Lcd.cpp

00001 #include "Task3Lcd.h"
00002 
00003 void ShowLcdTask(void)
00004 {/**
00005  *\brief TASK 3, display desired data on LCD
00006  */
00007  
00008  static int Previous=0;
00009 
00010  os.SetTimer(SHOW_LCD_TMR, SHOW_LCD_TIMER, 0);
00011  while(1)
00012  {
00013  os.WaitEvent(SHOW_LCD_EVT);
00014 
00015     if(Previous != Menu)
00016     {// clear the display when function changes
00017         lcd.cls();
00018         Previous=Menu;
00019     }
00020     
00021     switch(Menu)
00022     {
00023         case 0:
00024             showSatLcd();
00025             Previous=0;
00026             break;
00027             
00028         case 1:
00029             if(info.sig != 0)
00030             {
00031                 showInfoLcd();
00032             }
00033             else
00034             {
00035                 showSatLcd();
00036             }
00037             Previous=1;    
00038             break;
00039         
00040         case 2:
00041             showMenuLcd();
00042             Previous=2;    
00043             break;
00044             
00045         case 3:
00046             showMenuLcd1();
00047             Previous=3;    
00048             break;  
00049             
00050         case 4: 
00051             ShowPathLcd();
00052             Previous=4;    
00053             break; 
00054             
00055         default:
00056             showInfoLcd();
00057             break;
00058     }
00059     //restart timer for other options
00060     os.SetTimer(SHOW_LCD_TMR, SHOW_LCD_TIMER, 0); 
00061  }
00062 }
00063 
00064 void ShowPathLcd(void)
00065 {
00066     static int ChooseDir=0;
00067     DegMinSec DecCoord;
00068 
00069     Ang[Gps]=info.direction;
00070     Ang[Mag]=CmpRead()-info.declination; //Compass reading corrected by declination
00071     Ang[Dir]=Path.Azimuth[0];
00072 
00073     ChooseDir++;
00074     if(ChooseDir<7)
00075     {
00076         showDirLcd(Mag);
00077     }
00078     else if(ChooseDir>=7 && ChooseDir<12)
00079     {
00080         showDirLcd(Gps);
00081     }
00082     else if(ChooseDir>=12)
00083     {
00084        ChooseDir=0;
00085     }
00086     showDirLcd(Dir);
00087     
00088     Deg2DegMinSec(nmea_ndeg2degree(Dest.lat), &DecCoord);
00089     lcd.locate(6,0);
00090     lcd.printf("%d%d\'%.0f", DecCoord.Deg, DecCoord.Min, DecCoord.Sec);
00091     lcd.printf("%c", Dest.lat >= 0 ? 'N': 'S');  
00092     
00093     Deg2DegMinSec(nmea_ndeg2degree(Dest.lon), &DecCoord);
00094     lcd.locate(6,1);
00095     lcd.printf("%d%d\'%.0f", DecCoord.Deg, DecCoord.Min, DecCoord.Sec);
00096     lcd.printf("%c", Dest.lon >= 0 ? 'E': 'W');  
00097     
00098     lcd.locate(6,2);
00099     lcd.printf(" dist m");
00100     lcd.locate(6,3);
00101     lcd.printf("%4.3f",Path.Dist);
00102     
00103 
00104 }
00105 
00106 void showDirLcd(int Indx)
00107 {/**
00108  *\brief  display a sort of compass on LCD
00109  */
00110     int Angle;
00111 
00112     Angle=Ang[Indx]/18;
00113 
00114     lcd.locate(CmpPos[Indx],0);
00115     lcd.printf("  %c  ",0xA5);
00116     lcd.locate(CmpPos[Indx],1);
00117     lcd.printf("%c   %c",0xA5, 0xA5);
00118     lcd.locate(CmpPos[Indx],2);
00119     lcd.printf("%c   %c",0xA5, 0xA5);
00120     lcd.locate(CmpPos[Indx],3);
00121     lcd.printf("  %c  ",0xA5);
00122     
00123     lcd.locate(CmpPos[Indx]+1,1);
00124     lcd.printf(Lab[Indx]);
00125     lcd.locate(CmpPos[Indx]+1,2);
00126     lcd.printf("%03i",Ang[Indx]);
00127         
00128     switch (Angle)
00129     {
00130         case 0:
00131             lcd.locate(CmpPos[Indx]+2,0);
00132             lcd.printf("%c",0xFF);
00133             break;
00134         case 1:
00135             lcd.locate(CmpPos[Indx]+2,0);
00136             lcd.printf("%c",0xFF);
00137             lcd.locate(CmpPos[Indx]+3,0);
00138             lcd.printf("%c",0xFF);
00139             break;
00140         case 2:
00141             lcd.locate(CmpPos[Indx]+3,0);
00142             lcd.printf("%c",0xFF);
00143             break;        
00144         case 3:
00145             lcd.locate(CmpPos[Indx]+3,0);
00146             lcd.printf("%c",0xFF);
00147             lcd.locate(CmpPos[Indx]+4,1);
00148             lcd.printf("%c",0xFF);
00149             break;        
00150         case 4:
00151             lcd.locate(CmpPos[Indx]+4,1);
00152             lcd.printf("%c",0xFF);
00153             break;
00154         case 5:       
00155             lcd.locate(CmpPos[Indx]+4,1);
00156             lcd.printf("%c",0xFF);
00157             lcd.locate(CmpPos[Indx]+4,2);
00158             lcd.printf("%c",0xFF);
00159             break;
00160         case 6:   
00161             lcd.locate(CmpPos[Indx]+4,2);
00162             lcd.printf("%c",0xFF);
00163             break;
00164         case 7:       
00165             lcd.locate(CmpPos[Indx]+4,2);
00166             lcd.printf("%c",0xFF);
00167             lcd.locate(CmpPos[Indx]+3,3);
00168             lcd.printf("%c",0xFF);
00169             break;
00170         case 8:   
00171             lcd.locate(CmpPos[Indx]+3,3);
00172             lcd.printf("%c",0xFF);
00173             break;
00174         case 9:       
00175             lcd.locate(CmpPos[Indx]+3,3);
00176             lcd.printf("%c",0xFF);
00177             lcd.locate(CmpPos[Indx]+2,3);
00178             lcd.printf("%c",0xFF);
00179             break;
00180         case 10:   
00181             lcd.locate(CmpPos[Indx]+2,3);
00182             lcd.printf("%c",0xFF);
00183             break;     
00184         case 11:       
00185             lcd.locate(CmpPos[Indx]+2,3);
00186             lcd.printf("%c",0xFF);
00187             lcd.locate(CmpPos[Indx]+1,3);
00188             lcd.printf("%c",0xFF);
00189             break;
00190         case 12:   
00191             lcd.locate(CmpPos[Indx]+1,3);
00192             lcd.printf("%c",0xFF);
00193             break;     
00194         case 13:       
00195             lcd.locate(CmpPos[Indx]+1,3);
00196             lcd.printf("%c",0xFF);
00197             lcd.locate(CmpPos[Indx]+0,2);
00198             lcd.printf("%c",0xFF);
00199             break;
00200         case 14:   
00201             lcd.locate(CmpPos[Indx]+0,2);
00202             lcd.printf("%c",0xFF);
00203             break;  
00204         case 15:       
00205             lcd.locate(CmpPos[Indx]+0,2);
00206             lcd.printf("%c",0xFF);
00207             lcd.locate(CmpPos[Indx]+0,1);
00208             lcd.printf("%c",0xFF);
00209             break;
00210         case 16:   
00211             lcd.locate(CmpPos[Indx]+0,1);
00212             lcd.printf("%c",0xFF);
00213             break;  
00214         case 17:       
00215             lcd.locate(CmpPos[Indx]+0,1);
00216             lcd.printf("%c",0xFF);
00217             lcd.locate(CmpPos[Indx]+1,0);
00218             lcd.printf("%c",0xFF);
00219             break;   
00220         case 18:   
00221             lcd.locate(CmpPos[Indx]+1,0);
00222             lcd.printf("%c",0xFF);
00223             break;  
00224         case 19:       
00225             lcd.locate(CmpPos[Indx]+1,0);
00226             lcd.printf("%c",0xFF);
00227             lcd.locate(CmpPos[Indx]+2,0);
00228             lcd.printf("%c",0xFF);
00229             break;   
00230     }
00231 }
00232 
00233 void showMenuLcd(void)
00234 {/**
00235  *\brief  display a selection menu on LCD
00236  */
00237     lcd.locate(0,0);
00238     lcd.printf("1 - item 1");
00239     lcd.locate(0,1);
00240     lcd.printf("2 - item 2");
00241     lcd.locate(0,2);
00242     lcd.printf("3 - item 3");
00243     lcd.locate(0,3);
00244     lcd.printf("4 - item 4");    
00245 }
00246 
00247 void showMenuLcd1(void)
00248 {/**
00249  *\brief  display a selection menu on LCD
00250  */
00251     lcd.locate(0,0);
00252     lcd.printf("5 - item 5");
00253     lcd.locate(0,1);
00254     lcd.printf("6 - item 6");
00255     lcd.locate(0,2);
00256     lcd.printf("7 - item 7");
00257     lcd.locate(0,3);
00258     lcd.printf("8 - item 8");    
00259 }
00260 
00261 void showSatLcd(void) 
00262 {/**
00263  *\brief displays satellite informations
00264  */
00265     for (int i = 0; i < NMEA_MAXSAT; i++) 
00266     {
00267         if(info.satinfo.sat[i].id < 20)
00268         {
00269             lcd.locate((info.satinfo.sat[i].id % 20) - 1,0);
00270         }
00271         else
00272         {
00273             lcd.locate((info.satinfo.sat[i].id % 20) - 1,1);    
00274         }
00275         
00276         if (info.satinfo.sat[i].sig > 0)
00277         {
00278             lcd.printf("%d",info.satinfo.sat[i].sig/10);
00279         }
00280         else
00281         {
00282             lcd.printf(" ");    
00283         }                   
00284     }
00285     lcd.locate(0,2);
00286     lcd.printf("12345678901234567890");
00287     lcd.locate(0, 3);
00288     lcd.printf("P%2.1f H%2.1f V%2.1f %iD",
00289     info.PDOP, info.HDOP, info.VDOP,info.fix);
00290 }    
00291     
00292 void showInfoLcd(void) 
00293 {/**
00294  *\brief Show nmea info on LCD 
00295  */
00296 
00297 //    static int lastSat = 0;
00298 //    int satInview = 0;
00299 
00300  if(info.sig != 0)
00301  { 
00302     lcd.locate(0, 0);
00303     lcd.printf("%2.5f%c %3.5f%c",
00304             latitude, info.lat >= 0 ? 'N': 'S',  
00305             longitude, info.lon >= 0 ? 'E': 'W');
00306   
00307     lcd.locate(0, 1);
00308     lcd.printf("H%.0f D%.0f_%.1f %iD", info.elv, info.direction, info.declination, info.fix);
00309 
00310     lcd.locate(0, 2);
00311     lcd.printf("P%2.1f H%2.1f V%2.1f S%i/%i",
00312         info.PDOP, info.HDOP, info.VDOP, info.satinfo.inuse, info.satinfo.inview);
00313         
00314    /* lcd.locate(0, 3);
00315     lcd.printf("%02d-%02d-%04d %02d:%02d:%02d ", 
00316         info.utc.day, info.utc.mon + 1, info.utc.year + 1900,
00317         info.utc.hour, info.utc.min, info.utc.sec); // Display JST (UTC + 9)
00318    */
00319 
00320 /*
00321     lcd.locate(0, 5);
00322     for (int i = 0; i < NMEA_MAXSAT; i++) {
00323         if (info.satinfo.sat[i].sig > 0) {
00324             satInview++;
00325             lcd.printf("  sat_id:%02d, sig:%02d, Inuse:%d \n",
00326                       info.satinfo.sat[i].id , info.satinfo.sat[i].sig,
00327                       info.satinfo.sat[i].in_use);
00328         }
00329     }
00330     for (int j = satInview; j <= lastSat; j++)
00331         lcd.printf("                             \n");     // delete line
00332     lastSat = satInview;
00333  */
00334  
00335  } 
00336  else
00337  {
00338     lcd.cls();
00339     lcd.locate(0,0);
00340     lcd.printf("NO FIX"); 
00341  }
00342 
00343  // Grab a snapshot of the current RTC time.
00344  time_t seconds = time(NULL);
00345  char buffer[32];
00346  if((info.sig != 0)&&(SetTimeOk!=0))  
00347  {
00348     strftime(buffer, 32, "%x %X", localtime(&seconds));
00349  }
00350  else
00351  {// if GPS time not valid doesn't display seconds
00352      strftime(buffer, 32, "%x %H:%M", localtime(&seconds));
00353      SetTimeOk = 0; // RTC was not set to a valid time 
00354  }
00355  lcd.locate(0,3);
00356  lcd.printf("%s", buffer);
00357 }