Initial Publish Leaning GPS/SDCARD
Dependencies: FileManager GPSGms6 SDFileSystem mbed
Fork of 2545_SD_Card by
main.cpp@2:c96b02fcb98e, 2016-05-06 (annotated)
- Committer:
- Lucyjungz
- Date:
- Fri May 06 20:16:30 2016 +0000
- Revision:
- 2:c96b02fcb98e
- Parent:
- 1:f911149acd35
- Child:
- 3:78eaf4291b84
Integrated with File Manager
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:5448330e1a33 | 1 | /* 2545_SD_Card Example |
eencae | 0:5448330e1a33 | 2 | |
eencae | 0:5448330e1a33 | 3 | Example of writing data to SD card. |
eencae | 0:5448330e1a33 | 4 | |
eencae | 0:5448330e1a33 | 5 | Based on FTF2014_lab4 Example |
eencae | 0:5448330e1a33 | 6 | |
eencae | 0:5448330e1a33 | 7 | https://developer.mbed.org/teams/Freescale/wiki/FTF2014_workshop |
eencae | 0:5448330e1a33 | 8 | |
eencae | 0:5448330e1a33 | 9 | Craig A. Evans, University of Leeds, Mar 2016 |
eencae | 0:5448330e1a33 | 10 | |
eencae | 0:5448330e1a33 | 11 | */ |
eencae | 0:5448330e1a33 | 12 | |
eencae | 0:5448330e1a33 | 13 | #include "mbed.h" |
eencae | 0:5448330e1a33 | 14 | #include "SDFileSystem.h" |
Lucyjungz | 1:f911149acd35 | 15 | #include "GPSGms6.h" |
Lucyjungz | 2:c96b02fcb98e | 16 | #include "FileManager.h" |
Lucyjungz | 1:f911149acd35 | 17 | |
eencae | 0:5448330e1a33 | 18 | |
eencae | 0:5448330e1a33 | 19 | // Connections to SD card holder on K64F (SPI interface) |
Lucyjungz | 1:f911149acd35 | 20 | SDFileSystem sd(PA_7, PA_6, PA_5, PA_0, "sd"); // MOSI, MISO, SCK, CS |
eencae | 0:5448330e1a33 | 21 | Serial serial(USBTX, USBRX); // for PC debug |
Lucyjungz | 1:f911149acd35 | 22 | GPSGms6 gps; |
Lucyjungz | 1:f911149acd35 | 23 | Timeout t1; |
Lucyjungz | 1:f911149acd35 | 24 | DigitalOut myled(LED1); |
Lucyjungz | 1:f911149acd35 | 25 | |
Lucyjungz | 2:c96b02fcb98e | 26 | float gps_interval = 3; |
Lucyjungz | 2:c96b02fcb98e | 27 | |
Lucyjungz | 2:c96b02fcb98e | 28 | |
Lucyjungz | 1:f911149acd35 | 29 | void t1out(void) |
Lucyjungz | 1:f911149acd35 | 30 | { |
Lucyjungz | 1:f911149acd35 | 31 | myled = !myled; |
Lucyjungz | 1:f911149acd35 | 32 | printf("\r\nGps header = %s", gps.latestGPRMC().header); |
Lucyjungz | 1:f911149acd35 | 33 | printf("\r\nGps status = %s", gps.latestGPRMC().status); |
Lucyjungz | 1:f911149acd35 | 34 | printf("\r\nGps time = %s", gps.latestGPRMC().time); |
Lucyjungz | 1:f911149acd35 | 35 | printf("\r\nGps date = %s", gps.latestGPRMC().date); |
Lucyjungz | 1:f911149acd35 | 36 | printf("\r\nGps lat = %s", gps.latestGPRMC().latitude); |
Lucyjungz | 1:f911149acd35 | 37 | printf("\r\nGps long = %s", gps.latestGPRMC().longitude); |
Lucyjungz | 1:f911149acd35 | 38 | printf("\r\nGps indicator = %s", gps.latestGPRMC().indicator); |
Lucyjungz | 2:c96b02fcb98e | 39 | |
Lucyjungz | 2:c96b02fcb98e | 40 | logGPSData( gps.latestGPRMC().date, gps.latestGPRMC().time); |
Lucyjungz | 2:c96b02fcb98e | 41 | serial.printf("\n#### Restart Timer #####"); |
Lucyjungz | 2:c96b02fcb98e | 42 | t1.attach(&t1out,gps_interval); |
Lucyjungz | 1:f911149acd35 | 43 | } |
eencae | 0:5448330e1a33 | 44 | |
eencae | 0:5448330e1a33 | 45 | int main() |
eencae | 0:5448330e1a33 | 46 | { |
Lucyjungz | 1:f911149acd35 | 47 | serial.baud(9600); // full-speed! |
Lucyjungz | 2:c96b02fcb98e | 48 | serial.printf("\n#### SD Card Initialization #####"); |
eencae | 0:5448330e1a33 | 49 | wait(1); |
eencae | 0:5448330e1a33 | 50 | |
eencae | 0:5448330e1a33 | 51 | // comment this line out if you don't want to delete the file! |
eencae | 0:5448330e1a33 | 52 | delete_file("/sd/test.txt"); |
eencae | 0:5448330e1a33 | 53 | |
eencae | 0:5448330e1a33 | 54 | ////////////////////// Simple writing example ////////////////////////// |
eencae | 0:5448330e1a33 | 55 | |
eencae | 0:5448330e1a33 | 56 | // open file for writing ('w') - creates file if it doesn't exist and overwrites |
eencae | 0:5448330e1a33 | 57 | // if it does. If you wish to add a score onto a list, then you can |
eencae | 0:5448330e1a33 | 58 | // append instead 'a'. This will open the file if it exists and start |
eencae | 0:5448330e1a33 | 59 | // writing at the end. It will create the file if it doesn't exist. |
eencae | 0:5448330e1a33 | 60 | |
Lucyjungz | 2:c96b02fcb98e | 61 | ////////////////////// read Setup File ////////////////////////// |
Lucyjungz | 2:c96b02fcb98e | 62 | readSetupFile(); |
Lucyjungz | 2:c96b02fcb98e | 63 | gps_interval = (float)GPSInterval()/1000; |
Lucyjungz | 2:c96b02fcb98e | 64 | logSystemData(gps_interval); |
eencae | 0:5448330e1a33 | 65 | |
eencae | 0:5448330e1a33 | 66 | |
eencae | 0:5448330e1a33 | 67 | |
eencae | 0:5448330e1a33 | 68 | /////////////////////////////////////////////////// |
Lucyjungz | 2:c96b02fcb98e | 69 | serial.printf("\n End of SD Card Initialization "); |
Lucyjungz | 1:f911149acd35 | 70 | |
Lucyjungz | 2:c96b02fcb98e | 71 | t1.attach(&t1out,gps_interval); |
Lucyjungz | 1:f911149acd35 | 72 | while(1); |
eencae | 0:5448330e1a33 | 73 | } |
eencae | 0:5448330e1a33 | 74 | |
Lucyjungz | 2:c96b02fcb98e | 75 |