Latest

Dependencies:   serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice

Revision:
8:c81b0ff8b822
Parent:
7:e2bf2d703867
Child:
9:fa8a35d9d6c0
--- a/main.cpp	Wed Nov 07 19:57:27 2018 +0000
+++ b/main.cpp	Fri Nov 09 17:58:40 2018 +0000
@@ -5,21 +5,38 @@
 #include "SDCard.hpp"
 #include "rtos.h"
 #include "mbed_events.h"
+#include "LCDdisplay.hpp"
 
-EventQueue queue;
+#define TAKE_SAMPLE 1
+#define SAMPLE_RATE 5
+
+//Queues
+EventQueue SDqueue;
+EventQueue LCDqueue;
 
 //Threads
-//Thread nwrkThread;
-Thread serial_terminal;
-Thread SD_thread;
+Thread SDqueue_thread;
+Thread LCDqueue_thread;
+Thread sterm_thread;
+Thread sample_thread(osPriorityHigh);
+//Thread ntwkthread
 
+Ticker sample;
+void sampleISR(void);
+void takesample(void);
+void samples(void);
 
 
 int main() {     
-    //Move threads into a thread init function
-    serial_terminal.start(serialterm);
-    queue.call_every(20000, SDalive);
-    SD_thread.start(callback(&queue, &EventQueue::dispatch_forever));
+    //Move threads into a thread init function?
+    SDqueue_thread.start(callback(&SDqueue, &EventQueue::dispatch_forever));
+    LCDqueue_thread.start(callback(&LCDqueue, &EventQueue::dispatch_forever));
+    
+    sterm_thread.start(serialterm);
+    sample_thread.start(samples);
+    
+    //Initialise, move into initialise function
+    SDcard();
     
     //Greeting
     printf("Testing\n\n");    
@@ -28,61 +45,9 @@
     post();
     
     printf("Send commands\n\r");
-    /*
-    //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);
-    }
+    sample.attach(&sampleISR, SAMPLE_RATE);
     
-    //Close File
-    fclose(fp);
-    
-    //Close down
-    sd.deinit();
-    printf("Unmounted...\n");
-    lcd.cls();
-    lcd.printf("Unmounted...\n\n");
-    */
     
     //Flash to indicate goodness
     while(true) {
@@ -91,6 +56,26 @@
     }
 }
 
+void sampleISR()
+{
+    sample_thread.signal_set(TAKE_SAMPLE);   
+}
+
+void samples()
+{
+    while(true)
+    {
+        //High priority thread 
+        Thread::signal_wait(TAKE_SAMPLE);
+        
+        double temp = sensor.getTemperature();
+        double pressure = sensor.getPressure();
+        
+        //Pass onto queues
+        LCDqueue.call(LCD_display,temp,pressure);
+        SDqueue.call(SDaddSample,temp,pressure);
+    }
+}