SMART CLEO Uart PIR

Files at this revision

API Documentation at this revision

Comitter:
SMART_CLEO
Date:
Wed Dec 06 08:42:05 2017 +0000
Parent:
0:49114a9f05a6
Commit message:
SMART_CLEO

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 49114a9f05a6 -r 611e7e2a13df main.cpp
--- a/main.cpp	Thu Sep 28 03:37:24 2017 +0000
+++ b/main.cpp	Wed Dec 06 08:42:05 2017 +0000
@@ -1,165 +1,60 @@
 #include "mbed.h"
 
-struct UART_buf
-{ 
-    uint8_t STA;
-    uint8_t MODE; 
-    uint8_t CMD;
-    uint8_t LEN;
-    uint8_t DATA[32];
-    uint8_t END; 
-     
-};
- 
-PinName pin_SOUND = PC_3;
+PinName pin_PIR = PB_2;
 
-AnalogIn adc_SOUND(pin_SOUND);
+InterruptIn Pir(pin_PIR);
 
 Serial SerialUART(PA_2, PA_3);
 
 uint8_t Buffer[37];
 
-//UART_buf RX_BUF;
-
-//Ticker Sensor_Timer;
+int pir_flag = 0;
 
-//void SerialUARTRX_ISR(void);
-//void Timer_setting(uint8_t cmd, uint8_t value);
-//void Sensor_Read(void);
+void PIR_ISR(void);
 void Sensor_Read_Data(uint8_t data);
 
 int main() {
 
-    uint8_t Sound_flag = 0;
-    int volt;
+    uint8_t PIR_check = 0;
     
     SerialUART.baud(115200);
     
-    //SerialUART.attach(&SerialUARTRX_ISR);
-    
-    //Timer_setting(0x06, 2);
+    Pir.rise(&PIR_ISR);
     
     while(1)
     {
-        volt = adc_SOUND.read()*3300;
-        if(Sound_flag && (volt <= 1000))
+        if(pir_flag)
+        {
+            pir_flag = 0;
+            if(PIR_check == 0)
+            {
+                Sensor_Read_Data(1);
+                PIR_check = 1;
+            }
+            wait(1);
+        }
+        else if(PIR_check)
         {
             Sensor_Read_Data(0);
-            Sound_flag = 0;
-            wait(1);
-        }
-        else if((Sound_flag == 0) && (volt > 1000))
-        {
-            Sensor_Read_Data(1);
-            Sound_flag = 1;
+            PIR_check = 0;
             wait(1);
         }
     }
 }
 
-/*void SerialUARTRX_ISR(void)
+void PIR_ISR(void)
 {
-    static uint8_t RX_count = 0, RX_Len = 32, RX_Status = 0;
-    uint8_t rx_da = SerialUART.getc();
-    switch(RX_Status)
-    {
-        case 0:
-            if(rx_da == 0x76)
-            {
-                RX_BUF.STA = rx_da;
-                RX_Status++;
-            }
-            break;
-        case 1:
-            RX_BUF.MODE = rx_da;
-            RX_Status++;
-            break;
-        case 2:
-            RX_BUF.CMD = rx_da;
-            RX_Status++;
-            break;
-        case 3:
-            RX_BUF.LEN = rx_da;
-            RX_Len = RX_BUF.LEN;
-            RX_Status++;
-            if(RX_Len == 0)
-                RX_Status++;
-            break;
-        case 4:
-            RX_BUF.DATA[RX_count] = rx_da;
-            RX_count++;
-            if(RX_count == RX_Len)
-            {
-                RX_Status++;
-                RX_count = 0;
-                RX_Len = 32;
-            }
-            break;
-        case 5:
-            if(rx_da == 0x3E)
-            {
-                RX_BUF.END = rx_da;
-                RX_Status = 0;
-                switch(RX_BUF.MODE)
-                {
-                    case 0x04:
-                        Timer_setting(RX_BUF.CMD, RX_BUF.DATA[0]);
-                        break;
-                }
-            }
-            break;
-    }
-}*/
-
-/*void Timer_setting(uint8_t cmd, uint8_t value)
-{
-    double Time_value = 0;
-    switch(cmd)
-    {
-        case 0x01:
-            Time_value = 30;
-            break;
-        case 0x02:
-            Time_value = 60;
-            break;
-        case 0x03:
-            Time_value = 120;
-            break;
-        case 0x04:
-            Time_value = 300;
-            break;
-        case 0x05:
-            Time_value = 600;
-            break;
-        case 0x06:
-            Time_value = value;
-            Time_value = 1.0/Time_value;
-            break;
-    }
-    Sensor_Timer.attach(&Sensor_Read, Time_value);
-}*/
+    pir_flag = 1;
+}
 
 void Sensor_Read_Data(uint8_t data)
 {
     Buffer[0] = 0x76;
     Buffer[1] = 0x01;
-    Buffer[2] = 0x06;
+    Buffer[2] = 0x10;
     Buffer[3] = 0x01;
     Buffer[4] = data;
     Buffer[5] = 0x3E;
     for(int i=0; i<6; i++)
         SerialUART.putc(Buffer[i]);
-}
-/*
-void Sensor_Read(void)
-{
-    Buffer[0] = 0x76;
-    Buffer[1] = 0x01;
-    Buffer[2] = 0x05;
-    Buffer[3] = 0x01;
-    Buffer[4] = IR_Detect;
-    Buffer[5] = 0x3E;
-    for(int i=0; i<6; i++)
-        SerialUART.putc(Buffer[i]);
-}
-*/
\ No newline at end of file
+}
\ No newline at end of file