Latest

Dependencies:   serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice

Revision:
1:31c7b4ab552b
Parent:
0:4afd4940a189
Child:
3:b1583f309b43
diff -r 4afd4940a189 -r 31c7b4ab552b main.cpp
--- a/main.cpp	Sun Nov 04 21:56:56 2018 +0000
+++ b/main.cpp	Sun Nov 04 23:12:38 2018 +0000
@@ -1,12 +1,83 @@
-#include "mbed.h"
+#include "sample_hardware.hpp"
+#include "Networkbits.hpp"
 
-DigitalOut myled(LED1);
+// This is a very short demo that demonstrates all the hardware used in the coursework.
+// You will need a network connection set up (covered elsewhere). The host PC should have the address 10.0.0.1
+
+//Threads
+Thread nwrkThread;
+ 
 
 int main() {
-    while(1) {
-        myled = 1; // LED is ON
-        wait(0.2); // 200 ms
-        myled = 0; // LED is OFF
-        wait(1.0); // 1 sec
+    //Greeting
+    printf("Testing\n\n");    
+    
+    //Power on self test
+    post();
+    
+    //Initialise the SD card (this needs to move)
+    if ( sd.init() != 0) {
+        printf("Init failed \n");
+        lcd.cls();
+        lcd.printf("CANNOT INIT SD");        
+        errorCode(FATAL);
+    } 
+    
+    //Create a filing system for SD Card
+    FATFileSystem fs("sd", &sd);     
+
+    //Open to WRITE
+    FILE* fp = fopen("/sd/test.csv","a");
+    if (fp == NULL) {
+        error("Could not open file for write\n");
+        lcd.cls();
+        lcd.printf("CANNOT OPEN FILE\n\n");
+        errorCode(FATAL);
+    }
+    
+    //Last message before sampling begins
+    lcd.cls();
+    lcd.printf("READY\n\n");
+        
+        
+    //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
+    fclose(fp);
+    
+    //Close down
+    sd.deinit();
+    printf("Unmounted...\n");
+    lcd.cls();
+    lcd.printf("Unmounted...\n\n");
+    
+    //Flash to indicate goodness
+    while(true) {
+        greenLED = 1;
+        wait(0.5);
+        greenLED = 0;
+        wait(0.1);    
     }
 }
+
+
+    
+