![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
gps
Dependencies: C12832_lcd FatFileSystemCpp GPS mbed MMA7660 PowerControl PwmIn
Fork of MSCUsbHost by
Diff: main.cpp
- Revision:
- 4:071ff93721f8
- Parent:
- 0:e294af8d0e07
- Child:
- 6:9303188c8010
--- a/main.cpp Mon Jul 30 13:49:56 2012 +0000 +++ b/main.cpp Fri May 09 18:25:57 2014 +0000 @@ -1,69 +1,55 @@ #include "mbed.h" +#include "GPS.h" +#include "C12832_lcd.h" #include "MSCFileSystem.h" -//#include <stat.h> + #define FSNAME "msc" + MSCFileSystem msc(FSNAME); +Serial pc(USBTX, USBRX); +GPS gps(p9, p10); +C12832_LCD lcd; + +float timing; -int main() -{ - DIR *d; - struct dirent *p; - //struct stat st; - //char path[PATH_MAX]; - - printf("\n\n================================\n"); - printf("USB Mass storage demo program for mbed LPC1768\n"); - printf("================================\n\n"); - - d = opendir("/" FSNAME); - - printf("\nList of files on the flash drive:\n"); - if ( d != NULL ) +int main() { + + FILE *fp; + fp = fopen( "/" FSNAME "/GPSData.txt", "w"); + fprintf(fp,""); + fclose(fp); + + while(1) { - while ( (p = readdir(d)) != NULL ) + + if(gps.sample()) { - printf(" - %s\n", p->d_name); - /* no <stat.h> on mbed, it seems :/ - sprintf(path, "/"FSNAME"/%s", p->d_name); - if ( stat(path, &st) == 0 ) - { - if ( S_ISDIR(st.st_mode) ) - printf(" <directory>\n"); - else - printf(" %d\n", st.st_size); - } - else - { - printf(" ???\n"); - }*/ + fp = fopen( "/" FSNAME "/GPSData.txt", "a"); + fprintf(fp, "%.1f ",timing); //time when read + fprintf(fp, "Longitude: %f ", gps.longitude); + fprintf(fp, "Latitude: %f\n", gps.latitude); + + pc.printf("%f, %f\r\n",gps.latitude,gps.longitude); + lcd.cls(); + lcd.locate(3,3); + lcd.printf("%.3f\n",gps.latitude);//print x to LCD at locate position + lcd.locate(28,3);//move LCD location for y component + lcd.printf("%.3f\n",gps.longitude);//print y to LCD to new locate position + + + wait(0.5); + fclose(fp); + timing = timing + 0.5; + } + + else + { + pc.printf("Oh Dear! No lock :(\r\n"); + lcd.cls(); + lcd.locate(3,3); + lcd.printf("No GPS Lock"); } - } - else - { - error("Could not open directory!"); + } - printf("\nTesting file write:\n"); - FILE *fp = fopen( "/" FSNAME "/msctest.txt", "w"); - if ( fp == NULL ) - { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello mass storage!"); - fclose(fp); - printf("\n - OK\n"); - - printf("\nTesting file read:\n"); - fp = fopen( "/" FSNAME "/msctest.txt", "r"); - if ( fp == NULL ) - { - error("Could not open file for read\n"); - } - char buf[256]; - if ( NULL == fgets(buf, sizeof(buf), fp) ) - { - error("Error reading from file\n"); - } - fclose(fp); - printf("\n - OK, read string: '%s'\n\n", buf); -} +} \ No newline at end of file