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:
sarvagyavaish
Date:
Mon Dec 02 20:21:10 2013 +0000
Parent:
2:bd69e4df7955
Child:
4:36e0aa194b45
Commit message:
dependencies broken;

Changed in this revision

HTTPServerHelloWorld.cpp Show diff for this revision Revisions of this file
SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
db.cpp Show annotated file Show diff for this revision Revisions of this file
db.h 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-rpc.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPServerHelloWorld.cpp	Fri Jul 09 14:46:34 2010 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,39 +0,0 @@
-#include "mbed.h"
-#include "EthernetNetIf.h"
-#include "HTTPServer.h"
-
-EthernetNetIf eth;  
-HTTPServer svr;
-
-DigitalOut led1(LED1);
-
-int main() {
-  printf("Setting up...\n");
-  EthernetErr ethErr = eth.setup();
-  if(ethErr)
-  {
-    printf("Error %d in setup.\n", ethErr);
-    return -1;
-  }
-  printf("Setup OK\n");
-  
-  svr.addHandler<SimpleHandler>("/"); //Default handler
-  svr.bind(80);
-  
-  printf("Listening...\n");
-    
-  Timer tm;
-  tm.start();
-  //Listen indefinitely
-  while(true)
-  {
-    Net::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/SDFileSystem.lib	Mon Dec 02 20:21:10 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/db.cpp	Mon Dec 02 20:21:10 2013 +0000
@@ -0,0 +1,112 @@
+#include "mbed.h"
+#include "db.h"
+#include "SDFileSystem.h"
+
+void db_insert_tuple(char *new_name, char *new_code)
+{
+
+    char tuple_code[128];
+    char tuple_name[128];
+    char tuple_id[128];
+    int id = 0;
+
+    // create file if it does not exist
+    FILE *ftemp = fopen("/sd/SmartRemote/db.txt", "a");
+    fclose(ftemp);
+
+    // read file to get last id
+    FILE *fdb = fopen("/sd/SmartRemote/db.txt", "r");
+    while ( !feof(fdb) ) {
+        db_get_tuple(fdb, tuple_id, tuple_name, tuple_code);
+        if (strlen(tuple_name) != 0) {
+            printf("Tuple: |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code);
+            id = atoi(tuple_id);
+        }
+    }
+    fclose(fdb);
+
+    // id of new tuple
+    id++;
+    sprintf(tuple_id, "%d", id);
+
+    // write new tuple to file
+    char new_row[128];
+    FILE *fwrite = fopen("/sd/SmartRemote/db.txt", "a");
+
+    if (fwrite == NULL) {                                                   // if error
+        printf("Could not open file for write\n");
+    }
+    sprintf(new_row, "%s\n%s\n%s\n", tuple_id, new_name, new_code);         // create new row
+
+    fprintf(fwrite, new_row);                                               // write to file
+    fclose(fwrite);                                                         // close file
+
+    printf("Record Added: %s\n", new_row);
+}
+
+void db_print_all(FILE *fread)
+{
+    char c;
+    while ( !feof(fread) ) {
+        c=fgetc(fread);
+        printf("%c", c);
+    }
+}
+
+void db_find_tuple(FILE *fread, int id_to_find, char *tuple_name, char *tuple_code)
+{
+    char tuple_id[128];
+    int id;
+
+    while ( !feof(fread) ) {
+        db_get_tuple(fread, tuple_id, tuple_name, tuple_code);
+        if (strlen(tuple_name) != 0) {
+            id = atoi(tuple_id);
+            if (id == id_to_find) {
+                break;
+            }
+        }
+        else {
+            sprintf(tuple_id, "%d", 0);
+            sprintf(tuple_id, "%s", "");
+            sprintf(tuple_id, "%s", "");
+        }
+    }
+
+    printf("Tuple Found: |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code);
+
+}
+
+void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str)
+{
+
+    unsigned char c;
+    int index;
+
+    // read ID;
+    index = 0;
+    do {
+        c = fgetc(fread);
+        id_str[index] = c;
+        index++;
+    } while (c != '\n' &&  !feof(fread) );
+    id_str[index-1] = 0;
+
+    // read NAME;
+    index = 0;
+    do {
+        c = fgetc(fread);
+        name_str[index] = c;
+        index++;
+    } while (c != '\n' &&  !feof(fread) );
+    name_str[index-1] = 0;
+
+    // read CODE
+    index = 0;
+    do {
+        c = fgetc(fread);
+        code_str[index] = c;
+        index++;
+    } while (c != '\n' &&  !feof(fread) );
+    code_str[index-1] = 0;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/db.h	Mon Dec 02 20:21:10 2013 +0000
@@ -0,0 +1,6 @@
+#include "mbed.h"
+
+void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str);
+void db_print_all(FILE *fread);
+void db_insert_tuple(char *new_name, char *new_code);
+void db_find_tuple(FILE *fread, int id, char *name, char *code);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 02 20:21:10 2013 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "HTTPServer.h"
+
+
+// Start DB
+#include <stdio.h>
+#include <stdlib.h>
+#include "SDFileSystem.h"
+#include "db.h"
+// End DB
+
+
+// Start RPC
+#include "RPCVariable.h"
+int Request;
+int Learn = 0;
+//Make these variables accessible over RPC by attaching them to an RPCVariable
+RPCVariable<int>(&Request), "Request");
+//RPCVariable RPCLearn(&Learn, "Learn");
+// End RPC
+
+
+EthernetNetIf eth;
+HTTPServer svr;
+
+DigitalOut led1(LED1);
+
+int main()
+{
+    printf("Setting up...\n");
+    EthernetErr ethErr = eth.setup();
+    if(ethErr) {
+        printf("Error %d in setup.\n", ethErr);
+        return -1;
+    }
+    printf("Setup OK\n");
+
+    svr.addHandler<SimpleHandler>("/"); //Default handler
+    svr.bind(80);
+
+
+    // DB Init
+    mkdir("/sd/SmartRemote", 0777);
+
+    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);
+    fclose(fread);
+    //End DB init
+
+
+    printf("Listening...\n");
+
+    Timer tm;
+    tm.start();
+    //Listen indefinitely
+    while(true) {
+        Net::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-rpc.lib	Mon Dec 02 20:21:10 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rpc/#4490a0d9cb2a
--- a/mbed.bld	Fri Jul 09 14:46:34 2010 +0000
+++ b/mbed.bld	Mon Dec 02 20:21:10 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da
+http://mbed.org/users/mbed_official/code/mbed/builds/673126e12c73
\ No newline at end of file