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:
sammacjunkie
Date:
Tue Dec 03 16:21:52 2013 +0000
Parent:
13:12749822ba56
Child:
15:c8074f5f241a
Commit message:
basically done

Changed in this revision

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
--- a/db.cpp	Tue Dec 03 16:02:15 2013 +0000
+++ b/db.cpp	Tue Dec 03 16:21:52 2013 +0000
@@ -57,8 +57,10 @@
     }
 }
 
-void db_find_tuple(FILE *fread, int id_to_find, char *tuple_name, char *tuple_code, char *tuple_bitlength, char *tuple_format)
+void db_find_tuple(int id_to_find, char *tuple_name, char *tuple_code, char *tuple_bitlength, char *tuple_format)
 {
+    FILE *fread = fopen("/sd/SmartRemote/db.txt", "r");
+    
     char tuple_id[128];
     int id;
 
@@ -80,7 +82,8 @@
     }
 
     printf("Tuple Found: |%s| \t |%s| \t |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format);
-
+    
+    fclose(fread);
 }
 
 void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str, char *bitlength_str, char *format_str)
--- a/db.h	Tue Dec 03 16:02:15 2013 +0000
+++ b/db.h	Tue Dec 03 16:21:52 2013 +0000
@@ -3,4 +3,4 @@
 void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str, char *bitlength, char *format);
 void db_print_all(FILE *fread);
 void db_insert_tuple(char *new_name, char *new_code, char *bitlength, char *format);
-void db_find_tuple(FILE *fread, int id, char *name, char *code, char *bitlength, char *format);
+void db_find_tuple(int id, char *name, char *code, char *bitlength, char *format);
--- a/main.cpp	Tue Dec 03 16:02:15 2013 +0000
+++ b/main.cpp	Tue Dec 03 16:21:52 2013 +0000
@@ -6,6 +6,7 @@
 #include "rtos.h"
 
 DigitalOut led1(LED1);
+DigitalOut led2(LED2);
 
 //Start IR
 #include "ReceiverIR.h"
@@ -94,16 +95,8 @@
     char tuple_code[128];
     char tuple_name[128];
     char tuple_bitlength[128];
-    char tuple_format[128];            
+    char tuple_format[128];
     char temp[20];
-
-
-    /*
-    db_insert_tuple(code, name);
-    FILE *fread = fopen("/sd/SmartRemote/db.txt", "r");
-    db_find_tuple(fread, Request, results_name, results_code);
-    fclose(fread);
-    */
     //End DB init
 
 
@@ -156,12 +149,12 @@
             for (int i = 0; i < 10; i++) {
                 if (tuple_name[i] == '~') tuple_name[i] = ' ';
             }
-            
+
             const int n = bitlength1 / 8 + (((bitlength1 % 8) != 0) ? 1 : 0);
             strcpy(tuple_code, "");
             for (int i = 0; i < n; i++) {
                 sprintf(temp, "%02X", buf1[i]);
-                strcat(tuple_code, temp); 
+                strcat(tuple_code, temp);
             }
 
             // Insert into DB
@@ -169,6 +162,25 @@
 
         }
 
+        if ( Request != 0) {
+            led2 = 1;
+            db_find_tuple(Request, tuple_name, tuple_code, tuple_bitlength, tuple_format);
+            {
+                RemoteIR::Format f = static_cast<RemoteIR::Format>(atoi(tuple_format));
+                bitlength1 = transmit(f, (uint8_t *)atoi(tuple_code), atoi(tuple_bitlength));
+                if (bitlength1 < 0) {
+                    continue;
+                }
+                printf("%d", (uint8_t *)atoi(tuple_code));
+                display_status("TRAN", bitlength1);
+                //display_data(buf1, bitlength1);
+                //display_format(format);
+            }
+            led2 = 0;
+            Request = 0;
+
+        }
+
     }
 
     return 0;