''

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_08012018a by Calvin Kalintra

Revision:
5:8aa72ee456fc
Parent:
4:5dbb5145d0a9
--- a/sd.h	Tue Jan 09 12:11:46 2018 +0000
+++ b/sd.h	Tue Jan 09 15:45:56 2018 +0000
@@ -1,73 +1,58 @@
  #include "mbed.h"
  #include "SDBlockDevice.h"
  #include "FATFileSystem.h"
- //#include "sample_hardware.hpp"
+ #include "putty.h"
  #include "mbed_events.h"
  
-
+DigitalOut redLED(PB_11), yellowLED(PB_10), greenLED(PE_15);
 SDBlockDevice sd(D11, D12, D13, D10); 
 EventQueue eq;
 FILE* fp;
 bool ejected = false; 
 void takeSample()
 {
-    if (ejected == true) {
-        return;    
-    }
-    float temp     = sensor.getTemperature();
-    float pressure = sensor.getPressure();
-    
-    fprintf(fp, "%f,%f\n", temp, pressure);
+    int counterb = 0;
+    while (counterb <= countera) 
+    {
+        if (ejected == true) 
+        {
+            return;    
+        }   
+        float temp_sd = data_tempa[counterb];
+        float pressure_sd = data_pressa[counterb];
+        float light_sd = data_lighta[counterb];
+        float date_a_sd = date_aa[counterb] ; 
+        float time_a_sd = time_aa [counterb];
+        float date0_a_sd = date0_aa[counterb];
+        float time0_a_sd = time0_aa[counterb];
+        fprintf(fp, "%i%i, %i%i, temp:%f, pressure: %f, light lvl:%f\n\r", time0_a, time_a_sd, date0_a_sd, date_a_sd, temp_sd,pressure_sd,light_sd);
+        redLED = 1;
+        Thread::wait(100);
+        redLED = 0;
     
-    redLED = 1;
-    Thread::wait(100);
-    redLED = 0;
-    
-    if ((SW1 == 1) && (SW2 == 1)) {
-        //Close File
-        fclose(fp);
-        
-        sd.deinit();
-        
-        puts("You can now remove the SD Card\n");
-        yellowLED = 1;
-        
-        ejected = true;
+        if ((sw1 == 1) && (sw2 == 1)) 
+        {
+            fclose(fp);
+            sd.deinit();
+            yellowLED = 1;
+            ejected = true;
+        }
     }
 }
  
- int main()
-{
-    //POWER ON SELF TEST
-    post();
-    
-    printf("Initialise\n");
-    //FileSystemLike(*sd);
-
-    // call the SDBlockDevice instance initialisation method.
-    if ( sd.init() != 0) {
-        printf("Init failed \n");
-        errorCode(FATAL);
-    }    
-    
-    //Create a filing system for SD Card
-    FATFileSystem fs("sd", &sd);
-    
-    // **************
-    // Open to APPEND
-    // **************
-    fp = fopen("/sd/test.txt","a");
-    
-    //Check file handle (stream)
-    if (fp == NULL) {
-        error("Could not open file for write\n");
-        errorCode(FATAL);
-    }
-    
-    //Set up tasks on the main thread
-    queue.call_every(5000, takeSample);
-    
-    //Main queue event loop
-    queue.dispatch();
-
-}
\ No newline at end of file
+//void sd()
+//{
+//    if (sd.init() != 0) {
+//        printf("Init failed \n");
+//        errorCode(FATAL);
+//    }    
+//    FATFileSystem fs("sd", &sd);
+//    fp = fopen("/sd/test.txt","a");
+//    if (fp == NULL) {
+//        error("Could not open file for write\n");
+//        errorCode(FATAL);
+//    }
+//    takeSample();
+//   
+//
+//}
\ No newline at end of file