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:
Tue Dec 03 04:04:04 2013 +0000
Parent:
6:70a0af38edcc
Child:
11:5ccd10dd22cc
Commit message:
added format and botlength to db

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
--- a/db.cpp	Tue Dec 03 03:49:12 2013 +0000
+++ b/db.cpp	Tue Dec 03 04:04:04 2013 +0000
@@ -2,12 +2,14 @@
 #include "db.h"
 #include "SDFileSystem.h"
 
-void db_insert_tuple(char *new_name, char *new_code)
+void db_insert_tuple(char *new_name, char *new_code, char *bitlength, char *format)
 {
 
     char tuple_code[128];
     char tuple_name[128];
     char tuple_id[128];
+    char tuple_bitlength[128];
+    char tuple_format[128];
     int id = 0;
 
     // create file if it does not exist
@@ -17,9 +19,9 @@
     // 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);
+        db_get_tuple(fdb, tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format);
         if (strlen(tuple_name) != 0) {
-            printf("Tuple: |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code);
+            printf("Tuple: |%s| \t |%s| \t |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format);
             id = atoi(tuple_id);
         }
     }
@@ -36,7 +38,9 @@
     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
+    
+    // create new row
+    sprintf(new_row, "%s\n%s\n%s\n%s\n%s\n", tuple_id, new_name, new_code, bitlength, format);
 
     fprintf(fwrite, new_row);                                               // write to file
     fclose(fwrite);                                                         // close file
@@ -53,13 +57,13 @@
     }
 }
 
-void db_find_tuple(FILE *fread, int id_to_find, char *tuple_name, char *tuple_code)
+void db_find_tuple(FILE *fread, int id_to_find, char *tuple_name, char *tuple_code, char *tuple_bitlength, char *tuple_format)
 {
     char tuple_id[128];
     int id;
 
     while ( !feof(fread) ) {
-        db_get_tuple(fread, tuple_id, tuple_name, tuple_code);
+        db_get_tuple(fread, tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format);
         if (strlen(tuple_name) != 0) {
             id = atoi(tuple_id);
             if (id == id_to_find) {
@@ -68,16 +72,18 @@
         }
         else {
             sprintf(tuple_id, "%d", 0);
-            sprintf(tuple_id, "%s", "");
-            sprintf(tuple_id, "%s", "");
+            sprintf(tuple_name, "%s", "");
+            sprintf(tuple_code, "%s", "");
+            sprintf(tuple_bitlength, "%s", "");
+            sprintf(tuple_format, "%s", "");
         }
     }
 
-    printf("Tuple Found: |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code);
+    printf("Tuple Found: |%s| \t |%s| \t |%s| \t |%s| \t |%s|\n", tuple_id, tuple_name, tuple_code, tuple_bitlength, tuple_format);
 
 }
 
-void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str)
+void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str, char *bitlength_str, char *format_str)
 {
 
     unsigned char c;
@@ -109,4 +115,22 @@
         index++;
     } while (c != '\n' &&  !feof(fread) );
     code_str[index-1] = 0;
+
+    // read BITLENGTH
+    index = 0;
+    do {
+        c = fgetc(fread);
+        bitlength_str[index] = c;
+        index++;
+    } while (c != '\n' &&  !feof(fread) );
+    bitlength_str[index-1] = 0;
+
+    // read FORMAT
+    index = 0;
+    do {
+        c = fgetc(fread);
+        format_str[index] = c;
+        index++;
+    } while (c != '\n' &&  !feof(fread) );
+    format_str[index-1] = 0;
 }
\ No newline at end of file
--- a/db.h	Tue Dec 03 03:49:12 2013 +0000
+++ b/db.h	Tue Dec 03 04:04:04 2013 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
 
-void db_get_tuple(FILE *fread, char *id_str, char *name_str, char *code_str);
+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);
-void db_find_tuple(FILE *fread, int id, char *name, char *code);
+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);