SmartRemote door E9

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

Fork of SmartRemote by Sam Kirsch

Files at this revision

API Documentation at this revision

Comitter:
sarvagyavaish
Date:
Tue Dec 03 15:12:46 2013 +0000
Parent:
11:5ccd10dd22cc
Child:
13:12749822ba56
Commit message:
learn switch case now stored data in db

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Dec 03 14:53:13 2013 +0000
+++ b/main.cpp	Tue Dec 03 15:12:46 2013 +0000
@@ -13,6 +13,7 @@
 #include "IR.h"
 //END IR
 
+
 // Start DB
 #include <stdio.h>
 #include <stdlib.h>
@@ -20,6 +21,7 @@
 #include "db.h"
 // End DB
 
+
 // Start RPC
 #include "RPCVariable.h"
 int Request = 0;
@@ -34,6 +36,7 @@
 char Learn_name7;
 char Learn_name8;
 char Learn_name9;
+
 //Make these variables accessible over RPC by attaching them to an RPCVariable
 RPCVariable<int> RPCRequest(&Request, "Request");
 RPCVariable<int> RPCLearn(&Learn, "Learn");
@@ -47,11 +50,9 @@
 RPCVariable<char> RPCLearner7(&Learn_name7, "Learn_name7");
 RPCVariable<char> RPCLearner8(&Learn_name8, "Learn_name8");
 RPCVariable<char> RPCLearner9(&Learn_name9, "Learn_name9");
-
+// End RPC
 
 
-// End RPC
-
 Serial pc(USBTX, USBRX, "pc");
 
 //  Instantiate a HTTPServer to handle incoming requests
@@ -89,11 +90,11 @@
     // DB Init
     mkdir("/sd/SmartRemote", 0777);
 
-    char code[] = "123AB";
-    char name[] = "Button Name";
+    char tuple_code[128];
+    char tuple_name[128];
+    char tuple_bitlength[128];
+    char tuple_format[128];
 
-    char results_code[128];
-    char results_name[128];
     /*
     db_insert_tuple(code, name);
     FILE *fread = fopen("/sd/SmartRemote/db.txt", "r");
@@ -125,7 +126,10 @@
             tm.start();
         }
         if (Learn) {
+            // Debug LED
             led1 = 1;
+            
+            // Receive the code
             {
                 bitlength1 = receive(&format, buf1, sizeof(buf1));
                 if (bitlength1 < 0) {
@@ -135,8 +139,17 @@
                 display_data(buf1, bitlength1);
                 //display_format(format);
             }
-            printf("%d",buf1);
-            //printf("%s",Learn_name);
+            
+            // Set up the variables
+            sprintf(tuple_name,         "%s", "TEST");
+            sprintf(tuple_code,         "%s", buf1);
+            sprintf(tuple_bitlength,    "%d", bitlength1);
+            sprintf(tuple_format,       "%s", format); 
+            
+            // Insert into DB
+            db_insert_tuple(tuple_name, tuple_code, tuple_bitlength, tuple_format);
+            
+            // Reset
             led1 = 0;
             Learn = 0;
         }