Time: 17:33 Date: 10/12/2017 Description: Task 1,7,8 Currently Functioning

Dependencies:   BME280 BMP280 TextLCD

Working Repository

Revision:
49:d51f96a46cc3
Parent:
48:244d6d81bb52
Child:
50:3d61ca637399
--- a/SD_CARD.cpp	Tue Jan 09 00:37:01 2018 +0000
+++ b/SD_CARD.cpp	Tue Jan 09 11:41:07 2018 +0000
@@ -1,6 +1,8 @@
 #include "SD_CARD.hpp"
 FILE* fp; 
 InterruptIn SD_CARD_DETECT(D0);
+   
+
 
 bool SD_Write = 1;
 void SD_Init()//Initialised the SD CARD
@@ -8,10 +10,10 @@
     
 }
 void SD_Card_Eject()
-{
+{/*
     SD_Write = 0;
     if(Log_Value==5){pc.printf("Closing File Ejecting SD Card\n");}
-    fclose(fp);//Close File
+    //fclose(fp);//Close File
     sd.deinit();//Close down
     LCD.Display_Clear();
     LCD.DDRAM_Address(0x00);
@@ -20,6 +22,7 @@
     LCD.Write_String("Unmounted");
     LCD.DDRAM_Address(0x00);
     pc.printf("SD Card Unmounted\n");
+    */
 }
 void SD_Card_Write()
 {
@@ -31,20 +34,32 @@
     if(Write_Pointer == mailsize - 1)
         {
             if(Log_Value==5){pc.printf("In SD_Card Thread\n");}
+            //Open to WRITE
+            FATFileSystem fs("sd", &sd);  
+            fp = fopen("/sd/test.csv","w");
             
-            //Open to WRITE
-            FILE* fp = fopen("/sd/test.csv","a"); 
+            if (fp == NULL) 
+            {
+            error("Could not open file for write in SD_Card\n");
+            LCD.Display_Clear();
+            LCD.Write_String("CANNOT OPEN FILE");
+            errorCode(FATAL);
+            }
+            //FILE* fp = fopen("/sd/hello.csv","w"); 
             if(Log_Value==5){pc.printf("File Opened\n");}  
                    
             for(int SD_Card_Data_Pointer = 0; SD_Card_Data_Pointer != mailsize; SD_Card_Data_Pointer++)
             {
+                if(Log_Value==5){pc.printf("Copying from address: %d\n", SD_Card_Data_Pointer);}
+                
+                //ofstream outfile ("Hello Tom.txt");
                 time_t Time = Data_Buffer[SD_Card_Data_Pointer].get_time();
                 tm* Time_Pointer = localtime(&Time);
                 int temp_day = Time_Pointer->tm_mday;
                 int temp_month = (Time_Pointer->tm_mon+1);//Set to current month
                 int temp_year = (Time_Pointer->tm_year+1900);//Set to current year
                     
-                int temp_hours = Time_Pointer->tm_hour;
+                int temp_hours = Time_Pointer->tm_hour; 
                 int temp_minute = Time_Pointer->tm_min;
                 int temp_seconds = Time_Pointer->tm_sec;
                     
@@ -64,3 +79,4 @@
             fclose(fp);
         }
 }
+