A smart remote using the sparkfun IR transmitter and receiver. The program also uses a web server to show the buttons on a mobile platform.

Dependencies:   EthernetInterface HTTPServer RemoteIR SDFileSystem mbed-rpc mbed-rtos mbed

Fork of SmartRemoteClean by Sarvagya Vaish

Revision:
4:36e0aa194b45
Child:
6:70a0af38edcc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IR.cpp	Tue Dec 03 02:40:59 2013 +0000
@@ -0,0 +1,99 @@
+#include "mbed.h"
+#include "IR.h"
+#include "ReceiverIR.h"
+#include "TransmitterIR.h"
+
+ReceiverIR ir_rx(p15);
+TransmitterIR ir_tx(p21);
+
+/**
+ * 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) {
+    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) {
+    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) {
+
+    printf("%-5.5s:%02d", status, bitlength);
+}
+
+/**
+ * Display a format of a data.
+ */
+void display_format(RemoteIR::Format format) {
+
+    switch (format) {
+        case RemoteIR::UNKNOWN:
+            printf("????????");
+            break;
+        case RemoteIR::NEC:
+            printf("NEC     ");
+            break;
+        case RemoteIR::NEC_REPEAT:
+            printf("NEC  (R)");
+            break;
+        case RemoteIR::AEHA:
+            printf("AEHA    ");
+            break;
+        case RemoteIR::AEHA_REPEAT:
+            printf("AEHA (R)");
+            break;
+        case RemoteIR::SONY:
+            printf("SONY    ");
+            break;
+    }
+}
+
+/**
+ * Display a data.
+ *
+ * @param buf Pointer to a buffer.
+ * @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++) {
+        printf("%02X", buf[i]);
+    }
+    for (int i = 0; i < 8 - n; i++) {
+        printf("--");
+    }
+}
\ No newline at end of file