RemotoIR Libraryに、IRC Helicopter Propo の受信処理と、受信パルス幅測定処理を追加したものです。

Dependents:   SwiftPropoIR_TestProgram irRawDataDisplay spinner2 LPC1114_ir-spinne_main-propo

Fork of RemoteIR by Shinichiro Nakamura

Files at this revision

API Documentation at this revision

Comitter:
suupen
Date:
Sat Aug 03 01:44:43 2013 +0000
Parent:
12:2379e13b8b34
Commit message:
????????????????????????????????(100ms??)???????????????????????????????

Changed in this revision

ReceiverIR.cpp Show annotated file Show diff for this revision Revisions of this file
ReceiverIR.h Show annotated file Show diff for this revision Revisions of this file
diff -r 2379e13b8b34 -r ec76e93a4d7c ReceiverIR.cpp
--- a/ReceiverIR.cpp	Sun Jun 23 07:23:56 2013 +0000
+++ b/ReceiverIR.cpp	Sat Aug 03 01:44:43 2013 +0000
@@ -7,7 +7,7 @@
  * -------------------------------------------------------
  * 130616 suupen
  * IRC Helicopter "SWIFT" Propo support
- *  Conditional compilation 
+ *  Conditional compilation
  *      "SWIFT_PROTCOL"
  *      "IR_RAW_DATA_ANALYSIS"
  *--------------------------------------------------------
@@ -25,7 +25,8 @@
  *
  * @param rxpin Pin for receive IR signal.
  */
-ReceiverIR::ReceiverIR(PinName rxpin) : evt(rxpin) {
+ReceiverIR::ReceiverIR(PinName rxpin) : evt(rxpin)
+{
     init_state();
     evt.fall(this, &ReceiverIR::isr_fall);
     evt.rise(this, &ReceiverIR::isr_rise);
@@ -36,7 +37,8 @@
 /**
  * Destructor.
  */
-ReceiverIR::~ReceiverIR() {
+ReceiverIR::~ReceiverIR()
+{
 }
 
 /**
@@ -44,7 +46,8 @@
  *
  * @return Current state.
  */
-ReceiverIR::State ReceiverIR::getState() {
+ReceiverIR::State ReceiverIR::getState()
+{
     LOCK();
     State s = work.state;
     UNLOCK();
@@ -60,7 +63,8 @@
  *
  * @return Data bit length.
  */
-int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength) {
+int ReceiverIR::getData(RemoteIR::Format *format, uint8_t *buf, int bitlength)
+{
     LOCK();
 
     if (bitlength < data.bitcount) {
@@ -81,7 +85,8 @@
     return nbits;
 }
 
-void ReceiverIR::init_state(void) {
+void ReceiverIR::init_state(void)
+{
     work.c1 = -1;
     work.c2 = -1;
     work.c3 = -1;
@@ -97,7 +102,17 @@
     }
 }
 
-void ReceiverIR::isr_wdt(void) {
+#ifdef ERRORWAIT
+void ReceiverIR::errorWait(void)
+{
+    work.state = ErrorWait;
+    timeout.detach();
+    timeout.attach_us(this, &ReceiverIR::isr_timeout, 50 * 1000);   // 50[ms]wait
+}
+#endif //ERRORWAIT
+
+void ReceiverIR::isr_wdt(void)
+{
     LOCK();
     static int cnt = 0;
     if ((Idle != work.state) || ((0 <= work.c1) || (0 <= work.c2) || (0 <= work.c3) || (0 <= work.d1) || (0 <= work.d2))) {
@@ -123,26 +138,27 @@
     UNLOCK();
 }
 
-void ReceiverIR::isr_fall(void) {
+void ReceiverIR::isr_fall(void)
+{
 
 #ifdef IR_RAW_DATA_ANALYSIS
     switch (work.state) {
-    case Idle:
-        if (work.c1 < 0){
-            check.bitcount = 0;
-            check.timecount[check.bitcount++] = 0;
-        } else {
-            check.timecount[check.bitcount++] = timer.read_us() & ~1;
-        }
-        break;
-    case Receiving:
- 
-        if ((check.bitcount < 1000))  { 
-            check.timecount[check.bitcount++] = timer.read_us() & ~1; 
-        }
-        break;
-    default:
-        break;
+        case Idle:
+            if (work.c1 < 0) {
+                check.bitcount = 0;
+                check.timecount[check.bitcount++] = 0;
+            } else {
+                check.timecount[check.bitcount++] = timer.read_us() & ~1;
+            }
+            break;
+        case Receiving:
+
+            if ((check.bitcount < 1000))  {
+                check.timecount[check.bitcount++] = timer.read_us() & ~1;
+            }
+            break;
+        default:
+            break;
     }
 #endif //IR_RAW_DATA_ANALYSIS
 
@@ -208,10 +224,14 @@
                     data.format = RemoteIR::UNKNOWN;
                     work.state = Receiving;
                     data.bitcount = 0;
-#else // ~IR_RAW_DATA_ANALYSIS                        
+#else // ~IR_RAW_DATA_ANALYSIS
+#ifdef ERRORWAIT
+                    errorWait();
+#else // ~ERRORWAIT                    
                     init_state();
+#endif // ERRORWAIT
 #endif // IR_RAW_DATA_ANALYSIS                
-                 }
+                }
             }
             break;
         case Receiving:
@@ -274,7 +294,7 @@
 #endif
             } else if (RemoteIR::SONY == data.format) {
                 work.d1 = timer.read_us();
-#ifdef SWIFT_PROTCOL            
+#ifdef SWIFT_PROTCOL
             } else if (RemoteIR::SWIFT == data.format) {
                 work.d2 = timer.read_us();
                 int a = work.d2 - work.d1;
@@ -307,9 +327,9 @@
 
 #ifdef IR_RAW_DATA_ANALYSIS
             } else if (RemoteIR::SWIFT == data.format) {
-                 /*
-                 * Set timeout for tail detection automatically.
-                 */
+                /*
+                * Set timeout for tail detection automatically.
+                */
                 timeout.detach();
                 timeout.attach_us(this, &ReceiverIR::isr_timeout, (work.c3 - work.c2) * 5);
 #endif // IR_RAW_DATA_ANALYSIS
@@ -317,22 +337,33 @@
             break;
         case Received:
             break;
+#ifdef ERRORWAIT
+        case ErrorWait:
+            errorWait();
+            break;
+#endif //ERRORWAIT
         default:
             break;
     }
     UNLOCK();
 }
 
-void ReceiverIR::isr_rise(void) {
+void ReceiverIR::isr_rise(void)
+{
 
 #ifdef IR_RAW_DATA_ANALYSIS
     switch (work.state) {
-    case Idle:
-    case Receiving:
-        check.timecount[check.bitcount++] = timer.read_us() | 1;
-        break;
-    default:
-        break;
+        case Idle:
+        case Receiving:
+            check.timecount[check.bitcount++] = timer.read_us() | 1;
+            break;
+#ifdef ERRORWAIT
+        case ErrorWait:
+            // nothing
+            break;
+#endif //ERRORWAIT
+        default:
+            break;
     }
 #endif //IR_RAW_DATA_ANALYSIS
 
@@ -399,13 +430,19 @@
             break;
         case Received:
             break;
+#ifdef ERRORWAIT
+        case ErrorWait:
+            // nothing
+            break;
+#endif //ERRORWAIT
         default:
             break;
     }
     UNLOCK();
 }
 
-void ReceiverIR::isr_timeout(void) {
+void ReceiverIR::isr_timeout(void)
+{
     LOCK();
 #if 0
     printf("# TIMEOUT [c1=%d, c2=%d, c3=%d, d1=%d, d2=%d, state=%d, format=%d, bitcount=%d]\n",
@@ -421,15 +458,17 @@
 
 #ifdef IR_RAW_DATA_ANALYSIS
 #if 1 //debug
-    for ( int i = 0; i < check.bitcount; i++){
+    for ( int i = 0; i < check.bitcount; i++) {
         printf("%02d : %06d , %06d , %04d \n",
-            i,
-            check.timecount[i],
-            check.timecount[i + 1],
-            (check.timecount[i + 1] - check.timecount[i]));
-            
-        if( (i % 2) != 0){printf("\n");}
-     }
+               i,
+               check.timecount[i],
+               check.timecount[i + 1],
+               (check.timecount[i + 1] - check.timecount[i]));
+
+        if( (i % 2) != 0) {
+            printf("\n");
+        }
+    }
     printf("\n");
 #endif //debug
 #endif //IR_RAW_DATA_ANALYSIS
@@ -442,6 +481,11 @@
         work.d1 = -1;
         work.d2 = -1;
     }
+#ifdef ERRORWAIT
+    else if(work.state == ErrorWait){
+        init_state();
+    }
+#endif // ERRORWAIT
     UNLOCK();
 }
 
diff -r 2379e13b8b34 -r ec76e93a4d7c ReceiverIR.h
--- a/ReceiverIR.h	Sun Jun 23 07:23:56 2013 +0000
+++ b/ReceiverIR.h	Sat Aug 03 01:44:43 2013 +0000
@@ -10,6 +10,7 @@
  *  Conditional compilation 
  *      "SWIFT_PROTCOL"
  *      "IR_RAW_DATA_ANALYSIS"
+ *      "ERRORWAIT" : recive error no fuuki taisaku
  *--------------------------------------------------------
  */
 
@@ -21,6 +22,7 @@
 #include "RemoteIR.h"
 
 //#define IR_RAW_DATA_ANALYSIS
+#define ERRORWAIT
 
 /**
  * IR receiver class.
@@ -46,7 +48,10 @@
     typedef enum {
         Idle,
         Receiving,
-        Received
+        Received,
+#ifdef ERRORWAIT        
+        ErrorWait, 
+#endif // ERRORWAIT
     } State;
     
     /**
@@ -105,6 +110,10 @@
    
     void init_state(void);
 
+#ifdef ERRORWAIT
+    void errorWait(void);
+#endif // ERRORWAIT
+
     void isr_wdt(void);
     void isr_fall(void);
     void isr_rise(void);