Control remoto universal con gestos

Dependencies:   RemoteIR X_NUCLEO_IKS01A2 mbed

Fork of 6DOrientation_IKS01A2 by ST

Files at this revision

API Documentation at this revision

Comitter:
CharlieO21
Date:
Sun May 27 03:07:14 2018 +0000
Parent:
16:72bc83ad74ff
Commit message:
Version Initial

Changed in this revision

RemoteIR.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 72bc83ad74ff -r fb403a9b13ae RemoteIR.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RemoteIR.lib	Sun May 27 03:07:14 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/RemoteIR/#268cc2ab63bd
diff -r 72bc83ad74ff -r fb403a9b13ae main.cpp
--- a/main.cpp	Thu Sep 07 15:04:03 2017 +0000
+++ b/main.cpp	Sun May 27 03:07:14 2018 +0000
@@ -39,6 +39,54 @@
 /* Includes */
 #include "mbed.h"
 #include "XNucleoIKS01A2.h"
+#include "ReceiverIR.h"
+#include "TransmitterIR.h"
+
+#define TEST_LOOP_BACK  0
+
+ReceiverIR ir_rx(PA_14);
+TransmitterIR ir_tx(PA_15);
+static int RC_Status = -1;
+
+/**
+ * Receive.
+ *
+ * @param format Pointer to a format.
+ * @param buf Pointer to a buffer.
+ * @param bufsiz Size of the buffer.
+ *
+ * @return Bit length of the received data.
+ */
+int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 1000) {
+    int cnt = 0;
+    while (ir_rx.getState() != ReceiverIR::Received) {
+        cnt++;
+        if (timeout < cnt) {
+            return -1;
+        }
+    }
+    return ir_rx.getData(format, buf, bufsiz * 8);
+}
+
+/**
+ * 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);
+}
 
 /* Instantiate the expansion board */
 static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
@@ -87,6 +135,7 @@
             "\r\n |                | " \
             "\r\n |                | " \
             "\r\n |________________| \r\n" );
+            RC_Status = 6;
   }
 
   else if ( xl == 1 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 0 ) {
@@ -98,6 +147,7 @@
             "\r\n |                | " \
             "\r\n |                | " \
             "\r\n |________________| \r\n" );
+            RC_Status = 5;
   }
   
   else if ( xl == 0 && yl == 0 && zl == 0 && xh == 1 && yh == 0 && zh == 0 ) {
@@ -109,6 +159,7 @@
             "\r\n |                | " \
             "\r\n |  *             | " \
             "\r\n |________________| \r\n" );
+            RC_Status = 4;
   }
   
   else if ( xl == 0 && yl == 1 && zl == 0 && xh == 0 && yh == 0 && zh == 0 ) {
@@ -120,17 +171,20 @@
             "\r\n |                | " \
             "\r\n |             *  | " \
             "\r\n |________________| \r\n" );
+            RC_Status = 3;
   }
   
   else if ( xl == 0 && yl == 0 && zl == 0 && xh == 0 && yh == 0 && zh == 1 ) {
     printf( "\r\n  __*_____________  " \
             "\r\n |________________| \r\n" );
+            RC_Status = 2;
   }
   
   else if ( xl == 0 && yl == 0 && zl == 1 && xh == 0 && yh == 0 && zh == 0 ) {
     printf( "\r\n  ________________  " \
             "\r\n |________________| " \
             "\r\n    *               \r\n" );
+            RC_Status = 1;            
   }
   
   else {
@@ -160,11 +214,7 @@
       if (status.D6DOrientationStatus) {
         /* Send 6D Orientation */
         send_orientation();
-        
-        /* Led blinking. */
-        myled = 1;
-        wait(0.2);
-        myled = 0;
+        printf("%d\r\n",RC_Status);
       }
     }