A porting of a GPS decoding and presenting program within the mbos RTOS. It is not a definitive application but a study program to test NMEA full decoding library and a first approach to an RTOS. Many thanks to Andrew Levido for his support and his patience on teaching me the RTOS principles from the other side of the Earth. It uses NMEA library by Tim (xtimor@gmail.com) ported by Ken Todotani (http://mbed.org/users/todotani/) on public mbed library (http://mbed.org/users/todotani/programs/GPS_nmeaLib/5yo4h) also available, as original universal C library, on http://nmea.sourceforge.net

Dependencies:   mbos Watchdog TextLCD mbed ConfigFile

Committer:
guiott
Date:
Fri Feb 03 16:29:52 2012 +0000
Revision:
3:a2f9eb3b8a16
Parent:
2:8917036cbf69

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
guiott 2:8917036cbf69 1 #include "Task3Lcd.h"
guiott 2:8917036cbf69 2
guiott 2:8917036cbf69 3 void ShowLcdTask(void)
guiott 2:8917036cbf69 4 {/**
guiott 2:8917036cbf69 5 *\brief TASK 3, display desired data on LCD
guiott 2:8917036cbf69 6 */
guiott 2:8917036cbf69 7
guiott 2:8917036cbf69 8 static int Previous=0;
guiott 2:8917036cbf69 9
guiott 2:8917036cbf69 10 os.SetTimer(SHOW_LCD_TMR, SHOW_LCD_TIMER, 0);
guiott 2:8917036cbf69 11 while(1)
guiott 2:8917036cbf69 12 {
guiott 2:8917036cbf69 13 os.WaitEvent(SHOW_LCD_EVT);
guiott 2:8917036cbf69 14
guiott 2:8917036cbf69 15 if(Previous != Menu)
guiott 2:8917036cbf69 16 {// clear the display when function changes
guiott 2:8917036cbf69 17 lcd.cls();
guiott 2:8917036cbf69 18 Previous=Menu;
guiott 2:8917036cbf69 19 }
guiott 2:8917036cbf69 20
guiott 2:8917036cbf69 21 switch(Menu)
guiott 2:8917036cbf69 22 {
guiott 2:8917036cbf69 23 case 0:
guiott 2:8917036cbf69 24 showSatLcd();
guiott 2:8917036cbf69 25 Previous=0;
guiott 2:8917036cbf69 26 break;
guiott 2:8917036cbf69 27
guiott 2:8917036cbf69 28 case 1:
guiott 2:8917036cbf69 29 if(info.sig != 0)
guiott 2:8917036cbf69 30 {
guiott 2:8917036cbf69 31 showInfoLcd();
guiott 2:8917036cbf69 32 }
guiott 2:8917036cbf69 33 else
guiott 2:8917036cbf69 34 {
guiott 2:8917036cbf69 35 showSatLcd();
guiott 2:8917036cbf69 36 }
guiott 2:8917036cbf69 37 Previous=1;
guiott 2:8917036cbf69 38 break;
guiott 2:8917036cbf69 39
guiott 2:8917036cbf69 40 case 2:
guiott 2:8917036cbf69 41 showMenuLcd();
guiott 2:8917036cbf69 42 Previous=2;
guiott 2:8917036cbf69 43 break;
guiott 2:8917036cbf69 44
guiott 2:8917036cbf69 45 case 3:
guiott 2:8917036cbf69 46 showMenuLcd1();
guiott 2:8917036cbf69 47 Previous=3;
guiott 2:8917036cbf69 48 break;
guiott 2:8917036cbf69 49
guiott 2:8917036cbf69 50 case 4:
guiott 2:8917036cbf69 51 ShowPathLcd();
guiott 2:8917036cbf69 52 Previous=4;
guiott 2:8917036cbf69 53 break;
guiott 2:8917036cbf69 54
guiott 2:8917036cbf69 55 default:
guiott 2:8917036cbf69 56 showInfoLcd();
guiott 2:8917036cbf69 57 break;
guiott 2:8917036cbf69 58 }
guiott 2:8917036cbf69 59 //restart timer for other options
guiott 2:8917036cbf69 60 os.SetTimer(SHOW_LCD_TMR, SHOW_LCD_TIMER, 0);
guiott 2:8917036cbf69 61 }
guiott 2:8917036cbf69 62 }
guiott 2:8917036cbf69 63
guiott 2:8917036cbf69 64 void ShowPathLcd(void)
guiott 2:8917036cbf69 65 {
guiott 2:8917036cbf69 66 static int ChooseDir=0;
guiott 2:8917036cbf69 67 DegMinSec DecCoord;
guiott 2:8917036cbf69 68
guiott 2:8917036cbf69 69 Ang[Gps]=info.direction;
guiott 2:8917036cbf69 70 Ang[Mag]=CmpRead()-info.declination; //Compass reading corrected by declination
guiott 2:8917036cbf69 71 Ang[Dir]=Path.Azimuth[0];
guiott 2:8917036cbf69 72
guiott 2:8917036cbf69 73 ChooseDir++;
guiott 2:8917036cbf69 74 if(ChooseDir<7)
guiott 2:8917036cbf69 75 {
guiott 2:8917036cbf69 76 showDirLcd(Mag);
guiott 2:8917036cbf69 77 }
guiott 2:8917036cbf69 78 else if(ChooseDir>=7 && ChooseDir<12)
guiott 2:8917036cbf69 79 {
guiott 2:8917036cbf69 80 showDirLcd(Gps);
guiott 2:8917036cbf69 81 }
guiott 2:8917036cbf69 82 else if(ChooseDir>=12)
guiott 2:8917036cbf69 83 {
guiott 2:8917036cbf69 84 ChooseDir=0;
guiott 2:8917036cbf69 85 }
guiott 2:8917036cbf69 86 showDirLcd(Dir);
guiott 2:8917036cbf69 87
guiott 2:8917036cbf69 88 Deg2DegMinSec(nmea_ndeg2degree(Dest.lat), &DecCoord);
guiott 2:8917036cbf69 89 lcd.locate(6,0);
guiott 2:8917036cbf69 90 lcd.printf("%d%d\'%.0f", DecCoord.Deg, DecCoord.Min, DecCoord.Sec);
guiott 2:8917036cbf69 91 lcd.printf("%c", Dest.lat >= 0 ? 'N': 'S');
guiott 2:8917036cbf69 92
guiott 2:8917036cbf69 93 Deg2DegMinSec(nmea_ndeg2degree(Dest.lon), &DecCoord);
guiott 2:8917036cbf69 94 lcd.locate(6,1);
guiott 2:8917036cbf69 95 lcd.printf("%d%d\'%.0f", DecCoord.Deg, DecCoord.Min, DecCoord.Sec);
guiott 2:8917036cbf69 96 lcd.printf("%c", Dest.lon >= 0 ? 'E': 'W');
guiott 2:8917036cbf69 97
guiott 2:8917036cbf69 98 lcd.locate(6,2);
guiott 2:8917036cbf69 99 lcd.printf(" dist m");
guiott 2:8917036cbf69 100 lcd.locate(6,3);
guiott 2:8917036cbf69 101 lcd.printf("%4.3f",Path.Dist);
guiott 2:8917036cbf69 102
guiott 2:8917036cbf69 103
guiott 2:8917036cbf69 104 }
guiott 2:8917036cbf69 105
guiott 2:8917036cbf69 106 void showDirLcd(int Indx)
guiott 2:8917036cbf69 107 {/**
guiott 2:8917036cbf69 108 *\brief display a sort of compass on LCD
guiott 2:8917036cbf69 109 */
guiott 2:8917036cbf69 110 int Angle;
guiott 2:8917036cbf69 111
guiott 2:8917036cbf69 112 Angle=Ang[Indx]/18;
guiott 2:8917036cbf69 113
guiott 2:8917036cbf69 114 lcd.locate(CmpPos[Indx],0);
guiott 2:8917036cbf69 115 lcd.printf(" %c ",0xA5);
guiott 2:8917036cbf69 116 lcd.locate(CmpPos[Indx],1);
guiott 2:8917036cbf69 117 lcd.printf("%c %c",0xA5, 0xA5);
guiott 2:8917036cbf69 118 lcd.locate(CmpPos[Indx],2);
guiott 2:8917036cbf69 119 lcd.printf("%c %c",0xA5, 0xA5);
guiott 2:8917036cbf69 120 lcd.locate(CmpPos[Indx],3);
guiott 2:8917036cbf69 121 lcd.printf(" %c ",0xA5);
guiott 2:8917036cbf69 122
guiott 2:8917036cbf69 123 lcd.locate(CmpPos[Indx]+1,1);
guiott 2:8917036cbf69 124 lcd.printf(Lab[Indx]);
guiott 2:8917036cbf69 125 lcd.locate(CmpPos[Indx]+1,2);
guiott 2:8917036cbf69 126 lcd.printf("%03i",Ang[Indx]);
guiott 2:8917036cbf69 127
guiott 2:8917036cbf69 128 switch (Angle)
guiott 2:8917036cbf69 129 {
guiott 2:8917036cbf69 130 case 0:
guiott 2:8917036cbf69 131 lcd.locate(CmpPos[Indx]+2,0);
guiott 2:8917036cbf69 132 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 133 break;
guiott 2:8917036cbf69 134 case 1:
guiott 2:8917036cbf69 135 lcd.locate(CmpPos[Indx]+2,0);
guiott 2:8917036cbf69 136 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 137 lcd.locate(CmpPos[Indx]+3,0);
guiott 2:8917036cbf69 138 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 139 break;
guiott 2:8917036cbf69 140 case 2:
guiott 2:8917036cbf69 141 lcd.locate(CmpPos[Indx]+3,0);
guiott 2:8917036cbf69 142 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 143 break;
guiott 2:8917036cbf69 144 case 3:
guiott 2:8917036cbf69 145 lcd.locate(CmpPos[Indx]+3,0);
guiott 2:8917036cbf69 146 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 147 lcd.locate(CmpPos[Indx]+4,1);
guiott 2:8917036cbf69 148 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 149 break;
guiott 2:8917036cbf69 150 case 4:
guiott 2:8917036cbf69 151 lcd.locate(CmpPos[Indx]+4,1);
guiott 2:8917036cbf69 152 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 153 break;
guiott 2:8917036cbf69 154 case 5:
guiott 2:8917036cbf69 155 lcd.locate(CmpPos[Indx]+4,1);
guiott 2:8917036cbf69 156 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 157 lcd.locate(CmpPos[Indx]+4,2);
guiott 2:8917036cbf69 158 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 159 break;
guiott 2:8917036cbf69 160 case 6:
guiott 2:8917036cbf69 161 lcd.locate(CmpPos[Indx]+4,2);
guiott 2:8917036cbf69 162 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 163 break;
guiott 2:8917036cbf69 164 case 7:
guiott 2:8917036cbf69 165 lcd.locate(CmpPos[Indx]+4,2);
guiott 2:8917036cbf69 166 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 167 lcd.locate(CmpPos[Indx]+3,3);
guiott 2:8917036cbf69 168 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 169 break;
guiott 2:8917036cbf69 170 case 8:
guiott 2:8917036cbf69 171 lcd.locate(CmpPos[Indx]+3,3);
guiott 2:8917036cbf69 172 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 173 break;
guiott 2:8917036cbf69 174 case 9:
guiott 2:8917036cbf69 175 lcd.locate(CmpPos[Indx]+3,3);
guiott 2:8917036cbf69 176 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 177 lcd.locate(CmpPos[Indx]+2,3);
guiott 2:8917036cbf69 178 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 179 break;
guiott 2:8917036cbf69 180 case 10:
guiott 2:8917036cbf69 181 lcd.locate(CmpPos[Indx]+2,3);
guiott 2:8917036cbf69 182 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 183 break;
guiott 2:8917036cbf69 184 case 11:
guiott 2:8917036cbf69 185 lcd.locate(CmpPos[Indx]+2,3);
guiott 2:8917036cbf69 186 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 187 lcd.locate(CmpPos[Indx]+1,3);
guiott 2:8917036cbf69 188 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 189 break;
guiott 2:8917036cbf69 190 case 12:
guiott 2:8917036cbf69 191 lcd.locate(CmpPos[Indx]+1,3);
guiott 2:8917036cbf69 192 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 193 break;
guiott 2:8917036cbf69 194 case 13:
guiott 2:8917036cbf69 195 lcd.locate(CmpPos[Indx]+1,3);
guiott 2:8917036cbf69 196 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 197 lcd.locate(CmpPos[Indx]+0,2);
guiott 2:8917036cbf69 198 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 199 break;
guiott 2:8917036cbf69 200 case 14:
guiott 2:8917036cbf69 201 lcd.locate(CmpPos[Indx]+0,2);
guiott 2:8917036cbf69 202 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 203 break;
guiott 2:8917036cbf69 204 case 15:
guiott 2:8917036cbf69 205 lcd.locate(CmpPos[Indx]+0,2);
guiott 2:8917036cbf69 206 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 207 lcd.locate(CmpPos[Indx]+0,1);
guiott 2:8917036cbf69 208 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 209 break;
guiott 2:8917036cbf69 210 case 16:
guiott 2:8917036cbf69 211 lcd.locate(CmpPos[Indx]+0,1);
guiott 2:8917036cbf69 212 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 213 break;
guiott 2:8917036cbf69 214 case 17:
guiott 2:8917036cbf69 215 lcd.locate(CmpPos[Indx]+0,1);
guiott 2:8917036cbf69 216 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 217 lcd.locate(CmpPos[Indx]+1,0);
guiott 2:8917036cbf69 218 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 219 break;
guiott 2:8917036cbf69 220 case 18:
guiott 2:8917036cbf69 221 lcd.locate(CmpPos[Indx]+1,0);
guiott 2:8917036cbf69 222 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 223 break;
guiott 2:8917036cbf69 224 case 19:
guiott 2:8917036cbf69 225 lcd.locate(CmpPos[Indx]+1,0);
guiott 2:8917036cbf69 226 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 227 lcd.locate(CmpPos[Indx]+2,0);
guiott 2:8917036cbf69 228 lcd.printf("%c",0xFF);
guiott 2:8917036cbf69 229 break;
guiott 2:8917036cbf69 230 }
guiott 2:8917036cbf69 231 }
guiott 2:8917036cbf69 232
guiott 2:8917036cbf69 233 void showMenuLcd(void)
guiott 2:8917036cbf69 234 {/**
guiott 2:8917036cbf69 235 *\brief display a selection menu on LCD
guiott 2:8917036cbf69 236 */
guiott 2:8917036cbf69 237 lcd.locate(0,0);
guiott 2:8917036cbf69 238 lcd.printf("1 - item 1");
guiott 2:8917036cbf69 239 lcd.locate(0,1);
guiott 2:8917036cbf69 240 lcd.printf("2 - item 2");
guiott 2:8917036cbf69 241 lcd.locate(0,2);
guiott 2:8917036cbf69 242 lcd.printf("3 - item 3");
guiott 2:8917036cbf69 243 lcd.locate(0,3);
guiott 2:8917036cbf69 244 lcd.printf("4 - item 4");
guiott 2:8917036cbf69 245 }
guiott 2:8917036cbf69 246
guiott 2:8917036cbf69 247 void showMenuLcd1(void)
guiott 2:8917036cbf69 248 {/**
guiott 2:8917036cbf69 249 *\brief display a selection menu on LCD
guiott 2:8917036cbf69 250 */
guiott 2:8917036cbf69 251 lcd.locate(0,0);
guiott 2:8917036cbf69 252 lcd.printf("5 - item 5");
guiott 2:8917036cbf69 253 lcd.locate(0,1);
guiott 2:8917036cbf69 254 lcd.printf("6 - item 6");
guiott 2:8917036cbf69 255 lcd.locate(0,2);
guiott 2:8917036cbf69 256 lcd.printf("7 - item 7");
guiott 2:8917036cbf69 257 lcd.locate(0,3);
guiott 2:8917036cbf69 258 lcd.printf("8 - item 8");
guiott 2:8917036cbf69 259 }
guiott 2:8917036cbf69 260
guiott 2:8917036cbf69 261 void showSatLcd(void)
guiott 2:8917036cbf69 262 {/**
guiott 2:8917036cbf69 263 *\brief displays satellite informations
guiott 2:8917036cbf69 264 */
guiott 2:8917036cbf69 265 for (int i = 0; i < NMEA_MAXSAT; i++)
guiott 2:8917036cbf69 266 {
guiott 2:8917036cbf69 267 if(info.satinfo.sat[i].id < 20)
guiott 2:8917036cbf69 268 {
guiott 2:8917036cbf69 269 lcd.locate((info.satinfo.sat[i].id % 20) - 1,0);
guiott 2:8917036cbf69 270 }
guiott 2:8917036cbf69 271 else
guiott 2:8917036cbf69 272 {
guiott 2:8917036cbf69 273 lcd.locate((info.satinfo.sat[i].id % 20) - 1,1);
guiott 2:8917036cbf69 274 }
guiott 2:8917036cbf69 275
guiott 2:8917036cbf69 276 if (info.satinfo.sat[i].sig > 0)
guiott 2:8917036cbf69 277 {
guiott 2:8917036cbf69 278 lcd.printf("%d",info.satinfo.sat[i].sig/10);
guiott 2:8917036cbf69 279 }
guiott 2:8917036cbf69 280 else
guiott 2:8917036cbf69 281 {
guiott 2:8917036cbf69 282 lcd.printf(" ");
guiott 2:8917036cbf69 283 }
guiott 2:8917036cbf69 284 }
guiott 2:8917036cbf69 285 lcd.locate(0,2);
guiott 2:8917036cbf69 286 lcd.printf("12345678901234567890");
guiott 2:8917036cbf69 287 lcd.locate(0, 3);
guiott 2:8917036cbf69 288 lcd.printf("P%2.1f H%2.1f V%2.1f %iD",
guiott 2:8917036cbf69 289 info.PDOP, info.HDOP, info.VDOP,info.fix);
guiott 2:8917036cbf69 290 }
guiott 2:8917036cbf69 291
guiott 2:8917036cbf69 292 void showInfoLcd(void)
guiott 2:8917036cbf69 293 {/**
guiott 2:8917036cbf69 294 *\brief Show nmea info on LCD
guiott 2:8917036cbf69 295 */
guiott 2:8917036cbf69 296
guiott 2:8917036cbf69 297 // static int lastSat = 0;
guiott 2:8917036cbf69 298 // int satInview = 0;
guiott 2:8917036cbf69 299
guiott 2:8917036cbf69 300 if(info.sig != 0)
guiott 2:8917036cbf69 301 {
guiott 2:8917036cbf69 302 lcd.locate(0, 0);
guiott 2:8917036cbf69 303 lcd.printf("%2.5f%c %3.5f%c",
guiott 2:8917036cbf69 304 latitude, info.lat >= 0 ? 'N': 'S',
guiott 2:8917036cbf69 305 longitude, info.lon >= 0 ? 'E': 'W');
guiott 2:8917036cbf69 306
guiott 2:8917036cbf69 307 lcd.locate(0, 1);
guiott 2:8917036cbf69 308 lcd.printf("H%.0f D%.0f_%.1f %iD", info.elv, info.direction, info.declination, info.fix);
guiott 2:8917036cbf69 309
guiott 2:8917036cbf69 310 lcd.locate(0, 2);
guiott 2:8917036cbf69 311 lcd.printf("P%2.1f H%2.1f V%2.1f S%i/%i",
guiott 2:8917036cbf69 312 info.PDOP, info.HDOP, info.VDOP, info.satinfo.inuse, info.satinfo.inview);
guiott 2:8917036cbf69 313
guiott 2:8917036cbf69 314 /* lcd.locate(0, 3);
guiott 2:8917036cbf69 315 lcd.printf("%02d-%02d-%04d %02d:%02d:%02d ",
guiott 2:8917036cbf69 316 info.utc.day, info.utc.mon + 1, info.utc.year + 1900,
guiott 2:8917036cbf69 317 info.utc.hour, info.utc.min, info.utc.sec); // Display JST (UTC + 9)
guiott 2:8917036cbf69 318 */
guiott 2:8917036cbf69 319
guiott 2:8917036cbf69 320 /*
guiott 2:8917036cbf69 321 lcd.locate(0, 5);
guiott 2:8917036cbf69 322 for (int i = 0; i < NMEA_MAXSAT; i++) {
guiott 2:8917036cbf69 323 if (info.satinfo.sat[i].sig > 0) {
guiott 2:8917036cbf69 324 satInview++;
guiott 2:8917036cbf69 325 lcd.printf(" sat_id:%02d, sig:%02d, Inuse:%d \n",
guiott 2:8917036cbf69 326 info.satinfo.sat[i].id , info.satinfo.sat[i].sig,
guiott 2:8917036cbf69 327 info.satinfo.sat[i].in_use);
guiott 2:8917036cbf69 328 }
guiott 2:8917036cbf69 329 }
guiott 2:8917036cbf69 330 for (int j = satInview; j <= lastSat; j++)
guiott 2:8917036cbf69 331 lcd.printf(" \n"); // delete line
guiott 2:8917036cbf69 332 lastSat = satInview;
guiott 2:8917036cbf69 333 */
guiott 2:8917036cbf69 334
guiott 2:8917036cbf69 335 }
guiott 2:8917036cbf69 336 else
guiott 2:8917036cbf69 337 {
guiott 2:8917036cbf69 338 lcd.cls();
guiott 2:8917036cbf69 339 lcd.locate(0,0);
guiott 2:8917036cbf69 340 lcd.printf("NO FIX");
guiott 2:8917036cbf69 341 }
guiott 2:8917036cbf69 342
guiott 2:8917036cbf69 343 // Grab a snapshot of the current RTC time.
guiott 2:8917036cbf69 344 time_t seconds = time(NULL);
guiott 2:8917036cbf69 345 char buffer[32];
guiott 2:8917036cbf69 346 if((info.sig != 0)&&(SetTimeOk!=0))
guiott 2:8917036cbf69 347 {
guiott 2:8917036cbf69 348 strftime(buffer, 32, "%x %X", localtime(&seconds));
guiott 2:8917036cbf69 349 }
guiott 2:8917036cbf69 350 else
guiott 2:8917036cbf69 351 {// if GPS time not valid doesn't display seconds
guiott 2:8917036cbf69 352 strftime(buffer, 32, "%x %H:%M", localtime(&seconds));
guiott 2:8917036cbf69 353 SetTimeOk = 0; // RTC was not set to a valid time
guiott 2:8917036cbf69 354 }
guiott 2:8917036cbf69 355 lcd.locate(0,3);
guiott 2:8917036cbf69 356 lcd.printf("%s", buffer);
guiott 2:8917036cbf69 357 }