gps
Dependencies: C12832_lcd FatFileSystemCpp GPS mbed MMA7660 PowerControl PwmIn
Fork of MSCUsbHost by
main.cpp@6:9303188c8010, 2014-05-10 (annotated)
- Committer:
- AlexF64
- Date:
- Sat May 10 22:35:12 2014 +0000
- Revision:
- 6:9303188c8010
- Parent:
- 4:071ff93721f8
all working now;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
igorsk | 0:e294af8d0e07 | 1 | #include "mbed.h" |
AlexF64 | 4:071ff93721f8 | 2 | #include "GPS.h" |
AlexF64 | 4:071ff93721f8 | 3 | #include "C12832_lcd.h" |
igorsk | 0:e294af8d0e07 | 4 | #include "MSCFileSystem.h" |
AlexF64 | 6:9303188c8010 | 5 | #include "PwmIn.h" |
AlexF64 | 6:9303188c8010 | 6 | #include "MMA7660.h" |
AlexF64 | 6:9303188c8010 | 7 | #include "EthernetPowerControl.h" |
igorsk | 0:e294af8d0e07 | 8 | |
igorsk | 0:e294af8d0e07 | 9 | #define FSNAME "msc" |
AlexF64 | 4:071ff93721f8 | 10 | |
igorsk | 0:e294af8d0e07 | 11 | MSCFileSystem msc(FSNAME); |
AlexF64 | 4:071ff93721f8 | 12 | Serial pc(USBTX, USBRX); |
AlexF64 | 4:071ff93721f8 | 13 | GPS gps(p9, p10); |
AlexF64 | 6:9303188c8010 | 14 | PwmIn Bearing(p21); |
AlexF64 | 4:071ff93721f8 | 15 | C12832_LCD lcd; |
AlexF64 | 6:9303188c8010 | 16 | MMA7660 MMA(p28, p27);// local name for the Accelerometer |
AlexF64 | 6:9303188c8010 | 17 | DigitalOut connectionLed(LED1); // debug LED |
AlexF64 | 6:9303188c8010 | 18 | |
AlexF64 | 4:071ff93721f8 | 19 | |
AlexF64 | 4:071ff93721f8 | 20 | float timing; |
igorsk | 0:e294af8d0e07 | 21 | |
AlexF64 | 4:071ff93721f8 | 22 | int main() { |
AlexF64 | 6:9303188c8010 | 23 | |
AlexF64 | 6:9303188c8010 | 24 | PHY_PowerDown(); |
AlexF64 | 6:9303188c8010 | 25 | |
AlexF64 | 4:071ff93721f8 | 26 | FILE *fp; |
AlexF64 | 4:071ff93721f8 | 27 | fp = fopen( "/" FSNAME "/GPSData.txt", "w"); |
AlexF64 | 4:071ff93721f8 | 28 | fprintf(fp,""); |
AlexF64 | 4:071ff93721f8 | 29 | fclose(fp); |
AlexF64 | 6:9303188c8010 | 30 | |
AlexF64 | 6:9303188c8010 | 31 | FILE *fp2; |
AlexF64 | 6:9303188c8010 | 32 | fp2 = fopen( "/" FSNAME "/CompassData.txt", "w"); |
AlexF64 | 6:9303188c8010 | 33 | fprintf(fp2,""); |
AlexF64 | 6:9303188c8010 | 34 | fclose(fp2); |
AlexF64 | 4:071ff93721f8 | 35 | |
AlexF64 | 6:9303188c8010 | 36 | FILE *fp3; |
AlexF64 | 6:9303188c8010 | 37 | fp3 = fopen( "/" FSNAME "/AccelerometerData.txt", "w"); |
AlexF64 | 6:9303188c8010 | 38 | fprintf(fp3,""); |
AlexF64 | 6:9303188c8010 | 39 | fclose(fp3); |
AlexF64 | 6:9303188c8010 | 40 | |
AlexF64 | 6:9303188c8010 | 41 | if ( fp == NULL ) |
AlexF64 | 6:9303188c8010 | 42 | { |
AlexF64 | 6:9303188c8010 | 43 | lcd.cls();//clear LCD for next reading round |
AlexF64 | 6:9303188c8010 | 44 | lcd.locate(3,3); |
AlexF64 | 6:9303188c8010 | 45 | lcd.printf("File error\n"); |
AlexF64 | 6:9303188c8010 | 46 | } |
AlexF64 | 6:9303188c8010 | 47 | |
AlexF64 | 6:9303188c8010 | 48 | if ( fp2 == NULL ) |
AlexF64 | 6:9303188c8010 | 49 | { |
AlexF64 | 6:9303188c8010 | 50 | lcd.cls();//clear LCD for next reading round |
AlexF64 | 6:9303188c8010 | 51 | lcd.locate(3,3); |
AlexF64 | 6:9303188c8010 | 52 | lcd.printf("File error\n"); |
AlexF64 | 6:9303188c8010 | 53 | } |
AlexF64 | 6:9303188c8010 | 54 | |
AlexF64 | 6:9303188c8010 | 55 | if ( fp3 == NULL ) |
AlexF64 | 6:9303188c8010 | 56 | { |
AlexF64 | 6:9303188c8010 | 57 | lcd.cls();//clear LCD for next reading round |
AlexF64 | 6:9303188c8010 | 58 | lcd.locate(3,3); |
AlexF64 | 6:9303188c8010 | 59 | lcd.printf("File error\n"); |
AlexF64 | 6:9303188c8010 | 60 | } |
AlexF64 | 6:9303188c8010 | 61 | |
AlexF64 | 6:9303188c8010 | 62 | if (MMA.testConnection()){ |
AlexF64 | 6:9303188c8010 | 63 | connectionLed = 1;// LEDs are very useful to demonstrate something is working |
AlexF64 | 6:9303188c8010 | 64 | } |
AlexF64 | 6:9303188c8010 | 65 | |
AlexF64 | 4:071ff93721f8 | 66 | while(1) |
igorsk | 0:e294af8d0e07 | 67 | { |
AlexF64 | 4:071ff93721f8 | 68 | |
AlexF64 | 4:071ff93721f8 | 69 | if(gps.sample()) |
igorsk | 0:e294af8d0e07 | 70 | { |
AlexF64 | 4:071ff93721f8 | 71 | fp = fopen( "/" FSNAME "/GPSData.txt", "a"); |
AlexF64 | 4:071ff93721f8 | 72 | fprintf(fp, "%.1f ",timing); //time when read |
AlexF64 | 6:9303188c8010 | 73 | fprintf(fp, "%f ", gps.longitude); |
AlexF64 | 6:9303188c8010 | 74 | fprintf(fp, "%f\n", gps.latitude); |
AlexF64 | 4:071ff93721f8 | 75 | |
AlexF64 | 4:071ff93721f8 | 76 | pc.printf("%f, %f\r\n",gps.latitude,gps.longitude); |
AlexF64 | 6:9303188c8010 | 77 | |
AlexF64 | 6:9303188c8010 | 78 | |
AlexF64 | 6:9303188c8010 | 79 | fp2 = fopen( "/" FSNAME "/CompassData.txt", "a"); |
AlexF64 | 6:9303188c8010 | 80 | float angle = Bearing.pulsewidth(); |
AlexF64 | 6:9303188c8010 | 81 | //pc.printf("\ntimer: %.1f",time); |
AlexF64 | 6:9303188c8010 | 82 | pc.printf("\nBearing: %.2f \r\n", (angle*10000)-10); |
AlexF64 | 6:9303188c8010 | 83 | fprintf(fp2, "%.1f ",timing); //time when read |
AlexF64 | 6:9303188c8010 | 84 | fprintf(fp2, "%.2f\r\n",(angle*10000)-10); //angle |
AlexF64 | 6:9303188c8010 | 85 | |
AlexF64 | 6:9303188c8010 | 86 | fp3 = fopen( "/" FSNAME "/AccelerometerData.txt", "a"); |
AlexF64 | 6:9303188c8010 | 87 | float zaxis = MMA.z(); |
AlexF64 | 6:9303188c8010 | 88 | float xaxis = MMA.x(); |
AlexF64 | 6:9303188c8010 | 89 | float yaxis = MMA.y(); |
AlexF64 | 6:9303188c8010 | 90 | |
AlexF64 | 6:9303188c8010 | 91 | pc.printf("%.2f ",xaxis); |
AlexF64 | 6:9303188c8010 | 92 | pc.printf("%.2f ",yaxis); |
AlexF64 | 6:9303188c8010 | 93 | pc.printf("%.2f \r\n",zaxis); |
AlexF64 | 6:9303188c8010 | 94 | fprintf(fp3, "%.1f ",timing); |
AlexF64 | 6:9303188c8010 | 95 | fprintf(fp3, "%.2f ",xaxis); |
AlexF64 | 6:9303188c8010 | 96 | fprintf(fp3, "%.2f ",yaxis); |
AlexF64 | 6:9303188c8010 | 97 | fprintf(fp3, "%.2f \n",zaxis); |
AlexF64 | 6:9303188c8010 | 98 | |
AlexF64 | 6:9303188c8010 | 99 | lcd.cls();//clear LCD for next reading round |
AlexF64 | 4:071ff93721f8 | 100 | lcd.locate(3,3); |
AlexF64 | 4:071ff93721f8 | 101 | lcd.printf("%.3f\n",gps.latitude);//print x to LCD at locate position |
AlexF64 | 6:9303188c8010 | 102 | lcd.locate(30,3);//move LCD location for y component |
AlexF64 | 6:9303188c8010 | 103 | lcd.printf("%.3f Lat/Long\n",gps.longitude);//print y to LCD to new locate position |
AlexF64 | 6:9303188c8010 | 104 | |
AlexF64 | 6:9303188c8010 | 105 | lcd.locate(3,21); |
AlexF64 | 6:9303188c8010 | 106 | lcd.printf("%.2f Angle\n",(angle*10000)-10); |
AlexF64 | 4:071ff93721f8 | 107 | |
AlexF64 | 6:9303188c8010 | 108 | lcd.locate(3,12);//initial LCD location for x component of acceleration |
AlexF64 | 6:9303188c8010 | 109 | lcd.printf("%.2f\n",MMA.x());//print x to LCD at locate position |
AlexF64 | 6:9303188c8010 | 110 | lcd.locate(28,12);//move LCD location for y component |
AlexF64 | 6:9303188c8010 | 111 | lcd.printf("%.2f\n",MMA.y());//print y to LCD to new locate position |
AlexF64 | 6:9303188c8010 | 112 | lcd.locate(53,12);//move LCD location for z component |
AlexF64 | 6:9303188c8010 | 113 | lcd.printf("%.2f XYZ\n",MMA.z());//print z to LCD |
AlexF64 | 6:9303188c8010 | 114 | |
AlexF64 | 6:9303188c8010 | 115 | wait(0.5); |
AlexF64 | 4:071ff93721f8 | 116 | fclose(fp); |
AlexF64 | 6:9303188c8010 | 117 | fclose(fp2); |
AlexF64 | 6:9303188c8010 | 118 | fclose(fp3); |
AlexF64 | 4:071ff93721f8 | 119 | timing = timing + 0.5; |
AlexF64 | 4:071ff93721f8 | 120 | } |
AlexF64 | 4:071ff93721f8 | 121 | |
AlexF64 | 4:071ff93721f8 | 122 | else |
AlexF64 | 4:071ff93721f8 | 123 | { |
AlexF64 | 4:071ff93721f8 | 124 | pc.printf("Oh Dear! No lock :(\r\n"); |
AlexF64 | 4:071ff93721f8 | 125 | lcd.cls(); |
AlexF64 | 4:071ff93721f8 | 126 | lcd.locate(3,3); |
AlexF64 | 4:071ff93721f8 | 127 | lcd.printf("No GPS Lock"); |
igorsk | 0:e294af8d0e07 | 128 | } |
AlexF64 | 4:071ff93721f8 | 129 | |
igorsk | 0:e294af8d0e07 | 130 | } |
AlexF64 | 4:071ff93721f8 | 131 | } |