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

Dependencies:   BME280 BMP280 TextLCD

Working Repository

Files at this revision

API Documentation at this revision

Comitter:
thomasmorris
Date:
Tue Jan 09 12:19:12 2018 +0000
Parent:
49:d51f96a46cc3
Commit message:
Dynamic Dating Working

Changed in this revision

FIFO.hpp Show annotated file Show diff for this revision Revisions of this file
SD_CARD.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FIFO.hpp	Tue Jan 09 11:41:07 2018 +0000
+++ b/FIFO.hpp	Tue Jan 09 12:19:12 2018 +0000
@@ -4,7 +4,7 @@
 #include "mbed.h"
 #include "rtos.h"
 //Definition of Data buffer size (120 in specification)
-#define mailsize 10
+#define mailsize 120
 
 //Variables
 
--- a/SD_CARD.cpp	Tue Jan 09 11:41:07 2018 +0000
+++ b/SD_CARD.cpp	Tue Jan 09 12:19:12 2018 +0000
@@ -3,7 +3,6 @@
 InterruptIn SD_CARD_DETECT(D0);
    
 
-
 bool SD_Write = 1;
 void SD_Init()//Initialised the SD CARD
 {
@@ -34,18 +33,28 @@
     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");
+            
+            FATFileSystem fs("sd", &sd);
+            
             
+            time_t File_Time = Data_Buffer[Write_Pointer - 1].get_time();
+            tm* File_Time_Pointer = localtime(&File_Time);
+            int File_temp_day = File_Time_Pointer->tm_mday;
+            int File_temp_month = (File_Time_Pointer->tm_mon+1);//Set to current month
+            int File_temp_year = (File_Time_Pointer->tm_year+1900);//Set to current year
+            
+            char FileToOpen[50] = {};
+            snprintf (FileToOpen, sizeof(char) * sizeof(FileToOpen), "/sd/%d_%02d_%02d.csv",File_temp_year,File_temp_month,File_temp_day);
+            
+            fp = fopen(FileToOpen,"wb");
             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"); 
+                error("Could not open file for write in SD_Card\n");
+                LCD.Display_Clear();
+                LCD.Write_String("CANNOT OPEN FILE");
+                errorCode(FATAL);
+            }                             //Open to WRITE
+            
             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++)
@@ -67,6 +76,7 @@
                 float temp_pressure = Data_Buffer[SD_Card_Data_Pointer].get_pressure();
                 float temp_light = Data_Buffer[SD_Card_Data_Pointer].get_light();
                 
+                
                 fprintf(fp, "Date: %02d/%02d/%d,",temp_day,temp_month,temp_year);//Date
                 fprintf(fp, "Time: %02d:%02d:%02d,",temp_hours,temp_minute, temp_seconds);//Time
                 fprintf(fp, "Temperature: %1.1f,",temp_temperature);//Temperature
@@ -74,9 +84,11 @@
                 fprintf(fp, "Light: %5.3f,",temp_light);//Light
                 fprintf(fp, "End of Data \n");//End of data
             }
-            if(Log_Value==5){pc.printf("Dumped data to SD Card\n");}
+            
             //Close File
             fclose(fp);
+            if(Log_Value==5){pc.printf("Dumped data to SD Card\n");}
+
         }
 }