tracker with usb

Dependencies:   C12832_lcd CMPS03 FatFileSystemCpp GPS_copy mbed

Fork of MSCUsbHost by Igor Skochinsky

Revision:
4:6c258ed4635e
Parent:
0:e294af8d0e07
--- a/main.cpp	Mon Jul 30 13:49:56 2012 +0000
+++ b/main.cpp	Sat Mar 10 12:17:10 2018 +0000
@@ -1,69 +1,54 @@
 #include "mbed.h"
+#include "CMPS03.h"
+#include "GPS.h"
+#include "C12832_lcd.h"
 #include "MSCFileSystem.h"
-//#include <stat.h>
-
 #define FSNAME "msc"
+C12832_LCD lcd;// Local name for the LCD
 MSCFileSystem msc(FSNAME);
+Serial pc(USBTX, USBRX);
+GPS gps(p9, p10);
+CMPS03 compass(p28, p27, CMPS03_DEFAULT_I2C_ADDRESS);
 
-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);
+int lock = 0;
+int main() {
+    DIR *d;
+    struct dirent *p;
+    d = opendir("/" FSNAME);
     
-    printf("\nList of files on the flash drive:\n");
-    if ( d != NULL )
-    {
-        while ( (p = readdir(d)) != NULL )
-        {
-        	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");
-        	}*/
+    lcd.cls();
+    lcd.locate(1,0); 
+    lcd.printf("GPS Tester");
+    lcd.locate(1,11);
+    lcd.printf("Connect GPS to pins 9 & 10");  
+    gps.Init();
+    gps.parseData();
+    while(1) {
+        if(gps.parseData()) {
+            FILE *fp = fopen( "/" FSNAME "/Tracker_data.txt", "w");
+            lcd.cls();
+            lcd.locate(1,0);
+            lcd.printf("%f, %f, %d\n", gps.latitude, gps.longitude, gps.hours);
+            lcd.locate(1,11);
+            lcd.printf("%02d:%02d:%02.0f Bearing is: %f\n", 
+                gps.hours, gps.minutes, gps.seconds, 
+                (compass.readBearing() / 10.0));
+            lcd.locate(1,22);
+            lcd.printf("Satellites: %02d\n", gps.satellites);
+            lcd.invert(0);
+            fprintf(fp, "%f %f %f %02d:%02d:%02.0f\n ", gps.latitude, gps.longitude,(compass.readBearing() / 10.0),gps.hours, gps.minutes, gps.seconds);
+            fclose(fp); 
+        } else {
+            lcd.cls();//clear LCD for next reading round
+            lcd.locate(1,0);
+            lcd.printf("No satellite lock\n");
+            lcd.locate(1,11);
+            lcd.printf("%02d:%02d:%02.0f %02d/%02d/%02d\n", 
+                gps.hours, gps.minutes, gps.seconds, 
+                gps.day, gps.month, gps.year);
+            lcd.locate(1,22);
+            lcd.printf("Satellites: %02d\n",gps.satellites);
+            lcd.invert(0);
         }
     }
-    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