newest

Dependencies:   BME280 BMP280 TextLCD mbed

Fork of CW_watchdog_08012018_fran by Calvin Kalintra

Files at this revision

API Documentation at this revision

Comitter:
ckalintra
Date:
Tue Jan 09 12:11:46 2018 +0000
Parent:
3:f5fe5071416a
Commit message:
fran

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
sd.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Jan 09 11:54:56 2018 +0000
+++ b/main.cpp	Tue Jan 09 12:11:46 2018 +0000
@@ -31,8 +31,8 @@
         lcd.printf("l:%1.2f", lvl);
         lcd.locate(0,0);
         lcd.printf("p:%5.1f", pressuref);
-        lcd.locate(10,1);
-        lcd.printf("t:%2.1f", tempf);
+        lcd.locate(8,1);
+        lcd.printf("t:%4.1f", tempf);
         display_time(); 
     }
     else if (dislcd == 0)
@@ -82,7 +82,7 @@
 //    {
 //        select_date();
 //    }
-    bmp.initialize();
+    //bmp.initialize();
     pc.printf("\n\rputty ready\n\r");
     display.attach(&lcddisp, T);
     second_pass.attach(&second_tick, 1.0);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sd.h	Tue Jan 09 12:11:46 2018 +0000
@@ -0,0 +1,73 @@
+ #include "mbed.h"
+ #include "SDBlockDevice.h"
+ #include "FATFileSystem.h"
+ //#include "sample_hardware.hpp"
+ #include "mbed_events.h"
+ 
+
+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);
+    
+    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;
+    }
+}
+ 
+ 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