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

Files at this revision

API Documentation at this revision

Comitter:
sammacjunkie
Date:
Tue Dec 03 02:40:59 2013 +0000
Parent:
3:a3b4d032f48f
Child:
5:6a8acf950116
Commit message:
libraries all fixed. RPCVariable added in and working

Changed in this revision

EthernetInterface.lib Show annotated file Show diff for this revision Revisions of this file
EthernetNetIf.lib Show diff for this revision Revisions of this file
HTTPServer.lib Show annotated file Show diff for this revision Revisions of this file
IR.cpp Show annotated file Show diff for this revision Revisions of this file
IR.h Show annotated file Show diff for this revision Revisions of this file
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
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/EthernetInterface.lib	Tue Dec 03 02:40:59 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/EthernetInterface/#cba86db5ab96
--- a/EthernetNetIf.lib	Mon Dec 02 20:21:10 2013 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/donatien/code/EthernetNetIf/#bc7df6da7589
--- a/HTTPServer.lib	Mon Dec 02 20:21:10 2013 +0000
+++ b/HTTPServer.lib	Tue Dec 03 02:40:59 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/HTTPServer/#d753966e4d97
+https://mbed.org/users/ollie8/code/HTTPServer/#5790d1dfe69f
--- /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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IR.h	Tue Dec 03 02:40:59 2013 +0000
@@ -0,0 +1,10 @@
+//PROTOTYPES
+#include "mbed.h"
+#include "ReceiverIR.h"
+#include "TransmitterIR.h"
+
+int receive(RemoteIR::Format *format, uint8_t *buf, int bufsiz, int timeout = 100);
+int transmit(RemoteIR::Format format, uint8_t *buf, int bitlength, int timeout = 100);
+void display_status(char *status, int bitlength);
+void display_format(RemoteIR::Format format);
+void display_data(uint8_t *buf, int bitlength);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RemoteIR.lib	Tue Dec 03 02:40:59 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/shintamainjp/code/RemoteIR/#268cc2ab63bd
--- a/main.cpp	Mon Dec 02 20:21:10 2013 +0000
+++ b/main.cpp	Tue Dec 03 02:40:59 2013 +0000
@@ -1,7 +1,15 @@
 #include "mbed.h"
-#include "EthernetNetIf.h"
+#include "EthernetInterface.h"
 #include "HTTPServer.h"
+#include "FsHandler.h"
+#include "RpcHandler.h"
+#include "rtos.h"
 
+//Start IR
+#include "ReceiverIR.h"
+#include "TransmitterIR.h"
+#include "IR.h"
+//END IR
 
 // Start DB
 #include <stdio.h>
@@ -13,31 +21,45 @@
 
 // Start RPC
 #include "RPCVariable.h"
-int Request;
+int Request = 0;
 int Learn = 0;
 //Make these variables accessible over RPC by attaching them to an RPCVariable
-RPCVariable<int>(&Request), "Request");
-//RPCVariable RPCLearn(&Learn, "Learn");
+RPCVariable<int> RPCRequest(&Request, "Request");
+RPCVariable<int> RPCLearn(&Learn, "Learn");
 // End RPC
 
+Serial pc(USBTX, USBRX, "pc");
 
-EthernetNetIf eth;
-HTTPServer svr;
+//  Instantiate a HTTPServer to handle incoming requests
+HTTPServer  svr;
+//  Instantiate a local file system handler named 'local' which will be used later to access files on the mbed.
+LocalFileSystem local("local");
 
-DigitalOut led1(LED1);
+SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed
 
 int main()
 {
-    printf("Setting up...\n");
-    EthernetErr ethErr = eth.setup();
-    if(ethErr) {
-        printf("Error %d in setup.\n", ethErr);
-        return -1;
+
+    printf("Setting up Apache...\n \r");
+
+    HTTPFsRequestHandler::mount("/local/", "/");
+    svr.addHandler<HTTPFsRequestHandler>("/");
+    svr.addHandler<HTTPRpcRequestHandler>("/rpc");
+
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+
+    // Now start the server on port 80.
+    if (!svr.start(80, &eth)) {
+        error("Server not starting !");
+        exit(0);
     }
-    printf("Setup OK\n");
 
-    svr.addHandler<SimpleHandler>("/"); //Default handler
-    svr.bind(80);
+    printf("IP: %s\n \r", eth.getIPAddress());
+    printf("Setup OK\n \r");
+
+
 
 
     // DB Init
@@ -45,29 +67,41 @@
 
     char code[] = "123AB";
     char name[] = "Button Name";
-    
+
     char results_code[128];
     char results_name[128];
-
+    /*
     db_insert_tuple(code, name);
     FILE *fread = fopen("/sd/SmartRemote/db.txt", "r");
-    db_find_tuple(fread, 2, results_name, results_code);
+    db_find_tuple(fread, Request, results_name, results_code);
     fclose(fread);
+    */
     //End DB init
 
 
-    printf("Listening...\n");
+    //IR Init
+    uint8_t buf1[32];
+    uint8_t buf2[32];
+    int bitlength1;
+    int bitlength2;
+    RemoteIR::Format format;
+    memset(buf1, 0x00, sizeof(buf1));
+    memset(buf2, 0x00, sizeof(buf2));
+    //END IR Init
+
+    printf("Listening...\n \r");
+
 
     Timer tm;
     tm.start();
     //Listen indefinitely
     while(true) {
-        Net::poll();
+        svr.poll();
         if(tm.read()>.5) {
-            led1=!led1; //Show that we are alive
             tm.start();
         }
     }
 
     return 0;
 }
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Tue Dec 03 02:40:59 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed-rtos/#29007aef10a4