赤外線リモコンの受信をパルス幅にて行います。 Displays the pulse width of the IR control.

Dependents:   IRLED_SendReceveDemo IRreceiver_PulseWidth

Revision:
0:612202986301
Child:
2:674f9ea95a5a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IRRcevPulseWidth.cpp	Sun Dec 25 08:54:15 2016 +0000
@@ -0,0 +1,69 @@
+#include "mbed.h"
+#include "IRRcevPulseWidth.h"
+
+IRRcevPulseWidth::IRRcevPulseWidth(PinName InputPin) : _inputPin(InputPin)
+{
+    fRcevStart = 0;
+    cIRRcev = 0;
+    cIRRceved = 0;
+    IRRcevState_prev = 1;
+}
+
+void IRRcevPulseWidth::init(uint16_t *dataPtr,uint16_t dataLim,uint32_t timeout_us)
+{
+    IRRcevTimeOut = timeout_us;
+    limitUpper_dataN = dataLim;
+    p_data = dataPtr;
+    _timer.start();
+    IRRcevMicroSec_prev = _timer.read_us();
+}
+    
+uint16_t IRRcevPulseWidth::getData_N(void)
+{
+    return cIRRceved;
+}
+    
+int8_t IRRcevPulseWidth::status(void)
+{
+    int8_t ret=0;
+    IRRcevMicroSec = _timer.read_us();
+    IRRcevMicroSec_diff = IRRcevMicroSec - IRRcevMicroSec_prev;
+
+    IRRcevState = _inputPin;
+    if( IRRcevState != IRRcevState_prev )
+    {
+        if(fRcevStart == 0)
+        {
+            fRcevStart = 1;
+        }
+        else
+        {
+            *(p_data+cIRRcev) = IRRcevMicroSec_diff;
+            cIRRcev++;
+            if(cIRRcev >= limitUpper_dataN)
+            {
+                cIRRcev = 0;
+                ret = -1;
+            }
+        }
+        IRRcevState_prev = IRRcevState;
+        IRRcevMicroSec_prev = IRRcevMicroSec;
+    }
+    else if( (IRRcevMicroSec_diff >= IRRcevTimeOut) && (cIRRcev != 0) )
+    {
+#if IR_RCEV_DEBUGOUT_ENABLE
+        DBG("Rceved\r\n");
+        DBG("RcevCnt:%d\r\n",cIRRcev);
+        for(i=0;i<cIRRcev;i++)
+        {
+            DBG("%d,",*(p_data+i));
+        }
+        DBG("\r\n");
+#endif
+        cIRRceved = cIRRcev;
+        cIRRcev = 0;
+        fRcevStart = 0;
+        ret = 1;
+    }
+    return ret;
+}