Test for Receiving IR

Dependencies:   mbed TextLCD RemoteIR

Files at this revision

API Documentation at this revision

Comitter:
furutani
Date:
Tue Jul 16 06:45:28 2019 +0000
Parent:
5:40750d5779ca
Commit message:
test for receive IR.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Oct 13 10:51:41 2010 +0000
+++ b/main.cpp	Tue Jul 16 06:45:28 2019 +0000
@@ -15,7 +15,6 @@
 
 ReceiverIR ir_rx(p15);
 TransmitterIR ir_tx(p21);
-TextLCD lcd(p24, p26, p27, p28, p29, p30);
 BusOut led(LED4, LED3, LED2, LED1);
 Ticker ledTicker;
 
@@ -40,56 +39,34 @@
 }
 
 /**
- * Transmit.
- *
- * @param format Format.
- * @param buf Pointer to a buffer.
- * @param bitlength Bit length of the data.
- *
- * @return Bit length of the received data.
- */
-int transmit(RemoteIR::Format format, uint8_t *buf, int bitlength, int timeout = 100) {
-    int cnt = 0;
-    while (ir_tx.getState() != TransmitterIR::Idle) {
-        cnt++;
-        if (timeout < cnt) {
-            return -1;
-        }
-    }
-    return ir_tx.setData(format, buf, bitlength);
-}
-
-/**
  * Display a current status.
  */
 void display_status(char *status, int bitlength) {
-    lcd.locate(8, 0);
-    lcd.printf("%-5.5s:%02d", status, bitlength);
+    printf("%-5.5s:%02d\r\n", status, bitlength);
 }
 
 /**
  * Display a format of a data.
  */
 void display_format(RemoteIR::Format format) {
-    lcd.locate(0, 0);
     switch (format) {
         case RemoteIR::UNKNOWN:
-            lcd.printf("????????");
+            printf("????????\r\n");
             break;
         case RemoteIR::NEC:
-            lcd.printf("NEC     ");
+            printf("NEC     \r\n");
             break;
         case RemoteIR::NEC_REPEAT:
-            lcd.printf("NEC  (R)");
+            printf("NEC  (R)\r\n");
             break;
         case RemoteIR::AEHA:
-            lcd.printf("AEHA    ");
+            printf("AEHA    \r\n");
             break;
         case RemoteIR::AEHA_REPEAT:
-            lcd.printf("AEHA (R)");
+            printf("AEHA (R)\r\n");
             break;
         case RemoteIR::SONY:
-            lcd.printf("SONY    ");
+            printf("SONY    \r\n");
             break;
     }
 }
@@ -101,14 +78,14 @@
  * @param bitlength Bit length of a data.
  */
 void display_data(uint8_t *buf, int bitlength) {
-    lcd.locate(0, 1);
     const int n = bitlength / 8 + (((bitlength % 8) != 0) ? 1 : 0);
     for (int i = 0; i < n; i++) {
-        lcd.printf("%02X", buf[i]);
+        printf("%02X", buf[i]);
     }
     for (int i = 0; i < 8 - n; i++) {
-        lcd.printf("--");
+        printf("--");
     }
+    printf("\r\n");
 }
 
 void ledfunc(void) {
@@ -125,23 +102,12 @@
     /*
      * Splash.
      */
-    lcd.cls();
-    lcd.locate(0, 0);
-    lcd.printf("RemoteIR        ");
-    lcd.locate(0, 1);
-    lcd.printf("Program example.");
-    wait(3);
+    printf("RemoteIR        \r\n");
+    printf("Program example.\r\n");
 
     /*
      * Initialize.
      */
-    led = 0;
-    lcd.cls();
-    lcd.locate(0, 0);
-    lcd.printf("Press a button  ");
-    lcd.locate(0, 1);
-    lcd.printf("on a controller.");
-
     /*
      * Execute.
      */
@@ -164,43 +130,5 @@
             display_data(buf1, bitlength1);
             display_format(format);
         }
-
-#if TEST_LOOP_BACK
-        wait_ms(100);
-
-        {
-            bitlength1 = transmit(format, buf1, bitlength1);
-            if (bitlength1 < 0) {
-                continue;
-            }
-            display_status("TRAN", bitlength1);
-            display_data(buf1, bitlength1);
-            display_format(format);
-        }
-
-        wait_ms(100);
-
-        {
-            bitlength2 = receive(&format, buf2, sizeof(buf2));
-            if (bitlength2 < 0) {
-                continue;
-            }
-            display_status("RECV", bitlength2);
-            display_data(buf2, bitlength2);
-            display_format(format);
-        }
-
-        wait_ms(100);
-
-        {
-            for (int i = 0; i < sizeof(buf1); i++) {
-                if (buf1[i] != buf2[i]) {
-                    display_status("CPERR", bitlength2);
-                    wait(1);
-                    continue;
-                }
-            }
-        }
-#endif
     }
 }
\ No newline at end of file