PIR still blocked by the XBee reading. Audio sensor not configured yet.

Dependencies:   BME280 SI1145 mbed

Revision:
1:d0db255b07a8
Parent:
0:7daf9b751759
Child:
2:dd4d53687372
--- a/main.cpp	Fri Jul 07 20:43:29 2017 +0000
+++ b/main.cpp	Tue Jul 18 15:08:42 2017 +0000
@@ -8,7 +8,7 @@
 */
 
 // Libraries
-#include "mbed.h"
+#include "mbed.h" 
 #include "BME280.h"
 #include "SI1145.h"
 
@@ -25,7 +25,8 @@
 SI1145 *uiv_sensor = new SI1145(i2c);
 
 // Declare the PIR interface
-InterruptIn MotionDetect(PA_1);
+InterruptIn PIR_sensor(PA_5);
+Ticker pir_timer;
 bool pir_enable = true;
 bool pir_trigger = false;
 
@@ -51,11 +52,16 @@
 
 // PIR interrupt. Set the pir_trigger to true when interrupted.
 void PIR(void){
-    pc.printf("void PIR(void){}\r\n");
+    //pc.printf("void PIR(void){}\r\n");
     pir_trigger = true;
-    if(pir_enable){
+}
+
+// This method is attached to a timer
+void PIR_timed_send(){
+    //pc.printf("PIR_timed_send();\r\n");
+    if(pir_enable && pir_trigger){
         SendPirFlag();
-        pc.printf("PIR FLAG ISR\r\n");
+        pir_trigger = false;
     }
 }
 
@@ -70,7 +76,8 @@
     pc.printf("\n\rMic test 1-2, 1-2\n\r");
     
     // Attach the PIR function to interrupt
-    MotionDetect.rise(&PIR);
+    PIR_sensor.rise(&PIR);
+    pir_timer.attach(&PIR_timed_send,3);
     
     char pc_data = 'e';
     char buffer[10];
@@ -93,27 +100,42 @@
             if(xb.writeable()){xb.printf("%c", pc_data);}
         }
         
-        if(pir_enable && pir_trigger){
-            SendPirFlag();
-        }
-        
         if(xb.readable()){
+            
             wait(0.01);
+            pc.printf("before the read loop\r\n");
+            
             for(int i = 0; i < sizeof(buffer); i++){
                 buffer[i] = xb.getc();
             }
+            
+            /*
+            // Try a while(readable()) loop to read stuff
+            int j = 0;
+            while(xb.readable() && j < 10){
+                wait(0.01);
+                buffer[j] = xb.getc();
+                
+                j = j+1;
+            }
+            */
+            pc.printf("after the read loop\r\n");
+            
+            // Print out a bunch of stuff
             pc.printf("=========================================\r\n");
             // Print out received message in char and int format 
-            pc.printf("RECV: ", buffer);
-                for(int i = 1; i < sizeof(buffer); i++){
-                    pc.printf("%c", buffer[i]);
-                }
-                pc.printf("\r\nRECV: ");
-                // Print out message (INT)
-                for(int i = 0; i < sizeof(buffer); i++){
-                    pc.printf("%i,", buffer[i]);
-                }
-                pc.printf("\r\n");
+            pc.printf("RECV: ");
+            for(int i = 1; i < sizeof(buffer); i++){
+                pc.printf("%c", buffer[i]);
+            }
+            pc.printf("\r\nRECV: ");
+            // Print out message (INT)
+            for(int i = 0; i < sizeof(buffer); i++){
+                pc.printf("%i,", buffer[i]);
+            }
+            pc.printf("\r\n");
+            
+            //Check the node id
             if(buffer[4] == nodeID){
                 send_enable = true;
             } else {
@@ -127,6 +149,7 @@
                 pir_enable = false;
                 pc.printf("pir_enable = false\r\n");
             }
+            
             memset(buffer, '\0', sizeof(buffer));
         }