Gitakichi Tokyo / Mbed 2 deprecated IR-remote

Dependencies:   mbed

Revision:
1:4847c54eed20
Parent:
0:a3131d121a8f
Child:
2:eca0702650ca
--- a/main.cpp	Tue Feb 11 04:30:44 2020 +0000
+++ b/main.cpp	Tue Feb 11 05:55:21 2020 +0000
@@ -13,17 +13,36 @@
 
     Timer timer;
     timer.start();
-    int iMicroSec_prev = timer.read_us();
+    //int iMicroSec_prev = timer.read_us();
     int iState_prev = 1;
-    while(1)
-    {
+    int time_start,time_end;
+    
+    while(1) {
         int iState = g_dpinIrReceiver;
-        if( iState != iState_prev )
-        {
-            iState_prev = iState;
-            int iMicroSec = timer.read_us();
-            g_serial.printf( "%d, ", iMicroSec - iMicroSec_prev );//hex
-            iMicroSec_prev = iMicroSec;
-        }
+       
+        //detect H signal
+        if( iState != iState_prev ) {
+        //timer start 
+            if(iState == 0) {
+                //timer.start();//reset
+                time_start = timer.read_us();//start(detect negedge
+            }
+            if(iState == 1) {//end (detect posedge
+                time_end = timer.read_us();//over flow?
+                //compare and output
+                int delta_t = time_end - time_start;
+                
+                if(delta_t > 8430)    g_serial.printf("flame,");
+                else                    g_serial.printf("data,");
+                
+                //g_serial.printf( "%d, ", time_start - time_end);
+            }
+        }  
+        iState_prev = iState;
+           
+        //iState_prev = iState;
+        //int iMicroSec = timer.read_us();
+        //g_serial.printf( "%d, ", iMicroSec - iMicroSec_prev );
+        //iMicroSec_prev = iMicroSec;
     }
 }
\ No newline at end of file