Mathew Swabey / SDCard

Dependents:   ELEC350_Project2 SDcard

Files at this revision

API Documentation at this revision

Comitter:
Swabey89
Date:
Fri Nov 09 17:56:55 2018 +0000
Parent:
2:9a5eea2adbf8
Child:
4:dc767b5f917b
Commit message:
SD card now has new functions, one will write the sampled data to the SD card

Changed in this revision

SDCard.cpp Show annotated file Show diff for this revision Revisions of this file
SDCard.hpp Show annotated file Show diff for this revision Revisions of this file
--- a/SDCard.cpp	Thu Nov 08 21:29:38 2018 +0000
+++ b/SDCard.cpp	Fri Nov 09 17:56:55 2018 +0000
@@ -1,5 +1,7 @@
 #include "SDCard.hpp"
 
+
+
 void SDcard(void)
 {
         
@@ -18,7 +20,7 @@
     FATFileSystem fs("sd", &sd);     
 
     //Open to WRITE
-    FILE* fp = fopen("/sd/test.csv","a");
+    FILE* fp = fopen("/sd/newtest.csv","a");
     if (fp == NULL) {
         error("Could not open file for write\n");
         lcd.cls();
@@ -26,29 +28,23 @@
         errorCode(FATAL);
     }
     
+    fclose(fp);
+    
     //Last message before sampling begins
     lcd.cls();
     lcd.printf("READY\n\n");
     
+    
+    
     //move?   
     //Press either switch to unmount
+    /*
     while ((SW1 == 0) && (SW2 == 0)) {
         
-        //Base loop delay
-        wait(1.0);
-        
-        //Read environmental sensors
-        double temp = sensor.getTemperature();
-        double pressure = sensor.getPressure();
-        
-        //Write new data to LCD (not fast!)
-        lcd.cls();
-        lcd.printf("Temp   Pressure\n"); 
-        lcd.printf("%6.1f ",temp);
-        lcd.printf("%.2f\n",pressure);
-        
+             
         //Write to SD (potentially slow)
         //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
+        
     }
     
     //Close File
@@ -59,21 +55,35 @@
     printf("Unmounted...\n");
     lcd.cls();
     lcd.printf("Unmounted...\n\n");
+    */
 }
 
 void SDread(int n)
 {
+    //Read n samples from the SD card
     if (n == -1) puts("Received command to read all");
     else printf("Received command to read %d\n", n);
 }
 
 void SDdelete(int n)
 {
+    //Delete n samples from the SD card
     if (n == -1) puts("Received command to delete all");
     else printf("Received command to delete %d\n", n);   
 }
 
+void SDaddSample(double temp, double pressure)
+{
+    //Add the sampled data to the SD card
+    
+    FILE* fp = fopen("/sd/newtest.csv","a");
+    fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure);
+    fclose(fp);
+    puts("SAMPLE ADDED TO SD CARD");
+}
+
 void SDalive(void)
 {
+    //Signal that the SD thread is still alive
     //puts("SD THREAD ALIVE\n");   
 }
\ No newline at end of file
--- a/SDCard.hpp	Thu Nov 08 21:29:38 2018 +0000
+++ b/SDCard.hpp	Fri Nov 09 17:56:55 2018 +0000
@@ -6,10 +6,11 @@
 #include "serial_terminal.hpp"
 #include "mbed_events.h"
 
-extern EventQueue queue;
+extern EventQueue SDqueue;
 
 void SDcard(void);
 void SDread(int n);
+void SDaddSample(double temp, double pressure);
 void SDdelete(int n);
 void SDalive(void);