Latest

Dependencies:   serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice

Revision:
11:3ad0327e8c9f
Parent:
10:0fffc988d325
Child:
12:3a54cbaa714c
--- a/main.cpp	Sat Nov 10 19:31:35 2018 +0000
+++ b/main.cpp	Sun Nov 18 15:19:55 2018 +0000
@@ -4,7 +4,7 @@
 #include "serial_terminal.hpp"
 #include "SDCard.hpp"
 #include "rtos.h"
-#include "mbed_events.h"
+#include "events/mbed_events.h"
 #include "LCDdisplay.hpp"
 
 
@@ -17,13 +17,14 @@
 //bool sample_enable = true;
 
 //Queues
-EventQueue SDqueue;
-EventQueue LCDqueue;
+EventQueue SDqueue(32*EVENTS_EVENT_SIZE);
+EventQueue LCDqueue(32*EVENTS_EVENT_SIZE);
+
 
 //Threads
-Thread SDqueue_thread(32*EVENTS_EVENT_SIZE);
-Thread LCDqueue_thread(32*EVENTS_EVENT_SIZE);
-Thread sterm_thread;
+Thread SDqueue_thread;
+Thread LCDqueue_thread;
+//Thread sterm_thread;
 Thread sample_thread(osPriorityHigh);
 //Thread ntwkthread
 
@@ -37,12 +38,27 @@
 FILE* fp;
 FATFileSystem* fs;
 
+
+//TEST
+Thread serialthread(osPriorityAboveNormal);
+EventQueue serialqueue(32*EVENTS_EVENT_SIZE);
+char buffer[256];
+RawSerial* pc;
+void serialISR(void);
+void serialiser(void);
+int i = 0;
+//TEST
+
+
+
 int main() {     
+    pc = new RawSerial(USBTX, USBRX);
+
     //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);
+    //sterm_thread.start(serialterm);
     sample_thread.start(samples);
     
     //Initialise, move into initialise function
@@ -50,15 +66,20 @@
     
     
     //Greeting
-    printf("Testing\n\n");  
+    pc->printf("Testing\n\n");  
      
     
     //Power on self test
     post();
     
-    printf("Send commands\n\r");
+    pc->printf("Send commands\n\r");
     
     sample.attach(&sampleISR, sample_rate);
+    
+    //TEST
+    serialthread.start(callback(&serialqueue, &EventQueue::dispatch_forever));
+    pc->attach(serialISR, Serial::RxIrq);
+    //TEST
         
     
     //Flash to indicate goodness
@@ -80,6 +101,8 @@
         //High priority thread 
         Thread::signal_wait(TAKE_SAMPLE);
         
+        //needs to be a class at some point
+        
         double temp = sensor.getTemperature();
         double pressure = sensor.getPressure();
         
@@ -89,4 +112,30 @@
     }
 }
     
+void serialISR()
+{
+    pc->attach(NULL, Serial::RxIrq);
+    yellowLED = !yellowLED;
+    serialqueue.call(serialiser);
+}
 
+void serialiser()
+{
+    
+    if (pc->readable())
+    {
+        buffer[i] = pc->getc();
+        if (buffer[i] == '\r')
+        {
+            //call serialterm
+            greenLED = !greenLED; 
+            i = 0;
+            serialqueue.call(serialterm); 
+                     
+        }
+        else i++;
+    }
+    pc->attach(serialISR, Serial::RxIrq);
+}
+
+//