Latest

Dependencies:   serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice

Revision:
24:81981815ef20
Parent:
23:f87fe0c55894
Child:
25:831dc928ccde
--- a/main.cpp	Wed Dec 19 12:03:50 2018 +0000
+++ b/main.cpp	Wed Dec 19 13:09:42 2018 +0000
@@ -7,13 +7,15 @@
 #include "events/mbed_events.h"
 #include "LCDdisplay.hpp"
 
-//Defines
-//moved
+//Defines TEST FOR SD CARD MOUNT AND UNMOUNT
+#define EDGE_FALLEN 0
+#define EDGE_RISEN 1
 
 //Signals
 #define TAKE_SAMPLE 1
 #define STORE_DATA 2
 
+
 //Global variables
 
 unsigned int newestIndex = BUFFERSIZE-1;    //First time it is incremented, it will be 0
@@ -43,10 +45,13 @@
 Thread producer_thread(osPriorityHigh);
 Thread consumer_thread;
 Thread serial_thread(osPriorityAboveNormal);
-Thread SDqueue_thread;
+Thread SDqueue_thread; //remove
 Thread LCDqueue_thread;
 Thread Network_thread;
 
+//TEST FOR SD CARD
+Thread SDmount_thread;
+
 //Timers
 Ticker sample;
 
@@ -57,6 +62,19 @@
 void serialISR(void);
 void serialData(void);
 
+
+
+//TEST FOR SD CARD MOUNT AND UNMOUNT
+Timeout userswTimeOut;
+int userswState = EDGE_FALLEN;
+InterruptIn   usersw(USER_BUTTON);
+void userswTimeOutHandler();
+void userswRisingEdge();
+void userswFallingEdge();
+void SDmount();
+
+
+
 int main() {   
     timeData = new tm;
     pc = new RawSerial(USBTX, USBRX);
@@ -75,11 +93,17 @@
     producer_thread.start(sampleProducer);
     consumer_thread.start(sampleConsumer);
     
+    //TEST FOR SD CARD
+    SDmount_thread.start(SDmount);
+    
     
     //Attach ISRs
     sample.attach(&sampleISR, sample_rate);    
     pc->attach(serialISR, Serial::RxIrq);
     
+    //TEST FOR SD CARD MOUNT AND UNMOUNT
+    usersw.rise(&userswRisingEdge);
+    
     //Flash to indicate goodness
     while(true) {
         greenLED = !greenLED;
@@ -193,3 +217,36 @@
         bufferLock.unlock();        
     }   
 }
+
+//TEST FOR MOUNTING AND UNMOUNTING SD CARD
+//Interrupt service routine for handling the timeout
+
+
+void userswTimeOutHandler() {
+    userswTimeOut.detach();            //Stop the timeout counter firing
+
+    //Which event does this follow?
+    switch (userswState) {
+    case EDGE_RISEN:    
+        usersw.fall(&userswFallingEdge);  //Now wait for a falling edge
+        break;
+    case EDGE_FALLEN:
+        usersw.rise(&userswRisingEdge);   //Now wait for a rising edge
+        break;
+    } //end switch 
+}
+
+//Interrupt service routine for a rising edge (press)
+void userswRisingEdge() {
+    usersw.rise(NULL);             //Disable detecting more rising edges
+    userswState = EDGE_RISEN;      //Flag state
+    userswTimeOut.attach(&userswTimeOutHandler, 0.2);    //Start timeout timer
+}
+
+//Interrupt service routive for SW1 falling edge (release)
+void userswFallingEdge() {
+    usersw.fall(NULL);                         //Disable this interrupt    
+    SDmount_thread.signal_set(SIGNAL_SD);
+    userswState = EDGE_FALLEN;                 //Flag state
+    userswTimeOut.attach(&userswTimeOutHandler, 0.2);    //Start timeout counter - may want to increase this  
+}