OldRemmote allows you to record IR remotes and upload the IR code to your smartphone to replay it later. Check www.julesthuillier.com for more information

Dependencies:   BLE_API mbed nRF51822

Revision:
4:688a955562ad
Parent:
3:a491b09cfd3b
--- a/main.cpp	Mon Feb 09 16:25:56 2015 +0000
+++ b/main.cpp	Mon Feb 09 16:43:09 2015 +0000
@@ -57,6 +57,7 @@
 uint8_t sendBufferIndex = 0;
 
 bool receivingDatas = false;
+bool recording = false;
 
 // Convertit un tableau de char en int
 int char_to_int(char *data)
@@ -320,6 +321,12 @@
             repeat();    
         }
         
+        // Start recording
+        else if(strncmp(option, "record", split) == 0)
+        {   
+             
+        }
+        
         
         else if(receivingDatas)
         {  
@@ -331,10 +338,11 @@
                 sendBufferIndex++;
                 sendBuffer[sendBufferIndex] = duration;
                 
-                if(sendBufferIndex == sendBuffer[0]-1)
+                if(sendBufferIndex == sendBuffer[0])
                 {
                     DEBUG("Reception Over\r\n"); 
-                    receivingDatas = false;    
+                    receivingDatas = false;   
+                    sendIR(sendBuffer); 
                 }
             }   
             else {
@@ -355,47 +363,53 @@
 
 void recordFinished()
 {
-    timerUp.reset();
-    timerDown.reset();
-    indexi = 0;
-    indexj = 0;
-    DEBUG("Record is over\r\n"); 
-    for(int i=0; i<100; i++)
-        DEBUG("%d - ",recordBuffers[0][i]);  
-    DEBUG("\r\n");
-    for(int i=0; i<100; i++)
-        DEBUG("%d - ",recordBuffers[1][i]);  
-    DEBUG("\r\n");
+    if(recording){
+        timerUp.reset();
+        timerDown.reset();
+        indexi = 0;
+        indexj = 0;
+        DEBUG("Record is over\r\n"); 
+        for(int i=0; i<100; i++)
+            DEBUG("%d - ",recordBuffers[0][i]);  
+        DEBUG("\r\n");
+        for(int i=0; i<100; i++)
+            DEBUG("%d - ",recordBuffers[1][i]);  
+        DEBUG("\r\n");
+    }
     
 }
 
 void irFall()
 {
-    // Arrete le timer
-    timerUp.stop();
-    
-    timerDown.reset();
-    timerDown.start();
-    
-    // Demarrage du timer de shutdown;
-    recordOffTimer.attach_us(&recordFinished, RECORD_OFF_TIMER);
-    if(indexj<100 && indexi <3)
-        recordBuffers[indexi][indexj] = timerUp.read_us();
-    indexj++;
+    if(recording){
+        // Arrete le timer
+        timerUp.stop();
+        
+        timerDown.reset();
+        timerDown.start();
+        
+        // Demarrage du timer de shutdown;
+        recordOffTimer.attach_us(&recordFinished, RECORD_OFF_TIMER);
+        if(indexj<100 && indexi <3)
+            recordBuffers[indexi][indexj] = timerUp.read_us();
+        indexj++;
+    }
 }
 
 void irRise()
 {
-    timerDown.stop();
-    
-    timerUp.reset();
-    timerUp.start();
-    
-    // Supprime le shutdown timer
-    recordOffTimer.detach();
-    if(indexj<100 && indexi <3)
-        recordBuffers[indexi][indexj] = timerDown.read_us();
-    indexj++;
+    if(recording){
+        timerDown.stop();
+        
+        timerUp.reset();
+        timerUp.start();
+        
+        // Supprime le shutdown timer
+        recordOffTimer.detach();
+        if(indexj<100 && indexi <3)
+            recordBuffers[indexi][indexj] = timerDown.read_us();
+        indexj++;
+    }
 }